package f;

import com.seewo.libmcuservice.constant.IMcuConstants;
import com.seewo.libmcuservice.constant.ITVStateConstants;
import com.seewo.sdk.model.SDKKeyboardCode;
import java.io.EOFException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import javax.annotation.Nullable;

/* JADX INFO: compiled from: Buffer.java */
/* JADX INFO: loaded from: classes.dex */
public final class c implements e, d, Cloneable {

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    private static final byte[] f3074c = {SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT_SQUARE_BRACKET, SDKKeyboardCode.FUNCTION_KEY_BOARD_RIGHT_SLASH, 50, SDKKeyboardCode.FUNCTION_KEY_BOARD_SEMICOLON, SDKKeyboardCode.FUNCTION_KEY_BOARD_SINGLE_QUOTE_MARK, SDKKeyboardCode.FUNCTION_KEY_BOARD_GRAVE_ACCENT, SDKKeyboardCode.FUNCTION_KEY_BOARD_COMMA, 55, SDKKeyboardCode.FUNCTION_KEY_BOARD_LEFT_SLASH, SDKKeyboardCode.FUNCTION_KEY_BOARD_CAPS_LOCK, 97, 98, 99, 100, 101, 102};

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    @Nullable
    p f3075d;

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

    /* JADX INFO: compiled from: Buffer.java */
    class a extends InputStream {
        a() {
        }

        @Override // java.io.InputStream
        public int available() {
            return (int) Math.min(c.this.f3076e, 2147483647L);
        }

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

        @Override // java.io.InputStream
        public int read() {
            c cVar = c.this;
            if (cVar.f3076e > 0) {
                return cVar.readByte() & IMcuConstants.DEFAULT_VALUE;
            }
            return -1;
        }

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

        @Override // java.io.InputStream
        public int read(byte[] bArr, int i, int i2) {
            return c.this.read(bArr, i, i2);
        }
    }

    public f A(int i) {
        return i == 0 ? f.f3079d : new r(this, i);
    }

    @Override // f.e
    public boolean B(long j, f fVar) {
        return l(j, fVar, 0, fVar.q());
    }

