package aq;

import dn.l;
import dn.p;
import kotlin.coroutines.jvm.internal.h;
import kotlin.jvm.internal.v0;
import rm.x;
import rm.y;
import tp.c0;
import tp.d2;
import vm.d;
import vm.g;
import zp.d0;
import zp.l0;

/* loaded from: classes3.dex */
public abstract class b {
    public static final void a(l lVar, d dVar) {
        Object f10;
        d a10 = h.a(dVar);
        try {
            g context = dVar.getContext();
            Object c10 = l0.c(context, null);
            try {
                Object invoke = ((l) v0.e(lVar, 1)).invoke(a10);
                f10 = wm.d.f();
                if (invoke != f10) {
                    a10.resumeWith(x.a(invoke));
                }
            } finally {
                l0.a(context, c10);
            }
        } catch (Throwable th2) {
            x.a aVar = x.f34910p;
            a10.resumeWith(x.a(y.a(th2)));
        }
    }

    public static final void b(p pVar, Object obj, d dVar) {
        Object f10;
        d a10 = h.a(dVar);
        try {
            g context = dVar.getContext();
            Object c10 = l0.c(context, null);
            try {
                Object invoke = ((p) v0.e(pVar, 2)).invoke(obj, a10);
                f10 = wm.d.f();
                if (invoke != f10) {
                    a10.resumeWith(x.a(invoke));
                }
            } finally {
                l0.a(context, c10);
            }
        } catch (Throwable th2) {
            x.a aVar = x.f34910p;
            a10.resumeWith(x.a(y.a(th2)));
        }
    }

    public static final Object c(d0 d0Var, Object obj, p pVar) {
        Object c0Var;
        Object f10;
        Object f11;
        Object f12;
        try {
            c0Var = ((p) v0.e(pVar, 2)).invoke(obj, d0Var);
        } catch (Throwable th2) {
            c0Var = new c0(th2, false, 2, null);
        }
        f10 = wm.d.f();
        if (c0Var == f10) {
            f12 = wm.d.f();
            return f12;
        }
        Object w02 = d0Var.w0(c0Var);
        if (w02 == d2.f36519b) {
            f11 = wm.d.f();
            return f11;
        }
        if (w02 instanceof c0) {
            throw ((c0) w02).f36494a;
        }
        return d2.h(w02);
    }
}
