package kotlinx.coroutines;

import h.l;

/* JADX INFO: compiled from: CompletionState.kt */
/* JADX INFO: loaded from: classes.dex */
public final class f0 {
    public static final <T> Object a(Object obj, h.u.d<? super T> dVar) {
        if (!(obj instanceof b0)) {
            l.a aVar = h.l.b;
            h.l.a(obj);
            return obj;
        }
        l.a aVar2 = h.l.b;
        Throwable thJ = ((b0) obj).a;
        if (r0.d() && (dVar instanceof h.u.j.a.e)) {
            thJ = kotlinx.coroutines.o2.p.j(thJ, (h.u.j.a.e) dVar);
        }
        Object objA = h.m.a(thJ);
        h.l.a(objA);
        return objA;
    }

    public static final <T> Object b(Object obj, h.x.c.l<? super Throwable, h.r> lVar) {
        Throwable thB = h.l.b(obj);
        return thB == null ? lVar != null ? new c0(obj, lVar) : obj : new b0(thB, false, 2, null);
    }

    public static final <T> Object c(Object obj, n<?> nVar) {
        Throwable thB = h.l.b(obj);
        if (thB != null) {
            if (r0.d() && (nVar instanceof h.u.j.a.e)) {
                thB = kotlinx.coroutines.o2.p.j(thB, (h.u.j.a.e) nVar);
            }
            obj = new b0(thB, false, 2, null);
        }
        return obj;
    }

    public static /* synthetic */ Object d(Object obj, h.x.c.l lVar, int i2, Object obj2) {
        if ((i2 & 1) != 0) {
            lVar = null;
        }
        return b(obj, lVar);
    }
}
