package Z6;

import com.google.android.gms.internal.measurement.C1;
import e7.AbstractC0892a;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.CancellationException;

/* JADX INFO: loaded from: classes.dex */
public abstract class H extends g7.i {

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f7472s;

    public H(int i) {
        super(0L, false);
        this.f7472s = i;
    }

    public abstract E6.d e();

    public Throwable g(Object obj) {
        C0377q c0377q = obj instanceof C0377q ? (C0377q) obj : null;
        if (c0377q != null) {
            return c0377q.f7541a;
        }
        return null;
    }

    public final void k(Throwable th) throws IllegalAccessException, InvocationTargetException {
        AbstractC0385z.p(e().h(), new C0384y("Fatal exception in coroutines machinery for " + this + ". Please read KDoc to 'handleFatalException' method and report this incident to maintainers", th));
    }

    public abstract Object l();

    @Override // java.lang.Runnable
    public final void run() throws IllegalAccessException, InvocationTargetException {
        try {
            E6.d dVarE = e();
            P6.g.c(dVarE, "null cannot be cast to non-null type kotlinx.coroutines.internal.DispatchedContinuation<T of kotlinx.coroutines.DispatchedTask>");
            e7.f fVar = (e7.f) dVarE;
            G6.c cVar = fVar.f12547u;
            Object obj = fVar.f12549w;
            E6.i iVarH = cVar.h();
            Object objN = AbstractC0892a.n(iVarH, obj);
            d0 d0Var = null;
            z0 z0VarB = objN != AbstractC0892a.f12536d ? AbstractC0385z.B(cVar, iVarH, objN) : null;
            try {
                E6.i iVarH2 = cVar.h();
                Object objL = l();
                Throwable thG = g(objL);
                if (thG == null) {
                    int i = this.f7472s;
                    boolean z8 = true;
                    if (i != 1 && i != 2) {
                        z8 = false;
                    }
                    if (z8) {
                        d0Var = (d0) iVarH2.K(C0379t.f7546r);
                    }
                }
                if (d0Var != null && !d0Var.a()) {
                    CancellationException cancellationExceptionR = d0Var.r();
                    b(cancellationExceptionR);
                    cVar.i(C1.j(cancellationExceptionR));
                } else if (thG != null) {
                    cVar.i(C1.j(thG));
                } else {
                    cVar.i(j(objL));
                }
                if (z0VarB == null || z0VarB.k0()) {
                    AbstractC0892a.g(iVarH, objN);
                }
            } catch (Throwable th) {
                if (z0VarB == null || z0VarB.k0()) {
                    AbstractC0892a.g(iVarH, objN);
                }
                throw th;
            }
        } catch (F e8) {
            AbstractC0385z.p(e().h(), e8.f7470q);
        } catch (Throwable th2) {
            k(th2);
        }
    }

    public void b(CancellationException cancellationException) {
    }

    public Object j(Object obj) {
        return obj;
    }
}
