package p5;

import androidx.media3.extractor.ts.PsExtractor;
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 m1.AbstractC2464a;
import x4.AbstractC3250p;

/* JADX INFO: renamed from: p5.j, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C2740j implements InterfaceC2742l, InterfaceC2741k, Cloneable, ByteChannel {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public K f23099a;

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

    public final C2743m A(long j4) throws EOFException {
        if (j4 < 0 || j4 > 2147483647L) {
            throw new IllegalArgumentException(A0.a.m("byteCount: ", j4).toString());
        }
        if (this.f23100b < j4) {
            throw new EOFException();
        }
        if (j4 < 4096) {
            return new C2743m(z(j4));
        }
        C2743m c2743mL = L((int) j4);
        J(j4);
        return c2743mL;
    }

    /* JADX WARN: Code restructure failed: missing block: B:19:0x004b, code lost:
    
        r1 = new p5.C2740j();
        r1.R(r9);
        r1.Q(r4);
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0056, code lost:
    
        if (r12 != false) goto L22;
     */
    /* JADX WARN: Code restructure failed: missing block: B:21:0x0058, code lost:
    
        r1.y();
     */
    /* JADX WARN: Code restructure failed: missing block: B:23:0x006a, code lost:
    
        throw new java.lang.NumberFormatException("Number too large: ".concat(r1.H()));
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long B() throws EOFException {
        byte b5;
        long j4;
        int i6;
        byte b6 = 48;
        long j6 = 0;
        if (this.f23100b == 0) {
            throw new EOFException();
        }
        long j7 = -7;
        long j8 = 0;
        int i7 = 0;
        boolean z6 = false;
        boolean z7 = false;
        loop0: while (true) {
            K k6 = this.f23099a;
            kotlin.jvm.internal.o.e(k6);
            int i8 = k6.f23062b;
            int i9 = k6.f23063c;
            while (i8 < i9) {
                i6 = 1;
                byte b7 = k6.f23061a[i8];
                b5 = b6;
                if (b7 < b6 || b7 > 57) {
                    j4 = j6;
                    if (b7 != 45 || i7 != 0) {
                        z7 = true;
                        break;
                    }
                    j7--;
                    z6 = true;
                } else {
                    int i10 = 48 - b7;
                    if (j8 < -922337203685477580L) {
                        break loop0;
                    }
                    if (j8 == -922337203685477580L) {
                        j4 = j6;
                        if (i10 < j7) {
                            break loop0;
                        }
                    } else {
                        j4 = j6;
                    }
                    j8 = (j8 * 10) + ((long) i10);
                }
                i8++;
                i7++;
                b6 = b5;
                j6 = j4;
            }
            b5 = b6;
            j4 = j6;
            i6 = 1;
            if (i8 == i9) {
                this.f23099a = k6.a();
                L.a(k6);
            } else {
                k6.f23062b = i8;
            }
            if (z7 || this.f23099a == null) {
                break;
            }
            b6 = b5;
            j6 = j4;
        }
        long j9 = this.f23100b - ((long) i7);
        this.f23100b = j9;
        if (i7 >= (z6 ? 2 : i6)) {
            return z6 ? j8 : -j8;
        }
        if (j9 == j4) {
            throw new EOFException();
        }
        StringBuilder sbB = AbstractC2464a.b(z6 ? "Expected a digit" : "Expected a digit or '-'", " but was 0x");
        byte bF = f(j4);
        char[] cArr = q5.b.f23734a;
        char c6 = cArr[(bF >> 4) & 15];
        char c7 = cArr[bF & 15];
        char[] cArr2 = new char[2];
        cArr2[0] = c6;
        cArr2[i6] = c7;
        sbB.append(new String(cArr2));
        throw new NumberFormatException(sbB.toString());
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x0092  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x009c  */
    /* JADX WARN: Removed duplicated region for block: B:35:0x00a0  */
    /* JADX WARN: Removed duplicated region for block: B:43:0x00a4 A[EDGE_INSN: B:43:0x00a4->B:37:0x00a4 BREAK  A[LOOP:0: B:5:0x0012->B:45:?], SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final long C() throws EOFException {
        int i6;
        if (this.f23100b == 0) {
            throw new EOFException();
        }
        int i7 = 0;
        boolean z6 = false;
        long j4 = 0;
        do {
            K k6 = this.f23099a;
            kotlin.jvm.internal.o.e(k6);
            int i8 = k6.f23062b;
            int i9 = k6.f23063c;
            while (i8 < i9) {
                byte b5 = k6.f23061a[i8];
                if (b5 >= 48 && b5 <= 57) {
                    i6 = b5 - 48;
                } else if (b5 >= 97 && b5 <= 102) {
                    i6 = b5 - 87;
                } else if (b5 >= 65 && b5 <= 70) {
                    i6 = b5 - 55;
                } else {
                    if (i7 == 0) {
                        char[] cArr = q5.b.f23734a;
                        throw new NumberFormatException("Expected leading [0-9a-fA-F] character but was 0x".concat(new String(new char[]{cArr[(b5 >> 4) & 15], cArr[b5 & 15]})));
                    }
                    z6 = true;
                    if (i8 != i9) {
                        this.f23099a = k6.a();
                        L.a(k6);
                    } else {
                        k6.f23062b = i8;
                    }
                    if (!z6) {
                        break;
                    }
                }
                if ((j4 & (-1152921504606846976L)) != 0) {
                    C2740j c2740j = new C2740j();
                    c2740j.S(j4);
                    c2740j.Q(b5);
                    throw new NumberFormatException("Number too large: ".concat(c2740j.H()));
                }
                j4 = (j4 << 4) | ((long) i6);
                i8++;
                i7++;
            }
            if (i8 != i9) {
            }
            if (!z6) {
            }
        } while (this.f23099a != null);
        this.f23100b -= (long) i7;
        return j4;
    }

    public final int D() throws EOFException {
        if (this.f23100b < 4) {
            throw new EOFException();
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        int i6 = k6.f23062b;
        int i7 = k6.f23063c;
        if (i7 - i6 < 4) {
            return ((y() & 255) << 24) | ((y() & 255) << 16) | ((y() & 255) << 8) | (y() & 255);
        }
        byte[] bArr = k6.f23061a;
        int i8 = i6 + 3;
        int i9 = ((bArr[i6 + 1] & 255) << 16) | ((bArr[i6] & 255) << 24) | ((bArr[i6 + 2] & 255) << 8);
        int i10 = i6 + 4;
        int i11 = i9 | (bArr[i8] & 255);
        this.f23100b -= 4;
        if (i10 != i7) {
            k6.f23062b = i10;
            return i11;
        }
        this.f23099a = k6.a();
        L.a(k6);
        return i11;
    }

    public final short E() throws EOFException {
        if (this.f23100b < 2) {
            throw new EOFException();
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        int i6 = k6.f23062b;
        int i7 = k6.f23063c;
        if (i7 - i6 < 2) {
            return (short) (((y() & 255) << 8) | (y() & 255));
        }
        int i8 = i6 + 1;
        byte[] bArr = k6.f23061a;
        int i9 = (bArr[i6] & 255) << 8;
        int i10 = i6 + 2;
        int i11 = (bArr[i8] & 255) | i9;
        this.f23100b -= 2;
        if (i10 == i7) {
            this.f23099a = k6.a();
            L.a(k6);
        } else {
            k6.f23062b = i10;
        }
        return (short) i11;
    }

    public final short F() throws EOFException {
        short sE = E();
        return (short) (((sE & 255) << 8) | ((65280 & sE) >>> 8));
    }

    public final String G(long j4, Charset charset) throws EOFException {
        kotlin.jvm.internal.o.h(charset, "charset");
        if (j4 < 0 || j4 > 2147483647L) {
            throw new IllegalArgumentException(A0.a.m("byteCount: ", j4).toString());
        }
        if (this.f23100b < j4) {
            throw new EOFException();
        }
        if (j4 == 0) {
            return "";
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        int i6 = k6.f23062b;
        if (((long) i6) + j4 > k6.f23063c) {
            return new String(z(j4), charset);
        }
        int i7 = (int) j4;
        String str = new String(k6.f23061a, i6, i7, charset);
        int i8 = k6.f23062b + i7;
        k6.f23062b = i8;
        this.f23100b -= j4;
        if (i8 == k6.f23063c) {
            this.f23099a = k6.a();
            L.a(k6);
        }
        return str;
    }

    public final String H() {
        return G(this.f23100b, S4.a.f6257a);
    }

    public final String I(long j4) throws EOFException {
        if (j4 < 0) {
            throw new IllegalArgumentException(A0.a.m("limit < 0: ", j4).toString());
        }
        long j6 = j4 != Long.MAX_VALUE ? j4 + 1 : Long.MAX_VALUE;
        long jK = k((byte) 10, 0L, j6);
        if (jK != -1) {
            return q5.a.a(this, jK);
        }
        if (j6 < this.f23100b && f(j6 - 1) == 13 && f(j6) == 10) {
            return q5.a.a(this, j6);
        }
        C2740j c2740j = new C2740j();
        c(c2740j, 0L, Math.min(32, this.f23100b));
        throw new EOFException("\\n not found: limit=" + Math.min(this.f23100b, j4) + " content=" + c2740j.A(c2740j.f23100b).e() + (char) 8230);
    }

    public final void J(long j4) throws EOFException {
        while (j4 > 0) {
            K k6 = this.f23099a;
            if (k6 == null) {
                throw new EOFException();
            }
            int iMin = (int) Math.min(j4, k6.f23063c - k6.f23062b);
            long j6 = iMin;
            this.f23100b -= j6;
            j4 -= j6;
            int i6 = k6.f23062b + iMin;
            k6.f23062b = i6;
            if (i6 == k6.f23063c) {
                this.f23099a = k6.a();
                L.a(k6);
            }
        }
    }

    public final C2743m K() {
        long j4 = this.f23100b;
        if (j4 <= 2147483647L) {
            return L((int) j4);
        }
        throw new IllegalStateException(("size > Int.MAX_VALUE: " + this.f23100b).toString());
    }

    public final C2743m L(int i6) {
        if (i6 == 0) {
            return C2743m.f23101d;
        }
        AbstractC2732b.e(this.f23100b, 0L, i6);
        K k6 = this.f23099a;
        int i7 = 0;
        int i8 = 0;
        int i9 = 0;
        while (i8 < i6) {
            kotlin.jvm.internal.o.e(k6);
            int i10 = k6.f23063c;
            int i11 = k6.f23062b;
            if (i10 == i11) {
                throw new AssertionError("s.limit == s.pos");
            }
            i8 += i10 - i11;
            i9++;
            k6 = k6.f23066f;
        }
        byte[][] bArr = new byte[i9][];
        int[] iArr = new int[i9 * 2];
        K k7 = this.f23099a;
        int i12 = 0;
        while (i7 < i6) {
            kotlin.jvm.internal.o.e(k7);
            bArr[i12] = k7.f23061a;
            i7 += k7.f23063c - k7.f23062b;
            iArr[i12] = Math.min(i7, i6);
            iArr[i12 + i9] = k7.f23062b;
            k7.f23064d = true;
            i12++;
            k7 = k7.f23066f;
        }
        return new M(bArr, iArr);
    }

    public final K M(int i6) {
        if (i6 < 1 || i6 > 8192) {
            throw new IllegalArgumentException("unexpected capacity");
        }
        K k6 = this.f23099a;
        if (k6 == null) {
            K kB = L.b();
            this.f23099a = kB;
            kB.f23067g = kB;
            kB.f23066f = kB;
            return kB;
        }
        K k7 = k6.f23067g;
        kotlin.jvm.internal.o.e(k7);
        if (k7.f23063c + i6 <= 8192 && k7.f23065e) {
            return k7;
        }
        K kB2 = L.b();
        k7.b(kB2);
        return kB2;
    }

    public final void N(C2743m byteString) {
        kotlin.jvm.internal.o.h(byteString, "byteString");
        byteString.u(this, byteString.d());
    }

    public final void O(byte[] source) {
        kotlin.jvm.internal.o.h(source, "source");
        P(source, 0, source.length);
    }

    public final void P(byte[] source, int i6, int i7) {
        kotlin.jvm.internal.o.h(source, "source");
        long j4 = i7;
        AbstractC2732b.e(source.length, i6, j4);
        int i8 = i7 + i6;
        while (i6 < i8) {
            K kM = M(1);
            int iMin = Math.min(i8 - i6, 8192 - kM.f23063c);
            int i9 = i6 + iMin;
            AbstractC3250p.y(source, kM.f23063c, i6, kM.f23061a, i9);
            kM.f23063c += iMin;
            i6 = i9;
        }
        this.f23100b += j4;
    }

    public final void Q(int i6) {
        K kM = M(1);
        int i7 = kM.f23063c;
        kM.f23063c = i7 + 1;
        kM.f23061a[i7] = (byte) i6;
        this.f23100b++;
    }

    public final void R(long j4) {
        boolean z6;
        byte[] bArr;
        if (j4 == 0) {
            Q(48);
            return;
        }
        if (j4 < 0) {
            j4 = -j4;
            if (j4 < 0) {
                W("-9223372036854775808");
                return;
            }
            z6 = true;
        } else {
            z6 = false;
        }
        byte[] bArr2 = q5.a.f23732a;
        int iNumberOfLeadingZeros = ((64 - Long.numberOfLeadingZeros(j4)) * 10) >>> 5;
        int i6 = iNumberOfLeadingZeros + (j4 > q5.a.f23733b[iNumberOfLeadingZeros] ? 1 : 0);
        if (z6) {
            i6++;
        }
        K kM = M(i6);
        int i7 = kM.f23063c + i6;
        while (true) {
            bArr = kM.f23061a;
            if (j4 == 0) {
                break;
            }
            long j6 = 10;
            i7--;
            bArr[i7] = q5.a.f23732a[(int) (j4 % j6)];
            j4 /= j6;
        }
        if (z6) {
            bArr[i7 - 1] = 45;
        }
        kM.f23063c += i6;
        this.f23100b += (long) i6;
    }

    public final void S(long j4) {
        if (j4 == 0) {
            Q(48);
            return;
        }
        long j6 = (j4 >>> 1) | j4;
        long j7 = j6 | (j6 >>> 2);
        long j8 = j7 | (j7 >>> 4);
        long j9 = j8 | (j8 >>> 8);
        long j10 = j9 | (j9 >>> 16);
        long j11 = j10 | (j10 >>> 32);
        long j12 = j11 - ((j11 >>> 1) & 6148914691236517205L);
        long j13 = ((j12 >>> 2) & 3689348814741910323L) + (j12 & 3689348814741910323L);
        long j14 = ((j13 >>> 4) + j13) & 1085102592571150095L;
        long j15 = j14 + (j14 >>> 8);
        long j16 = j15 + (j15 >>> 16);
        int i6 = (int) ((((j16 & 63) + ((j16 >>> 32) & 63)) + ((long) 3)) / ((long) 4));
        K kM = M(i6);
        int i7 = kM.f23063c;
        for (int i8 = (i7 + i6) - 1; i8 >= i7; i8--) {
            kM.f23061a[i8] = q5.a.f23732a[(int) (15 & j4)];
            j4 >>>= 4;
        }
        kM.f23063c += i6;
        this.f23100b += (long) i6;
    }

    public final void T(int i6) {
        K kM = M(4);
        int i7 = kM.f23063c;
        byte[] bArr = kM.f23061a;
        bArr[i7] = (byte) ((i6 >>> 24) & 255);
        bArr[i7 + 1] = (byte) ((i6 >>> 16) & 255);
        bArr[i7 + 2] = (byte) ((i6 >>> 8) & 255);
        bArr[i7 + 3] = (byte) (i6 & 255);
        kM.f23063c = i7 + 4;
        this.f23100b += 4;
    }

    public final void U(OutputStream out, long j4) throws IOException {
        kotlin.jvm.internal.o.h(out, "out");
        AbstractC2732b.e(this.f23100b, 0L, j4);
        K k6 = this.f23099a;
        long j6 = j4;
        while (j6 > 0) {
            kotlin.jvm.internal.o.e(k6);
            int iMin = (int) Math.min(j6, k6.f23063c - k6.f23062b);
            out.write(k6.f23061a, k6.f23062b, iMin);
            int i6 = k6.f23062b + iMin;
            k6.f23062b = i6;
            long j7 = iMin;
            this.f23100b -= j7;
            j6 -= j7;
            if (i6 == k6.f23063c) {
                K kA = k6.a();
                this.f23099a = kA;
                L.a(k6);
                k6 = kA;
            }
        }
    }

    public final void V(int i6, int i7, String string) {
        char cCharAt;
        kotlin.jvm.internal.o.h(string, "string");
        if (i6 < 0) {
            throw new IllegalArgumentException(Z0.o.l("beginIndex < 0: ", i6).toString());
        }
        if (i7 < i6) {
            throw new IllegalArgumentException(com.google.android.recaptcha.internal.a.i(i7, i6, "endIndex < beginIndex: ", " < ").toString());
        }
        if (i7 > string.length()) {
            StringBuilder sbR = com.google.android.recaptcha.internal.a.r(i7, "endIndex > string.length: ", " > ");
            sbR.append(string.length());
            throw new IllegalArgumentException(sbR.toString().toString());
        }
        while (i6 < i7) {
            char cCharAt2 = string.charAt(i6);
            if (cCharAt2 < 128) {
                K kM = M(1);
                int i8 = kM.f23063c - i6;
                int iMin = Math.min(i7, 8192 - i8);
                int i9 = i6 + 1;
                byte[] bArr = kM.f23061a;
                bArr[i6 + i8] = (byte) cCharAt2;
                while (true) {
                    i6 = i9;
                    if (i6 >= iMin || (cCharAt = string.charAt(i6)) >= 128) {
                        break;
                    }
                    i9 = i6 + 1;
                    bArr[i6 + i8] = (byte) cCharAt;
                }
                int i10 = kM.f23063c;
                int i11 = (i8 + i6) - i10;
                kM.f23063c = i10 + i11;
                this.f23100b += (long) i11;
            } else {
                if (cCharAt2 < 2048) {
                    K kM2 = M(2);
                    int i12 = kM2.f23063c;
                    byte b5 = (byte) ((cCharAt2 >> 6) | PsExtractor.AUDIO_STREAM);
                    byte[] bArr2 = kM2.f23061a;
                    bArr2[i12] = b5;
                    bArr2[i12 + 1] = (byte) ((cCharAt2 & '?') | 128);
                    kM2.f23063c = i12 + 2;
                    this.f23100b += 2;
                } else if (cCharAt2 < 55296 || cCharAt2 > 57343) {
                    K kM3 = M(3);
                    int i13 = kM3.f23063c;
                    byte[] bArr3 = kM3.f23061a;
                    bArr3[i13] = (byte) ((cCharAt2 >> '\f') | 224);
                    bArr3[i13 + 1] = (byte) ((63 & (cCharAt2 >> 6)) | 128);
                    bArr3[i13 + 2] = (byte) ((cCharAt2 & '?') | 128);
                    kM3.f23063c = i13 + 3;
                    this.f23100b += 3;
                } else {
                    int i14 = i6 + 1;
                    char cCharAt3 = i14 < i7 ? string.charAt(i14) : (char) 0;
                    if (cCharAt2 > 56319 || 56320 > cCharAt3 || cCharAt3 >= 57344) {
                        Q(63);
                        i6 = i14;
                    } else {
                        int i15 = (((cCharAt2 & 1023) << 10) | (cCharAt3 & 1023)) + androidx.media3.common.C.DEFAULT_BUFFER_SEGMENT_SIZE;
                        K kM4 = M(4);
                        int i16 = kM4.f23063c;
                        byte b6 = (byte) ((i15 >> 18) | PsExtractor.VIDEO_STREAM_MASK);
                        byte[] bArr4 = kM4.f23061a;
                        bArr4[i16] = b6;
                        bArr4[i16 + 1] = (byte) (((i15 >> 12) & 63) | 128);
                        bArr4[i16 + 2] = (byte) (((i15 >> 6) & 63) | 128);
                        bArr4[i16 + 3] = (byte) ((i15 & 63) | 128);
                        kM4.f23063c = i16 + 4;
                        this.f23100b += 4;
                        i6 += 2;
                    }
                }
                i6++;
            }
        }
    }

    public final void W(String string) {
        kotlin.jvm.internal.o.h(string, "string");
        V(0, string.length(), string);
    }

    public final void X(int i6) {
        if (i6 < 128) {
            Q(i6);
            return;
        }
        if (i6 < 2048) {
            K kM = M(2);
            int i7 = kM.f23063c;
            byte b5 = (byte) ((i6 >> 6) | PsExtractor.AUDIO_STREAM);
            byte[] bArr = kM.f23061a;
            bArr[i7] = b5;
            bArr[i7 + 1] = (byte) ((i6 & 63) | 128);
            kM.f23063c = i7 + 2;
            this.f23100b += 2;
            return;
        }
        if (55296 <= i6 && i6 < 57344) {
            Q(63);
            return;
        }
        if (i6 < 65536) {
            K kM2 = M(3);
            int i8 = kM2.f23063c;
            byte[] bArr2 = kM2.f23061a;
            bArr2[i8] = (byte) ((i6 >> 12) | 224);
            bArr2[i8 + 1] = (byte) (((i6 >> 6) & 63) | 128);
            bArr2[i8 + 2] = (byte) ((i6 & 63) | 128);
            kM2.f23063c = i8 + 3;
            this.f23100b += 3;
            return;
        }
        if (i6 > 1114111) {
            throw new IllegalArgumentException("Unexpected code point: 0x".concat(AbstractC2732b.m(i6)));
        }
        K kM3 = M(4);
        int i9 = kM3.f23063c;
        byte b6 = (byte) ((i6 >> 18) | PsExtractor.VIDEO_STREAM_MASK);
        byte[] bArr3 = kM3.f23061a;
        bArr3[i9] = b6;
        bArr3[i9 + 1] = (byte) (((i6 >> 12) & 63) | 128);
        bArr3[i9 + 2] = (byte) (((i6 >> 6) & 63) | 128);
        bArr3[i9 + 3] = (byte) ((i6 & 63) | 128);
        kM3.f23063c = i9 + 4;
        this.f23100b += 4;
    }

    public final void a() throws EOFException {
        J(this.f23100b);
    }

    public final long b() {
        long j4 = this.f23100b;
        if (j4 == 0) {
            return 0L;
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        K k7 = k6.f23067g;
        kotlin.jvm.internal.o.e(k7);
        int i6 = k7.f23063c;
        return (i6 >= 8192 || !k7.f23065e) ? j4 : j4 - ((long) (i6 - k7.f23062b));
    }

    public final void c(C2740j out, long j4, long j6) {
        kotlin.jvm.internal.o.h(out, "out");
        long j7 = j4;
        AbstractC2732b.e(this.f23100b, j7, j6);
        if (j6 == 0) {
            return;
        }
        out.f23100b += j6;
        K k6 = this.f23099a;
        while (true) {
            kotlin.jvm.internal.o.e(k6);
            long j8 = k6.f23063c - k6.f23062b;
            if (j7 < j8) {
                break;
            }
            j7 -= j8;
            k6 = k6.f23066f;
        }
        K k7 = k6;
        long j9 = j6;
        while (j9 > 0) {
            kotlin.jvm.internal.o.e(k7);
            K kC = k7.c();
            int i6 = kC.f23062b + ((int) j7);
            kC.f23062b = i6;
            kC.f23063c = Math.min(i6 + ((int) j9), kC.f23063c);
            K k8 = out.f23099a;
            if (k8 == null) {
                kC.f23067g = kC;
                kC.f23066f = kC;
                out.f23099a = kC;
            } else {
                K k9 = k8.f23067g;
                kotlin.jvm.internal.o.e(k9);
                k9.b(kC);
            }
            j9 -= (long) (kC.f23063c - kC.f23062b);
            k7 = k7.f23066f;
            j7 = 0;
        }
    }

    public final Object clone() {
        C2740j c2740j = new C2740j();
        if (this.f23100b == 0) {
            return c2740j;
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        K kC = k6.c();
        c2740j.f23099a = kC;
        kC.f23067g = kC;
        kC.f23066f = kC;
        for (K k7 = k6.f23066f; k7 != k6; k7 = k7.f23066f) {
            K k8 = kC.f23067g;
            kotlin.jvm.internal.o.e(k8);
            kotlin.jvm.internal.o.e(k7);
            k8.b(k7.c());
        }
        c2740j.f23100b = this.f23100b;
        return c2740j;
    }

    public final boolean d() {
        return this.f23100b == 0;
    }

    public final boolean equals(Object obj) {
        boolean z6 = true;
        if (this == obj) {
            return true;
        }
        boolean z7 = false;
        if (!(obj instanceof C2740j)) {
            return false;
        }
        long j4 = this.f23100b;
        C2740j c2740j = (C2740j) obj;
        if (j4 != c2740j.f23100b) {
            return false;
        }
        if (j4 == 0) {
            return true;
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        K k7 = c2740j.f23099a;
        kotlin.jvm.internal.o.e(k7);
        int i6 = k6.f23062b;
        int i7 = k7.f23062b;
        long j6 = 0;
        while (j6 < this.f23100b) {
            long jMin = Math.min(k6.f23063c - i6, k7.f23063c - i7);
            long j7 = 0;
            while (j7 < jMin) {
                int i8 = i6 + 1;
                boolean z8 = z6;
                byte b5 = k6.f23061a[i6];
                int i9 = i7 + 1;
                boolean z9 = z7;
                if (b5 != k7.f23061a[i7]) {
                    return z9;
                }
                j7++;
                i7 = i9;
                i6 = i8;
                z6 = z8;
                z7 = z9;
            }
            boolean z10 = z6;
            boolean z11 = z7;
            if (i6 == k6.f23063c) {
                K k8 = k6.f23066f;
                kotlin.jvm.internal.o.e(k8);
                i6 = k8.f23062b;
                k6 = k8;
            }
            if (i7 == k7.f23063c) {
                k7 = k7.f23066f;
                kotlin.jvm.internal.o.e(k7);
                i7 = k7.f23062b;
            }
            j6 += jMin;
            z6 = z10;
            z7 = z11;
        }
        return z6;
    }

    public final byte f(long j4) {
        AbstractC2732b.e(this.f23100b, j4, 1L);
        K k6 = this.f23099a;
        if (k6 == null) {
            kotlin.jvm.internal.o.e(null);
            throw null;
        }
        long j6 = this.f23100b;
        if (j6 - j4 < j4) {
            while (j6 > j4) {
                k6 = k6.f23067g;
                kotlin.jvm.internal.o.e(k6);
                j6 -= (long) (k6.f23063c - k6.f23062b);
            }
            return k6.f23061a[(int) ((((long) k6.f23062b) + j4) - j6)];
        }
        long j7 = 0;
        while (true) {
            int i6 = k6.f23063c;
            int i7 = k6.f23062b;
            long j8 = ((long) (i6 - i7)) + j7;
            if (j8 > j4) {
                return k6.f23061a[(int) ((((long) i7) + j4) - j7)];
            }
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
            j7 = j8;
        }
    }

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k h(int i6) {
        Q(i6);
        return this;
    }

    public final int hashCode() {
        K k6 = this.f23099a;
        if (k6 == null) {
            return 0;
        }
        int i6 = 1;
        do {
            int i7 = k6.f23063c;
            for (int i8 = k6.f23062b; i8 < i7; i8++) {
                i6 = (i6 * 31) + k6.f23061a[i8];
            }
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
        } while (k6 != this.f23099a);
        return i6;
    }

    public final long i(C2743m targetBytes) {
        int i6;
        int i7;
        kotlin.jvm.internal.o.h(targetBytes, "targetBytes");
        K k6 = this.f23099a;
        if (k6 == null) {
            return -1L;
        }
        long j4 = this.f23100b;
        long j6 = 0;
        byte[] bArr = targetBytes.f23102a;
        if (j4 < 0) {
            while (j4 > 0) {
                k6 = k6.f23067g;
                kotlin.jvm.internal.o.e(k6);
                j4 -= (long) (k6.f23063c - k6.f23062b);
            }
            if (bArr.length == 2) {
                byte b5 = bArr[0];
                byte b6 = bArr[1];
                while (j4 < this.f23100b) {
                    i6 = (int) ((((long) k6.f23062b) + j6) - j4);
                    int i8 = k6.f23063c;
                    while (i6 < i8) {
                        byte b7 = k6.f23061a[i6];
                        if (b7 == b5 || b7 == b6) {
                            i7 = k6.f23062b;
                        } else {
                            i6++;
                        }
                    }
                    j6 = ((long) (k6.f23063c - k6.f23062b)) + j4;
                    k6 = k6.f23066f;
                    kotlin.jvm.internal.o.e(k6);
                    j4 = j6;
                }
                return -1L;
            }
            while (j4 < this.f23100b) {
                i6 = (int) ((((long) k6.f23062b) + j6) - j4);
                int i9 = k6.f23063c;
                while (i6 < i9) {
                    byte b8 = k6.f23061a[i6];
                    for (byte b9 : bArr) {
                        if (b8 == b9) {
                            i7 = k6.f23062b;
                        }
                    }
                    i6++;
                }
                j6 = ((long) (k6.f23063c - k6.f23062b)) + j4;
                k6 = k6.f23066f;
                kotlin.jvm.internal.o.e(k6);
                j4 = j6;
            }
            return -1L;
        }
        j4 = 0;
        while (true) {
            long j7 = ((long) (k6.f23063c - k6.f23062b)) + j4;
            if (j7 > 0) {
                break;
            }
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
            j4 = j7;
        }
        if (bArr.length == 2) {
            byte b10 = bArr[0];
            byte b11 = bArr[1];
            while (j4 < this.f23100b) {
                i6 = (int) ((((long) k6.f23062b) + j6) - j4);
                int i10 = k6.f23063c;
                while (i6 < i10) {
                    byte b12 = k6.f23061a[i6];
                    if (b12 == b10 || b12 == b11) {
                        i7 = k6.f23062b;
                    } else {
                        i6++;
                    }
                }
                j6 = ((long) (k6.f23063c - k6.f23062b)) + j4;
                k6 = k6.f23066f;
                kotlin.jvm.internal.o.e(k6);
                j4 = j6;
            }
            return -1L;
        }
        while (j4 < this.f23100b) {
            i6 = (int) ((((long) k6.f23062b) + j6) - j4);
            int i11 = k6.f23063c;
            while (i6 < i11) {
                byte b13 = k6.f23061a[i6];
                for (byte b14 : bArr) {
                    if (b13 == b14) {
                        i7 = k6.f23062b;
                    }
                }
                i6++;
            }
            j6 = ((long) (k6.f23063c - k6.f23062b)) + j4;
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
            j4 = j6;
        }
        return -1L;
        return ((long) (i6 - i7)) + j4;
    }

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

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k j(C2743m c2743m) {
        N(c2743m);
        return this;
    }

    @Override // p5.InterfaceC2742l
    public final long k(byte b5, long j4, long j6) {
        K k6;
        long j7 = 0;
        if (0 > j4 || j4 > j6) {
            throw new IllegalArgumentException(("size=" + this.f23100b + " fromIndex=" + j4 + " toIndex=" + j6).toString());
        }
        long j8 = this.f23100b;
        if (j6 > j8) {
            j6 = j8;
        }
        if (j4 == j6 || (k6 = this.f23099a) == null) {
            return -1L;
        }
        if (j8 - j4 < j4) {
            while (j8 > j4) {
                k6 = k6.f23067g;
                kotlin.jvm.internal.o.e(k6);
                j8 -= (long) (k6.f23063c - k6.f23062b);
            }
            while (j8 < j6) {
                int iMin = (int) Math.min(k6.f23063c, (((long) k6.f23062b) + j6) - j8);
                for (int i6 = (int) ((((long) k6.f23062b) + j4) - j8); i6 < iMin; i6++) {
                    if (k6.f23061a[i6] == b5) {
                        return ((long) (i6 - k6.f23062b)) + j8;
                    }
                }
                j8 += (long) (k6.f23063c - k6.f23062b);
                k6 = k6.f23066f;
                kotlin.jvm.internal.o.e(k6);
                j4 = j8;
            }
            return -1L;
        }
        while (true) {
            long j9 = ((long) (k6.f23063c - k6.f23062b)) + j7;
            if (j9 > j4) {
                break;
            }
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
            j7 = j9;
        }
        while (j7 < j6) {
            int iMin2 = (int) Math.min(k6.f23063c, (((long) k6.f23062b) + j6) - j7);
            for (int i7 = (int) ((((long) k6.f23062b) + j4) - j7); i7 < iMin2; i7++) {
                if (k6.f23061a[i7] == b5) {
                    return ((long) (i7 - k6.f23062b)) + j7;
                }
            }
            j7 += (long) (k6.f23063c - k6.f23062b);
            k6 = k6.f23066f;
            kotlin.jvm.internal.o.e(k6);
            j4 = j7;
        }
        return -1L;
    }

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k l(byte[] bArr, int i6) {
        P(bArr, 0, i6);
        return this;
    }

    @Override // p5.InterfaceC2742l
    public final int m(F options) throws EOFException {
        kotlin.jvm.internal.o.h(options, "options");
        int iB = q5.a.b(this, options, false);
        if (iB == -1) {
            return -1;
        }
        J(options.f23045a[iB].d());
        return iB;
    }

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k n(String str) {
        W(str);
        return this;
    }

    @Override // p5.InterfaceC2742l
    public final String o(Charset charset) {
        kotlin.jvm.internal.o.h(charset, "charset");
        return G(this.f23100b, charset);
    }

    @Override // p5.InterfaceC2742l
    public final boolean p(long j4) {
        return this.f23100b >= j4;
    }

    @Override // p5.InterfaceC2742l
    public final J peek() {
        return AbstractC2732b.c(new H(this));
    }

    @Override // p5.InterfaceC2741k
    public final long q(P source) {
        kotlin.jvm.internal.o.h(source, "source");
        long j4 = 0;
        while (true) {
            long j6 = source.read(this, 8192L);
            if (j6 == -1) {
                return j4;
            }
            j4 += j6;
        }
    }

    @Override // p5.InterfaceC2742l
    public final boolean r(long j4, C2743m bytes) {
        kotlin.jvm.internal.o.h(bytes, "bytes");
        int iD = bytes.d();
        if (j4 >= 0 && iD >= 0 && this.f23100b - j4 >= iD && bytes.d() >= iD) {
            for (int i6 = 0; i6 < iD; i6++) {
                if (f(((long) i6) + j4) == bytes.i(i6)) {
                }
            }
            return true;
        }
        return false;
    }

    @Override // p5.P
    public final long read(C2740j sink, long j4) {
        kotlin.jvm.internal.o.h(sink, "sink");
        if (j4 < 0) {
            throw new IllegalArgumentException(A0.a.m("byteCount < 0: ", j4).toString());
        }
        long j6 = this.f23100b;
        if (j6 == 0) {
            return -1L;
        }
        if (j4 > j6) {
            j4 = j6;
        }
        sink.write(this, j4);
        return j4;
    }

    @Override // p5.InterfaceC2742l
    public final String s() {
        return I(Long.MAX_VALUE);
    }

    public final int t(byte[] sink, int i6, int i7) {
        kotlin.jvm.internal.o.h(sink, "sink");
        AbstractC2732b.e(sink.length, i6, i7);
        K k6 = this.f23099a;
        if (k6 == null) {
            return -1;
        }
        int iMin = Math.min(i7, k6.f23063c - k6.f23062b);
        int i8 = k6.f23062b;
        AbstractC3250p.y(k6.f23061a, i6, i8, sink, i8 + iMin);
        int i9 = k6.f23062b + iMin;
        k6.f23062b = i9;
        this.f23100b -= (long) iMin;
        if (i9 == k6.f23063c) {
            this.f23099a = k6.a();
            L.a(k6);
        }
        return iMin;
    }

    @Override // p5.P
    public final S timeout() {
        return S.f23074d;
    }

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

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k u(byte[] bArr) {
        O(bArr);
        return this;
    }

    @Override // p5.InterfaceC2742l
    public final long v(I i6) {
        long j4 = this.f23100b;
        if (j4 > 0) {
            i6.write(this, j4);
        }
        return j4;
    }

    @Override // p5.InterfaceC2741k
    public final /* bridge */ /* synthetic */ InterfaceC2741k w(long j4) {
        R(j4);
        return this;
    }

    @Override // p5.N
    public final void write(C2740j source, long j4) {
        K kB;
        kotlin.jvm.internal.o.h(source, "source");
        if (source == this) {
            throw new IllegalArgumentException("source == this");
        }
        AbstractC2732b.e(source.f23100b, 0L, j4);
        while (j4 > 0) {
            K k6 = source.f23099a;
            kotlin.jvm.internal.o.e(k6);
            int i6 = k6.f23063c;
            K k7 = source.f23099a;
            kotlin.jvm.internal.o.e(k7);
            long j6 = i6 - k7.f23062b;
            int i7 = 0;
            if (j4 < j6) {
                K k8 = this.f23099a;
                K k9 = k8 != null ? k8.f23067g : null;
                if (k9 != null && k9.f23065e) {
                    if ((((long) k9.f23063c) + j4) - ((long) (k9.f23064d ? 0 : k9.f23062b)) <= 8192) {
                        K k10 = source.f23099a;
                        kotlin.jvm.internal.o.e(k10);
                        k10.d(k9, (int) j4);
                        source.f23100b -= j4;
                        this.f23100b += j4;
                        return;
                    }
                }
                K k11 = source.f23099a;
                kotlin.jvm.internal.o.e(k11);
                int i8 = (int) j4;
                if (i8 <= 0 || i8 > k11.f23063c - k11.f23062b) {
                    throw new IllegalArgumentException("byteCount out of range");
                }
                if (i8 >= 1024) {
                    kB = k11.c();
                } else {
                    kB = L.b();
                    int i9 = k11.f23062b;
                    AbstractC3250p.y(k11.f23061a, 0, i9, kB.f23061a, i9 + i8);
                }
                kB.f23063c = kB.f23062b + i8;
                k11.f23062b += i8;
                K k12 = k11.f23067g;
                kotlin.jvm.internal.o.e(k12);
                k12.b(kB);
                source.f23099a = kB;
            }
            K k13 = source.f23099a;
            kotlin.jvm.internal.o.e(k13);
            long j7 = k13.f23063c - k13.f23062b;
            source.f23099a = k13.a();
            K k14 = this.f23099a;
            if (k14 == null) {
                this.f23099a = k13;
                k13.f23067g = k13;
                k13.f23066f = k13;
            } else {
                K k15 = k14.f23067g;
                kotlin.jvm.internal.o.e(k15);
                k15.b(k13);
                K k16 = k13.f23067g;
                if (k16 == k13) {
                    throw new IllegalStateException("cannot compact");
                }
                kotlin.jvm.internal.o.e(k16);
                if (k16.f23065e) {
                    int i10 = k13.f23063c - k13.f23062b;
                    K k17 = k13.f23067g;
                    kotlin.jvm.internal.o.e(k17);
                    int i11 = 8192 - k17.f23063c;
                    K k18 = k13.f23067g;
                    kotlin.jvm.internal.o.e(k18);
                    if (!k18.f23064d) {
                        K k19 = k13.f23067g;
                        kotlin.jvm.internal.o.e(k19);
                        i7 = k19.f23062b;
                    }
                    if (i10 <= i11 + i7) {
                        K k20 = k13.f23067g;
                        kotlin.jvm.internal.o.e(k20);
                        k13.d(k20, i10);
                        k13.a();
                        L.a(k13);
                    }
                }
            }
            source.f23100b -= j7;
            this.f23100b += j7;
            j4 -= j7;
        }
    }

    @Override // p5.InterfaceC2742l
    public final InputStream x() {
        return new C2739i(this, 0);
    }

    public final byte y() throws EOFException {
        if (this.f23100b == 0) {
            throw new EOFException();
        }
        K k6 = this.f23099a;
        kotlin.jvm.internal.o.e(k6);
        int i6 = k6.f23062b;
        int i7 = k6.f23063c;
        int i8 = i6 + 1;
        byte b5 = k6.f23061a[i6];
        this.f23100b--;
        if (i8 != i7) {
            k6.f23062b = i8;
            return b5;
        }
        this.f23099a = k6.a();
        L.a(k6);
        return b5;
    }

    public final byte[] z(long j4) throws EOFException {
        if (j4 < 0 || j4 > 2147483647L) {
            throw new IllegalArgumentException(A0.a.m("byteCount: ", j4).toString());
        }
        if (this.f23100b < j4) {
            throw new EOFException();
        }
        byte[] sink = new byte[(int) j4];
        kotlin.jvm.internal.o.h(sink, "sink");
        int i6 = 0;
        while (i6 < sink.length) {
            int iT = t(sink, i6, sink.length - i6);
            if (iT == -1) {
                throw new EOFException();
            }
            i6 += iT;
        }
        return sink;
    }

    @Override // java.nio.channels.ReadableByteChannel
    public final int read(ByteBuffer sink) {
        kotlin.jvm.internal.o.h(sink, "sink");
        K k6 = this.f23099a;
        if (k6 == null) {
            return -1;
        }
        int iMin = Math.min(sink.remaining(), k6.f23063c - k6.f23062b);
        sink.put(k6.f23061a, k6.f23062b, iMin);
        int i6 = k6.f23062b + iMin;
        k6.f23062b = i6;
        this.f23100b -= (long) iMin;
        if (i6 == k6.f23063c) {
            this.f23099a = k6.a();
            L.a(k6);
        }
        return iMin;
    }

    @Override // java.io.Closeable, java.lang.AutoCloseable, java.nio.channels.Channel, p5.N
    public final void close() {
    }

    @Override // p5.InterfaceC2742l
    public final C2740j e() {
        return this;
    }

    @Override // p5.InterfaceC2741k, p5.N, java.io.Flushable
    public final void flush() {
    }

    @Override // java.nio.channels.WritableByteChannel
    public final int write(ByteBuffer source) {
        kotlin.jvm.internal.o.h(source, "source");
        int iRemaining = source.remaining();
        int i6 = iRemaining;
        while (i6 > 0) {
            K kM = M(1);
            int iMin = Math.min(i6, 8192 - kM.f23063c);
            source.get(kM.f23061a, kM.f23063c, iMin);
            i6 -= iMin;
            kM.f23063c += iMin;
        }
        this.f23100b += (long) iRemaining;
        return iRemaining;
    }
}
