package i;

import com.cvte.vman.instance.InvokeCmd;
import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;
import java.util.Arrays;
import org.snmp4j.agent.mo.snmp.DisplayString;
import org.snmp4j.mp.MPv3;
import org.snmp4j.smi.Counter32;

/* JADX INFO: compiled from: Buffer.kt */
/* JADX INFO: loaded from: classes.dex */
public final class f implements h, g, Cloneable, ByteChannel {
    public y b;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    private long f1019e;

    /* JADX INFO: compiled from: Buffer.kt */
    public static final class a implements Closeable {
        public f b;

        /* JADX INFO: renamed from: e, reason: collision with root package name */
        public boolean f1020e;

        /* JADX INFO: renamed from: f, reason: collision with root package name */
        private y f1021f;

        /* JADX INFO: renamed from: h, reason: collision with root package name */
        public byte[] f1023h;

        /* JADX INFO: renamed from: g, reason: collision with root package name */
        public long f1022g = -1;

        /* JADX INFO: renamed from: i, reason: collision with root package name */
        public int f1024i = -1;

        /* JADX INFO: renamed from: j, reason: collision with root package name */
        public int f1025j = -1;

        public final int a() {
            long j2 = this.f1022g;
            f fVar = this.b;
            h.x.d.k.b(fVar);
            if (!(j2 != fVar.J())) {
                throw new IllegalStateException("no more bytes".toString());
            }
            long j3 = this.f1022g;
            return d(j3 == -1 ? 0L : j3 + ((long) (this.f1025j - this.f1024i)));
        }

        public final long b(long j2) {
            f fVar = this.b;
            if (fVar == null) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            if (!this.f1020e) {
                throw new IllegalStateException("resizeBuffer() only permitted for read/write buffers".toString());
            }
            long J = fVar.J();
            int i2 = 1;
            if (j2 <= J) {
                if (!(j2 >= 0)) {
                    throw new IllegalArgumentException(("newSize < 0: " + j2).toString());
                }
                long j3 = J - j2;
                while (true) {
                    if (j3 <= 0) {
                        break;
                    }
                    y yVar = fVar.b;
                    h.x.d.k.b(yVar);
                    y yVar2 = yVar.f1057g;
                    h.x.d.k.b(yVar2);
                    int i3 = yVar2.f1053c;
                    long j4 = i3 - yVar2.b;
                    if (j4 > j3) {
                        yVar2.f1053c = i3 - ((int) j3);
                        break;
                    }
                    fVar.b = yVar2.b();
                    z.b(yVar2);
                    j3 -= j4;
                }
                this.f1021f = null;
                this.f1022g = j2;
                this.f1023h = null;
                this.f1024i = -1;
                this.f1025j = -1;
            } else if (j2 > J) {
                long j5 = j2 - J;
                boolean z = true;
                while (j5 > 0) {
                    y yVarP = fVar.P(i2);
                    int iMin = (int) Math.min(j5, 8192 - yVarP.f1053c);
                    int i4 = yVarP.f1053c + iMin;
                    yVarP.f1053c = i4;
                    j5 -= (long) iMin;
                    if (z) {
                        this.f1021f = yVarP;
                        this.f1022g = J;
                        this.f1023h = yVarP.a;
                        this.f1024i = i4 - iMin;
                        this.f1025j = i4;
                        z = false;
                    }
                    i2 = 1;
                }
            }
            fVar.H(j2);
            return J;
        }

        @Override // java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (!(this.b != null)) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            this.b = null;
            this.f1021f = null;
            this.f1022g = -1L;
            this.f1023h = null;
            this.f1024i = -1;
            this.f1025j = -1;
        }

