package kotlinx.coroutines.channels;

import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlinx.coroutines.u;

/* JADX INFO: loaded from: classes.dex */
public abstract class h {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final g f29338a = new g();

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final Object a(l lVar, sd.a aVar, Continuation continuation) {
        ProduceKt$awaitClose$1 produceKt$awaitClose$1;
        if (continuation instanceof ProduceKt$awaitClose$1) {
            produceKt$awaitClose$1 = (ProduceKt$awaitClose$1) continuation;
            int i10 = produceKt$awaitClose$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                produceKt$awaitClose$1.label = i10 - Integer.MIN_VALUE;
            } else {
                produceKt$awaitClose$1 = new ProduceKt$awaitClose$1(continuation);
            }
        }
        Object obj = produceKt$awaitClose$1.result;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = produceKt$awaitClose$1.label;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                if (produceKt$awaitClose$1.getContext().m(u.f29565b) != lVar) {
                    throw new IllegalStateException("awaitClose() can only be invoked from the producer context".toString());
                }
                produceKt$awaitClose$1.L$0 = lVar;
                produceKt$awaitClose$1.L$1 = aVar;
                produceKt$awaitClose$1.label = 1;
                kotlinx.coroutines.h hVar = new kotlinx.coroutines.h(1, nb.g.F(produceKt$awaitClose$1));
                hVar.t();
                ((k) lVar).a(new ProduceKt$awaitClose$4$1(hVar));
                if (hVar.s() == coroutineSingletons) {
                    return coroutineSingletons;
                }
            } else {
                if (i11 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                aVar = (sd.a) produceKt$awaitClose$1.L$1;
                kotlin.a.d(obj);
            }
            aVar.invoke();
            return kd.e.f29109a;
        } catch (Throwable th) {
            aVar.invoke();
            throw th;
        }
    }
}
