package Y4;

import I2.C0317a;
import J0.s1;
import K.C0466m0;
import V4.AbstractC0748a;
import V4.B0;
import V4.C0763h0;
import V4.InterfaceC0765i0;
import V4.v0;
import Z4.AbstractC0870c;
import Z4.C0868a;
import java.io.Serializable;
import java.util.NoSuchElementException;
import java.util.concurrent.CancellationException;
import m3.AbstractC2467b;
import n2.AbstractC2613d;
import w4.C3137A;

/* JADX INFO: loaded from: classes3.dex */
public abstract class O {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final C0317a f8890a = new C0317a("NO_VALUE", 4);

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final C0317a f8891b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final C0317a f8892c;

    static {
        int i6 = 4;
        f8891b = new C0317a("NONE", i6);
        f8892c = new C0317a("PENDING", i6);
    }

    public static final N a(int i6, int i7, X4.a aVar) {
        if (i6 < 0) {
            throw new IllegalArgumentException(Z0.o.l("replay cannot be negative, but was ", i6).toString());
        }
        if (i7 < 0) {
            throw new IllegalArgumentException(Z0.o.l("extraBufferCapacity cannot be negative, but was ", i7).toString());
        }
        if (i6 <= 0 && i7 <= 0 && aVar != X4.a.f8640a) {
            throw new IllegalArgumentException(("replay or extraBufferCapacity must be positive with non-default onBufferOverflow strategy " + aVar).toString());
        }
        int i8 = i7 + i6;
        if (i8 < 0) {
            i8 = Integer.MAX_VALUE;
        }
        return new N(i6, i8, aVar);
    }

