package V4;

import a5.AbstractC0988a;
import java.util.concurrent.CancellationException;
import m3.AbstractC2467b;

/* JADX INFO: loaded from: classes3.dex */
public abstract class M extends c5.i {

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

    public M(int i6) {
        super(0L, false);
        this.f8257c = i6;
    }

    public abstract A4.d d();

    public Throwable e(Object obj) {
        C0784w c0784w = obj instanceof C0784w ? (C0784w) obj : null;
        if (c0784w != null) {
            return c0784w.f8346a;
        }
        return null;
    }

    public final void g(Throwable th) {
        E.s(d().getContext(), new I4.a("Fatal exception in coroutines machinery for " + this + ". Please read KDoc to 'handleFatalException' method and report this incident to maintainers", th));
    }

    public abstract Object h();

    @Override // java.lang.Runnable
    public final void run() {
        try {
            A4.d dVarD = d();
            kotlin.jvm.internal.o.f(dVarD, "null cannot be cast to non-null type kotlinx.coroutines.internal.DispatchedContinuation<T of kotlinx.coroutines.DispatchedTask>");
            a5.f fVar = (a5.f) dVarD;
            C4.c cVar = fVar.f10823e;
            Object obj = fVar.f10825j;
            A4.j context = cVar.getContext();
            Object objL = AbstractC0988a.l(context, obj);
            InterfaceC0765i0 interfaceC0765i0 = null;
            L0 l0G = objL != AbstractC0988a.f10812d ? E.G(cVar, context, objL) : null;
            try {
                A4.j context2 = cVar.getContext();
                Object objH = h();
                Throwable thE = e(objH);
                if (thE == null) {
                    int i6 = this.f8257c;
                    boolean z6 = true;
                    if (i6 != 1 && i6 != 2) {
                        z6 = false;
                    }
                    if (z6) {
                        interfaceC0765i0 = (InterfaceC0765i0) context2.get(C0763h0.f8306a);
                    }
                }
                if (interfaceC0765i0 != null && !interfaceC0765i0.isActive()) {
                    CancellationException cancellationException = interfaceC0765i0.getCancellationException();
                    c(cancellationException);
                    cVar.resumeWith(AbstractC2467b.d(cancellationException));
                } else if (thE != null) {
                    cVar.resumeWith(AbstractC2467b.d(thE));
                } else {
                    cVar.resumeWith(f(objH));
                }
                if (l0G == null || l0G.X()) {
                    AbstractC0988a.g(context, objL);
                }
            } catch (Throwable th) {
                if (l0G == null || l0G.X()) {
                    AbstractC0988a.g(context, objL);
                }
                throw th;
            }
        } catch (Throwable th2) {
            g(th2);
        }
    }

    public void c(CancellationException cancellationException) {
    }

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