package zp;

import java.util.concurrent.CancellationException;
import rm.x;
import tp.e1;
import tp.t2;
import tp.u1;
import tp.w2;

/* loaded from: classes3.dex */
public abstract class k {

    /* renamed from: a */
    private static final h0 f53558a = new h0("UNDEFINED");

    /* renamed from: b */
    public static final h0 f53559b = new h0("REUSABLE_CLAIMED");

    /* JADX WARN: Finally extract failed */
    public static final void b(vm.d dVar, Object obj, dn.l lVar) {
        boolean z10;
        if (!(dVar instanceof j)) {
            dVar.resumeWith(obj);
            return;
        }
        j jVar = (j) dVar;
        Object b10 = tp.g0.b(obj, lVar);
        if (jVar.f53553s.L(jVar.getContext())) {
            jVar.f53555u = b10;
            jVar.f36601r = 1;
            jVar.f53553s.C(jVar.getContext(), jVar);
            return;
        }
        e1 b11 = t2.f36590a.b();
        if (b11.n0()) {
            jVar.f53555u = b10;
            jVar.f36601r = 1;
            b11.e0(jVar);
            return;
        }
        b11.j0(true);
        try {
            u1 u1Var = (u1) jVar.getContext().d(u1.f36592j);
            if (u1Var == null || u1Var.b()) {
                z10 = false;
            } else {
                CancellationException t10 = u1Var.t();
                jVar.b(b10, t10);
                x.a aVar = rm.x.f34910p;
                jVar.resumeWith(rm.x.a(rm.y.a(t10)));
                z10 = true;
            }
            if (!z10) {
                vm.d dVar2 = jVar.f53554t;
                Object obj2 = jVar.f53556v;
                vm.g context = dVar2.getContext();
                Object c10 = l0.c(context, obj2);
                w2 g10 = c10 != l0.f53561a ? tp.h0.g(dVar2, context, c10) : null;
                try {
                    jVar.f53554t.resumeWith(obj);
                    rm.n0 n0Var = rm.n0.f34904a;
                    if (g10 == null || g10.X0()) {
                        l0.a(context, c10);
                    }
                } catch (Throwable th2) {
                    if (g10 == null || g10.X0()) {
                        l0.a(context, c10);
                    }
                    throw th2;
                }
            }
            do {
            } while (b11.q0());
        } finally {
            try {
            } finally {
            }
        }
    }

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