package androidx.datastore.core;

import java.util.concurrent.atomic.AtomicInteger;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.jvm.functions.Function2;

/* JADX INFO: loaded from: classes.dex */
public final class b0 implements u {

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

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final xyz.stream.api.a0 f1910b = new xyz.stream.api.a0();

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final kotlinx.coroutines.flow.q f1911c = new kotlinx.coroutines.flow.q(new SingleProcessCoordinator$updateNotifications$1(2, null));

    public b0(String str) {
    }

    public final Integer a() {
        return new Integer(((AtomicInteger) this.f1910b.f35758b).get());
    }

    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(Continuation continuation, sd.l lVar) {
        SingleProcessCoordinator$lock$1 singleProcessCoordinator$lock$1;
        kotlinx.coroutines.sync.a aVar;
        kotlinx.coroutines.sync.a aVar2;
        Throwable th;
        if (continuation instanceof SingleProcessCoordinator$lock$1) {
            singleProcessCoordinator$lock$1 = (SingleProcessCoordinator$lock$1) continuation;
            int i10 = singleProcessCoordinator$lock$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                singleProcessCoordinator$lock$1.label = i10 - Integer.MIN_VALUE;
            } else {
                singleProcessCoordinator$lock$1 = new SingleProcessCoordinator$lock$1(this, continuation);
            }
        }
        Object obj = singleProcessCoordinator$lock$1.result;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = singleProcessCoordinator$lock$1.label;
        try {
            if (i11 == 0) {
                kotlin.a.d(obj);
                singleProcessCoordinator$lock$1.L$0 = lVar;
                aVar = this.f1909a;
                singleProcessCoordinator$lock$1.L$1 = aVar;
                singleProcessCoordinator$lock$1.label = 1;
                if (aVar.e(singleProcessCoordinator$lock$1) == coroutineSingletons) {
                    return coroutineSingletons;
                }
            } else {
                if (i11 != 1) {
                    if (i11 != 2) {
                        throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                    }
                    aVar2 = (kotlinx.coroutines.sync.a) singleProcessCoordinator$lock$1.L$0;
                    try {
                        kotlin.a.d(obj);
                        aVar2.g(null);
                        return obj;
                    } catch (Throwable th2) {
                        th = th2;
                        aVar2.g(null);
                        throw th;
                    }
                }
                kotlinx.coroutines.sync.a aVar3 = (kotlinx.coroutines.sync.a) singleProcessCoordinator$lock$1.L$1;
                sd.l lVar2 = (sd.l) singleProcessCoordinator$lock$1.L$0;
                kotlin.a.d(obj);
                aVar = aVar3;
                lVar = lVar2;
            }
            singleProcessCoordinator$lock$1.L$0 = aVar;
            singleProcessCoordinator$lock$1.L$1 = null;
            singleProcessCoordinator$lock$1.label = 2;
            Object objInvoke = lVar.invoke(singleProcessCoordinator$lock$1);
            if (objInvoke == coroutineSingletons) {
                return coroutineSingletons;
            }
            aVar2 = aVar;
            obj = objInvoke;
            aVar2.g(null);
            return obj;
        } catch (Throwable th3) {
            aVar2 = aVar;
            th = th3;
            aVar2.g(null);
            throw th;
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0057  */
    /* JADX WARN: Removed duplicated region for block: B:29:0x0061  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object c(Function2 function2, Continuation continuation) {
        SingleProcessCoordinator$tryLock$1 singleProcessCoordinator$tryLock$1;
        kotlinx.coroutines.sync.a aVar;
        Throwable th;
        boolean z10;
        if (continuation instanceof SingleProcessCoordinator$tryLock$1) {
            singleProcessCoordinator$tryLock$1 = (SingleProcessCoordinator$tryLock$1) continuation;
            int i10 = singleProcessCoordinator$tryLock$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                singleProcessCoordinator$tryLock$1.label = i10 - Integer.MIN_VALUE;
            } else {
                singleProcessCoordinator$tryLock$1 = new SingleProcessCoordinator$tryLock$1(this, continuation);
            }
        }
        Object obj = singleProcessCoordinator$tryLock$1.result;
        Object obj2 = CoroutineSingletons.f29226a;
        int i11 = singleProcessCoordinator$tryLock$1.label;
        if (i11 != 0) {
            if (i11 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            z10 = singleProcessCoordinator$tryLock$1.Z$0;
            aVar = (kotlinx.coroutines.sync.a) singleProcessCoordinator$tryLock$1.L$0;
            try {
                kotlin.a.d(obj);
                if (z10) {
                    aVar.g(null);
                }
                return obj;
            } catch (Throwable th2) {
                th = th2;
                if (z10) {
                }
                throw th;
            }
        }
        kotlin.a.d(obj);
        kotlinx.coroutines.sync.c cVar = this.f1909a;
        boolean zC = cVar.c(null);
        try {
            Object objValueOf = Boolean.valueOf(zC);
            singleProcessCoordinator$tryLock$1.L$0 = cVar;
            singleProcessCoordinator$tryLock$1.Z$0 = zC;
            singleProcessCoordinator$tryLock$1.label = 1;
            Object objInvoke = function2.invoke(objValueOf, singleProcessCoordinator$tryLock$1);
            if (objInvoke == obj2) {
                return obj2;
            }
            aVar = cVar;
            obj = objInvoke;
            z10 = zC;
            if (z10) {
            }
            return obj;
        } catch (Throwable th3) {
            aVar = cVar;
            th = th3;
            z10 = zC;
            if (z10) {
                aVar.g(null);
            }
            throw th;
        }
    }
}