    public static final c0 c(Object obj) {
        if (obj == null) {
            obj = AbstractC0870c.f9163b;
        }
        return new c0(obj);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object d(e0 e0Var, J4.f fVar, Throwable th, C4.c cVar) {
        C0847m c0847m;
        if (cVar instanceof C0847m) {
            c0847m = (C0847m) cVar;
            int i6 = c0847m.f8956c;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c0847m.f8956c = i6 - Integer.MIN_VALUE;
            } else {
                c0847m = new C0847m(cVar);
            }
        }
        Object obj = c0847m.f8955b;
        Object obj2 = B4.a.f492a;
        int i7 = c0847m.f8956c;
        try {
            if (i7 == 0) {
                AbstractC2467b.l(obj);
                c0847m.f8954a = th;
                c0847m.f8956c = 1;
                if (fVar.invoke(e0Var, th, c0847m) == obj2) {
                    return obj2;
                }
            } else {
                if (i7 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                th = c0847m.f8954a;
                AbstractC2467b.l(obj);
            }
            return C3137A.f25453a;
        } catch (Throwable th2) {
            if (th != null && th != th2) {
                AbstractC2613d.b(th2, th);
            }
            throw th2;
        }
    }

    public static final void e(Object[] objArr, long j4, Object obj) {
        objArr[((int) j4) & (objArr.length - 1)] = obj;
    }

    public static InterfaceC0843i f(InterfaceC0843i interfaceC0843i, int i6) {
        X4.a aVar = X4.a.f8640a;
        if (i6 < 0 && i6 != -2 && i6 != -1) {
            throw new IllegalArgumentException(Z0.o.l("Buffer size should be non-negative, BUFFERED, or CONFLATED, but was ", i6).toString());
        }
        if (i6 == -1) {
            aVar = X4.a.f8641b;
            i6 = 0;
        }
        return interfaceC0843i instanceof Z4.u ? AbstractC0870c.a((Z4.u) interfaceC0843i, null, i6, aVar, 1) : new Z4.j(i6, A4.k.f106a, aVar, interfaceC0843i);
    }

    public static final C0837c g(J4.e eVar) {
        return new C0837c(eVar, A4.k.f106a, -2, X4.a.f8640a);
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Serializable h(InterfaceC0843i interfaceC0843i, InterfaceC0844j interfaceC0844j, C4.c cVar) throws Throwable {
        C0852s c0852s;
        kotlin.jvm.internal.C c6;
        InterfaceC0765i0 interfaceC0765i0;
        CancellationException cancellationException;
        if (cVar instanceof C0852s) {
            c0852s = (C0852s) cVar;
            int i6 = c0852s.f8980c;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c0852s.f8980c = i6 - Integer.MIN_VALUE;
            } else {
                c0852s = new C0852s(cVar);
            }
        }
        Object obj = c0852s.f8979b;
        B4.a aVar = B4.a.f492a;
        int i7 = c0852s.f8980c;
        if (i7 == 0) {
            AbstractC2467b.l(obj);
            kotlin.jvm.internal.C c7 = new kotlin.jvm.internal.C();
            try {
                InterfaceC0844j c0466m0 = new C0466m0(2, interfaceC0844j, c7);
                c0852s.f8978a = c7;
                c0852s.f8980c = 1;
                if (interfaceC0843i.collect(c0466m0, c0852s) == aVar) {
                    return aVar;
                }
                return null;
            } catch (Throwable th) {
                th = th;
                c6 = c7;
            }
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            c6 = c0852s.f8978a;
            try {
                AbstractC2467b.l(obj);
                return null;
            } catch (Throwable th2) {
                th = th2;
            }
        }
        Throwable th3 = (Throwable) c6.f20115a;
        if ((th3 != null && th3.equals(th)) || ((interfaceC0765i0 = (InterfaceC0765i0) c0852s.getContext().get(C0763h0.f8306a)) != null && interfaceC0765i0.isCancelled() && (cancellationException = interfaceC0765i0.getCancellationException()) != null && cancellationException.equals(th))) {
            throw th;
        }
        if (th3 == null) {
            return th;
        }
        if (th instanceof CancellationException) {
            AbstractC2613d.b(th3, th);
            throw th3;
        }
        AbstractC2613d.b(th, th3);
        throw th;
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x0030  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final I2.O i(InterfaceC0843i interfaceC0843i, int i6) {
        Z4.g gVar;
        InterfaceC0843i interfaceC0843iG;
        X4.i.f8683i.getClass();
        int i7 = X4.h.f8682b;
        if (i6 >= i7) {
            i7 = i6;
        }
        int i8 = i7 - i6;
        if (!(interfaceC0843i instanceof Z4.g) || (interfaceC0843iG = (gVar = (Z4.g) interfaceC0843i).g()) == null) {
            return new I2.O(i8, A4.k.f106a, X4.a.f8640a, interfaceC0843i);
        }
        X4.a aVar = gVar.f9174c;
        int i9 = gVar.f9173b;
        if (i9 != -3 && i9 != -2 && i9 != 0) {
            i8 = i9;
        } else if (aVar == X4.a.f8640a) {
            if (i9 == 0) {
                i8 = 0;
            }
        } else if (i6 == 0) {
            i8 = 1;
        }
        return new I2.O(i8, gVar.f9172a, aVar, interfaceC0843iG);
    }

    public static final InterfaceC0843i j(InterfaceC0843i interfaceC0843i) {
        if (interfaceC0843i instanceof a0) {
            return interfaceC0843i;
        }
        if (!(interfaceC0843i instanceof C0842h)) {
            return new C0842h(interfaceC0843i);
        }
        ((C0842h) interfaceC0843i).getClass();
        return interfaceC0843i;
    }

    /* JADX WARN: Code restructure failed: missing block: B:32:0x0085, code lost:
    
        if (r2.emit(r10, r0) == r1) goto L33;
     */
    /* JADX WARN: Removed duplicated region for block: B:27:0x0066  */
    /* JADX WARN: Removed duplicated region for block: B:28:0x0067  */
    /* JADX WARN: Removed duplicated region for block: B:31:0x0073 A[Catch: all -> 0x0035, TRY_LEAVE, TryCatch #1 {all -> 0x0035, blocks: (B:13:0x002f, B:25:0x0056, B:29:0x006b, B:31:0x0073, B:20:0x0047, B:24:0x0052), top: B:52:0x0021 }] */
    /* JADX WARN: Removed duplicated region for block: B:34:0x0088  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:32:0x0085 -> B:14:0x0032). Please report as a decompilation issue!!! */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object k(InterfaceC0844j interfaceC0844j, X4.v vVar, boolean z6, A4.d dVar) throws Throwable {
        C0846l c0846l;
        X4.b it;
        X4.b bVar;
        InterfaceC0844j interfaceC0844j2;
        Object objB;
        if (dVar instanceof C0846l) {
            c0846l = (C0846l) dVar;
            int i6 = c0846l.f8953f;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c0846l.f8953f = i6 - Integer.MIN_VALUE;
            } else {
                c0846l = new C0846l(dVar);
            }
        }
        Object obj = c0846l.f8952e;
        B4.a aVar = B4.a.f492a;
        int i7 = c0846l.f8953f;
        CancellationException cancellationExceptionA = null;
        try {
            if (i7 == 0) {
                AbstractC2467b.l(obj);
                if (interfaceC0844j instanceof e0) {
                    throw ((e0) interfaceC0844j).f8939a;
                }
                it = vVar.iterator();
                c0846l.f8948a = interfaceC0844j;
                c0846l.f8949b = vVar;
                c0846l.f8950c = it;
                c0846l.f8951d = z6;
                c0846l.f8953f = 1;
                objB = it.b(c0846l);
                if (objB != aVar) {
                }
            } else if (i7 == 1) {
                z6 = c0846l.f8951d;
                bVar = c0846l.f8950c;
                vVar = c0846l.f8949b;
                interfaceC0844j2 = c0846l.f8948a;
                AbstractC2467b.l(obj);
                if (((Boolean) obj).booleanValue()) {
                }
            } else {
                if (i7 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                z6 = c0846l.f8951d;
                bVar = c0846l.f8950c;
                vVar = c0846l.f8949b;
                interfaceC0844j2 = c0846l.f8948a;
                AbstractC2467b.l(obj);
                it = bVar;
                interfaceC0844j = interfaceC0844j2;
                c0846l.f8948a = interfaceC0844j;
                c0846l.f8949b = vVar;
                c0846l.f8950c = it;
                c0846l.f8951d = z6;
                c0846l.f8953f = 1;
                objB = it.b(c0846l);
                if (objB != aVar) {
                    return aVar;
                }
                interfaceC0844j2 = interfaceC0844j;
                bVar = it;
                obj = objB;
                if (((Boolean) obj).booleanValue()) {
                    if (z6) {
                        vVar.cancel(null);
                    }
                    return C3137A.f25453a;
                }
                Object objC = bVar.c();
                c0846l.f8948a = interfaceC0844j2;
                c0846l.f8949b = vVar;
                c0846l.f8950c = bVar;
                c0846l.f8951d = z6;
                c0846l.f8953f = 2;
            }
        } finally {
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x006b  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object l(InterfaceC0843i interfaceC0843i, A4.d dVar) {
        C0859z c0859z;
        kotlin.jvm.internal.C c6;
        C0868a e6;
        s1 s1Var;
        if (dVar instanceof C0859z) {
            c0859z = (C0859z) dVar;
            int i6 = c0859z.f9008d;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                c0859z.f9008d = i6 - Integer.MIN_VALUE;
            } else {
                c0859z = new C0859z(dVar);
            }
        }
        Object obj = c0859z.f9007c;
        Object obj2 = B4.a.f492a;
        int i7 = c0859z.f9008d;
        C0317a c0317a = AbstractC0870c.f9163b;
        if (i7 == 0) {
            AbstractC2467b.l(obj);
            kotlin.jvm.internal.C c7 = new kotlin.jvm.internal.C();
            c7.f20115a = c0317a;
            s1 s1Var2 = new s1(c7, 4);
            try {
                c0859z.f9005a = c7;
                c0859z.f9006b = s1Var2;
                c0859z.f9008d = 1;
                if (interfaceC0843i.collect(s1Var2, c0859z) == obj2) {
                    return obj2;
                }
                c6 = c7;
            } catch (C0868a e7) {
                c6 = c7;
                e6 = e7;
                s1Var = s1Var2;
                if (e6.f9157a != s1Var) {
                    throw e6;
                }
            }
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            s1Var = c0859z.f9006b;
            c6 = c0859z.f9005a;
            try {
                AbstractC2467b.l(obj);
            } catch (C0868a e8) {
                e6 = e8;
                if (e6.f9157a != s1Var) {
                }
            }
        }
        Object obj3 = c6.f20115a;
        if (obj3 != c0317a) {
            return obj3;
        }
        throw new NoSuchElementException("Expected at least one element");
    }

    /* JADX WARN: Removed duplicated region for block: B:32:0x007c  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object m(InterfaceC0843i interfaceC0843i, J4.e eVar, A4.d dVar) {
        A a6;
        J4.e eVar2;
        kotlin.jvm.internal.C c6;
        C0868a e6;
        C0466m0 c0466m0;
        if (dVar instanceof A) {
            a6 = (A) dVar;
            int i6 = a6.f8850e;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                a6.f8850e = i6 - Integer.MIN_VALUE;
            } else {
                a6 = new A(dVar);
            }
        }
        Object obj = a6.f8849d;
        Object obj2 = B4.a.f492a;
        int i7 = a6.f8850e;
        C0317a c0317a = AbstractC0870c.f9163b;
        if (i7 == 0) {
            AbstractC2467b.l(obj);
            kotlin.jvm.internal.C c7 = new kotlin.jvm.internal.C();
            c7.f20115a = c0317a;
            C0466m0 c0466m02 = new C0466m0(eVar, c7);
            try {
                a6.f8846a = eVar;
                a6.f8847b = c7;
                a6.f8848c = c0466m02;
                a6.f8850e = 1;
                if (interfaceC0843i.collect(c0466m02, a6) == obj2) {
                    return obj2;
                }
                eVar2 = eVar;
                c6 = c7;
            } catch (C0868a e7) {
                eVar2 = eVar;
                c6 = c7;
                e6 = e7;
                c0466m0 = c0466m02;
                if (e6.f9157a != c0466m0) {
                    throw e6;
                }
            }
        } else {
            if (i7 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            c0466m0 = a6.f8848c;
            c6 = a6.f8847b;
            eVar2 = a6.f8846a;
            try {
                AbstractC2467b.l(obj);
            } catch (C0868a e8) {
                e6 = e8;
                if (e6.f9157a != c0466m0) {
                }
            }
        }
        Object obj3 = c6.f20115a;
        if (obj3 != c0317a) {
            return obj3;
        }
        throw new NoSuchElementException("Expected at least one element matching the predicate " + eVar2);
    }

    public static final InterfaceC0843i n(K k6, A4.j jVar, int i6, X4.a aVar) {
        return ((i6 == 0 || i6 == -3) && aVar == X4.a.f8640a) ? k6 : new Z4.j(i6, jVar, aVar, k6);
    }

    public static final J o(InterfaceC0843i interfaceC0843i, V4.C c6, T t6, Object obj) {
        I2.O oI = i(interfaceC0843i, 1);
        c0 c0VarC = c(obj);
        InterfaceC0843i interfaceC0843i2 = (InterfaceC0843i) oI.f2524b;
        V4.D d6 = t6.equals(S.f8899a) ? V4.D.f8225a : V4.D.f8228d;
        D d7 = new D(t6, interfaceC0843i2, c0VarC, obj, null);
        A4.j jVarZ = V4.E.z(c6, (A4.j) oI.f2526d);
        AbstractC0748a v0Var = d6 == V4.D.f8226b ? new v0(jVarZ, d7) : new B0(jVarZ, true);
        v0Var.W(d6, v0Var, d7);
        return new J(c0VarC);
    }
}
