package androidx.datastore.core;

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

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final kotlinx.coroutines.sync.c f1965a = kotlinx.coroutines.sync.d.a();

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final kotlinx.coroutines.o f1966b = ua.b.a();

    public abstract Object a(Continuation continuation);

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(Continuation continuation) throws Throwable {
        RunOnce$runIfNeeded$1 runOnce$runIfNeeded$1;
        kotlinx.coroutines.sync.a aVar;
        y yVar;
        kotlinx.coroutines.sync.a aVar2;
        Throwable th;
        y yVar2;
        if (continuation instanceof RunOnce$runIfNeeded$1) {
            runOnce$runIfNeeded$1 = (RunOnce$runIfNeeded$1) continuation;
            int i10 = runOnce$runIfNeeded$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                runOnce$runIfNeeded$1.label = i10 - Integer.MIN_VALUE;
            } else {
                runOnce$runIfNeeded$1 = new RunOnce$runIfNeeded$1(this, continuation);
            }
        }
        Object obj = runOnce$runIfNeeded$1.result;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = runOnce$runIfNeeded$1.label;
        kd.e eVar = kd.e.f29109a;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                if (!(this.f1966b.G() instanceof v0)) {
                    return eVar;
                }
                runOnce$runIfNeeded$1.L$0 = this;
                aVar = this.f1965a;
                runOnce$runIfNeeded$1.L$1 = aVar;
                runOnce$runIfNeeded$1.label = 1;
                if (aVar.e(runOnce$runIfNeeded$1) == coroutineSingletons) {
                    return coroutineSingletons;
                }
                yVar = this;
            } else {
                if (i11 != 1) {
                    if (i11 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    aVar2 = (kotlinx.coroutines.sync.a) runOnce$runIfNeeded$1.L$1;
                    yVar2 = (y) runOnce$runIfNeeded$1.L$0;
                    try {
                        kotlin.a.d(obj);
                        yVar2.f1966b.N(eVar);
                        aVar2.g(null);
                        return eVar;
                    } catch (Throwable th2) {
                        th = th2;
                        aVar2.g(null);
                        throw th;
                    }
                }
                kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) runOnce$runIfNeeded$1.L$1;
                yVar = (y) runOnce$runIfNeeded$1.L$0;
                kotlin.a.d(obj);
                aVar = aVar3;
            }
            if (!(yVar.f1966b.G() instanceof v0)) {
                aVar.g(null);
                return eVar;
            }
            runOnce$runIfNeeded$1.L$0 = yVar;
            runOnce$runIfNeeded$1.L$1 = aVar;
            runOnce$runIfNeeded$1.label = 2;
            if (yVar.a(runOnce$runIfNeeded$1) == coroutineSingletons) {
                return coroutineSingletons;
            }
            aVar2 = aVar;
            yVar2 = yVar;
            yVar2.f1966b.N(eVar);
            aVar2.g(null);
            return eVar;
        } catch (Throwable th3) {
            aVar2 = aVar;
            th = th3;
            aVar2.g(null);
            throw th;
        }
    }
}