        public final int d(long j2) {
            y yVar;
            f fVar = this.b;
            if (fVar == null) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            if (j2 < -1 || j2 > fVar.J()) {
                h.x.d.x xVar = h.x.d.x.a;
                String str = String.format("offset=%s > size=%s", Arrays.copyOf(new Object[]{Long.valueOf(j2), Long.valueOf(fVar.J())}, 2));
                h.x.d.k.c(str, "java.lang.String.format(format, *args)");
                throw new ArrayIndexOutOfBoundsException(str);
            }
            if (j2 == -1 || j2 == fVar.J()) {
                this.f1021f = null;
                this.f1022g = j2;
                this.f1023h = null;
                this.f1024i = -1;
                this.f1025j = -1;
                return -1;
            }
            long j3 = 0;
            long J = fVar.J();
            y yVar2 = fVar.b;
            y yVar3 = this.f1021f;
            if (yVar3 != null) {
                long j4 = this.f1022g;
                int i2 = this.f1024i;
                h.x.d.k.b(yVar3);
                long j5 = j4 - ((long) (i2 - yVar3.b));
                if (j5 > j2) {
                    yVar = yVar2;
                    yVar2 = this.f1021f;
                    J = j5;
                } else {
                    yVar = this.f1021f;
                    j3 = j5;
                }
            } else {
                yVar = yVar2;
            }
            if (J - j2 > j2 - j3) {
                while (true) {
                    h.x.d.k.b(yVar);
                    int i3 = yVar.f1053c;
                    int i4 = yVar.b;
                    if (j2 < ((long) (i3 - i4)) + j3) {
                        break;
                    }
                    j3 += (long) (i3 - i4);
                    yVar = yVar.f1056f;
                }
            } else {
                while (J > j2) {
                    h.x.d.k.b(yVar2);
                    yVar2 = yVar2.f1057g;
                    h.x.d.k.b(yVar2);
                    J -= (long) (yVar2.f1053c - yVar2.b);
                }
                j3 = J;
                yVar = yVar2;
            }
            if (this.f1020e) {
                h.x.d.k.b(yVar);
                if (yVar.f1054d) {
                    y yVarF = yVar.f();
                    if (fVar.b == yVar) {
                        fVar.b = yVarF;
                    }
                    yVar.c(yVarF);
                    y yVar4 = yVarF.f1057g;
                    h.x.d.k.b(yVar4);
                    yVar4.b();
                    yVar = yVarF;
                }
            }
            this.f1021f = yVar;
            this.f1022g = j2;
            h.x.d.k.b(yVar);
            this.f1023h = yVar.a;
            int i5 = yVar.b + ((int) (j2 - j3));
            this.f1024i = i5;
            int i6 = yVar.f1053c;
            this.f1025j = i6;
            return i6 - i5;
        }
    }

    public static /* synthetic */ a y(f fVar, a aVar, int i2, Object obj) {
        if ((i2 & 1) != 0) {
            aVar = new a();
        }
        fVar.x(aVar);
        return aVar;
    }

    public short A() throws EOFException {
        return c.d(readShort());
    }

    @Override // i.h
    public boolean B() {
        return this.f1019e == 0;
    }

    @Override // i.h
    public byte[] C(long j2) throws EOFException {
        if (!(j2 >= 0 && j2 <= ((long) MPv3.MAX_MESSAGE_ID))) {
            throw new IllegalArgumentException(("byteCount: " + j2).toString());
        }
        if (J() < j2) {
            throw new EOFException();
        }
        byte[] bArr = new byte[(int) j2];
        readFully(bArr);
        return bArr;
    }

    public String D(long j2, Charset charset) throws EOFException {
        h.x.d.k.d(charset, "charset");
        if (!(j2 >= 0 && j2 <= ((long) MPv3.MAX_MESSAGE_ID))) {
            throw new IllegalArgumentException(("byteCount: " + j2).toString());
        }
        if (this.f1019e < j2) {
            throw new EOFException();
        }
        if (j2 == 0) {
            return "";
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        int i2 = yVar.b;
        if (((long) i2) + j2 > yVar.f1053c) {
            return new String(C(j2), charset);
        }
        int i3 = (int) j2;
        String str = new String(yVar.a, i2, i3, charset);
        int i4 = yVar.b + i3;
        yVar.b = i4;
        this.f1019e -= j2;
        if (i4 == yVar.f1053c) {
            this.b = yVar.b();
            z.b(yVar);
        }
        return str;
    }

    public String E() {
        return D(this.f1019e, h.c0.d.b);
    }

    public String F(long j2) throws EOFException {
        return D(j2, h.c0.d.b);
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g G(i iVar) {
        Q(iVar);
        return this;
    }

    public final void H(long j2) {
        this.f1019e = j2;
    }

    @Override // i.h
    public void I(f fVar, long j2) throws EOFException {
        h.x.d.k.d(fVar, "sink");
        if (J() >= j2) {
            fVar.write(this, j2);
        } else {
            fVar.write(this, J());
            throw new EOFException();
        }
    }

    public final long J() {
        return this.f1019e;
    }

    public final i K() {
        if (J() <= ((long) MPv3.MAX_MESSAGE_ID)) {
            return N((int) J());
        }
        throw new IllegalStateException(("size > Int.MAX_VALUE: " + J()).toString());
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g L() {
        m();
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:36:0x00ae  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00b8  */
    /* JADX WARN: Removed duplicated region for block: B:39:0x00be  */
    /* JADX WARN: Removed duplicated region for block: B:52:0x00c2 A[EDGE_INSN: B:52:0x00c2->B:41:0x00c2 BREAK  A[LOOP:0: B:5:0x0011->B:54:?], SYNTHETIC] */
    @Override // i.h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long M() throws java.io.EOFException {
        /*
            Method dump skipped, instruction units count: 216
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: i.f.M():long");
    }

    public final i N(int i2) {
        if (i2 == 0) {
            return i.f1026g;
        }
        c.b(J(), 0L, i2);
        y yVar = this.b;
        int i3 = 0;
        int i4 = 0;
        int i5 = 0;
        while (i4 < i2) {
            h.x.d.k.b(yVar);
            int i6 = yVar.f1053c;
            int i7 = yVar.b;
            if (i6 == i7) {
                throw new AssertionError("s.limit == s.pos");
            }
            i4 += i6 - i7;
            i5++;
            yVar = yVar.f1056f;
        }
        byte[][] bArr = new byte[i5][];
        int[] iArr = new int[i5 * 2];
        y yVar2 = this.b;
        int i8 = 0;
        while (i3 < i2) {
            h.x.d.k.b(yVar2);
            bArr[i8] = yVar2.a;
            i3 += yVar2.f1053c - yVar2.b;
            iArr[i8] = Math.min(i3, i2);
            iArr[i8 + i5] = yVar2.b;
            yVar2.f1054d = true;
            i8++;
            yVar2 = yVar2.f1056f;
        }
        return new a0(bArr, iArr);
    }

    @Override // i.h
    public String O(long j2) throws EOFException {
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(("limit < 0: " + j2).toString());
        }
        long j3 = j2 != Long.MAX_VALUE ? j2 + 1 : Long.MAX_VALUE;
        byte b2 = (byte) 10;
        long jP = p(b2, 0L, j3);
        if (jP != -1) {
            return i.f0.a.c(this, jP);
        }
        if (j3 < J() && n(j3 - 1) == ((byte) 13) && n(j3) == b2) {
            return i.f0.a.c(this, j3);
        }
        f fVar = new f();
        j(fVar, 0L, Math.min(32, J()));
        throw new EOFException("\\n not found: limit=" + Math.min(J(), j2) + " content=" + fVar.g().i() + (char) 8230);
    }

    public final y P(int i2) {
        if (!(i2 >= 1 && i2 <= 8192)) {
            throw new IllegalArgumentException("unexpected capacity".toString());
        }
        y yVar = this.b;
        if (yVar == null) {
            y yVarC = z.c();
            this.b = yVarC;
            yVarC.f1057g = yVarC;
            yVarC.f1056f = yVarC;
            return yVarC;
        }
        h.x.d.k.b(yVar);
        y yVar2 = yVar.f1057g;
        h.x.d.k.b(yVar2);
        if (yVar2.f1053c + i2 <= 8192 && yVar2.f1055e) {
            return yVar2;
        }
        y yVarC2 = z.c();
        yVar2.c(yVarC2);
        return yVarC2;
    }

    public f Q(i iVar) {
        h.x.d.k.d(iVar, "byteString");
        iVar.x(this, 0, iVar.s());
        return this;
    }

    public f R(d0 d0Var, long j2) throws IOException {
        h.x.d.k.d(d0Var, "source");
        while (j2 > 0) {
            long j3 = d0Var.read(this, j2);
            if (j3 == -1) {
                throw new EOFException();
            }
            j2 -= j3;
        }
        return this;
    }

    public f S(byte[] bArr) {
        h.x.d.k.d(bArr, "source");
        T(bArr, 0, bArr.length);
        return this;
    }

    public f T(byte[] bArr, int i2, int i3) {
        h.x.d.k.d(bArr, "source");
        long j2 = i3;
        c.b(bArr.length, i2, j2);
        int i4 = i3 + i2;
        while (i2 < i4) {
            y yVarP = P(1);
            int iMin = Math.min(i4 - i2, 8192 - yVarP.f1053c);
            int i5 = i2 + iMin;
            h.s.d.c(bArr, yVarP.a, yVarP.f1053c, i2, i5);
            yVarP.f1053c += iMin;
            i2 = i5;
        }
        H(J() + j2);
        return this;
    }

    public f U(int i2) {
        y yVarP = P(1);
        byte[] bArr = yVarP.a;
        int i3 = yVarP.f1053c;
        yVarP.f1053c = i3 + 1;
        bArr[i3] = (byte) i2;
        H(J() + 1);
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:13:0x0029  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x006e  */
    /* JADX WARN: Removed duplicated region for block: B:67:0x00e8  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x00f7 A[LOOP:0: B:69:0x00f3->B:71:0x00f7, LOOP_END] */
    /* JADX WARN: Removed duplicated region for block: B:73:0x0109  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public i.f V(long r13) {
        /*
            Method dump skipped, instruction units count: 287
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: i.f.V(long):i.f");
    }

    public f W(long j2) {
        if (j2 == 0) {
            U(48);
        } else {
            long j3 = (j2 >>> 1) | j2;
            long j4 = j3 | (j3 >>> 2);
            long j5 = j4 | (j4 >>> 4);
            long j6 = j5 | (j5 >>> 8);
            long j7 = j6 | (j6 >>> 16);
            long j8 = j7 | (j7 >>> 32);
            long j9 = j8 - ((j8 >>> 1) & 6148914691236517205L);
            long j10 = ((j9 >>> 2) & 3689348814741910323L) + (j9 & 3689348814741910323L);
            long j11 = ((j10 >>> 4) + j10) & 1085102592571150095L;
            long j12 = j11 + (j11 >>> 8);
            long j13 = j12 + (j12 >>> 16);
            int i2 = (int) ((((j13 & 63) + ((j13 >>> 32) & 63)) + ((long) 3)) / ((long) 4));
            y yVarP = P(i2);
            byte[] bArr = yVarP.a;
            int i3 = yVarP.f1053c;
            for (int i4 = (i3 + i2) - 1; i4 >= i3; i4--) {
                bArr[i4] = i.f0.a.a()[(int) (15 & j2)];
                j2 >>>= 4;
            }
            yVarP.f1053c += i2;
            H(J() + ((long) i2));
        }
        return this;
    }

    public f X(int i2) {
        y yVarP = P(4);
        byte[] bArr = yVarP.a;
        int i3 = yVarP.f1053c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 24) & DisplayString.MAX_SIZE);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((i2 >>> 16) & DisplayString.MAX_SIZE);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((i2 >>> 8) & DisplayString.MAX_SIZE);
        bArr[i6] = (byte) (i2 & DisplayString.MAX_SIZE);
        yVarP.f1053c = i6 + 1;
        H(J() + 4);
        return this;
    }

    @Override // i.h
    public void Y(long j2) throws EOFException {
        if (this.f1019e < j2) {
            throw new EOFException();
        }
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g Z(String str) {
        i0(str);
        return this;
    }

    public final void a() throws EOFException {
        skip(J());
    }

    public f a0(long j2) {
        y yVarP = P(8);
        byte[] bArr = yVarP.a;
        int i2 = yVarP.f1053c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((j2 >>> 56) & 255);
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((j2 >>> 48) & 255);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((j2 >>> 40) & 255);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((j2 >>> 32) & 255);
        int i7 = i6 + 1;
        bArr[i6] = (byte) ((j2 >>> 24) & 255);
        int i8 = i7 + 1;
        bArr[i7] = (byte) ((j2 >>> 16) & 255);
        int i9 = i8 + 1;
        bArr[i8] = (byte) ((j2 >>> 8) & 255);
        bArr[i9] = (byte) (j2 & 255);
        yVarP.f1053c = i9 + 1;
        H(J() + 8);
        return this;
    }

    /* JADX INFO: renamed from: b, reason: merged with bridge method [inline-methods] */
    public f clone() {
        return i();
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g b0(long j2) {
        V(j2);
        return this;
    }

    @Override // i.h, i.g
    public f c() {
        return this;
    }

    public f c0(int i2) {
        y yVarP = P(2);
        byte[] bArr = yVarP.a;
        int i3 = yVarP.f1053c;
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i2 >>> 8) & DisplayString.MAX_SIZE);
        bArr[i4] = (byte) (i2 & DisplayString.MAX_SIZE);
        yVarP.f1053c = i4 + 1;
        H(J() + 2);
        return this;
    }

    @Override // i.d0, java.io.Closeable, java.lang.AutoCloseable
    public void close() {
    }

    public final long d() {
        long J = J();
        if (J == 0) {
            return 0L;
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        y yVar2 = yVar.f1057g;
        h.x.d.k.b(yVar2);
        int i2 = yVar2.f1053c;
        if (i2 < 8192 && yVar2.f1055e) {
            J -= (long) (i2 - yVar2.b);
        }
        return J;
    }

    public f d0(String str, int i2, int i3, Charset charset) {
        h.x.d.k.d(str, "string");
        h.x.d.k.d(charset, "charset");
        if (!(i2 >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i2).toString());
        }
        if (!(i3 >= i2)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i3 + " < " + i2).toString());
        }
        if (!(i3 <= str.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i3 + " > " + str.length()).toString());
        }
        if (h.x.d.k.a(charset, h.c0.d.b)) {
            j0(str, i2, i3);
            return this;
        }
        String strSubstring = str.substring(i2, i3);
        h.x.d.k.c(strSubstring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
        if (strSubstring == null) {
            throw new NullPointerException("null cannot be cast to non-null type java.lang.String");
        }
        byte[] bytes = strSubstring.getBytes(charset);
        h.x.d.k.c(bytes, "(this as java.lang.String).getBytes(charset)");
        T(bytes, 0, bytes.length);
        return this;
    }

    @Override // i.g
    public long e(d0 d0Var) throws IOException {
        h.x.d.k.d(d0Var, "source");
        long j2 = 0;
        while (true) {
            long j3 = d0Var.read(this, InvokeCmd.CMD_TOUCH_CTRL_START);
            if (j3 == -1) {
                return j2;
            }
            j2 += j3;
        }
    }

    @Override // i.h
    public boolean e0(long j2, i iVar) {
        h.x.d.k.d(iVar, "bytes");
        return u(j2, iVar, 0, iVar.s());
    }

    public boolean equals(Object obj) {
        if (this != obj) {
            if (!(obj instanceof f)) {
                return false;
            }
            f fVar = (f) obj;
            if (J() != fVar.J()) {
                return false;
            }
            if (J() != 0) {
                y yVar = this.b;
                h.x.d.k.b(yVar);
                y yVar2 = fVar.b;
                h.x.d.k.b(yVar2);
                int i2 = yVar.b;
                int i3 = yVar2.b;
                long j2 = 0;
                while (j2 < J()) {
                    long jMin = Math.min(yVar.f1053c - i2, yVar2.f1053c - i3);
                    long j3 = 0;
                    while (j3 < jMin) {
                        int i4 = i2 + 1;
                        int i5 = i3 + 1;
                        if (yVar.a[i2] != yVar2.a[i3]) {
                            return false;
                        }
                        j3++;
                        i2 = i4;
                        i3 = i5;
                    }
                    if (i2 == yVar.f1053c) {
                        yVar = yVar.f1056f;
                        h.x.d.k.b(yVar);
                        i2 = yVar.b;
                    }
                    if (i3 == yVar2.f1053c) {
                        yVar2 = yVar2.f1056f;
                        h.x.d.k.b(yVar2);
                        i3 = yVar2.b;
                    }
                    j2 += jMin;
                }
            }
        }
        return true;
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g f(long j2) {
        W(j2);
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x009a  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00a4  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00a8  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00ac A[EDGE_INSN: B:44:0x00ac->B:37:0x00ac BREAK  A[LOOP:0: B:5:0x000d->B:46:?], SYNTHETIC] */
    @Override // i.h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long f0() throws java.io.EOFException {
        /*
            r15 = this;
            long r0 = r15.J()
            r2 = 0
            int r4 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            if (r4 == 0) goto Lb6
            r0 = 0
            r4 = r2
            r1 = 0
        Ld:
            i.y r6 = r15.b
            h.x.d.k.b(r6)
            byte[] r7 = r6.a
            int r8 = r6.b
            int r9 = r6.f1053c
        L18:
            if (r8 >= r9) goto L98
            r10 = r7[r8]
            r11 = 48
            byte r11 = (byte) r11
            if (r10 < r11) goto L29
            r12 = 57
            byte r12 = (byte) r12
            if (r10 > r12) goto L29
            int r11 = r10 - r11
            goto L43
        L29:
            r11 = 97
            byte r11 = (byte) r11
            if (r10 < r11) goto L38
            r12 = 102(0x66, float:1.43E-43)
            byte r12 = (byte) r12
            if (r10 > r12) goto L38
        L33:
            int r11 = r10 - r11
            int r11 = r11 + 10
            goto L43
        L38:
            r11 = 65
            byte r11 = (byte) r11
            if (r10 < r11) goto L79
            r12 = 70
            byte r12 = (byte) r12
            if (r10 > r12) goto L79
            goto L33
        L43:
            r12 = -1152921504606846976(0xf000000000000000, double:-3.105036184601418E231)
            long r12 = r12 & r4
            int r14 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1))
            if (r14 != 0) goto L53
            r10 = 4
            long r4 = r4 << r10
            long r10 = (long) r11
            long r4 = r4 | r10
            int r8 = r8 + 1
            int r0 = r0 + 1
            goto L18
        L53:
            i.f r0 = new i.f
            r0.<init>()
            r0.W(r4)
            r0.U(r10)
            java.lang.NumberFormatException r1 = new java.lang.NumberFormatException
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            r2.<init>()
            java.lang.String r3 = "Number too large: "
            r2.append(r3)
            java.lang.String r0 = r0.E()
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            r1.<init>(r0)
            throw r1
        L79:
            if (r0 == 0) goto L7d
            r1 = 1
            goto L98
        L7d:
            java.lang.NumberFormatException r0 = new java.lang.NumberFormatException
            java.lang.StringBuilder r1 = new java.lang.StringBuilder
            r1.<init>()
            java.lang.String r2 = "Expected leading [0-9a-fA-F] character but was 0x"
            r1.append(r2)
            java.lang.String r2 = i.c.e(r10)
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            r0.<init>(r1)
            throw r0
        L98:
            if (r8 != r9) goto La4
            i.y r7 = r6.b()
            r15.b = r7
            i.z.b(r6)
            goto La6
        La4:
            r6.b = r8
        La6:
            if (r1 != 0) goto Lac
            i.y r6 = r15.b
            if (r6 != 0) goto Ld
        Lac:
            long r1 = r15.J()
            long r6 = (long) r0
            long r1 = r1 - r6
            r15.H(r1)
            return r4
        Lb6:
            java.io.EOFException r0 = new java.io.EOFException
            r0.<init>()
            goto Lbd
        Lbc:
            throw r0
        Lbd:
            goto Lbc
        */
        throw new UnsupportedOperationException("Method not decompiled: i.f.f0():long");
    }

    @Override // i.g, i.b0, java.io.Flushable
    public void flush() {
    }

    @Override // i.h
    public i g() {
        return h(J());
    }

    public f g0(String str, Charset charset) {
        h.x.d.k.d(str, "string");
        h.x.d.k.d(charset, "charset");
        d0(str, 0, str.length(), charset);
        return this;
    }

    @Override // i.h
    public i h(long j2) throws EOFException {
        if (!(j2 >= 0 && j2 <= ((long) MPv3.MAX_MESSAGE_ID))) {
            throw new IllegalArgumentException(("byteCount: " + j2).toString());
        }
        if (J() < j2) {
            throw new EOFException();
        }
        if (j2 < 4096) {
            return new i(C(j2));
        }
        i iVarN = N((int) j2);
        skip(j2);
        return iVarN;
    }

    @Override // i.h
    public String h0(Charset charset) {
        h.x.d.k.d(charset, "charset");
        return D(this.f1019e, charset);
    }

    public int hashCode() {
        y yVar = this.b;
        if (yVar == null) {
            return 0;
        }
        int i2 = 1;
        do {
            int i3 = yVar.f1053c;
            for (int i4 = yVar.b; i4 < i3; i4++) {
                i2 = (i2 * 31) + yVar.a[i4];
            }
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
        } while (yVar != this.b);
        return i2;
    }

    public final f i() {
        f fVar = new f();
        if (J() != 0) {
            y yVar = this.b;
            h.x.d.k.b(yVar);
            y yVarD = yVar.d();
            fVar.b = yVarD;
            yVarD.f1057g = yVarD;
            yVarD.f1056f = yVarD;
            for (y yVar2 = yVar.f1056f; yVar2 != yVar; yVar2 = yVar2.f1056f) {
                y yVar3 = yVarD.f1057g;
                h.x.d.k.b(yVar3);
                h.x.d.k.b(yVar2);
                yVar3.c(yVar2.d());
            }
            fVar.H(J());
        }
        return fVar;
    }

    public f i0(String str) {
        h.x.d.k.d(str, "string");
        j0(str, 0, str.length());
        return this;
    }

    @Override // java.nio.channels.Channel
    public boolean isOpen() {
        return true;
    }

    public final f j(f fVar, long j2, long j3) {
        h.x.d.k.d(fVar, "out");
        c.b(J(), j2, j3);
        if (j3 != 0) {
            fVar.H(fVar.J() + j3);
            y yVar = this.b;
            while (true) {
                h.x.d.k.b(yVar);
                int i2 = yVar.f1053c;
                int i3 = yVar.b;
                if (j2 < i2 - i3) {
                    break;
                }
                j2 -= (long) (i2 - i3);
                yVar = yVar.f1056f;
            }
            while (j3 > 0) {
                h.x.d.k.b(yVar);
                y yVarD = yVar.d();
                int i4 = yVarD.b + ((int) j2);
                yVarD.b = i4;
                yVarD.f1053c = Math.min(i4 + ((int) j3), yVarD.f1053c);
                y yVar2 = fVar.b;
                if (yVar2 == null) {
                    yVarD.f1057g = yVarD;
                    yVarD.f1056f = yVarD;
                    fVar.b = yVarD;
                } else {
                    h.x.d.k.b(yVar2);
                    y yVar3 = yVar2.f1057g;
                    h.x.d.k.b(yVar3);
                    yVar3.c(yVarD);
                }
                j3 -= (long) (yVarD.f1053c - yVarD.b);
                yVar = yVar.f1056f;
                j2 = 0;
            }
        }
        return this;
    }

    public f j0(String str, int i2, int i3) {
        h.x.d.k.d(str, "string");
        if (!(i2 >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i2).toString());
        }
        if (!(i3 >= i2)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i3 + " < " + i2).toString());
        }
        if (!(i3 <= str.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i3 + " > " + str.length()).toString());
        }
        while (i2 < i3) {
            char cCharAt = str.charAt(i2);
            if (cCharAt < 128) {
                y yVarP = P(1);
                byte[] bArr = yVarP.a;
                int i4 = yVarP.f1053c - i2;
                int iMin = Math.min(i3, 8192 - i4);
                int i5 = i2 + 1;
                bArr[i2 + i4] = (byte) cCharAt;
                while (i5 < iMin) {
                    char cCharAt2 = str.charAt(i5);
                    if (cCharAt2 >= 128) {
                        break;
                    }
                    bArr[i5 + i4] = (byte) cCharAt2;
                    i5++;
                }
                int i6 = yVarP.f1053c;
                int i7 = (i4 + i5) - i6;
                yVarP.f1053c = i6 + i7;
                H(J() + ((long) i7));
                i2 = i5;
            } else {
                if (cCharAt < 2048) {
                    y yVarP2 = P(2);
                    byte[] bArr2 = yVarP2.a;
                    int i8 = yVarP2.f1053c;
                    bArr2[i8] = (byte) ((cCharAt >> 6) | 192);
                    bArr2[i8 + 1] = (byte) ((cCharAt & '?') | 128);
                    yVarP2.f1053c = i8 + 2;
                    H(J() + 2);
                } else if (cCharAt < 55296 || cCharAt > 57343) {
                    y yVarP3 = P(3);
                    byte[] bArr3 = yVarP3.a;
                    int i9 = yVarP3.f1053c;
                    bArr3[i9] = (byte) ((cCharAt >> '\f') | 224);
                    bArr3[i9 + 1] = (byte) ((63 & (cCharAt >> 6)) | 128);
                    bArr3[i9 + 2] = (byte) ((cCharAt & '?') | 128);
                    yVarP3.f1053c = i9 + 3;
                    H(J() + 3);
                } else {
                    int i10 = i2 + 1;
                    char cCharAt3 = i10 < i3 ? str.charAt(i10) : (char) 0;
                    if (cCharAt > 56319 || 56320 > cCharAt3 || 57343 < cCharAt3) {
                        U(63);
                        i2 = i10;
                    } else {
                        int i11 = (((cCharAt & 1023) << 10) | (cCharAt3 & 1023)) + 65536;
                        y yVarP4 = P(4);
                        byte[] bArr4 = yVarP4.a;
                        int i12 = yVarP4.f1053c;
                        bArr4[i12] = (byte) ((i11 >> 18) | 240);
                        bArr4[i12 + 1] = (byte) (((i11 >> 12) & 63) | 128);
                        bArr4[i12 + 2] = (byte) (((i11 >> 6) & 63) | 128);
                        bArr4[i12 + 3] = (byte) ((i11 & 63) | 128);
                        yVarP4.f1053c = i12 + 4;
                        H(J() + 4);
                        i2 += 2;
                    }
                }
                i2++;
            }
        }
        return this;
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g k() {
        l();
        return this;
    }

    @Override // i.h
    public InputStream k0() {
        return new b();
    }

    public f l() {
        return this;
    }

    public f l0(int i2) {
        if (i2 < 128) {
            U(i2);
        } else if (i2 < 2048) {
            y yVarP = P(2);
            byte[] bArr = yVarP.a;
            int i3 = yVarP.f1053c;
            bArr[i3] = (byte) ((i2 >> 6) | 192);
            bArr[i3 + 1] = (byte) ((i2 & 63) | 128);
            yVarP.f1053c = i3 + 2;
            H(J() + 2);
        } else if (55296 <= i2 && 57343 >= i2) {
            U(63);
        } else if (i2 < 65536) {
            y yVarP2 = P(3);
            byte[] bArr2 = yVarP2.a;
            int i4 = yVarP2.f1053c;
            bArr2[i4] = (byte) ((i2 >> 12) | 224);
            bArr2[i4 + 1] = (byte) (((i2 >> 6) & 63) | 128);
            bArr2[i4 + 2] = (byte) ((i2 & 63) | 128);
            yVarP2.f1053c = i4 + 3;
            H(J() + 3);
        } else {
            if (i2 > 1114111) {
                throw new IllegalArgumentException("Unexpected code point: 0x" + c.f(i2));
            }
            y yVarP3 = P(4);
            byte[] bArr3 = yVarP3.a;
            int i5 = yVarP3.f1053c;
            bArr3[i5] = (byte) ((i2 >> 18) | 240);
            bArr3[i5 + 1] = (byte) (((i2 >> 12) & 63) | 128);
            bArr3[i5 + 2] = (byte) (((i2 >> 6) & 63) | 128);
            bArr3[i5 + 3] = (byte) ((i2 & 63) | 128);
            yVarP3.f1053c = i5 + 4;
            H(J() + 4);
        }
        return this;
    }

    public f m() {
        return this;
    }

    @Override // i.h
    public int m0(t tVar) throws EOFException {
        h.x.d.k.d(tVar, "options");
        int iE = i.f0.a.e(this, tVar, false, 2, null);
        if (iE == -1) {
            return -1;
        }
        skip(tVar.d()[iE].s());
        return iE;
    }

    public final byte n(long j2) {
        c.b(J(), j2, 1L);
        y yVar = this.b;
        if (yVar == null) {
            y yVar2 = null;
            h.x.d.k.b(null);
            return yVar2.a[(int) ((((long) yVar2.b) + j2) - (-1))];
        }
        if (J() - j2 < j2) {
            long J = J();
            while (J > j2) {
                yVar = yVar.f1057g;
                h.x.d.k.b(yVar);
                J -= (long) (yVar.f1053c - yVar.b);
            }
            h.x.d.k.b(yVar);
            return yVar.a[(int) ((((long) yVar.b) + j2) - J)];
        }
        long j3 = 0;
        while (true) {
            long j4 = ((long) (yVar.f1053c - yVar.b)) + j3;
            if (j4 > j2) {
                h.x.d.k.b(yVar);
                return yVar.a[(int) ((((long) yVar.b) + j2) - j3)];
            }
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
            j3 = j4;
        }
    }

    @Override // i.h
    public boolean o(long j2) {
        return this.f1019e >= j2;
    }

    public long p(byte b2, long j2, long j3) {
        y yVar;
        int i2;
        long J = 0;
        if (!(0 <= j2 && j3 >= j2)) {
            throw new IllegalArgumentException(("size=" + J() + " fromIndex=" + j2 + " toIndex=" + j3).toString());
        }
        if (j3 > J()) {
            j3 = J();
        }
        if (j2 == j3 || (yVar = this.b) == null) {
            return -1L;
        }
        if (J() - j2 < j2) {
            J = J();
            while (J > j2) {
                yVar = yVar.f1057g;
                h.x.d.k.b(yVar);
                J -= (long) (yVar.f1053c - yVar.b);
            }
            if (yVar == null) {
                return -1L;
            }
            while (J < j3) {
                byte[] bArr = yVar.a;
                int iMin = (int) Math.min(yVar.f1053c, (((long) yVar.b) + j3) - J);
                i2 = (int) ((((long) yVar.b) + j2) - J);
                while (i2 < iMin) {
                    if (bArr[i2] != b2) {
                        i2++;
                    }
                }
                J += (long) (yVar.f1053c - yVar.b);
                yVar = yVar.f1056f;
                h.x.d.k.b(yVar);
                j2 = J;
            }
            return -1L;
        }
        while (true) {
            long j4 = ((long) (yVar.f1053c - yVar.b)) + J;
            if (j4 > j2) {
                break;
            }
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
            J = j4;
        }
        if (yVar == null) {
            return -1L;
        }
        while (J < j3) {
            byte[] bArr2 = yVar.a;
            int iMin2 = (int) Math.min(yVar.f1053c, (((long) yVar.b) + j3) - J);
            i2 = (int) ((((long) yVar.b) + j2) - J);
            while (i2 < iMin2) {
                if (bArr2[i2] != b2) {
                    i2++;
                }
            }
            J += (long) (yVar.f1053c - yVar.b);
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
            j2 = J;
        }
        return -1L;
        return ((long) (i2 - yVar.b)) + J;
    }

    @Override // i.h
    public h peek() {
        return q.d(new v(this));
    }

    public long q(i iVar) throws IOException {
        h.x.d.k.d(iVar, "bytes");
        return r(iVar, 0L);
    }

    public long r(i iVar, long j2) throws IOException {
        long j3 = j2;
        h.x.d.k.d(iVar, "bytes");
        if (!(iVar.s() > 0)) {
            throw new IllegalArgumentException("bytes is empty".toString());
        }
        long j4 = 0;
        if (!(j3 >= 0)) {
            throw new IllegalArgumentException(("fromIndex < 0: " + j3).toString());
        }
        y yVar = this.b;
        if (yVar != null) {
            if (J() - j3 < j3) {
                long J = J();
                while (J > j3) {
                    yVar = yVar.f1057g;
                    h.x.d.k.b(yVar);
                    J -= (long) (yVar.f1053c - yVar.b);
                }
                if (yVar != null) {
                    byte[] bArrJ = iVar.j();
                    byte b2 = bArrJ[0];
                    int iS = iVar.s();
                    long J2 = (J() - ((long) iS)) + 1;
                    while (J < J2) {
                        byte[] bArr = yVar.a;
                        long j5 = J;
                        int iMin = (int) Math.min(yVar.f1053c, (((long) yVar.b) + J2) - J);
                        for (int i2 = (int) ((((long) yVar.b) + j3) - j5); i2 < iMin; i2++) {
                            if (bArr[i2] == b2 && i.f0.a.b(yVar, i2 + 1, bArrJ, 1, iS)) {
                                return ((long) (i2 - yVar.b)) + j5;
                            }
                        }
                        J = j5 + ((long) (yVar.f1053c - yVar.b));
                        yVar = yVar.f1056f;
                        h.x.d.k.b(yVar);
                        j3 = J;
                    }
                }
            } else {
                while (true) {
                    long j6 = ((long) (yVar.f1053c - yVar.b)) + j4;
                    if (j6 > j3) {
                        break;
                    }
                    yVar = yVar.f1056f;
                    h.x.d.k.b(yVar);
                    j4 = j6;
                }
                if (yVar != null) {
                    byte[] bArrJ2 = iVar.j();
                    byte b3 = bArrJ2[0];
                    int iS2 = iVar.s();
                    long J3 = (J() - ((long) iS2)) + 1;
                    while (j4 < J3) {
                        byte[] bArr2 = yVar.a;
                        long j7 = J3;
                        int iMin2 = (int) Math.min(yVar.f1053c, (((long) yVar.b) + J3) - j4);
                        for (int i3 = (int) ((((long) yVar.b) + j3) - j4); i3 < iMin2; i3++) {
                            if (bArr2[i3] == b3 && i.f0.a.b(yVar, i3 + 1, bArrJ2, 1, iS2)) {
                                return ((long) (i3 - yVar.b)) + j4;
                            }
                        }
                        j4 += (long) (yVar.f1053c - yVar.b);
                        yVar = yVar.f1056f;
                        h.x.d.k.b(yVar);
                        j3 = j4;
                        J3 = j7;
                    }
                }
            }
        }
        return -1L;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer byteBuffer) throws IOException {
        h.x.d.k.d(byteBuffer, "sink");
        y yVar = this.b;
        if (yVar == null) {
            return -1;
        }
        int iMin = Math.min(byteBuffer.remaining(), yVar.f1053c - yVar.b);
        byteBuffer.put(yVar.a, yVar.b, iMin);
        int i2 = yVar.b + iMin;
        yVar.b = i2;
        this.f1019e -= (long) iMin;
        if (i2 == yVar.f1053c) {
            this.b = yVar.b();
            z.b(yVar);
        }
        return iMin;
    }

    @Override // i.h
    public byte readByte() throws EOFException {
        if (J() == 0) {
            throw new EOFException();
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        int i2 = yVar.b;
        int i3 = yVar.f1053c;
        int i4 = i2 + 1;
        byte b2 = yVar.a[i2];
        H(J() - 1);
        if (i4 == i3) {
            this.b = yVar.b();
            z.b(yVar);
        } else {
            yVar.b = i4;
        }
        return b2;
    }

    @Override // i.h
    public void readFully(byte[] bArr) throws EOFException {
        h.x.d.k.d(bArr, "sink");
        int i2 = 0;
        while (i2 < bArr.length) {
            int i3 = read(bArr, i2, bArr.length - i2);
            if (i3 == -1) {
                throw new EOFException();
            }
            i2 += i3;
        }
    }

    @Override // i.h
    public int readInt() throws EOFException {
        if (J() < 4) {
            throw new EOFException();
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        int i2 = yVar.b;
        int i3 = yVar.f1053c;
        if (i3 - i2 < 4) {
            return ((readByte() & 255) << 24) | ((readByte() & 255) << 16) | ((readByte() & 255) << 8) | (readByte() & 255);
        }
        byte[] bArr = yVar.a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & 255) << 24) | ((bArr[i4] & 255) << 16);
        int i7 = i5 + 1;
        int i8 = i6 | ((bArr[i5] & 255) << 8);
        int i9 = i7 + 1;
        int i10 = i8 | (bArr[i7] & 255);
        H(J() - 4);
        if (i9 == i3) {
            this.b = yVar.b();
            z.b(yVar);
        } else {
            yVar.b = i9;
        }
        return i10;
    }

    @Override // i.h
    public long readLong() throws EOFException {
        if (J() < 8) {
            throw new EOFException();
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        int i2 = yVar.b;
        int i3 = yVar.f1053c;
        if (i3 - i2 < 8) {
            return ((((long) readInt()) & Counter32.MAX_COUNTER32_VALUE) << 32) | (Counter32.MAX_COUNTER32_VALUE & ((long) readInt()));
        }
        byte[] bArr = yVar.a;
        int i4 = i2 + 1;
        long j2 = (((long) bArr[i2]) & 255) << 56;
        int i5 = i4 + 1;
        long j3 = j2 | ((((long) bArr[i4]) & 255) << 48);
        int i6 = i5 + 1;
        long j4 = j3 | ((((long) bArr[i5]) & 255) << 40);
        int i7 = i6 + 1;
        long j5 = ((((long) bArr[i6]) & 255) << 32) | j4;
        int i8 = i7 + 1;
        long j6 = j5 | ((((long) bArr[i7]) & 255) << 24);
        int i9 = i8 + 1;
        long j7 = j6 | ((((long) bArr[i8]) & 255) << 16);
        int i10 = i9 + 1;
        long j8 = j7 | ((((long) bArr[i9]) & 255) << 8);
        int i11 = i10 + 1;
        long j9 = j8 | (((long) bArr[i10]) & 255);
        H(J() - 8);
        if (i11 == i3) {
            this.b = yVar.b();
            z.b(yVar);
        } else {
            yVar.b = i11;
        }
        return j9;
    }

    @Override // i.h
    public short readShort() throws EOFException {
        if (J() < 2) {
            throw new EOFException();
        }
        y yVar = this.b;
        h.x.d.k.b(yVar);
        int i2 = yVar.b;
        int i3 = yVar.f1053c;
        if (i3 - i2 < 2) {
            return (short) (((readByte() & 255) << 8) | (readByte() & 255));
        }
        byte[] bArr = yVar.a;
        int i4 = i2 + 1;
        int i5 = i4 + 1;
        int i6 = ((bArr[i2] & 255) << 8) | (bArr[i4] & 255);
        H(J() - 2);
        if (i5 == i3) {
            this.b = yVar.b();
            z.b(yVar);
        } else {
            yVar.b = i5;
        }
        return (short) i6;
    }

    public long s(i iVar) {
        h.x.d.k.d(iVar, "targetBytes");
        return t(iVar, 0L);
    }

    @Override // i.h
    public void skip(long j2) throws EOFException {
        while (j2 > 0) {
            y yVar = this.b;
            if (yVar == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j2, yVar.f1053c - yVar.b);
            long j3 = iMin;
            H(J() - j3);
            j2 -= j3;
            int i2 = yVar.b + iMin;
            yVar.b = i2;
            if (i2 == yVar.f1053c) {
                this.b = yVar.b();
                z.b(yVar);
            }
        }
    }

    public long t(i iVar, long j2) {
        int i2;
        int i3;
        h.x.d.k.d(iVar, "targetBytes");
        long J = 0;
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(("fromIndex < 0: " + j2).toString());
        }
        y yVar = this.b;
        if (yVar == null) {
            return -1L;
        }
        if (J() - j2 < j2) {
            J = J();
            while (J > j2) {
                yVar = yVar.f1057g;
                h.x.d.k.b(yVar);
                J -= (long) (yVar.f1053c - yVar.b);
            }
            if (yVar == null) {
                return -1L;
            }
            if (iVar.s() == 2) {
                byte bD = iVar.d(0);
                byte bD2 = iVar.d(1);
                while (J < J()) {
                    byte[] bArr = yVar.a;
                    i2 = (int) ((((long) yVar.b) + j2) - J);
                    int i4 = yVar.f1053c;
                    while (i2 < i4) {
                        byte b2 = bArr[i2];
                        if (b2 == bD || b2 == bD2) {
                            i3 = yVar.b;
                        } else {
                            i2++;
                        }
                    }
                    J += (long) (yVar.f1053c - yVar.b);
                    yVar = yVar.f1056f;
                    h.x.d.k.b(yVar);
                    j2 = J;
                }
                return -1L;
            }
            byte[] bArrJ = iVar.j();
            while (J < J()) {
                byte[] bArr2 = yVar.a;
                i2 = (int) ((((long) yVar.b) + j2) - J);
                int i5 = yVar.f1053c;
                while (i2 < i5) {
                    byte b3 = bArr2[i2];
                    for (byte b4 : bArrJ) {
                        if (b3 == b4) {
                            i3 = yVar.b;
                        }
                    }
                    i2++;
                }
                J += (long) (yVar.f1053c - yVar.b);
                yVar = yVar.f1056f;
                h.x.d.k.b(yVar);
                j2 = J;
            }
            return -1L;
        }
        while (true) {
            long j3 = ((long) (yVar.f1053c - yVar.b)) + J;
            if (j3 > j2) {
                break;
            }
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
            J = j3;
        }
        if (yVar == null) {
            return -1L;
        }
        if (iVar.s() == 2) {
            byte bD3 = iVar.d(0);
            byte bD4 = iVar.d(1);
            while (J < J()) {
                byte[] bArr3 = yVar.a;
                i2 = (int) ((((long) yVar.b) + j2) - J);
                int i6 = yVar.f1053c;
                while (i2 < i6) {
                    byte b5 = bArr3[i2];
                    if (b5 == bD3 || b5 == bD4) {
                        i3 = yVar.b;
                    } else {
                        i2++;
                    }
                }
                J += (long) (yVar.f1053c - yVar.b);
                yVar = yVar.f1056f;
                h.x.d.k.b(yVar);
                j2 = J;
            }
            return -1L;
        }
        byte[] bArrJ2 = iVar.j();
        while (J < J()) {
            byte[] bArr4 = yVar.a;
            i2 = (int) ((((long) yVar.b) + j2) - J);
            int i7 = yVar.f1053c;
            while (i2 < i7) {
                byte b6 = bArr4[i2];
                for (byte b7 : bArrJ2) {
                    if (b6 == b7) {
                        i3 = yVar.b;
                    }
                }
                i2++;
            }
            J += (long) (yVar.f1053c - yVar.b);
            yVar = yVar.f1056f;
            h.x.d.k.b(yVar);
            j2 = J;
        }
        return -1L;
        return ((long) (i2 - i3)) + J;
    }

    @Override // i.d0
    public e0 timeout() {
        return e0.NONE;
    }

    public String toString() {
        return K().toString();
    }

    public boolean u(long j2, i iVar, int i2, int i3) {
        h.x.d.k.d(iVar, "bytes");
        if (j2 < 0 || i2 < 0 || i3 < 0 || J() - j2 < i3 || iVar.s() - i2 < i3) {
            return false;
        }
        for (int i4 = 0; i4 < i3; i4++) {
            if (n(((long) i4) + j2) != iVar.d(i2 + i4)) {
                return false;
            }
        }
        return true;
    }

    @Override // i.h
    public String v() throws EOFException {
        return O(Long.MAX_VALUE);
    }

    @Override // i.h
    public byte[] w() {
        return C(J());
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g write(byte[] bArr) {
        S(bArr);
        return this;
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g writeByte(int i2) {
        U(i2);
        return this;
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g writeInt(int i2) {
        X(i2);
        return this;
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g writeShort(int i2) {
        c0(i2);
        return this;
    }

    public final a x(a aVar) {
        h.x.d.k.d(aVar, "unsafeCursor");
        if (!(aVar.b == null)) {
            throw new IllegalStateException("already attached to a buffer".toString());
        }
        aVar.b = this;
        aVar.f1020e = true;
        return aVar;
    }

    public int z() throws EOFException {
        return c.c(readInt());
    }

    /* JADX INFO: compiled from: Buffer.kt */
    public static final class b extends InputStream {
        b() {
        }

        @Override // java.io.InputStream
        public int available() {
            return (int) Math.min(f.this.J(), MPv3.MAX_MESSAGE_ID);
        }

        @Override // java.io.InputStream, java.io.Closeable, java.lang.AutoCloseable
        public void close() {
        }

        @Override // java.io.InputStream
        public int read() {
            if (f.this.J() > 0) {
                return f.this.readByte() & 255;
            }
            return -1;
        }

        public String toString() {
            return f.this + ".inputStream()";
        }

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i2, int i3) {
            h.x.d.k.d(bArr, "sink");
            return f.this.read(bArr, i2, i3);
        }
    }

    @Override // i.g
    public /* bridge */ /* synthetic */ g write(byte[] bArr, int i2, int i3) {
        T(bArr, i2, i3);
        return this;
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) throws IOException {
        h.x.d.k.d(byteBuffer, "source");
        int iRemaining = byteBuffer.remaining();
        int i2 = iRemaining;
        while (i2 > 0) {
            y yVarP = P(1);
            int iMin = Math.min(i2, 8192 - yVarP.f1053c);
            byteBuffer.get(yVarP.a, yVarP.f1053c, iMin);
            i2 -= iMin;
            yVarP.f1053c += iMin;
        }
        this.f1019e += (long) iRemaining;
        return iRemaining;
    }

    public int read(byte[] bArr, int i2, int i3) {
        h.x.d.k.d(bArr, "sink");
        c.b(bArr.length, i2, i3);
        y yVar = this.b;
        if (yVar == null) {
            return -1;
        }
        int iMin = Math.min(i3, yVar.f1053c - yVar.b);
        byte[] bArr2 = yVar.a;
        int i4 = yVar.b;
        h.s.d.c(bArr2, bArr, i2, i4, i4 + iMin);
        yVar.b += iMin;
        H(J() - ((long) iMin));
        if (yVar.b != yVar.f1053c) {
            return iMin;
        }
        this.b = yVar.b();
        z.b(yVar);
        return iMin;
    }

    @Override // i.b0
    public void write(f fVar, long j2) {
        y yVar;
        h.x.d.k.d(fVar, "source");
        if (fVar != this) {
            c.b(fVar.J(), 0L, j2);
            while (j2 > 0) {
                y yVar2 = fVar.b;
                h.x.d.k.b(yVar2);
                int i2 = yVar2.f1053c;
                h.x.d.k.b(fVar.b);
                if (j2 < i2 - r2.b) {
                    y yVar3 = this.b;
                    if (yVar3 != null) {
                        h.x.d.k.b(yVar3);
                        yVar = yVar3.f1057g;
                    } else {
                        yVar = null;
                    }
                    if (yVar != null && yVar.f1055e) {
                        if ((((long) yVar.f1053c) + j2) - ((long) (yVar.f1054d ? 0 : yVar.b)) <= InvokeCmd.CMD_TOUCH_CTRL_START) {
                            y yVar4 = fVar.b;
                            h.x.d.k.b(yVar4);
                            yVar4.g(yVar, (int) j2);
                            fVar.H(fVar.J() - j2);
                            H(J() + j2);
                            return;
                        }
                    }
                    y yVar5 = fVar.b;
                    h.x.d.k.b(yVar5);
                    fVar.b = yVar5.e((int) j2);
                }
                y yVar6 = fVar.b;
                h.x.d.k.b(yVar6);
                long j3 = yVar6.f1053c - yVar6.b;
                fVar.b = yVar6.b();
                y yVar7 = this.b;
                if (yVar7 == null) {
                    this.b = yVar6;
                    yVar6.f1057g = yVar6;
                    yVar6.f1056f = yVar6;
                } else {
                    h.x.d.k.b(yVar7);
                    y yVar8 = yVar7.f1057g;
                    h.x.d.k.b(yVar8);
                    yVar8.c(yVar6);
                    yVar6.a();
                }
                fVar.H(fVar.J() - j3);
                H(J() + j3);
                j2 -= j3;
            }
            return;
        }
        throw new IllegalArgumentException("source == this".toString());
    }

    @Override // i.d0
    public long read(f fVar, long j2) {
        h.x.d.k.d(fVar, "sink");
        if (!(j2 >= 0)) {
            throw new IllegalArgumentException(("byteCount < 0: " + j2).toString());
        }
        if (J() == 0) {
            return -1L;
        }
        if (j2 > J()) {
            j2 = J();
        }
        fVar.write(this, j2);
        return j2;
    }
}
