package d;

import java.io.Closeable;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.ByteChannel;
import java.nio.charset.Charset;
import java.util.Arrays;

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

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    private static final byte[] f1562d;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public v f1563b;

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

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

        /* JADX INFO: renamed from: b, reason: collision with root package name */
        public f f1565b;

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

        /* JADX INFO: renamed from: d, reason: collision with root package name */
        private v f1567d;

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

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

        public final int F(long j) {
            f fVar = this.f1565b;
            if (fVar == null) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            if (j < -1 || j > fVar.b0()) {
                c.q.d.t tVar = c.q.d.t.f1451a;
                String str = String.format("offset=%s > size=%s", Arrays.copyOf(new Object[]{Long.valueOf(j), Long.valueOf(fVar.b0())}, 2));
                c.q.d.j.b(str, "java.lang.String.format(format, *args)");
                throw new ArrayIndexOutOfBoundsException(str);
            }
            if (j == -1 || j == fVar.b0()) {
                this.f1567d = null;
                this.f1568e = j;
                this.f1569f = null;
                this.g = -1;
                this.h = -1;
                return -1;
            }
            long j2 = 0;
            long jB0 = fVar.b0();
            v vVar = fVar.f1563b;
            v vVar2 = this.f1567d;
            if (vVar2 != null) {
                long j3 = this.f1568e;
                int i = this.g;
                if (vVar2 == null) {
                    c.q.d.j.g();
                    throw null;
                }
                long j4 = j3 - ((long) (i - vVar2.f1607b));
                if (j4 > j) {
                    jB0 = j4;
                    vVar2 = vVar;
                    vVar = vVar2;
                } else {
                    j2 = j4;
                }
            } else {
                vVar2 = vVar;
            }
            if (jB0 - j > j - j2) {
                while (vVar2 != null) {
                    int i2 = vVar2.f1608c;
                    int i3 = vVar2.f1607b;
                    if (j >= ((long) (i2 - i3)) + j2) {
                        j2 += (long) (i2 - i3);
                        vVar2 = vVar2.f1611f;
                    }
                }
                c.q.d.j.g();
                throw null;
            }
            while (jB0 > j) {
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                vVar = vVar.g;
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                jB0 -= (long) (vVar.f1608c - vVar.f1607b);
            }
            j2 = jB0;
            vVar2 = vVar;
            if (this.f1566c) {
                if (vVar2 == null) {
                    c.q.d.j.g();
                    throw null;
                }
                if (vVar2.f1609d) {
                    v vVarF = vVar2.f();
                    if (fVar.f1563b == vVar2) {
                        fVar.f1563b = vVarF;
                    }
                    vVar2.c(vVarF);
                    v vVar3 = vVarF.g;
                    if (vVar3 == null) {
                        c.q.d.j.g();
                        throw null;
                    }
                    vVar3.b();
                    vVar2 = vVarF;
                }
            }
            this.f1567d = vVar2;
            this.f1568e = j;
            if (vVar2 == null) {
                c.q.d.j.g();
                throw null;
            }
            this.f1569f = vVar2.f1606a;
            int i4 = vVar2.f1607b + ((int) (j - j2));
            this.g = i4;
            int i5 = vVar2.f1608c;
            this.h = i5;
            return i5 - i4;
        }

        @Override // java.io.Closeable, java.lang.AutoCloseable
        public void close() {
            if (!(this.f1565b != null)) {
                throw new IllegalStateException("not attached to a buffer".toString());
            }
            this.f1565b = null;
            this.f1567d = null;
            this.f1568e = -1L;
            this.f1569f = null;
            this.g = -1;
            this.h = -1;
        }

        public final int v() {
            long j = this.f1568e;
            f fVar = this.f1565b;
            if (fVar == null) {
                c.q.d.j.g();
                throw null;
            }
            if (!(j != fVar.b0())) {
                throw new IllegalStateException("no more bytes".toString());
            }
            long j2 = this.f1568e;
            return F(j2 == -1 ? 0L : j2 + ((long) (this.h - this.g)));
        }
    }

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

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

        @Override // java.io.OutputStream, java.io.Flushable
        public void flush() {
        }

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

        @Override // java.io.OutputStream
        public void write(int i) {
            f.this.j0(i);
        }

        @Override // java.io.OutputStream
        public void write(byte[] bArr, int i, int i2) {
            c.q.d.j.c(bArr, "data");
            f.this.h0(bArr, i, i2);
        }
    }

    static {
        byte[] bytes = "0123456789abcdef".getBytes(c.u.c.f1470a);
        c.q.d.j.b(bytes, "(this as java.lang.String).getBytes(charset)");
        f1562d = bytes;
    }

    public static /* bridge */ /* synthetic */ int Z(f fVar, q qVar, boolean z, int i, Object obj) {
        if ((i & 2) != 0) {
            z = false;
        }
        return fVar.Y(qVar, z);
    }

    @Override // d.h
    public byte[] A(long j) throws EOFException {
        if (!(j >= 0 && j <= ((long) Integer.MAX_VALUE))) {
            throw new IllegalArgumentException(("byteCount: " + j).toString());
        }
        if (this.f1564c < j) {
            throw new EOFException();
        }
        byte[] bArr = new byte[(int) j];
        readFully(bArr);
        return bArr;
    }

    /* JADX WARN: Removed duplicated region for block: B:34:0x0097  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00a1  */
    /* JADX WARN: Removed duplicated region for block: B:37:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:48:0x00a9 A[EDGE_INSN: B:48:0x00a9->B:39:0x00a9 BREAK  A[LOOP:0: B:5:0x000b->B:50:?], SYNTHETIC] */
    @Override // d.h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long B() throws java.io.EOFException {
        /*
            r14 = this;
            long r0 = r14.f1564c
            r2 = 0
            int r0 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            if (r0 == 0) goto Lb5
            r0 = 0
            r1 = r0
            r4 = r2
        Lb:
            d.v r6 = r14.f1563b
            if (r6 == 0) goto Lb0
            byte[] r7 = r6.f1606a
            int r8 = r6.f1607b
            int r9 = r6.f1608c
        L15:
            if (r8 >= r9) goto L95
            r10 = r7[r8]
            r11 = 48
            byte r11 = (byte) r11
            if (r10 < r11) goto L26
            r12 = 57
            byte r12 = (byte) r12
            if (r10 > r12) goto L26
            int r11 = r10 - r11
            goto L40
        L26:
            r11 = 97
            byte r11 = (byte) r11
            if (r10 < r11) goto L35
            r12 = 102(0x66, float:1.43E-43)
            byte r12 = (byte) r12
            if (r10 > r12) goto L35
        L30:
            int r11 = r10 - r11
            int r11 = r11 + 10
            goto L40
        L35:
            r11 = 65
            byte r11 = (byte) r11
            if (r10 < r11) goto L76
            r12 = 70
            byte r12 = (byte) r12
            if (r10 > r12) goto L76
            goto L30
        L40:
            r12 = -1152921504606846976(0xf000000000000000, double:-3.105036184601418E231)
            long r12 = r12 & r4
            int r12 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1))
            if (r12 != 0) goto L50
            r10 = 4
            long r4 = r4 << r10
            long r10 = (long) r11
            long r4 = r4 | r10
            int r8 = r8 + 1
            int r0 = r0 + 1
            goto L15
        L50:
            d.f r0 = new d.f
            r0.<init>()
            r0.l0(r4)
            r0.j0(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.V()
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            r1.<init>(r0)
            throw r1
        L76:
            if (r0 == 0) goto L7a
            r1 = 1
            goto L95
        L7a:
            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 = java.lang.Integer.toHexString(r10)
            r1.append(r2)
            java.lang.String r1 = r1.toString()
            r0.<init>(r1)
            throw r0
        L95:
            if (r8 != r9) goto La1
            d.v r7 = r6.b()
            r14.f1563b = r7
            d.w.a(r6)
            goto La3
        La1:
            r6.f1607b = r8
        La3:
            if (r1 != 0) goto La9
            d.v r6 = r14.f1563b
            if (r6 != 0) goto Lb
        La9:
            long r1 = r14.f1564c
            long r6 = (long) r0
            long r1 = r1 - r6
            r14.f1564c = r1
            return r4
        Lb0:
            c.q.d.j.g()
            r0 = 0
            throw r0
        Lb5:
            java.io.EOFException r0 = new java.io.EOFException
            r0.<init>()
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: d.f.B():long");
    }

    @Override // d.h
    public String C(Charset charset) {
        c.q.d.j.c(charset, "charset");
        return U(this.f1564c, charset);
    }

    @Override // d.h
    public InputStream D() {
        return new b();
    }

    @Override // d.h
    public int E(q qVar) throws EOFException {
        c.q.d.j.c(qVar, "options");
        int iZ = Z(this, qVar, false, 2, null);
        if (iZ == -1) {
            return -1;
        }
        l(qVar.c()[iZ].s());
        return iZ;
    }

    /* JADX INFO: renamed from: F, reason: merged with bridge method [inline-methods] */
    public f clone() {
        f fVar = new f();
        if (this.f1564c == 0) {
            return fVar;
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        v vVarD = vVar.d();
        fVar.f1563b = vVarD;
        if (vVarD == null) {
            c.q.d.j.g();
            throw null;
        }
        vVarD.g = vVarD;
        if (vVarD == null) {
            c.q.d.j.g();
            throw null;
        }
        if (vVarD == null) {
            c.q.d.j.g();
            throw null;
        }
        vVarD.f1611f = vVarD;
        v vVar2 = this.f1563b;
        if (vVar2 == null) {
            c.q.d.j.g();
            throw null;
        }
        for (v vVar3 = vVar2.f1611f; vVar3 != this.f1563b; vVar3 = vVar3.f1611f) {
            v vVar4 = fVar.f1563b;
            if (vVar4 == null) {
                c.q.d.j.g();
                throw null;
            }
            v vVar5 = vVar4.g;
            if (vVar5 == null) {
                c.q.d.j.g();
                throw null;
            }
            if (vVar3 == null) {
                c.q.d.j.g();
                throw null;
            }
            vVar5.c(vVar3.d());
        }
        fVar.f1564c = this.f1564c;
        return fVar;
    }

    public final long G() {
        long j = this.f1564c;
        if (j == 0) {
            return 0L;
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        v vVar2 = vVar.g;
        if (vVar2 != null) {
            int i = vVar2.f1608c;
            return (i >= 8192 || !vVar2.f1610e) ? j : j - ((long) (i - vVar2.f1607b));
        }
        c.q.d.j.g();
        throw null;
    }

    public final f H(f fVar, long j, long j2) {
        c.q.d.j.c(fVar, "out");
        d.c.b(this.f1564c, j, j2);
        if (j2 == 0) {
            return this;
        }
        fVar.f1564c += j2;
        v vVar = this.f1563b;
        while (vVar != null) {
            int i = vVar.f1608c;
            int i2 = vVar.f1607b;
            if (j < i - i2) {
                while (j2 > 0) {
                    if (vVar == null) {
                        c.q.d.j.g();
                        throw null;
                    }
                    v vVarD = vVar.d();
                    int i3 = vVarD.f1607b + ((int) j);
                    vVarD.f1607b = i3;
                    vVarD.f1608c = Math.min(i3 + ((int) j2), vVarD.f1608c);
                    v vVar2 = fVar.f1563b;
                    if (vVar2 == null) {
                        vVarD.g = vVarD;
                        vVarD.f1611f = vVarD;
                        fVar.f1563b = vVarD;
                    } else {
                        if (vVar2 == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        v vVar3 = vVar2.g;
                        if (vVar3 == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        vVar3.c(vVarD);
                    }
                    j2 -= (long) (vVarD.f1608c - vVarD.f1607b);
                    vVar = vVar.f1611f;
                    j = 0;
                }
                return this;
            }
            j -= (long) (i - i2);
            vVar = vVar.f1611f;
        }
        c.q.d.j.g();
        throw null;
    }

    public f I() {
        return this;
    }

    public f J() {
        return this;
    }

    public final byte K(long j) {
        d.c.b(this.f1564c, j, 1L);
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        if (b0() - j < j) {
            long jB0 = b0();
            while (jB0 > j) {
                vVar = vVar.g;
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                jB0 -= (long) (vVar.f1608c - vVar.f1607b);
            }
            if (vVar != null) {
                return vVar.f1606a[(int) ((((long) vVar.f1607b) + j) - jB0)];
            }
            c.q.d.j.g();
            throw null;
        }
        long j2 = 0;
        while (true) {
            int i = vVar.f1608c;
            int i2 = vVar.f1607b;
            long j3 = ((long) (i - i2)) + j2;
            if (j3 > j) {
                if (vVar != null) {
                    return vVar.f1606a[(int) ((((long) i2) + j) - j2)];
                }
                c.q.d.j.g();
                throw null;
            }
            vVar = vVar.f1611f;
            if (vVar == null) {
                c.q.d.j.g();
                throw null;
            }
            j2 = j3;
        }
    }

    public long L(byte b2, long j, long j2) {
        v vVar;
        int i;
        long j3 = j;
        long j4 = j2;
        long jB0 = 0;
        if (!(0 <= j3 && j4 >= j3)) {
            throw new IllegalArgumentException(("size=" + this.f1564c + " fromIndex=" + j3 + " toIndex=" + j4).toString());
        }
        long j5 = this.f1564c;
        if (j4 > j5) {
            j4 = j5;
        }
        long j6 = -1;
        if (j3 != j4 && (vVar = this.f1563b) != null) {
            if (b0() - j3 < j3) {
                jB0 = b0();
                while (jB0 > j3) {
                    vVar = vVar.g;
                    if (vVar == null) {
                        c.q.d.j.g();
                        throw null;
                    }
                    jB0 -= (long) (vVar.f1608c - vVar.f1607b);
                }
                if (vVar == null) {
                    return -1L;
                }
                while (jB0 < j4) {
                    byte[] bArr = vVar.f1606a;
                    int iMin = (int) Math.min(vVar.f1608c, (((long) vVar.f1607b) + j4) - jB0);
                    i = (int) ((((long) vVar.f1607b) + j3) - jB0);
                    while (i < iMin) {
                        if (bArr[i] != b2) {
                            i++;
                        }
                    }
                    jB0 += (long) (vVar.f1608c - vVar.f1607b);
                    vVar = vVar.f1611f;
                    if (vVar == null) {
                        c.q.d.j.g();
                        throw null;
                    }
                    j3 = jB0;
                    j6 = -1;
                }
                return j6;
            }
            while (true) {
                long j7 = ((long) (vVar.f1608c - vVar.f1607b)) + jB0;
                if (j7 > j3) {
                    if (vVar == null) {
                        return -1L;
                    }
                    while (jB0 < j4) {
                        byte[] bArr2 = vVar.f1606a;
                        int iMin2 = (int) Math.min(vVar.f1608c, (((long) vVar.f1607b) + j4) - jB0);
                        i = (int) ((((long) vVar.f1607b) + j3) - jB0);
                        while (i < iMin2) {
                            if (bArr2[i] != b2) {
                                i++;
                            }
                        }
                        jB0 += (long) (vVar.f1608c - vVar.f1607b);
                        vVar = vVar.f1611f;
                        if (vVar == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        j3 = jB0;
                    }
                    return -1L;
                }
                vVar = vVar.f1611f;
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                jB0 = j7;
            }
            return ((long) (i - vVar.f1607b)) + jB0;
        }
        return -1L;
    }

    public long M(i iVar) {
        c.q.d.j.c(iVar, "targetBytes");
        return N(iVar, 0L);
    }

    public long N(i iVar, long j) {
        int i;
        int i2;
        c.q.d.j.c(iVar, "targetBytes");
        long jB0 = 0;
        if (!(j >= 0)) {
            throw new IllegalArgumentException(("fromIndex < 0: " + j).toString());
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            return -1L;
        }
        if (b0() - j < j) {
            jB0 = b0();
            while (jB0 > j) {
                vVar = vVar.g;
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                jB0 -= (long) (vVar.f1608c - vVar.f1607b);
            }
            if (vVar != null) {
                if (iVar.s() == 2) {
                    byte bD = iVar.d(0);
                    byte bD2 = iVar.d(1);
                    while (jB0 < this.f1564c) {
                        byte[] bArr = vVar.f1606a;
                        i = (int) ((((long) vVar.f1607b) + j) - jB0);
                        int i3 = vVar.f1608c;
                        while (i < i3) {
                            byte b2 = bArr[i];
                            if (b2 == bD || b2 == bD2) {
                                i2 = vVar.f1607b;
                            } else {
                                i++;
                            }
                        }
                        jB0 += (long) (vVar.f1608c - vVar.f1607b);
                        vVar = vVar.f1611f;
                        if (vVar == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        j = jB0;
                    }
                } else {
                    byte[] bArrJ = iVar.j();
                    while (jB0 < this.f1564c) {
                        byte[] bArr2 = vVar.f1606a;
                        i = (int) ((((long) vVar.f1607b) + j) - jB0);
                        int i4 = vVar.f1608c;
                        while (i < i4) {
                            byte b3 = bArr2[i];
                            for (byte b4 : bArrJ) {
                                if (b3 == b4) {
                                    i2 = vVar.f1607b;
                                }
                            }
                            i++;
                        }
                        jB0 += (long) (vVar.f1608c - vVar.f1607b);
                        vVar = vVar.f1611f;
                        if (vVar == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        j = jB0;
                    }
                }
            }
            return -1L;
        }
        while (true) {
            long j2 = ((long) (vVar.f1608c - vVar.f1607b)) + jB0;
            if (j2 > j) {
                if (vVar != null) {
                    if (iVar.s() == 2) {
                        byte bD3 = iVar.d(0);
                        byte bD4 = iVar.d(1);
                        while (jB0 < this.f1564c) {
                            byte[] bArr3 = vVar.f1606a;
                            i = (int) ((((long) vVar.f1607b) + j) - jB0);
                            int i5 = vVar.f1608c;
                            while (i < i5) {
                                byte b5 = bArr3[i];
                                if (b5 != bD3 && b5 != bD4) {
                                    i++;
                                }
                            }
                            jB0 += (long) (vVar.f1608c - vVar.f1607b);
                            vVar = vVar.f1611f;
                            if (vVar == null) {
                                c.q.d.j.g();
                                throw null;
                            }
                            j = jB0;
                        }
                    } else {
                        byte[] bArrJ2 = iVar.j();
                        while (jB0 < this.f1564c) {
                            byte[] bArr4 = vVar.f1606a;
                            i = (int) ((((long) vVar.f1607b) + j) - jB0);
                            int i6 = vVar.f1608c;
                            while (i < i6) {
                                byte b6 = bArr4[i];
                                for (byte b7 : bArrJ2) {
                                    if (b6 != b7) {
                                    }
                                }
                                i++;
                            }
                            jB0 += (long) (vVar.f1608c - vVar.f1607b);
                            vVar = vVar.f1611f;
                            if (vVar == null) {
                                c.q.d.j.g();
                                throw null;
                            }
                            j = jB0;
                        }
                    }
                }
                return -1L;
            }
            vVar = vVar.f1611f;
            if (vVar == null) {
                c.q.d.j.g();
                throw null;
            }
            jB0 = j2;
        }
        i2 = vVar.f1607b;
        return ((long) (i - i2)) + jB0;
    }

    public OutputStream O() {
        return new c();
    }

    public int P(byte[] bArr, int i, int i2) {
        c.q.d.j.c(bArr, "sink");
        d.c.b(bArr.length, i, i2);
        v vVar = this.f1563b;
        if (vVar == null) {
            return -1;
        }
        int iMin = Math.min(i2, vVar.f1608c - vVar.f1607b);
        System.arraycopy(vVar.f1606a, vVar.f1607b, bArr, i, iMin);
        int i3 = vVar.f1607b + iMin;
        vVar.f1607b = i3;
        this.f1564c -= (long) iMin;
        if (i3 == vVar.f1608c) {
            this.f1563b = vVar.b();
            w.a(vVar);
        }
        return iMin;
    }

    public final a Q(a aVar) {
        c.q.d.j.c(aVar, "unsafeCursor");
        if (!(aVar.f1565b == null)) {
            throw new IllegalStateException("already attached to a buffer".toString());
        }
        aVar.f1565b = this;
        aVar.f1566c = true;
        return aVar;
    }

    public i R() {
        return new i(t());
    }

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

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

    public String U(long j, Charset charset) throws EOFException {
        c.q.d.j.c(charset, "charset");
        if (!(j >= 0 && j <= ((long) Integer.MAX_VALUE))) {
            throw new IllegalArgumentException(("byteCount: " + j).toString());
        }
        if (this.f1564c < j) {
            throw new EOFException();
        }
        if (j == 0) {
            return "";
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        if (((long) i) + j > vVar.f1608c) {
            return new String(A(j), charset);
        }
        int i2 = (int) j;
        String str = new String(vVar.f1606a, i, i2, charset);
        int i3 = vVar.f1607b + i2;
        vVar.f1607b = i3;
        this.f1564c -= j;
        if (i3 == vVar.f1608c) {
            this.f1563b = vVar.b();
            w.a(vVar);
        }
        return str;
    }

    public String V() {
        return U(this.f1564c, c.u.c.f1470a);
    }

    public String W(long j) throws EOFException {
        return U(j, c.u.c.f1470a);
    }

    public final String X(long j) throws EOFException {
        if (j > 0) {
            long j2 = j - 1;
            if (K(j2) == ((byte) 13)) {
                String strW = W(j2);
                l(2L);
                return strW;
            }
        }
        String strW2 = W(j);
        l(1L);
        return strW2;
    }

    /* JADX WARN: Code restructure failed: missing block: B:26:0x0056, code lost:
    
        if (r19 == false) goto L28;
     */
    /* JADX WARN: Code restructure failed: missing block: B:27:0x0058, code lost:
    
        return r3;
     */
    /* JADX WARN: Code restructure failed: missing block: B:28:0x0059, code lost:
    
        return r11;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final int Y(d.q r18, boolean r19) {
        /*
            r17 = this;
            java.lang.String r0 = "options"
            r1 = r18
            c.q.d.j.c(r1, r0)
            r0 = r17
            d.v r2 = r0.f1563b
            r3 = -2
            r4 = -1
            if (r2 == 0) goto Lb1
            byte[] r5 = r2.f1606a
            int r6 = r2.f1607b
            int r7 = r2.f1608c
            int[] r1 = r18.e()
            r8 = 0
            r10 = r2
            r11 = r4
            r9 = r8
        L1d:
            int r12 = r9 + 1
            r9 = r1[r9]
            int r13 = r12 + 1
            r12 = r1[r12]
            if (r12 == r4) goto L28
            r11 = r12
        L28:
            if (r10 != 0) goto L2b
            goto L56
        L2b:
            r12 = 0
            if (r9 >= 0) goto L7e
            int r9 = r9 * (-1)
            int r14 = r13 + r9
        L32:
            int r9 = r6 + 1
            r6 = r5[r6]
            r6 = r6 & 255(0xff, float:3.57E-43)
            int r15 = r13 + 1
            r13 = r1[r13]
            if (r6 == r13) goto L3f
            return r11
        L3f:
            if (r15 != r14) goto L43
            r6 = 1
            goto L44
        L43:
            r6 = r8
        L44:
            if (r9 != r7) goto L6b
            if (r10 == 0) goto L67
            d.v r5 = r10.f1611f
            if (r5 == 0) goto L63
            int r7 = r5.f1607b
            byte[] r9 = r5.f1606a
            int r10 = r5.f1608c
            if (r5 != r2) goto L5d
            if (r6 != 0) goto L5a
        L56:
            if (r19 == 0) goto L59
            return r3
        L59:
            return r11
        L5a:
            r5 = r9
            r9 = r12
            goto L71
        L5d:
            r16 = r9
            r9 = r5
            r5 = r16
            goto L71
        L63:
            c.q.d.j.g()
            throw r12
        L67:
            c.q.d.j.g()
            throw r12
        L6b:
            r16 = r10
            r10 = r7
            r7 = r9
            r9 = r16
        L71:
            if (r6 == 0) goto L79
            r6 = r1[r15]
            r3 = r7
            r7 = r10
            r10 = r9
            goto La5
        L79:
            r6 = r7
            r7 = r10
            r13 = r15
            r10 = r9
            goto L32
        L7e:
            int r14 = r6 + 1
            r6 = r5[r6]
            r6 = r6 & 255(0xff, float:3.57E-43)
            int r15 = r13 + r9
        L86:
            if (r13 != r15) goto L89
            return r11
        L89:
            r3 = r1[r13]
            if (r6 != r3) goto Lad
            int r13 = r13 + r9
            r6 = r1[r13]
            if (r14 != r7) goto La4
            d.v r10 = r10.f1611f
            if (r10 == 0) goto La0
            int r3 = r10.f1607b
            byte[] r5 = r10.f1606a
            int r7 = r10.f1608c
            if (r10 != r2) goto La5
            r10 = r12
            goto La5
        La0:
            c.q.d.j.g()
            throw r12
        La4:
            r3 = r14
        La5:
            if (r6 < 0) goto La8
            return r6
        La8:
            int r9 = -r6
            r6 = r3
            r3 = -2
            goto L1d
        Lad:
            int r13 = r13 + 1
            r3 = -2
            goto L86
        Lb1:
            if (r19 == 0) goto Lb5
            r3 = -2
            goto Lb6
        Lb5:
            r3 = r4
        Lb6:
            return r3
        */
        throw new UnsupportedOperationException("Method not decompiled: d.f.Y(d.q, boolean):int");
    }

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

    public final void a0(long j) {
        this.f1564c = j;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g b(byte[] bArr) {
        g0(bArr);
        return this;
    }

    public final long b0() {
        return this.f1564c;
    }

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

    public final i c0() {
        if (this.f1564c <= ((long) Integer.MAX_VALUE)) {
            return d0((int) this.f1564c);
        }
        throw new IllegalStateException(("size > Integer.MAX_VALUE: " + this.f1564c).toString());
    }

    public final void clear() throws EOFException {
        l(this.f1564c);
    }

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

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

    public final i d0(int i) {
        return i == 0 ? i.f1572e : x.i.a(this, i);
    }

    @Override // d.h
    public void e(f fVar, long j) throws EOFException {
        c.q.d.j.c(fVar, "sink");
        long j2 = this.f1564c;
        if (j2 >= j) {
            fVar.write(this, j);
        } else {
            fVar.write(this, j2);
            throw new EOFException();
        }
    }

    public final v e0(int i) {
        if (!(i >= 1 && i <= 8192)) {
            throw new IllegalArgumentException("unexpected capacity".toString());
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            v vVarB = w.b();
            this.f1563b = vVarB;
            vVarB.g = vVarB;
            vVarB.f1611f = vVarB;
            return vVarB;
        }
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        v vVar2 = vVar.g;
        if (vVar2 == null) {
            c.q.d.j.g();
            throw null;
        }
        if (vVar2.f1608c + i <= 8192 && vVar2.f1610e) {
            return vVar2;
        }
        v vVarB2 = w.b();
        vVar2.c(vVarB2);
        return vVarB2;
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof f)) {
            return false;
        }
        long j = this.f1564c;
        f fVar = (f) obj;
        if (j != fVar.f1564c) {
            return false;
        }
        long j2 = 0;
        if (j == 0) {
            return true;
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        v vVar2 = fVar.f1563b;
        if (vVar2 == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        int i2 = vVar2.f1607b;
        long j3 = 0;
        while (j3 < this.f1564c) {
            long jMin = Math.min(vVar.f1608c - i, vVar2.f1608c - i2);
            long j4 = j2;
            while (j4 < jMin) {
                int i3 = i + 1;
                int i4 = i2 + 1;
                if (vVar.f1606a[i] != vVar2.f1606a[i2]) {
                    return false;
                }
                j4++;
                i = i3;
                i2 = i4;
            }
            if (i == vVar.f1608c) {
                vVar = vVar.f1611f;
                if (vVar == null) {
                    c.q.d.j.g();
                    throw null;
                }
                i = vVar.f1607b;
            }
            if (i2 == vVar2.f1608c) {
                vVar2 = vVar2.f1611f;
                if (vVar2 == null) {
                    c.q.d.j.g();
                    throw null;
                }
                i2 = vVar2.f1607b;
            }
            j3 += jMin;
            j2 = 0;
        }
        return true;
    }

    @Override // d.g
    public long f(a0 a0Var) throws IOException {
        c.q.d.j.c(a0Var, "source");
        long j = 0;
        while (true) {
            long j2 = a0Var.read(this, 8192);
            if (j2 == -1) {
                return j;
            }
            j += j2;
        }
    }

    public f f0(i iVar) {
        c.q.d.j.c(iVar, "byteString");
        iVar.w(this);
        return this;
    }

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

    @Override // d.g
    public /* bridge */ /* synthetic */ g g() {
        J();
        return this;
    }

    public f g0(byte[] bArr) {
        c.q.d.j.c(bArr, "source");
        h0(bArr, 0, bArr.length);
        return this;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g h(long j) {
        l0(j);
        return this;
    }

    public f h0(byte[] bArr, int i, int i2) {
        c.q.d.j.c(bArr, "source");
        long j = i2;
        d.c.b(bArr.length, i, j);
        int i3 = i2 + i;
        while (i < i3) {
            v vVarE0 = e0(1);
            int iMin = Math.min(i3 - i, 8192 - vVarE0.f1608c);
            System.arraycopy(bArr, i, vVarE0.f1606a, vVarE0.f1608c, iMin);
            i += iMin;
            vVarE0.f1608c += iMin;
        }
        this.f1564c += j;
        return this;
    }

    public int hashCode() {
        v vVar = this.f1563b;
        if (vVar == null) {
            return 0;
        }
        int i = 1;
        do {
            int i2 = vVar.f1608c;
            for (int i3 = vVar.f1607b; i3 < i2; i3++) {
                i = (i * 31) + vVar.f1606a[i3];
            }
            vVar = vVar.f1611f;
            if (vVar == null) {
                c.q.d.j.g();
                throw null;
            }
        } while (vVar != this.f1563b);
        return i;
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x009b  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00a5  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00a9  */
    /* JADX WARN: Removed duplicated region for block: B:53:0x00ad A[EDGE_INSN: B:53:0x00ad->B:40:0x00ad BREAK  A[LOOP:0: B:5:0x000f->B:55:?], SYNTHETIC] */
    @Override // d.h
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long i() throws java.io.EOFException {
        /*
            r17 = this;
            r0 = r17
            long r1 = r0.f1564c
            r3 = 0
            int r1 = (r1 > r3 ? 1 : (r1 == r3 ? 0 : -1))
            if (r1 == 0) goto Lbd
            r5 = -7
            r7 = 0
            r8 = r7
            r9 = r8
        Lf:
            d.v r10 = r0.f1563b
            if (r10 == 0) goto Lb8
            byte[] r11 = r10.f1606a
            int r12 = r10.f1607b
            int r13 = r10.f1608c
        L19:
            if (r12 >= r13) goto L99
            r15 = r11[r12]
            r14 = 48
            byte r14 = (byte) r14
            if (r15 < r14) goto L6a
            r1 = 57
            byte r1 = (byte) r1
            if (r15 > r1) goto L6a
            int r14 = r14 - r15
            r1 = -922337203685477580(0xf333333333333334, double:-8.390303882365713E246)
            int r16 = (r3 > r1 ? 1 : (r3 == r1 ? 0 : -1))
            if (r16 < 0) goto L3f
            if (r16 != 0) goto L39
            long r1 = (long) r14
            int r1 = (r1 > r5 ? 1 : (r1 == r5 ? 0 : -1))
            if (r1 >= 0) goto L39
            goto L3f
        L39:
            r1 = 10
            long r3 = r3 * r1
            long r1 = (long) r14
            long r3 = r3 + r1
            goto L75
        L3f:
            d.f r1 = new d.f
            r1.<init>()
            r1.k0(r3)
            r1.j0(r15)
            if (r8 != 0) goto L4f
            r1.readByte()
        L4f:
            java.lang.NumberFormatException r2 = new java.lang.NumberFormatException
            java.lang.StringBuilder r3 = new java.lang.StringBuilder
            r3.<init>()
            java.lang.String r4 = "Number too large: "
            r3.append(r4)
            java.lang.String r1 = r1.V()
            r3.append(r1)
            java.lang.String r1 = r3.toString()
            r2.<init>(r1)
            throw r2
        L6a:
            r1 = 45
            byte r1 = (byte) r1
            if (r15 != r1) goto L7a
            if (r7 != 0) goto L7a
            r1 = 1
            long r5 = r5 - r1
            r8 = 1
        L75:
            int r12 = r12 + 1
            int r7 = r7 + 1
            goto L19
        L7a:
            if (r7 == 0) goto L7e
            r9 = 1
            goto L99
        L7e:
            java.lang.NumberFormatException r1 = new java.lang.NumberFormatException
            java.lang.StringBuilder r2 = new java.lang.StringBuilder
            r2.<init>()
            java.lang.String r3 = "Expected leading [0-9] or '-' character but was 0x"
            r2.append(r3)
            java.lang.String r3 = java.lang.Integer.toHexString(r15)
            r2.append(r3)
            java.lang.String r2 = r2.toString()
            r1.<init>(r2)
            throw r1
        L99:
            if (r12 != r13) goto La5
            d.v r1 = r10.b()
            r0.f1563b = r1
            d.w.a(r10)
            goto La7
        La5:
            r10.f1607b = r12
        La7:
            if (r9 != 0) goto Lad
            d.v r1 = r0.f1563b
            if (r1 != 0) goto Lf
        Lad:
            long r1 = r0.f1564c
            long r5 = (long) r7
            long r1 = r1 - r5
            r0.f1564c = r1
            if (r8 == 0) goto Lb6
            goto Lb7
        Lb6:
            long r3 = -r3
        Lb7:
            return r3
        Lb8:
            c.q.d.j.g()
            r1 = 0
            throw r1
        Lbd:
            java.io.EOFException r1 = new java.io.EOFException
            r1.<init>()
            throw r1
        */
        throw new UnsupportedOperationException("Method not decompiled: d.f.i():long");
    }

    public g i0(a0 a0Var, long j) throws IOException {
        c.q.d.j.c(a0Var, "source");
        while (j > 0) {
            long j2 = a0Var.read(this, j);
            if (j2 == -1) {
                throw new EOFException();
            }
            j -= j2;
        }
        return this;
    }

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

    @Override // d.h
    public i j(long j) throws EOFException {
        return new i(A(j));
    }

    public f j0(int i) {
        v vVarE0 = e0(1);
        byte[] bArr = vVarE0.f1606a;
        int i2 = vVarE0.f1608c;
        vVarE0.f1608c = i2 + 1;
        bArr[i2] = (byte) i;
        this.f1564c++;
        return this;
    }

    @Override // d.h
    public String k(long j) throws EOFException {
        if (!(j >= 0)) {
            throw new IllegalArgumentException(("limit < 0: " + j).toString());
        }
        long j2 = j != Long.MAX_VALUE ? j + 1 : Long.MAX_VALUE;
        byte b2 = (byte) 10;
        long jL = L(b2, 0L, j2);
        if (jL != -1) {
            return X(jL);
        }
        if (j2 < this.f1564c && K(j2 - 1) == ((byte) 13) && K(j2) == b2) {
            return X(j2);
        }
        f fVar = new f();
        H(fVar, 0L, Math.min(32, this.f1564c));
        throw new EOFException("\\n not found: limit=" + Math.min(this.f1564c, j) + " content=" + fVar.R().i() + (char) 8230);
    }

    public f k0(long j) {
        int i;
        if (j == 0) {
            j0(48);
            return this;
        }
        boolean z = false;
        int i2 = 1;
        if (j < 0) {
            j = -j;
            if (j < 0) {
                r0("-9223372036854775808");
                return this;
            }
            z = true;
        }
        if (j < 100000000) {
            if (j >= 10000) {
                i = j < 1000000 ? j < 100000 ? 5 : 6 : j < 10000000 ? 7 : 8;
            } else if (j >= 100) {
                i = j < 1000 ? 3 : 4;
            } else if (j >= 10) {
                i2 = 2;
            }
            i2 = i;
        } else if (j < 1000000000000L) {
            if (j < 10000000000L) {
                i2 = j < 1000000000 ? 9 : 10;
            } else {
                i = j < 100000000000L ? 11 : 12;
                i2 = i;
            }
        } else if (j >= 1000000000000000L) {
            i2 = j < 100000000000000000L ? j < 10000000000000000L ? 16 : 17 : j < 1000000000000000000L ? 18 : 19;
        } else if (j < 10000000000000L) {
            i2 = 13;
        } else {
            i = j < 100000000000000L ? 14 : 15;
            i2 = i;
        }
        if (z) {
            i2++;
        }
        v vVarE0 = e0(i2);
        byte[] bArr = vVarE0.f1606a;
        int i3 = vVarE0.f1608c + i2;
        while (j != 0) {
            long j2 = 10;
            i3--;
            bArr[i3] = f1562d[(int) (j % j2)];
            j /= j2;
        }
        if (z) {
            bArr[i3 - 1] = (byte) 45;
        }
        vVarE0.f1608c += i2;
        this.f1564c += (long) i2;
        return this;
    }

    @Override // d.h
    public void l(long j) throws EOFException {
        while (j > 0) {
            v vVar = this.f1563b;
            if (vVar == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j, vVar.f1608c - vVar.f1607b);
            long j2 = iMin;
            this.f1564c -= j2;
            j -= j2;
            int i = vVar.f1607b + iMin;
            vVar.f1607b = i;
            if (i == vVar.f1608c) {
                this.f1563b = vVar.b();
                w.a(vVar);
            }
        }
    }

    public f l0(long j) {
        if (j == 0) {
            j0(48);
            return this;
        }
        int iNumberOfTrailingZeros = (Long.numberOfTrailingZeros(Long.highestOneBit(j)) / 4) + 1;
        v vVarE0 = e0(iNumberOfTrailingZeros);
        byte[] bArr = vVarE0.f1606a;
        int i = vVarE0.f1608c;
        for (int i2 = (i + iNumberOfTrailingZeros) - 1; i2 >= i; i2--) {
            bArr[i2] = f1562d[(int) (15 & j)];
            j >>>= 4;
        }
        vVarE0.f1608c += iNumberOfTrailingZeros;
        this.f1564c += (long) iNumberOfTrailingZeros;
        return this;
    }

    @Override // d.h
    public long m(y yVar) throws IOException {
        c.q.d.j.c(yVar, "sink");
        long j = this.f1564c;
        if (j > 0) {
            yVar.write(this, j);
        }
        return j;
    }

    public f m0(int i) {
        v vVarE0 = e0(4);
        byte[] bArr = vVarE0.f1606a;
        int i2 = vVarE0.f1608c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 24) & 255);
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((i >>> 16) & 255);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((i >>> 8) & 255);
        bArr[i5] = (byte) (i & 255);
        vVarE0.f1608c = i5 + 1;
        this.f1564c += 4;
        return this;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g n() {
        I();
        return this;
    }

    public f n0(long j) {
        v vVarE0 = e0(8);
        byte[] bArr = vVarE0.f1606a;
        int i = vVarE0.f1608c;
        int i2 = i + 1;
        bArr[i] = (byte) ((j >>> 56) & 255);
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((j >>> 48) & 255);
        int i4 = i3 + 1;
        bArr[i3] = (byte) ((j >>> 40) & 255);
        int i5 = i4 + 1;
        bArr[i4] = (byte) ((j >>> 32) & 255);
        int i6 = i5 + 1;
        bArr[i5] = (byte) ((j >>> 24) & 255);
        int i7 = i6 + 1;
        bArr[i6] = (byte) ((j >>> 16) & 255);
        int i8 = i7 + 1;
        bArr[i7] = (byte) ((j >>> 8) & 255);
        bArr[i8] = (byte) (j & 255);
        vVarE0.f1608c = i8 + 1;
        this.f1564c += 8;
        return this;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g o(int i) {
        o0(i);
        return this;
    }

    public f o0(int i) {
        v vVarE0 = e0(2);
        byte[] bArr = vVarE0.f1606a;
        int i2 = vVarE0.f1608c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 8) & 255);
        bArr[i3] = (byte) (i & 255);
        vVarE0.f1608c = i3 + 1;
        this.f1564c += 2;
        return this;
    }

    @Override // d.h
    public boolean p(long j) {
        return this.f1564c >= j;
    }

    public f p0(String str, int i, int i2, Charset charset) {
        c.q.d.j.c(str, "string");
        c.q.d.j.c(charset, "charset");
        if (!(i >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i).toString());
        }
        if (!(i2 >= i)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i2 + " < " + i).toString());
        }
        if (!(i2 <= str.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i2 + " > " + str.length()).toString());
        }
        if (c.q.d.j.a(charset, c.u.c.f1470a)) {
            s0(str, i, i2);
            return this;
        }
        String strSubstring = str.substring(i, i2);
        c.q.d.j.b(strSubstring, "(this as java.lang.Strin…ing(startIndex, endIndex)");
        if (strSubstring == null) {
            throw new c.h("null cannot be cast to non-null type java.lang.String");
        }
        byte[] bytes = strSubstring.getBytes(charset);
        c.q.d.j.b(bytes, "(this as java.lang.String).getBytes(charset)");
        h0(bytes, 0, bytes.length);
        return this;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g q(int i) {
        m0(i);
        return this;
    }

    public f q0(String str, Charset charset) {
        c.q.d.j.c(str, "string");
        c.q.d.j.c(charset, "charset");
        p0(str, 0, str.length(), charset);
        return this;
    }

    @Override // d.h
    public h r() {
        return p.d(new s(this));
    }

    public f r0(String str) {
        c.q.d.j.c(str, "string");
        s0(str, 0, str.length());
        return this;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public int read(ByteBuffer byteBuffer) throws IOException {
        c.q.d.j.c(byteBuffer, "sink");
        v vVar = this.f1563b;
        if (vVar == null) {
            return -1;
        }
        int iMin = Math.min(byteBuffer.remaining(), vVar.f1608c - vVar.f1607b);
        byteBuffer.put(vVar.f1606a, vVar.f1607b, iMin);
        int i = vVar.f1607b + iMin;
        vVar.f1607b = i;
        this.f1564c -= (long) iMin;
        if (i == vVar.f1608c) {
            this.f1563b = vVar.b();
            w.a(vVar);
        }
        return iMin;
    }

    @Override // d.h
    public byte readByte() throws EOFException {
        long j = this.f1564c;
        if (j == 0) {
            throw new EOFException();
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        int i2 = vVar.f1608c;
        int i3 = i + 1;
        byte b2 = vVar.f1606a[i];
        this.f1564c = j - 1;
        if (i3 == i2) {
            this.f1563b = vVar.b();
            w.a(vVar);
        } else {
            vVar.f1607b = i3;
        }
        return b2;
    }

    @Override // d.h
    public void readFully(byte[] bArr) throws EOFException {
        c.q.d.j.c(bArr, "sink");
        int i = 0;
        while (i < bArr.length) {
            int iP = P(bArr, i, bArr.length - i);
            if (iP == -1) {
                throw new EOFException();
            }
            i += iP;
        }
    }

    @Override // d.h
    public int readInt() throws EOFException {
        long j = this.f1564c;
        if (j < 4) {
            throw new EOFException();
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        int i2 = vVar.f1608c;
        if (i2 - i < 4) {
            return ((readByte() & 255) << 24) | ((readByte() & 255) << 16) | ((readByte() & 255) << 8) | (readByte() & 255);
        }
        byte[] bArr = vVar.f1606a;
        int i3 = i + 1;
        int i4 = i3 + 1;
        int i5 = ((bArr[i] & 255) << 24) | ((bArr[i3] & 255) << 16);
        int i6 = i4 + 1;
        int i7 = i5 | ((bArr[i4] & 255) << 8);
        int i8 = i6 + 1;
        int i9 = i7 | (bArr[i6] & 255);
        this.f1564c = j - 4;
        if (i8 == i2) {
            this.f1563b = vVar.b();
            w.a(vVar);
        } else {
            vVar.f1607b = i8;
        }
        return i9;
    }

    @Override // d.h
    public long readLong() throws EOFException {
        long j = this.f1564c;
        if (j < 8) {
            throw new EOFException();
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        int i2 = vVar.f1608c;
        if (i2 - i < 8) {
            return ((((long) readInt()) & 4294967295L) << 32) | (4294967295L & ((long) readInt()));
        }
        byte[] bArr = vVar.f1606a;
        int i3 = i + 1;
        long j2 = (((long) bArr[i]) & 255) << 56;
        int i4 = i3 + 1;
        long j3 = ((((long) bArr[i3]) & 255) << 48) | j2;
        int i5 = i4 + 1;
        long j4 = j3 | ((((long) bArr[i4]) & 255) << 40);
        int i6 = i5 + 1;
        int i7 = i6 + 1;
        long j5 = j4 | ((((long) bArr[i5]) & 255) << 32) | ((((long) bArr[i6]) & 255) << 24);
        int i8 = i7 + 1;
        long j6 = j5 | ((((long) bArr[i7]) & 255) << 16);
        int i9 = i8 + 1;
        long j7 = j6 | ((((long) bArr[i8]) & 255) << 8);
        int i10 = i9 + 1;
        long j8 = j7 | (((long) bArr[i9]) & 255);
        this.f1564c = j - 8;
        if (i10 == i2) {
            this.f1563b = vVar.b();
            w.a(vVar);
        } else {
            vVar.f1607b = i10;
        }
        return j8;
    }

    @Override // d.h
    public short readShort() throws EOFException {
        long j = this.f1564c;
        if (j < 2) {
            throw new EOFException();
        }
        v vVar = this.f1563b;
        if (vVar == null) {
            c.q.d.j.g();
            throw null;
        }
        int i = vVar.f1607b;
        int i2 = vVar.f1608c;
        if (i2 - i < 2) {
            return (short) (((readByte() & 255) << 8) | (readByte() & 255));
        }
        byte[] bArr = vVar.f1606a;
        int i3 = i + 1;
        int i4 = i3 + 1;
        int i5 = ((bArr[i] & 255) << 8) | (bArr[i3] & 255);
        this.f1564c = j - 2;
        if (i4 == i2) {
            this.f1563b = vVar.b();
            w.a(vVar);
        } else {
            vVar.f1607b = i4;
        }
        return (short) i5;
    }

    @Override // d.h
    public String s() throws EOFException {
        return k(Long.MAX_VALUE);
    }

    public f s0(String str, int i, int i2) {
        c.q.d.j.c(str, "string");
        if (!(i >= 0)) {
            throw new IllegalArgumentException(("beginIndex < 0: " + i).toString());
        }
        if (!(i2 >= i)) {
            throw new IllegalArgumentException(("endIndex < beginIndex: " + i2 + " < " + i).toString());
        }
        if (!(i2 <= str.length())) {
            throw new IllegalArgumentException(("endIndex > string.length: " + i2 + " > " + str.length()).toString());
        }
        while (i < i2) {
            char cCharAt = str.charAt(i);
            if (cCharAt < 128) {
                v vVarE0 = e0(1);
                byte[] bArr = vVarE0.f1606a;
                int i3 = vVarE0.f1608c - i;
                int iMin = Math.min(i2, 8192 - i3);
                int i4 = i + 1;
                bArr[i + i3] = (byte) cCharAt;
                while (i4 < iMin) {
                    char cCharAt2 = str.charAt(i4);
                    if (cCharAt2 >= 128) {
                        break;
                    }
                    bArr[i4 + i3] = (byte) cCharAt2;
                    i4++;
                }
                int i5 = vVarE0.f1608c;
                int i6 = (i3 + i4) - i5;
                vVarE0.f1608c = i5 + i6;
                this.f1564c += (long) i6;
                i = i4;
            } else {
                if (cCharAt < 2048) {
                    v vVarE02 = e0(2);
                    byte[] bArr2 = vVarE02.f1606a;
                    int i7 = vVarE02.f1608c;
                    bArr2[i7] = (byte) ((cCharAt >> 6) | 192);
                    bArr2[i7 + 1] = (byte) ((cCharAt & '?') | 128);
                    vVarE02.f1608c = i7 + 2;
                    this.f1564c += 2;
                } else if (cCharAt < 55296 || cCharAt > 57343) {
                    v vVarE03 = e0(3);
                    byte[] bArr3 = vVarE03.f1606a;
                    int i8 = vVarE03.f1608c;
                    bArr3[i8] = (byte) ((cCharAt >> '\f') | 224);
                    bArr3[i8 + 1] = (byte) ((63 & (cCharAt >> 6)) | 128);
                    bArr3[i8 + 2] = (byte) ((cCharAt & '?') | 128);
                    vVarE03.f1608c = i8 + 3;
                    this.f1564c += 3;
                } else {
                    int i9 = i + 1;
                    char cCharAt3 = i9 < i2 ? str.charAt(i9) : (char) 0;
                    if (cCharAt > 56319 || 56320 > cCharAt3 || 57343 < cCharAt3) {
                        j0(63);
                        i = i9;
                    } else {
                        int i10 = (((cCharAt & 1023) << 10) | (cCharAt3 & 1023)) + 65536;
                        v vVarE04 = e0(4);
                        byte[] bArr4 = vVarE04.f1606a;
                        int i11 = vVarE04.f1608c;
                        bArr4[i11] = (byte) ((i10 >> 18) | 240);
                        bArr4[i11 + 1] = (byte) (((i10 >> 12) & 63) | 128);
                        bArr4[i11 + 2] = (byte) (((i10 >> 6) & 63) | 128);
                        bArr4[i11 + 3] = (byte) ((i10 & 63) | 128);
                        vVarE04.f1608c = i11 + 4;
                        this.f1564c += 4;
                        i += 2;
                    }
                }
                i++;
            }
        }
        return this;
    }

    @Override // d.h
    public byte[] t() {
        return A(this.f1564c);
    }

    public f t0(int i) {
        if (i < 128) {
            j0(i);
        } else if (i < 2048) {
            v vVarE0 = e0(2);
            byte[] bArr = vVarE0.f1606a;
            int i2 = vVarE0.f1608c;
            bArr[i2] = (byte) ((i >> 6) | 192);
            bArr[i2 + 1] = (byte) ((i & 63) | 128);
            vVarE0.f1608c = i2 + 2;
            this.f1564c += 2;
        } else if (55296 <= i && 57343 >= i) {
            j0(63);
        } else if (i < 65536) {
            v vVarE02 = e0(3);
            byte[] bArr2 = vVarE02.f1606a;
            int i3 = vVarE02.f1608c;
            bArr2[i3] = (byte) ((i >> 12) | 224);
            bArr2[i3 + 1] = (byte) (((i >> 6) & 63) | 128);
            bArr2[i3 + 2] = (byte) ((i & 63) | 128);
            vVarE02.f1608c = i3 + 3;
            this.f1564c += 3;
        } else {
            if (i > 1114111) {
                throw new IllegalArgumentException("Unexpected code point: " + Integer.toHexString(i));
            }
            v vVarE03 = e0(4);
            byte[] bArr3 = vVarE03.f1606a;
            int i4 = vVarE03.f1608c;
            bArr3[i4] = (byte) ((i >> 18) | 240);
            bArr3[i4 + 1] = (byte) (((i >> 12) & 63) | 128);
            bArr3[i4 + 2] = (byte) (((i >> 6) & 63) | 128);
            bArr3[i4 + 3] = (byte) ((i & 63) | 128);
            vVarE03.f1608c = i4 + 4;
            this.f1564c += 4;
        }
        return this;
    }

    @Override // d.a0
    public b0 timeout() {
        return b0.NONE;
    }

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

    @Override // d.h
    public void u(long j) throws EOFException {
        if (this.f1564c < j) {
            throw new EOFException();
        }
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g w(String str) {
        r0(str);
        return this;
    }

    @Override // java.nio.channels.WritableByteChannel
    public int write(ByteBuffer byteBuffer) throws IOException {
        c.q.d.j.c(byteBuffer, "source");
        int iRemaining = byteBuffer.remaining();
        int i = iRemaining;
        while (i > 0) {
            v vVarE0 = e0(1);
            int iMin = Math.min(i, 8192 - vVarE0.f1608c);
            byteBuffer.get(vVarE0.f1606a, vVarE0.f1608c, iMin);
            i -= iMin;
            vVarE0.f1608c += iMin;
        }
        this.f1564c += (long) iRemaining;
        return iRemaining;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g x(long j) {
        k0(j);
        return this;
    }

    @Override // d.h
    public boolean y() {
        return this.f1564c == 0;
    }

    @Override // d.g
    public /* bridge */ /* synthetic */ g z(int i) {
        j0(i);
        return this;
    }

    /* 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.b0(), Integer.MAX_VALUE);
        }

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

        @Override // java.io.InputStream
        public int read() {
            if (f.this.b0() > 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 i, int i2) {
            c.q.d.j.c(bArr, "sink");
            return f.this.P(bArr, i, i2);
        }
    }

    @Override // d.y
    public void write(f fVar, long j) {
        v vVar;
        c.q.d.j.c(fVar, "source");
        if (fVar != this) {
            d.c.b(fVar.f1564c, 0L, j);
            while (j > 0) {
                v vVar2 = fVar.f1563b;
                if (vVar2 == null) {
                    c.q.d.j.g();
                    throw null;
                }
                int i = vVar2.f1608c;
                if (vVar2 != null) {
                    if (j < i - vVar2.f1607b) {
                        v vVar3 = this.f1563b;
                        if (vVar3 == null) {
                            vVar = null;
                        } else {
                            if (vVar3 == null) {
                                c.q.d.j.g();
                                throw null;
                            }
                            vVar = vVar3.g;
                        }
                        if (vVar != null && vVar.f1610e) {
                            if ((((long) vVar.f1608c) + j) - ((long) (vVar.f1609d ? 0 : vVar.f1607b)) <= 8192) {
                                v vVar4 = fVar.f1563b;
                                if (vVar4 != null) {
                                    vVar4.g(vVar, (int) j);
                                    fVar.f1564c -= j;
                                    this.f1564c += j;
                                    return;
                                }
                                c.q.d.j.g();
                                throw null;
                            }
                        }
                        v vVar5 = fVar.f1563b;
                        if (vVar5 == null) {
                            c.q.d.j.g();
                            throw null;
                        }
                        fVar.f1563b = vVar5.e((int) j);
                    }
                    v vVar6 = fVar.f1563b;
                    if (vVar6 != null) {
                        long j2 = vVar6.f1608c - vVar6.f1607b;
                        fVar.f1563b = vVar6.b();
                        v vVar7 = this.f1563b;
                        if (vVar7 == null) {
                            this.f1563b = vVar6;
                            vVar6.g = vVar6;
                            vVar6.f1611f = vVar6;
                        } else if (vVar7 != null) {
                            v vVar8 = vVar7.g;
                            if (vVar8 != null) {
                                vVar8.c(vVar6);
                                vVar6.a();
                            } else {
                                c.q.d.j.g();
                                throw null;
                            }
                        } else {
                            c.q.d.j.g();
                            throw null;
                        }
                        fVar.f1564c -= j2;
                        this.f1564c += j2;
                        j -= j2;
                    } else {
                        c.q.d.j.g();
                        throw null;
                    }
                } else {
                    c.q.d.j.g();
                    throw null;
                }
            }
            return;
        }
        throw new IllegalArgumentException("source == this".toString());
    }

    @Override // d.a0
    public long read(f fVar, long j) {
        c.q.d.j.c(fVar, "sink");
        if (j >= 0) {
            long j2 = this.f1564c;
            if (j2 == 0) {
                return -1L;
            }
            if (j > j2) {
                j = j2;
            }
            fVar.write(this, j);
            return j;
        }
        throw new IllegalArgumentException(("byteCount < 0: " + j).toString());
    }
}
