package g.a.n2;

import f.l;
import g.a.b1;
import g.a.i2;
import g.a.k2;
import g.a.l0;
import g.a.n1;
import java.util.concurrent.CancellationException;

/* JADX INFO: compiled from: DispatchedContinuation.kt */
/* JADX INFO: loaded from: classes.dex */
public final class h {
    private static final b0 a = new b0("UNDEFINED");

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final b0 f4070b = new b0("REUSABLE_CLAIMED");

    /* JADX WARN: Finally extract failed */
    public static final <T> void b(f.w.d<? super T> dVar, Object obj, f.z.c.l<? super Throwable, f.t> lVar) {
        boolean z;
        if (!(dVar instanceof g)) {
            dVar.resumeWith(obj);
            return;
        }
        g gVar = (g) dVar;
        Object objB = g.a.x.b(obj, lVar);
        if (gVar.f4066h.x(gVar.getContext())) {
            gVar.f4068j = objB;
            gVar.f4160g = 1;
            gVar.f4066h.w(gVar.getContext(), gVar);
            return;
        }
        l0.a();
        b1 b1VarA = i2.a.a();
        if (b1VarA.M()) {
            gVar.f4068j = objB;
            gVar.f4160g = 1;
            b1VarA.D(gVar);
            return;
        }
        b1VarA.H(true);
        try {
            n1 n1Var = (n1) gVar.getContext().get(n1.f4054e);
            if (n1Var == null || n1Var.isActive()) {
                z = false;
            } else {
                CancellationException cancellationExceptionN = n1Var.n();
                gVar.a(objB, cancellationExceptionN);
                l.a aVar = f.l.f3940b;
                Object objA = f.m.a(cancellationExceptionN);
                f.l.a(objA);
                gVar.resumeWith(objA);
                z = true;
            }
            if (!z) {
                f.w.d<T> dVar2 = gVar.f4067i;
                Object obj2 = gVar.f4069k;
                f.w.g context = dVar2.getContext();
                Object objC = f0.c(context, obj2);
                k2<?> k2VarG = objC != f0.a ? g.a.a0.g(dVar2, context, objC) : null;
                try {
                    gVar.f4067i.resumeWith(obj);
                    f.t tVar = f.t.a;
                    if (k2VarG == null || k2VarG.w0()) {
                        f0.a(context, objC);
                    }
                } catch (Throwable th) {
                    if (k2VarG == null || k2VarG.w0()) {
                        f0.a(context, objC);
                    }
                    throw th;
                }
            }
            while (b1VarA.P()) {
            }
        } finally {
            try {
            } finally {
            }
        }
    }

    public static /* synthetic */ void c(f.w.d dVar, Object obj, f.z.c.l lVar, int i2, Object obj2) {
        if ((i2 & 2) != 0) {
            lVar = null;
        }
        b(dVar, obj, lVar);
    }
}