    @Override // f.e
    public String C(Charset charset) {
        try {
            return o(this.f3076e, charset);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    p D(int i) {
        if (i < 1 || i > 8192) {
            throw new IllegalArgumentException();
        }
        p pVar = this.f3075d;
        if (pVar != null) {
            p pVar2 = pVar.f3114g;
            return (pVar2.f3110c + i > 8192 || !pVar2.f3112e) ? pVar2.c(q.b()) : pVar2;
        }
        p pVarB = q.b();
        this.f3075d = pVarB;
        pVarB.f3114g = pVarB;
        pVarB.f3113f = pVarB;
        return pVarB;
    }

    @Override // f.d
    /* JADX INFO: renamed from: E, reason: merged with bridge method [inline-methods] */
    public c U(f fVar) {
        if (fVar == null) {
            throw new IllegalArgumentException("byteString == null");
        }
        fVar.w(this);
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: F, reason: merged with bridge method [inline-methods] */
    public c write(byte[] bArr) {
        if (bArr != null) {
            return write(bArr, 0, bArr.length);
        }
        throw new IllegalArgumentException("source == null");
    }

    @Override // f.d
    public long G(t tVar) throws IOException {
        if (tVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        long j = 0;
        while (true) {
            long j2 = tVar.read(this, 8192L);
            if (j2 == -1) {
                return j;
            }
            j += j2;
        }
    }

    @Override // f.d
    /* JADX INFO: renamed from: I, reason: merged with bridge method [inline-methods] */
    public c write(byte[] bArr, int i, int i2) {
        if (bArr == null) {
            throw new IllegalArgumentException("source == null");
        }
        long j = i2;
        v.b(bArr.length, i, j);
        int i3 = i2 + i;
        while (i < i3) {
            p pVarD = D(1);
            int iMin = Math.min(i3 - i, 8192 - pVarD.f3110c);
            System.arraycopy(bArr, i, pVarD.f3108a, pVarD.f3110c, iMin);
            i += iMin;
            pVarD.f3110c += iMin;
        }
        this.f3076e += j;
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: J, reason: merged with bridge method [inline-methods] */
    public c writeByte(int i) {
        p pVarD = D(1);
        byte[] bArr = pVarD.f3108a;
        int i2 = pVarD.f3110c;
        pVarD.f3110c = i2 + 1;
        bArr[i2] = (byte) i;
        this.f3076e++;
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: K, reason: merged with bridge method [inline-methods] */
    public c d0(long j) {
        if (j == 0) {
            return writeByte(48);
        }
        boolean z = false;
        int i = 1;
        if (j < 0) {
            j = -j;
            if (j < 0) {
                return z("-9223372036854775808");
            }
            z = true;
        }
        if (j >= 100000000) {
            i = j < 1000000000000L ? j < 10000000000L ? j < 1000000000 ? 9 : 10 : j < 100000000000L ? 11 : 12 : j < 1000000000000000L ? j < 10000000000000L ? 13 : j < 100000000000000L ? 14 : 15 : j < 100000000000000000L ? j < 10000000000000000L ? 16 : 17 : j < 1000000000000000000L ? 18 : 19;
        } else 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) {
            i = 2;
        }
        if (z) {
            i++;
        }
        p pVarD = D(i);
        byte[] bArr = pVarD.f3108a;
        int i2 = pVarD.f3110c + i;
        while (j != 0) {
            i2--;
            bArr[i2] = f3074c[(int) (j % 10)];
            j /= 10;
        }
        if (z) {
            bArr[i2 - 1] = SDKKeyboardCode.FUNCTION_KEY_BOARD_MINUS;
        }
        pVarD.f3110c += i;
        this.f3076e += (long) i;
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: L, reason: merged with bridge method [inline-methods] */
    public c H(long j) {
        if (j == 0) {
            return writeByte(48);
        }
        int iNumberOfTrailingZeros = (Long.numberOfTrailingZeros(Long.highestOneBit(j)) / 4) + 1;
        p pVarD = D(iNumberOfTrailingZeros);
        byte[] bArr = pVarD.f3108a;
        int i = pVarD.f3110c;
        for (int i2 = (i + iNumberOfTrailingZeros) - 1; i2 >= i; i2--) {
            bArr[i2] = f3074c[(int) (15 & j)];
            j >>>= 4;
        }
        pVarD.f3110c += iNumberOfTrailingZeros;
        this.f3076e += (long) iNumberOfTrailingZeros;
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: M, reason: merged with bridge method [inline-methods] */
    public c writeInt(int i) {
        p pVarD = D(4);
        byte[] bArr = pVarD.f3108a;
        int i2 = pVarD.f3110c;
        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);
        pVarD.f3110c = i5 + 1;
        this.f3076e += 4;
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: N, reason: merged with bridge method [inline-methods] */
    public c writeLong(long j) {
        p pVarD = D(8);
        byte[] bArr = pVarD.f3108a;
        int i = pVarD.f3110c;
        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);
        pVarD.f3110c = i8 + 1;
        this.f3076e += 8;
        return this;
    }

    @Override // f.e
    public String O() throws EOFException {
        return w(Long.MAX_VALUE);
    }

    @Override // f.d
    /* JADX INFO: renamed from: P, reason: merged with bridge method [inline-methods] */
    public c writeShort(int i) {
        p pVarD = D(2);
        byte[] bArr = pVarD.f3108a;
        int i2 = pVarD.f3110c;
        int i3 = i2 + 1;
        bArr[i2] = (byte) ((i >>> 8) & 255);
        bArr[i3] = (byte) (i & 255);
        pVarD.f3110c = i3 + 1;
        this.f3076e += 2;
        return this;
    }

    @Override // f.e
    public int Q() {
        return v.c(readInt());
    }

    public c R(String str, int i, int i2, Charset charset) {
        if (str == null) {
            throw new IllegalArgumentException("string == null");
        }
        if (i < 0) {
            throw new IllegalAccessError("beginIndex < 0: " + i);
        }
        if (i2 < i) {
            throw new IllegalArgumentException("endIndex < beginIndex: " + i2 + " < " + i);
        }
        if (i2 <= str.length()) {
            if (charset == null) {
                throw new IllegalArgumentException("charset == null");
            }
            if (charset.equals(v.f3117a)) {
                return X(str, i, i2);
            }
            byte[] bytes = str.substring(i, i2).getBytes(charset);
            return write(bytes, 0, bytes.length);
        }
        throw new IllegalArgumentException("endIndex > string.length: " + i2 + " > " + str.length());
    }

    @Override // f.e
    public byte[] S(long j) throws EOFException {
        v.b(this.f3076e, 0L, j);
        if (j <= 2147483647L) {
            byte[] bArr = new byte[(int) j];
            readFully(bArr);
            return bArr;
        }
        throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + j);
    }

    public c T(String str, Charset charset) {
        return R(str, 0, str.length(), charset);
    }

    @Override // f.d
    /* JADX INFO: renamed from: V, reason: merged with bridge method [inline-methods] */
    public c z(String str) {
        return X(str, 0, str.length());
    }

    @Override // f.e
    public short W() {
        return v.d(readShort());
    }

    public c X(String str, int i, int i2) {
        if (str == null) {
            throw new IllegalArgumentException("string == null");
        }
        if (i < 0) {
            throw new IllegalArgumentException("beginIndex < 0: " + i);
        }
        if (i2 < i) {
            throw new IllegalArgumentException("endIndex < beginIndex: " + i2 + " < " + i);
        }
        if (i2 > str.length()) {
            throw new IllegalArgumentException("endIndex > string.length: " + i2 + " > " + str.length());
        }
        while (i < i2) {
            char cCharAt = str.charAt(i);
            if (cCharAt < 128) {
                p pVarD = D(1);
                byte[] bArr = pVarD.f3108a;
                int i3 = pVarD.f3110c - 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 = pVarD.f3110c;
                int i6 = (i3 + i4) - i5;
                pVarD.f3110c = i5 + i6;
                this.f3076e += (long) i6;
                i = i4;
            } else {
                if (cCharAt < 2048) {
                    writeByte((cCharAt >> 6) | ITVStateConstants.ACTION_OUT_SETTING_AUTO_UPDATES);
                    writeByte((cCharAt & '?') | 128);
                } else if (cCharAt < 55296 || cCharAt > 57343) {
                    writeByte((cCharAt >> '\f') | 224);
                    writeByte(((cCharAt >> 6) & 63) | 128);
                    writeByte((cCharAt & '?') | 128);
                } else {
                    int i7 = i + 1;
                    char cCharAt3 = i7 < i2 ? str.charAt(i7) : (char) 0;
                    if (cCharAt > 56319 || cCharAt3 < 56320 || cCharAt3 > 57343) {
                        writeByte(63);
                        i = i7;
                    } else {
                        int i8 = (((cCharAt & 10239) << 10) | (9215 & cCharAt3)) + 65536;
                        writeByte((i8 >> 18) | 240);
                        writeByte(((i8 >> 12) & 63) | 128);
                        writeByte(((i8 >> 6) & 63) | 128);
                        writeByte((i8 & 63) | 128);
                        i += 2;
                    }
                }
                i++;
            }
        }
        return this;
    }

    public c Y(int i) {
        if (i < 128) {
            writeByte(i);
        } else if (i < 2048) {
            writeByte((i >> 6) | ITVStateConstants.ACTION_OUT_SETTING_AUTO_UPDATES);
            writeByte((i & 63) | 128);
        } else if (i < 65536) {
            if (i < 55296 || i > 57343) {
                writeByte((i >> 12) | 224);
                writeByte(((i >> 6) & 63) | 128);
                writeByte((i & 63) | 128);
            } else {
                writeByte(63);
            }
        } else {
            if (i > 1114111) {
                throw new IllegalArgumentException("Unexpected code point: " + Integer.toHexString(i));
            }
            writeByte((i >> 18) | 240);
            writeByte(((i >> 12) & 63) | 128);
            writeByte(((i >> 6) & 63) | 128);
            writeByte((i & 63) | 128);
        }
        return this;
    }

    @Override // f.e
    public boolean a(long j) {
        return this.f3076e >= j;
    }

    public void b() {
        try {
            skip(this.f3076e);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // f.e, f.d
    public c buffer() {
        return this;
    }

    /* JADX INFO: renamed from: c, reason: merged with bridge method [inline-methods] */
    public c clone() {
        c cVar = new c();
        if (this.f3076e == 0) {
            return cVar;
        }
        p pVar = new p(this.f3075d);
        cVar.f3075d = pVar;
        pVar.f3114g = pVar;
        pVar.f3113f = pVar;
        p pVar2 = this.f3075d;
        while (true) {
            pVar2 = pVar2.f3113f;
            if (pVar2 == this.f3075d) {
                cVar.f3076e = this.f3076e;
                return cVar;
            }
            cVar.f3075d.f3114g.c(new p(pVar2));
        }
    }

    @Override // f.e
    public void c0(long j) throws EOFException {
        if (this.f3076e < j) {
            throw new EOFException();
        }
    }

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

    @Override // f.e
    public f d(long j) throws EOFException {
        return new f(S(j));
    }

    public long e() {
        long j = this.f3076e;
        if (j == 0) {
            return 0L;
        }
        p pVar = this.f3075d.f3114g;
        int i = pVar.f3110c;
        return (i >= 8192 || !pVar.f3112e) ? j : j - ((long) (i - pVar.f3109b));
    }

    public boolean equals(Object obj) {
        if (this == obj) {
            return true;
        }
        if (!(obj instanceof c)) {
            return false;
        }
        c cVar = (c) obj;
        long j = this.f3076e;
        if (j != cVar.f3076e) {
            return false;
        }
        long j2 = 0;
        if (j == 0) {
            return true;
        }
        p pVar = this.f3075d;
        p pVar2 = cVar.f3075d;
        int i = pVar.f3109b;
        int i2 = pVar2.f3109b;
        while (j2 < this.f3076e) {
            long jMin = Math.min(pVar.f3110c - i, pVar2.f3110c - i2);
            int i3 = 0;
            while (i3 < jMin) {
                int i4 = i + 1;
                int i5 = i2 + 1;
                if (pVar.f3108a[i] != pVar2.f3108a[i2]) {
                    return false;
                }
                i3++;
                i = i4;
                i2 = i5;
            }
            if (i == pVar.f3110c) {
                pVar = pVar.f3113f;
                i = pVar.f3109b;
            }
            if (i2 == pVar2.f3110c) {
                pVar2 = pVar2.f3113f;
                i2 = pVar2.f3109b;
            }
            j2 += jMin;
        }
        return true;
    }

    @Override // f.d
    public d f() {
        return this;
    }

    @Override // f.e
    public long f0(byte b2) {
        return k(b2, 0L, Long.MAX_VALUE);
    }

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

    public c g(c cVar, long j, long j2) {
        if (cVar == null) {
            throw new IllegalArgumentException("out == null");
        }
        v.b(this.f3076e, j, j2);
        if (j2 == 0) {
            return this;
        }
        cVar.f3076e += j2;
        p pVar = this.f3075d;
        while (true) {
            int i = pVar.f3110c;
            int i2 = pVar.f3109b;
            if (j < i - i2) {
                break;
            }
            j -= (long) (i - i2);
            pVar = pVar.f3113f;
        }
        while (j2 > 0) {
            p pVar2 = new p(pVar);
            int i3 = (int) (((long) pVar2.f3109b) + j);
            pVar2.f3109b = i3;
            pVar2.f3110c = Math.min(i3 + ((int) j2), pVar2.f3110c);
            p pVar3 = cVar.f3075d;
            if (pVar3 == null) {
                pVar2.f3114g = pVar2;
                pVar2.f3113f = pVar2;
                cVar.f3075d = pVar2;
            } else {
                pVar3.f3114g.c(pVar2);
            }
            j2 -= (long) (pVar2.f3110c - pVar2.f3109b);
            pVar = pVar.f3113f;
            j = 0;
        }
        return this;
    }

    @Override // f.d
    /* JADX INFO: renamed from: h, reason: merged with bridge method [inline-methods] */
    public c r() {
        return this;
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0093  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x009d  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x00a1  */
    /* JADX WARN: Removed duplicated region for block: B:44:0x00a5 A[EDGE_INSN: B:44:0x00a5->B:38:0x00a5 BREAK  A[LOOP:0: B:5:0x000b->B:46:?], SYNTHETIC] */
    @Override // f.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long h0() {
        /*
            r14 = this;
            long r0 = r14.f3076e
            r2 = 0
            int r0 = (r0 > r2 ? 1 : (r0 == r2 ? 0 : -1))
            if (r0 == 0) goto Lac
            r0 = 0
            r1 = r0
            r4 = r2
        Lb:
            f.p r6 = r14.f3075d
            byte[] r7 = r6.f3108a
            int r8 = r6.f3109b
            int r9 = r6.f3110c
        L13:
            if (r8 >= r9) goto L91
            r10 = r7[r8]
            r11 = 48
            if (r10 < r11) goto L22
            r11 = 57
            if (r10 > r11) goto L22
            int r11 = r10 + (-48)
            goto L3a
        L22:
            r11 = 97
            if (r10 < r11) goto L2f
            r11 = 102(0x66, float:1.43E-43)
            if (r10 > r11) goto L2f
            int r11 = r10 + (-97)
        L2c:
            int r11 = r11 + 10
            goto L3a
        L2f:
            r11 = 65
            if (r10 < r11) goto L72
            r11 = 70
            if (r10 > r11) goto L72
            int r11 = r10 + (-65)
            goto L2c
        L3a:
            r12 = -1152921504606846976(0xf000000000000000, double:-3.105036184601418E231)
            long r12 = r12 & r4
            int r12 = (r12 > r2 ? 1 : (r12 == r2 ? 0 : -1))
            if (r12 != 0) goto L4a
            r10 = 4
            long r4 = r4 << r10
            long r10 = (long) r11
            long r4 = r4 | r10
            int r8 = r8 + 1
            int r0 = r0 + 1
            goto L13
        L4a:
            f.c r0 = new f.c
            r0.<init>()
            f.c r0 = r0.H(r4)
            f.c r0 = r0.writeByte(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.p()
            r2.append(r0)
            java.lang.String r0 = r2.toString()
            r1.<init>(r0)
            throw r1
        L72:
            if (r0 == 0) goto L76
            r1 = 1
            goto L91
        L76:
            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
        L91:
            if (r8 != r9) goto L9d
            f.p r7 = r6.b()
            r14.f3075d = r7
            f.q.a(r6)
            goto L9f
        L9d:
            r6.f3109b = r8
        L9f:
            if (r1 != 0) goto La5
            f.p r6 = r14.f3075d
            if (r6 != 0) goto Lb
        La5:
            long r1 = r14.f3076e
            long r6 = (long) r0
            long r1 = r1 - r6
            r14.f3076e = r1
            return r4
        Lac:
            java.lang.IllegalStateException r0 = new java.lang.IllegalStateException
            java.lang.String r1 = "size == 0"
            r0.<init>(r1)
            throw r0
        */
        throw new UnsupportedOperationException("Method not decompiled: f.c.h0():long");
    }

    public int hashCode() {
        p pVar = this.f3075d;
        if (pVar == null) {
            return 0;
        }
        int i = 1;
        do {
            int i2 = pVar.f3110c;
            for (int i3 = pVar.f3109b; i3 < i2; i3++) {
                i = (i * 31) + pVar.f3108a[i3];
            }
            pVar = pVar.f3113f;
        } while (pVar != this.f3075d);
        return i;
    }

    public byte i(long j) {
        v.b(this.f3076e, j, 1L);
        p pVar = this.f3075d;
        while (true) {
            int i = pVar.f3110c;
            int i2 = pVar.f3109b;
            long j2 = i - i2;
            if (j < j2) {
                return pVar.f3108a[i2 + ((int) j)];
            }
            j -= j2;
            pVar = pVar.f3113f;
        }
    }

    @Override // f.e
    public byte[] j() {
        try {
            return S(this.f3076e);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // f.e
    public InputStream j0() {
        return new a();
    }

    public long k(byte b2, long j, long j2) {
        p pVar;
        long j3 = 0;
        if (j < 0 || j2 < j) {
            throw new IllegalArgumentException(String.format("size=%s fromIndex=%s toIndex=%s", Long.valueOf(this.f3076e), Long.valueOf(j), Long.valueOf(j2)));
        }
        long j4 = this.f3076e;
        long j5 = j2 > j4 ? j4 : j2;
        if (j == j5 || (pVar = this.f3075d) == null) {
            return -1L;
        }
        if (j4 - j < j) {
            while (j4 > j) {
                pVar = pVar.f3114g;
                j4 -= (long) (pVar.f3110c - pVar.f3109b);
            }
        } else {
            while (true) {
                long j6 = ((long) (pVar.f3110c - pVar.f3109b)) + j3;
                if (j6 >= j) {
                    break;
                }
                pVar = pVar.f3113f;
                j3 = j6;
            }
            j4 = j3;
        }
        long j7 = j;
        while (j4 < j5) {
            byte[] bArr = pVar.f3108a;
            int iMin = (int) Math.min(pVar.f3110c, (((long) pVar.f3109b) + j5) - j4);
            for (int i = (int) ((((long) pVar.f3109b) + j7) - j4); i < iMin; i++) {
                if (bArr[i] == b2) {
                    return ((long) (i - pVar.f3109b)) + j4;
                }
            }
            j4 += (long) (pVar.f3110c - pVar.f3109b);
            pVar = pVar.f3113f;
            j7 = j4;
        }
        return -1L;
    }

    public boolean l(long j, f fVar, int i, int i2) {
        if (j < 0 || i < 0 || i2 < 0 || this.f3076e - j < i2 || fVar.q() - i < i2) {
            return false;
        }
        for (int i3 = 0; i3 < i2; i3++) {
            if (i(((long) i3) + j) != fVar.i(i + i3)) {
                return false;
            }
        }
        return true;
    }

    @Override // f.e
    public boolean m() {
        return this.f3076e == 0;
    }

    public f n() {
        return new f(j());
    }

    public String o(long j, Charset charset) throws EOFException {
        v.b(this.f3076e, 0L, j);
        if (charset == null) {
            throw new IllegalArgumentException("charset == null");
        }
        if (j > 2147483647L) {
            throw new IllegalArgumentException("byteCount > Integer.MAX_VALUE: " + j);
        }
        if (j == 0) {
            return "";
        }
        p pVar = this.f3075d;
        if (((long) pVar.f3109b) + j > pVar.f3110c) {
            return new String(S(j), charset);
        }
        String str = new String(pVar.f3108a, pVar.f3109b, (int) j, charset);
        int i = (int) (((long) pVar.f3109b) + j);
        pVar.f3109b = i;
        this.f3076e -= j;
        if (i == pVar.f3110c) {
            this.f3075d = pVar.b();
            q.a(pVar);
        }
        return str;
    }

    public String p() {
        try {
            return o(this.f3076e, v.f3117a);
        } catch (EOFException e2) {
            throw new AssertionError(e2);
        }
    }

    @Override // f.e
    public void q(c cVar, long j) throws EOFException {
        long j2 = this.f3076e;
        if (j2 >= j) {
            cVar.write(this, j);
        } else {
            cVar.write(this, j2);
            throw new EOFException();
        }
    }

    @Override // f.e
    public int read(byte[] bArr, int i, int i2) {
        v.b(bArr.length, i, i2);
        p pVar = this.f3075d;
        if (pVar == null) {
            return -1;
        }
        int iMin = Math.min(i2, pVar.f3110c - pVar.f3109b);
        System.arraycopy(pVar.f3108a, pVar.f3109b, bArr, i, iMin);
        int i3 = pVar.f3109b + iMin;
        pVar.f3109b = i3;
        this.f3076e -= (long) iMin;
        if (i3 == pVar.f3110c) {
            this.f3075d = pVar.b();
            q.a(pVar);
        }
        return iMin;
    }

    @Override // f.e
    public byte readByte() {
        long j = this.f3076e;
        if (j == 0) {
            throw new IllegalStateException("size == 0");
        }
        p pVar = this.f3075d;
        int i = pVar.f3109b;
        int i2 = pVar.f3110c;
        int i3 = i + 1;
        byte b2 = pVar.f3108a[i];
        this.f3076e = j - 1;
        if (i3 == i2) {
            this.f3075d = pVar.b();
            q.a(pVar);
        } else {
            pVar.f3109b = i3;
        }
        return b2;
    }

    @Override // f.e
    public void readFully(byte[] bArr) throws EOFException {
        int i = 0;
        while (i < bArr.length) {
            int i2 = read(bArr, i, bArr.length - i);
            if (i2 == -1) {
                throw new EOFException();
            }
            i += i2;
        }
    }

    @Override // f.e
    public int readInt() {
        long j = this.f3076e;
        if (j < 4) {
            throw new IllegalStateException("size < 4: " + this.f3076e);
        }
        p pVar = this.f3075d;
        int i = pVar.f3109b;
        int i2 = pVar.f3110c;
        if (i2 - i < 4) {
            return ((readByte() & IMcuConstants.DEFAULT_VALUE) << 24) | ((readByte() & IMcuConstants.DEFAULT_VALUE) << 16) | ((readByte() & IMcuConstants.DEFAULT_VALUE) << 8) | (readByte() & IMcuConstants.DEFAULT_VALUE);
        }
        byte[] bArr = pVar.f3108a;
        int i3 = i + 1;
        int i4 = i3 + 1;
        int i5 = ((bArr[i] & IMcuConstants.DEFAULT_VALUE) << 24) | ((bArr[i3] & IMcuConstants.DEFAULT_VALUE) << 16);
        int i6 = i4 + 1;
        int i7 = i5 | ((bArr[i4] & IMcuConstants.DEFAULT_VALUE) << 8);
        int i8 = i6 + 1;
        int i9 = i7 | (bArr[i6] & IMcuConstants.DEFAULT_VALUE);
        this.f3076e = j - 4;
        if (i8 == i2) {
            this.f3075d = pVar.b();
            q.a(pVar);
        } else {
            pVar.f3109b = i8;
        }
        return i9;
    }

    @Override // f.e
    public long readLong() {
        long j = this.f3076e;
        if (j < 8) {
            throw new IllegalStateException("size < 8: " + this.f3076e);
        }
        p pVar = this.f3075d;
        int i = pVar.f3109b;
        int i2 = pVar.f3110c;
        if (i2 - i < 8) {
            return ((((long) readInt()) & 4294967295L) << 32) | (4294967295L & ((long) readInt()));
        }
        byte[] bArr = pVar.f3108a;
        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.f3076e = j - 8;
        if (i10 == i2) {
            this.f3075d = pVar.b();
            q.a(pVar);
        } else {
            pVar.f3109b = i10;
        }
        return j8;
    }

    @Override // f.e
    public short readShort() {
        long j = this.f3076e;
        if (j < 2) {
            throw new IllegalStateException("size < 2: " + this.f3076e);
        }
        p pVar = this.f3075d;
        int i = pVar.f3109b;
        int i2 = pVar.f3110c;
        if (i2 - i < 2) {
            return (short) (((readByte() & IMcuConstants.DEFAULT_VALUE) << 8) | (readByte() & IMcuConstants.DEFAULT_VALUE));
        }
        byte[] bArr = pVar.f3108a;
        int i3 = i + 1;
        int i4 = i3 + 1;
        int i5 = ((bArr[i] & IMcuConstants.DEFAULT_VALUE) << 8) | (bArr[i3] & IMcuConstants.DEFAULT_VALUE);
        this.f3076e = j - 2;
        if (i4 == i2) {
            this.f3075d = pVar.b();
            q.a(pVar);
        } else {
            pVar.f3109b = i4;
        }
        return (short) i5;
    }

    /* JADX WARN: Code restructure failed: missing block: B:18:0x003c, code lost:
    
        r1 = new f.c().K(r3).J(r15);
     */
    /* JADX WARN: Code restructure failed: missing block: B:19:0x0049, code lost:
    
        if (r8 != false) goto L21;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x004b, code lost:
    
        r1.readByte();
     */
    /* JADX WARN: Code restructure failed: missing block: B:22:0x0068, code lost:
    
        throw new java.lang.NumberFormatException("Number too large: " + r1.p());
     */
    /* JADX WARN: Removed duplicated region for block: B:33:0x009e  */
    /* JADX WARN: Removed duplicated region for block: B:34:0x00a8  */
    @Override // f.e
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public long s() {
        /*
            Method dump skipped, instruction units count: 203
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: f.c.s():long");
    }

    @Override // f.e
    public void skip(long j) throws EOFException {
        while (j > 0) {
            if (this.f3075d == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j, r0.f3110c - r0.f3109b);
            long j2 = iMin;
            this.f3076e -= j2;
            j -= j2;
            p pVar = this.f3075d;
            int i = pVar.f3109b + iMin;
            pVar.f3109b = i;
            if (i == pVar.f3110c) {
                this.f3075d = pVar.b();
                q.a(pVar);
            }
        }
    }

    public String t(long j) throws EOFException {
        return o(j, v.f3117a);
    }

    @Override // f.t
    public u timeout() {
        return u.NONE;
    }

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

    public int u() throws EOFException {
        int i;
        int i2;
        int i3;
        if (this.f3076e == 0) {
            throw new EOFException();
        }
        byte bI = i(0L);
        if ((bI & 128) == 0) {
            i = bI & 127;
            i3 = 0;
            i2 = 1;
        } else if ((bI & 224) == 192) {
            i = bI & SDKKeyboardCode.FUNCTION_KEY_BOARD_2;
            i2 = 2;
            i3 = 128;
        } else if ((bI & 240) == 224) {
            i = bI & SDKKeyboardCode.FUNCTION_KEY_BOARD_L;
            i2 = 3;
            i3 = 2048;
        } else {
            if ((bI & 248) != 240) {
                skip(1L);
                return 65533;
            }
            i = bI & 7;
            i2 = 4;
            i3 = 65536;
        }
        long j = i2;
        if (this.f3076e < j) {
            throw new EOFException("size < " + i2 + ": " + this.f3076e + " (to read code point prefixed 0x" + Integer.toHexString(bI) + ")");
        }
        for (int i4 = 1; i4 < i2; i4++) {
            long j2 = i4;
            byte bI2 = i(j2);
            if ((bI2 & 192) != 128) {
                skip(j2);
                return 65533;
            }
            i = (i << 6) | (bI2 & SDKKeyboardCode.FUNCTION_KEY_BOARD_F6);
        }
        skip(j);
        if (i > 1114111) {
            return 65533;
        }
        if ((i < 55296 || i > 57343) && i >= i3) {
            return i;
        }
        return 65533;
    }

    String v(long j) throws EOFException {
        if (j > 0) {
            long j2 = j - 1;
            if (i(j2) == 13) {
                String strT = t(j2);
                skip(2L);
                return strT;
            }
        }
        String strT2 = t(j);
        skip(1L);
        return strT2;
    }

    public String w(long j) throws EOFException {
        if (j < 0) {
            throw new IllegalArgumentException("limit < 0: " + j);
        }
        long j2 = j != Long.MAX_VALUE ? j + 1 : Long.MAX_VALUE;
        long jK = k((byte) 10, 0L, j2);
        if (jK != -1) {
            return v(jK);
        }
        if (j2 < x() && i(j2 - 1) == 13 && i(j2) == 10) {
            return v(j2);
        }
        c cVar = new c();
        g(cVar, 0L, Math.min(32L, x()));
        throw new EOFException("\\n not found: limit=" + Math.min(x(), j) + " content=" + cVar.n().j() + (char) 8230);
    }

    public long x() {
        return this.f3076e;
    }

    public f y() {
        long j = this.f3076e;
        if (j <= 2147483647L) {
            return A((int) j);
        }
        throw new IllegalArgumentException("size > Integer.MAX_VALUE: " + this.f3076e);
    }

    @Override // f.s
    public void write(c cVar, long j) {
        if (cVar == null) {
            throw new IllegalArgumentException("source == null");
        }
        if (cVar != this) {
            v.b(cVar.f3076e, 0L, j);
            while (j > 0) {
                p pVar = cVar.f3075d;
                if (j < pVar.f3110c - pVar.f3109b) {
                    p pVar2 = this.f3075d;
                    p pVar3 = pVar2 != null ? pVar2.f3114g : null;
                    if (pVar3 != null && pVar3.f3112e) {
                        if ((((long) pVar3.f3110c) + j) - ((long) (pVar3.f3111d ? 0 : pVar3.f3109b)) <= 8192) {
                            pVar.e(pVar3, (int) j);
                            cVar.f3076e -= j;
                            this.f3076e += j;
                            return;
                        }
                    }
                    cVar.f3075d = pVar.d((int) j);
                }
                p pVar4 = cVar.f3075d;
                long j2 = pVar4.f3110c - pVar4.f3109b;
                cVar.f3075d = pVar4.b();
                p pVar5 = this.f3075d;
                if (pVar5 == null) {
                    this.f3075d = pVar4;
                    pVar4.f3114g = pVar4;
                    pVar4.f3113f = pVar4;
                } else {
                    pVar5.f3114g.c(pVar4).a();
                }
                cVar.f3076e -= j2;
                this.f3076e += j2;
                j -= j2;
            }
            return;
        }
        throw new IllegalArgumentException("source == this");
    }

    @Override // f.t
    public long read(c cVar, long j) {
        if (cVar == null) {
            throw new IllegalArgumentException("sink == null");
        }
        if (j >= 0) {
            long j2 = this.f3076e;
            if (j2 == 0) {
                return -1L;
            }
            if (j > j2) {
                j = j2;
            }
            cVar.write(this, j);
            return j;
        }
        throw new IllegalArgumentException("byteCount < 0: " + j);
    }
}
