package o;

import java.util.Arrays;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.h80, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public class C1363h80 extends AbstractC1536j0 implements InterfaceC1000dR, InterfaceC2104oz, InterfaceC0795bD {
    public final int p;
    public final int q;
    public final int r;
    public Object[] s;
    public long t;
    public long u;
    public int v;
    public int w;

    public C1363h80(int i, int i2, int i3) {
        this.p = i;
        this.q = i2;
        this.r = i3;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:35:0x007f A[Catch: all -> 0x0036, TRY_ENTER, TryCatch #0 {all -> 0x0036, blocks: (B:15:0x002f, B:32:0x0075, B:35:0x007f, B:39:0x0092, B:42:0x0099, B:43:0x009d, B:44:0x009e, B:22:0x0049), top: B:51:0x001e }] */
    /* JADX WARN: Removed duplicated region for block: B:57:0x0090 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Type inference failed for: r4v1, types: [o.j0] */
    /* JADX WARN: Type inference failed for: r4v12 */
    /* JADX WARN: Type inference failed for: r4v2 */
    /* JADX WARN: Type inference failed for: r4v4, types: [o.h80] */
    /* JADX WARN: Type inference failed for: r4v5 */
    /* JADX WARN: Type inference failed for: r4v7 */
    /* JADX WARN: Type inference failed for: r9v0, types: [o.qz] */
    /* JADX WARN: Type inference failed for: r9v1 */
    /* JADX WARN: Type inference failed for: r9v16 */
    /* JADX WARN: Type inference failed for: r9v17 */
    /* JADX WARN: Type inference failed for: r9v18 */
    /* JADX WARN: Type inference failed for: r9v2, types: [o.k0] */
    /* JADX WARN: Type inference failed for: r9v3 */
    /* JADX WARN: Type inference failed for: r9v4 */
    /* JADX WARN: Type inference failed for: r9v5, types: [o.i80] */
    /* JADX WARN: Type inference failed for: r9v8, types: [o.i80] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:45:0x00ac -> B:16:0x0032). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static void k(o.C1363h80 r8, o.InterfaceC2294qz r9, o.InterfaceC0220Im r10) throws java.lang.Throwable {
        /*
            boolean r0 = r10 instanceof o.C1267g80
            if (r0 == 0) goto L13
            r0 = r10
            o.g80 r0 = (o.C1267g80) r0
            int r1 = r0.u
            r2 = -2147483648(0xffffffff80000000, float:-0.0)
            r3 = r1 & r2
            if (r3 == 0) goto L13
            int r1 = r1 - r2
            r0.u = r1
            goto L18
        L13:
            o.g80 r0 = new o.g80
            r0.<init>(r8, r10)
        L18:
            java.lang.Object r10 = r0.s
            int r1 = r0.u
            r2 = 3
            r3 = 2
            if (r1 == 0) goto L5c
            r8 = 1
            if (r1 == r8) goto L4d
            if (r1 == r3) goto L41
            if (r1 != r2) goto L39
            o.TI r8 = r0.r
            o.i80 r9 = r0.q
            o.qz r1 = r0.p
            o.h80 r4 = r0.f538o
            o.IJ.H(r10)     // Catch: java.lang.Throwable -> L36
        L32:
            r10 = r1
            r1 = r8
            r8 = r4
            goto L72
        L36:
            r8 = move-exception
            goto Lb2
        L39:
            java.lang.IllegalStateException r8 = new java.lang.IllegalStateException
            java.lang.String r9 = "call to 'resume' before 'invoke' with coroutine"
            r8.<init>(r9)
            throw r8
        L41:
            o.TI r8 = r0.r
            o.i80 r9 = r0.q
            o.qz r1 = r0.p
            o.h80 r4 = r0.f538o
            o.IJ.H(r10)     // Catch: java.lang.Throwable -> L36
            goto L75
        L4d:
            o.i80 r9 = r0.q
            o.qz r8 = r0.p
            o.h80 r1 = r0.f538o
            o.IJ.H(r10)     // Catch: java.lang.Throwable -> L59
            r10 = r8
            r8 = r1
            goto L68
        L59:
            r8 = move-exception
            r4 = r1
            goto Lb2
        L5c:
            o.IJ.H(r10)
            o.k0 r10 = r8.d()
            o.i80 r10 = (o.C1459i80) r10
            r7 = r10
            r10 = r9
            r9 = r7
        L68:
            o.vn r1 = r0.m     // Catch: java.lang.Throwable -> Laf
            o.Zu r4 = o.C0669Zu.K     // Catch: java.lang.Throwable -> Laf
            o.tn r1 = r1.m(r4)     // Catch: java.lang.Throwable -> Laf
            o.TI r1 = (o.TI) r1     // Catch: java.lang.Throwable -> Laf
        L72:
            r4 = r8
            r8 = r1
            r1 = r10
        L75:
            java.lang.Object r10 = r4.t(r9)     // Catch: java.lang.Throwable -> L36
            o.xq r5 = o.C1884mi0.g     // Catch: java.lang.Throwable -> L36
            o.Dn r6 = o.EnumC0091Dn.l
            if (r10 != r5) goto L90
            r0.f538o = r4     // Catch: java.lang.Throwable -> L36
            r0.p = r1     // Catch: java.lang.Throwable -> L36
            r0.q = r9     // Catch: java.lang.Throwable -> L36
            r0.r = r8     // Catch: java.lang.Throwable -> L36
            r0.u = r3     // Catch: java.lang.Throwable -> L36
            java.lang.Object r10 = r4.i(r9, r0)     // Catch: java.lang.Throwable -> L36
            if (r10 != r6) goto L75
            goto Lae
        L90:
            if (r8 == 0) goto L9e
            boolean r5 = r8.b()     // Catch: java.lang.Throwable -> L36
            if (r5 == 0) goto L99
            goto L9e
        L99:
            java.util.concurrent.CancellationException r8 = r8.z()     // Catch: java.lang.Throwable -> L36
            throw r8     // Catch: java.lang.Throwable -> L36
        L9e:
            r0.f538o = r4     // Catch: java.lang.Throwable -> L36
            r0.p = r1     // Catch: java.lang.Throwable -> L36
            r0.q = r9     // Catch: java.lang.Throwable -> L36
            r0.r = r8     // Catch: java.lang.Throwable -> L36
            r0.u = r2     // Catch: java.lang.Throwable -> L36
            java.lang.Object r10 = r1.c(r10, r0)     // Catch: java.lang.Throwable -> L36
            if (r10 != r6) goto L32
        Lae:
            return
        Laf:
            r10 = move-exception
            r4 = r8
            r8 = r10
        Lb2:
            r4.g(r9)
            throw r8
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1363h80.k(o.h80, o.qz, o.Im):void");
    }

    @Override // o.InterfaceC2104oz
    public final Object a(InterfaceC2294qz interfaceC2294qz, InterfaceC0220Im interfaceC0220Im) throws Throwable {
        k(this, interfaceC2294qz, interfaceC0220Im);
        return EnumC0091Dn.l;
    }

    @Override // o.InterfaceC0795bD
    public final InterfaceC2104oz b(InterfaceC2747vn interfaceC2747vn, int i, int i2) {
        return ((i == 0 || i == -3) && i2 == 1) ? this : new C1118eh(this, interfaceC2747vn, i, i2);
    }

    @Override // o.InterfaceC2294qz
    public final Object c(Object obj, InterfaceC0220Im interfaceC0220Im) throws Throwable {
        Throwable th;
        InterfaceC0220Im[] interfaceC0220ImArrN;
        C1171f80 c1171f80;
        if (q(obj)) {
            return Oh0.a;
        }
        C2448sg c2448sg = new C2448sg(1, AbstractC2539te.G(interfaceC0220Im));
        c2448sg.r();
        InterfaceC0220Im[] interfaceC0220ImArrN2 = AbstractC2539te.a;
        synchronized (this) {
            try {
                if (r(obj)) {
                    try {
                        c2448sg.resumeWith(Oh0.a);
                        interfaceC0220ImArrN = n(interfaceC0220ImArrN2);
                        c1171f80 = null;
                    } catch (Throwable th2) {
                        th = th2;
                        throw th;
                    }
                } else {
                    try {
                        C1171f80 c1171f802 = new C1171f80(this, o() + this.v + this.w, obj, c2448sg);
                        m(c1171f802);
                        this.w++;
                        if (this.q == 0) {
                            interfaceC0220ImArrN2 = n(interfaceC0220ImArrN2);
                        }
                        interfaceC0220ImArrN = interfaceC0220ImArrN2;
                        c1171f80 = c1171f802;
                    } catch (Throwable th3) {
                        th = th3;
                        th = th;
                        throw th;
                    }
                }
                if (c1171f80 != null) {
                    c2448sg.x(new C1499ig(2, c1171f80));
                }
                for (InterfaceC0220Im interfaceC0220Im2 : interfaceC0220ImArrN) {
                    if (interfaceC0220Im2 != null) {
                        interfaceC0220Im2.resumeWith(Oh0.a);
                    }
                }
                Object objQ = c2448sg.q();
                EnumC0091Dn enumC0091Dn = EnumC0091Dn.l;
                if (objQ != enumC0091Dn) {
                    objQ = Oh0.a;
                }
                return objQ == enumC0091Dn ? objQ : Oh0.a;
            } catch (Throwable th4) {
                th = th4;
            }
        }
    }

    @Override // o.AbstractC1536j0
    public final AbstractC1631k0 e() {
        C1459i80 c1459i80 = new C1459i80();
        c1459i80.a = -1L;
        return c1459i80;
    }

    @Override // o.AbstractC1536j0
    public final AbstractC1631k0[] f() {
        return new C1459i80[2];
    }

    public final Object i(C1459i80 c1459i80, C1267g80 c1267g80) {
        C2448sg c2448sg = new C2448sg(1, AbstractC2539te.G(c1267g80));
        c2448sg.r();
        synchronized (this) {
            try {
                if (s(c1459i80) < 0) {
                    c1459i80.b = c2448sg;
                } else {
                    c2448sg.resumeWith(Oh0.a);
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        Object objQ = c2448sg.q();
        return objQ == EnumC0091Dn.l ? objQ : Oh0.a;
    }

    public final void j() {
        if (this.q != 0 || this.w > 1) {
            Object[] objArr = this.s;
            while (this.w > 0 && C1884mi0.h(objArr, (o() + (this.v + this.w)) - 1) == C1884mi0.g) {
                this.w--;
                C1884mi0.j(objArr, o() + this.v + this.w, null);
            }
        }
    }

    public final void l() {
        AbstractC1631k0[] abstractC1631k0Arr;
        C1884mi0.j(this.s, o(), null);
        this.v--;
        long jO = o() + 1;
        if (this.t < jO) {
            this.t = jO;
        }
        if (this.u < jO) {
            if (this.m != 0 && (abstractC1631k0Arr = this.l) != null) {
                for (AbstractC1631k0 abstractC1631k0 : abstractC1631k0Arr) {
                    if (abstractC1631k0 != null) {
                        C1459i80 c1459i80 = (C1459i80) abstractC1631k0;
                        long j = c1459i80.a;
                        if (j >= 0 && j < jO) {
                            c1459i80.a = jO;
                        }
                    }
                }
            }
            this.u = jO;
        }
    }

    public final void m(Object obj) {
        int i = this.v + this.w;
        Object[] objArrP = this.s;
        if (objArrP == null) {
            objArrP = p(null, 0, 2);
        } else if (i >= objArrP.length) {
            objArrP = p(objArrP, i, objArrP.length * 2);
        }
        C1884mi0.j(objArrP, o() + i, obj);
    }

    /* JADX WARN: Multi-variable type inference failed */
    public final InterfaceC0220Im[] n(InterfaceC0220Im[] interfaceC0220ImArr) {
        AbstractC1631k0[] abstractC1631k0Arr;
        C1459i80 c1459i80;
        C2448sg c2448sg;
        int length = interfaceC0220ImArr.length;
        if (this.m != 0 && (abstractC1631k0Arr = this.l) != null) {
            int length2 = abstractC1631k0Arr.length;
            int i = 0;
            interfaceC0220ImArr = interfaceC0220ImArr;
            while (i < length2) {
                AbstractC1631k0 abstractC1631k0 = abstractC1631k0Arr[i];
                if (abstractC1631k0 != null && (c2448sg = (c1459i80 = (C1459i80) abstractC1631k0).b) != null && s(c1459i80) >= 0) {
                    int length3 = interfaceC0220ImArr.length;
                    interfaceC0220ImArr = interfaceC0220ImArr;
                    if (length >= length3) {
                        interfaceC0220ImArr = Arrays.copyOf(interfaceC0220ImArr, Math.max(2, interfaceC0220ImArr.length * 2));
                    }
                    interfaceC0220ImArr[length] = c2448sg;
                    c1459i80.b = null;
                    length++;
                }
                i++;
                interfaceC0220ImArr = interfaceC0220ImArr;
            }
        }
        return interfaceC0220ImArr;
    }

    public final long o() {
        return Math.min(this.u, this.t);
    }

    public final Object[] p(Object[] objArr, int i, int i2) {
        if (i2 <= 0) {
            throw new IllegalStateException("Buffer size overflow");
        }
        Object[] objArr2 = new Object[i2];
        this.s = objArr2;
        if (objArr != null) {
            long jO = o();
            for (int i3 = 0; i3 < i; i3++) {
                long j = i3 + jO;
                C1884mi0.j(objArr2, j, objArr[((int) j) & (objArr.length - 1)]);
            }
        }
        return objArr2;
    }

    public final boolean q(Object obj) {
        int i;
        boolean z;
        InterfaceC0220Im[] interfaceC0220ImArrN = AbstractC2539te.a;
        synchronized (this) {
            if (r(obj)) {
                interfaceC0220ImArrN = n(interfaceC0220ImArrN);
                z = true;
            } else {
                z = false;
            }
        }
        for (InterfaceC0220Im interfaceC0220Im : interfaceC0220ImArrN) {
            if (interfaceC0220Im != null) {
                interfaceC0220Im.resumeWith(Oh0.a);
            }
        }
        return z;
    }

    /* JADX WARN: Removed duplicated region for block: B:25:0x0047  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public final boolean r(java.lang.Object r13) {
        /*
            r12 = this;
            int r1 = r12.m
            int r2 = r12.p
            r9 = 1
            if (r1 != 0) goto L23
            if (r2 != 0) goto Lb
            goto L7f
        Lb:
            r12.m(r13)
            int r1 = r12.v
            int r1 = r1 + r9
            r12.v = r1
            if (r1 <= r2) goto L18
            r12.l()
        L18:
            long r1 = r12.o()
            int r3 = r12.v
            long r3 = (long) r3
            long r1 = r1 + r3
            r12.u = r1
            return r9
        L23:
            int r1 = r12.v
            int r3 = r12.q
            if (r1 < r3) goto L47
            long r4 = r12.u
            long r6 = r12.t
            int r1 = (r4 > r6 ? 1 : (r4 == r6 ? 0 : -1))
            if (r1 > 0) goto L47
            int r1 = r12.r
            int r1 = o.AbstractC2462sn.w(r1)
            if (r1 == 0) goto L45
            if (r1 == r9) goto L47
            r2 = 2
            if (r1 != r2) goto L3f
            goto L7f
        L3f:
            o.pj r1 = new o.pj
            r1.<init>()
            throw r1
        L45:
            r1 = 0
            return r1
        L47:
            r12.m(r13)
            int r1 = r12.v
            int r1 = r1 + r9
            r12.v = r1
            if (r1 <= r3) goto L54
            r12.l()
        L54:
            long r3 = r12.o()
            int r1 = r12.v
            long r5 = (long) r1
            long r3 = r3 + r5
            long r5 = r12.t
            long r3 = r3 - r5
            int r1 = (int) r3
            if (r1 <= r2) goto L7f
            r1 = 1
            long r1 = r1 + r5
            long r3 = r12.u
            long r5 = r12.o()
            int r7 = r12.v
            long r7 = (long) r7
            long r5 = r5 + r7
            long r7 = r12.o()
            int r10 = r12.v
            long r10 = (long) r10
            long r7 = r7 + r10
            int r10 = r12.w
            long r10 = (long) r10
            long r7 = r7 + r10
            r0 = r12
            r0.u(r1, r3, r5, r7)
        L7f:
            return r9
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C1363h80.r(java.lang.Object):boolean");
    }

    public final long s(C1459i80 c1459i80) {
        long j = c1459i80.a;
        if (j < o() + this.v) {
            return j;
        }
        if (this.q <= 0 && j <= o() && this.w != 0) {
            return j;
        }
        return -1L;
    }

    public final Object t(C1459i80 c1459i80) {
        Object obj;
        InterfaceC0220Im[] interfaceC0220ImArrV = AbstractC2539te.a;
        synchronized (this) {
            try {
                long jS = s(c1459i80);
                if (jS < 0) {
                    obj = C1884mi0.g;
                } else {
                    long j = c1459i80.a;
                    Object objH = C1884mi0.h(this.s, jS);
                    if (objH instanceof C1171f80) {
                        objH = ((C1171f80) objH).n;
                    }
                    c1459i80.a = jS + 1;
                    Object obj2 = objH;
                    interfaceC0220ImArrV = v(j);
                    obj = obj2;
                }
            } catch (Throwable th) {
                throw th;
            }
        }
        for (InterfaceC0220Im interfaceC0220Im : interfaceC0220ImArrV) {
            if (interfaceC0220Im != null) {
                interfaceC0220Im.resumeWith(Oh0.a);
            }
        }
        return obj;
    }

    public final void u(long j, long j2, long j3, long j4) {
        long jMin = Math.min(j2, j);
        for (long jO = o(); jO < jMin; jO++) {
            C1884mi0.j(this.s, jO, null);
        }
        this.t = j;
        this.u = j2;
        this.v = (int) (j3 - jMin);
        this.w = (int) (j4 - j3);
    }

    public final InterfaceC0220Im[] v(long j) {
        long j2;
        long j3;
        long j4;
        InterfaceC0220Im[] interfaceC0220ImArr;
        InterfaceC0220Im[] interfaceC0220ImArr2;
        AbstractC1631k0[] abstractC1631k0Arr;
        C2943xq c2943xq = C1884mi0.g;
        InterfaceC0220Im[] interfaceC0220ImArr3 = AbstractC2539te.a;
        if (j <= this.u) {
            long jO = o();
            long j5 = this.v + jO;
            int i = this.q;
            if (i == 0 && this.w > 0) {
                j5++;
            }
            int i2 = 0;
            if (this.m != 0 && (abstractC1631k0Arr = this.l) != null) {
                for (AbstractC1631k0 abstractC1631k0 : abstractC1631k0Arr) {
                    if (abstractC1631k0 != null) {
                        long j6 = ((C1459i80) abstractC1631k0).a;
                        if (j6 >= 0 && j6 < j5) {
                            j5 = j6;
                        }
                    }
                }
            }
            if (j5 > this.u) {
                long jO2 = o() + this.v;
                int iMin = this.m > 0 ? Math.min(this.w, i - ((int) (jO2 - j5))) : this.w;
                long j7 = this.w + jO2;
                if (iMin > 0) {
                    j4 = 1;
                    Object[] objArr = this.s;
                    j2 = jO;
                    InterfaceC0220Im[] interfaceC0220ImArr4 = new InterfaceC0220Im[iMin];
                    long j8 = jO2;
                    while (true) {
                        if (jO2 >= j7) {
                            interfaceC0220ImArr2 = interfaceC0220ImArr4;
                            j3 = j5;
                            break;
                        }
                        Object objH = C1884mi0.h(objArr, jO2);
                        if (objH != c2943xq) {
                            C1171f80 c1171f80 = (C1171f80) objH;
                            interfaceC0220ImArr2 = interfaceC0220ImArr4;
                            int i3 = i2 + 1;
                            j3 = j5;
                            interfaceC0220ImArr2[i2] = c1171f80.f522o;
                            C1884mi0.j(objArr, jO2, c2943xq);
                            C1884mi0.j(objArr, j8, c1171f80.n);
                            j8++;
                            if (i3 >= iMin) {
                                break;
                            }
                            i2 = i3;
                        } else {
                            interfaceC0220ImArr2 = interfaceC0220ImArr4;
                            j3 = j5;
                        }
                        jO2++;
                        interfaceC0220ImArr4 = interfaceC0220ImArr2;
                        j5 = j3;
                    }
                    jO2 = j8;
                    interfaceC0220ImArr = interfaceC0220ImArr2;
                } else {
                    j2 = jO;
                    j3 = j5;
                    j4 = 1;
                    interfaceC0220ImArr = interfaceC0220ImArr3;
                }
                int i4 = (int) (jO2 - j2);
                long j9 = this.m == 0 ? jO2 : j3;
                long jMax = Math.max(this.t, jO2 - Math.min(this.p, i4));
                if (i == 0 && jMax < j7 && F3.c(C1884mi0.h(this.s, jMax), c2943xq)) {
                    jO2 += j4;
                    jMax += j4;
                }
                u(jMax, j9, jO2, j7);
                j();
                return interfaceC0220ImArr.length == 0 ? interfaceC0220ImArr : n(interfaceC0220ImArr);
            }
        }
        return interfaceC0220ImArr3;
    }
}
