package e7;

import Z6.AbstractC0378s;
import Z6.AbstractC0385z;
import Z6.C0377q;
import Z6.C0379t;
import Z6.F;
import Z6.InterfaceC0380u;
import Z6.U;
import Z6.d0;
import Z6.t0;
import Z6.z0;
import com.google.android.gms.internal.measurement.C1;
import d5.AbstractC0844a;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;

/* JADX INFO: renamed from: e7.a, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
public abstract class AbstractC0892a {

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final B3.f f12534b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final B3.f f12535c;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final B3.f f12533a = new B3.f(5, "CLOSED");

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final B3.f f12536d = new B3.f(5, "NO_THREAD_ELEMENTS");

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public static final E6.b f12537e = new E6.b(6);

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public static final E6.b f12538f = new E6.b(7);

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public static final E6.b f12539g = new E6.b(8);

    static {
        int i = 5;
        f12534b = new B3.f(i, "UNDEFINED");
        f12535c = new B3.f(i, "REUSABLE_CLAIMED");
    }

    public static final void a(int i) {
        if (i < 1) {
            throw new IllegalArgumentException(AbstractC0844a.j("Expected positive parallelism level, but got ", i).toString());
        }
    }

    public static final Object b(r rVar, long j8, O6.p pVar) {
        AtomicReferenceFieldUpdater atomicReferenceFieldUpdater;
        while (true) {
            if (rVar.f12574s >= j8 && !rVar.d()) {
                return rVar;
            }
            Object obj = b.f12540q.get(rVar);
            B3.f fVar = f12533a;
            if (obj == fVar) {
                return fVar;
            }
            r rVar2 = (r) ((b) obj);
            if (rVar2 == null) {
                rVar2 = (r) pVar.k(Long.valueOf(rVar.f12574s + 1), rVar);
                do {
                    atomicReferenceFieldUpdater = b.f12540q;
                    if (atomicReferenceFieldUpdater.compareAndSet(rVar, null, rVar2)) {
                        if (rVar.d()) {
                            rVar.e();
                        }
                    }
                } while (atomicReferenceFieldUpdater.get(rVar) == null);
            }
            rVar = rVar2;
        }
    }

    public static final r c(Object obj) {
        if (obj != f12533a) {
            return (r) obj;
        }
        throw new IllegalStateException("Does not contain segment");
    }

    public static final void d(E6.i iVar, Throwable th) throws IllegalAccessException, InvocationTargetException {
        Throwable runtimeException;
        Iterator it = d.f12543a.iterator();
        while (it.hasNext()) {
            try {
                ((InterfaceC0380u) it.next()).f0(th);
            } catch (Throwable th2) {
                if (th == th2) {
                    runtimeException = th;
                } else {
                    runtimeException = new RuntimeException("Exception while trying to handle coroutine exception", th2);
                    android.support.v4.media.session.a.a(runtimeException, th);
                }
                Thread threadCurrentThread = Thread.currentThread();
                threadCurrentThread.getUncaughtExceptionHandler().uncaughtException(threadCurrentThread, runtimeException);
            }
        }
        try {
            android.support.v4.media.session.a.a(th, new e(iVar));
        } catch (Throwable unused) {
        }
        Thread threadCurrentThread2 = Thread.currentThread();
        threadCurrentThread2.getUncaughtExceptionHandler().uncaughtException(threadCurrentThread2, th);
    }

    public static final boolean e(Object obj) {
        return obj == f12533a;
    }

    public static final Object f(Object obj, Object obj2) {
        if (obj == null) {
            return obj2;
        }
        if (obj instanceof ArrayList) {
            ((ArrayList) obj).add(obj2);
            return obj;
        }
        ArrayList arrayList = new ArrayList(4);
        arrayList.add(obj);
        arrayList.add(obj2);
        return arrayList;
    }

    public static final void g(E6.i iVar, Object obj) {
        if (obj == f12536d) {
            return;
        }
        if (!(obj instanceof x)) {
            Object objO = iVar.O(null, f12538f);
            P6.g.c(objO, "null cannot be cast to non-null type kotlinx.coroutines.ThreadContextElement<kotlin.Any?>");
            ((u) objO).c(obj);
            return;
        }
        x xVar = (x) obj;
        u[] uVarArr = xVar.f12585c;
        int length = uVarArr.length - 1;
        if (length < 0) {
            return;
        }
        while (true) {
            int i = length - 1;
            u uVar = uVarArr[length];
            P6.g.b(uVar);
            uVar.c(xVar.f12584b[length]);
            if (i < 0) {
                return;
            } else {
                length = i;
            }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x0095 A[Catch: all -> 0x0074, DONT_GENERATE, TryCatch #2 {all -> 0x0074, blocks: (B:19:0x0054, B:21:0x0062, B:23:0x0068, B:36:0x0098, B:26:0x0076, B:28:0x0084, B:33:0x008f, B:35:0x0095, B:41:0x00a5, B:44:0x00ae, B:43:0x00ab, B:31:0x008a), top: B:57:0x0054, inners: #0 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final void h(E6.d dVar, Object obj) throws F {
        d0 d0Var;
        if (!(dVar instanceof f)) {
            dVar.i(obj);
            return;
        }
        f fVar = (f) dVar;
        Throwable thA = A6.j.a(obj);
        Object c0377q = thA == null ? obj : new C0377q(thA, false);
        AbstractC0378s abstractC0378s = fVar.f12546t;
        G6.c cVar = fVar.f12547u;
        if (j(abstractC0378s, cVar.h())) {
            fVar.f12548v = c0377q;
            fVar.f7472s = 1;
            i(abstractC0378s, cVar.h(), fVar);
            return;
        }
        U uA = t0.a();
        if (uA.f7489s >= 4294967296L) {
            fVar.f12548v = c0377q;
            fVar.f7472s = 1;
            B6.i iVar = uA.f7491u;
            if (iVar == null) {
                iVar = new B6.i();
                uA.f7491u = iVar;
            }
            iVar.addLast(fVar);
            return;
        }
        uA.o0(true);
        try {
            d0Var = (d0) cVar.h().K(C0379t.f7546r);
        } finally {
            try {
            } finally {
            }
        }
        if (d0Var == null || d0Var.a()) {
            Object obj2 = fVar.f12549w;
            E6.i iVarH = cVar.h();
            Object objN = n(iVarH, obj2);
            z0 z0VarB = objN != f12536d ? AbstractC0385z.B(cVar, iVarH, objN) : null;
            try {
                cVar.i(obj);
            } finally {
                if (z0VarB == null || z0VarB.k0()) {
                    g(iVarH, objN);
                }
            }
        }
        fVar.i(C1.j(d0Var.r()));
        while (uA.q0()) {
        }
    }

    public static final void i(AbstractC0378s abstractC0378s, E6.i iVar, Runnable runnable) throws F {
        try {
            abstractC0378s.j0(iVar, runnable);
        } catch (Throwable th) {
            throw new F(th, abstractC0378s, iVar);
        }
    }

    public static final boolean j(AbstractC0378s abstractC0378s, E6.i iVar) throws F {
        try {
            return abstractC0378s.k0(iVar);
        } catch (Throwable th) {
            throw new F(th, abstractC0378s, iVar);
        }
    }

    public static final long k(String str, long j8, long j9, long j10) {
        String property;
        int i = t.f12576a;
        try {
            property = System.getProperty(str);
        } catch (SecurityException unused) {
            property = null;
        }
        if (property == null) {
            return j8;
        }
        Long lF = X6.m.F(property);
        if (lF == null) {
            throw new IllegalStateException(("System property '" + str + "' has unrecognized value '" + property + '\'').toString());
        }
        long jLongValue = lF.longValue();
        if (j9 <= jLongValue && jLongValue <= j10) {
            return jLongValue;
        }
        throw new IllegalStateException(("System property '" + str + "' should be in range " + j9 + ".." + j10 + ", but is '" + jLongValue + '\'').toString());
    }

    public static int l(int i, int i5, String str) {
        return (int) k(str, i, 1, (i5 & 8) != 0 ? Integer.MAX_VALUE : 2097150);
    }

    public static final Object m(E6.i iVar) {
        Object objO = iVar.O(0, f12537e);
        P6.g.b(objO);
        return objO;
    }

    public static final Object n(E6.i iVar, Object obj) {
        if (obj == null) {
            obj = m(iVar);
        }
        return obj == 0 ? f12536d : obj instanceof Integer ? iVar.O(new x(((Number) obj).intValue(), iVar), f12539g) : ((u) obj).d(iVar);
    }
}
