package defpackage;

import androidx.room.RoomDatabase;
import defpackage.gj1;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;

/* JADX INFO: renamed from: m58, reason: from Kotlin metadata and case insensitive filesystem */
/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\b\n\u0000\n\u0002\u0018\u0002\n\u0000\u0010\u0002\u001a\u00028\u0000\"\u0004\b\u0000\u0010\u0000*\u00020\u0001H\u008a@"}, d2 = {"R", "Lak1;", "<anonymous>"}, k = 3, mv = {1, 8, 0})
@DebugMetadata(c = "androidx.room.RoomDatabaseKt$withTransaction$transactionBlock$1", f = "RoomDatabaseExt.kt", i = {0}, l = {62}, m = "invokeSuspend", n = {"transactionElement"}, s = {"L$0"})
final class C0617m58 extends SuspendLambda implements gr3<ak1, Continuation<Object>, Object> {
    public int a;
    public /* synthetic */ Object b;
    public final /* synthetic */ RoomDatabase c;
    public final /* synthetic */ sq3 d;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0617m58(RoomDatabase roomDatabase, sq3 sq3Var, Continuation continuation) {
        super(2, continuation);
        this.c = roomDatabase;
        this.d = sq3Var;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        C0617m58 c0617m58 = new C0617m58(this.c, this.d, continuation);
        c0617m58.b = obj;
        return c0617m58;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((C0617m58) create((ak1) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Type inference failed for: r0v0, types: [ck1, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r0v5 */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Object invokeSuspend(Object obj) throws Throwable {
        Throwable th;
        us9 us9Var;
        us9 us9Var2 = ck1.a;
        int i = this.a;
        RoomDatabase roomDatabase = this.c;
        try {
            if (i == 0) {
                s38.b(obj);
                gj1.b bVarCb = ((ak1) this.b).getI().cb(us9.c);
                cr4.d(bVarCb);
                us9 us9Var3 = (us9) bVarCb;
                us9Var3.b.incrementAndGet();
                try {
                    roomDatabase.beginTransaction();
                    try {
                        sq3 sq3Var = this.d;
                        this.b = us9Var3;
                        this.a = 1;
                        Object objInvoke = sq3Var.invoke(this);
                        if (objInvoke == us9Var2) {
                            return us9Var2;
                        }
                        us9Var = us9Var3;
                        obj = objInvoke;
                    } catch (Throwable th2) {
                        th = th2;
                        roomDatabase.endTransaction();
                        throw th;
                    }
                } catch (Throwable th3) {
                    us9Var2 = us9Var3;
                    th = th3;
                    if (us9Var2.b.decrementAndGet() >= 0) {
                        throw th;
                    }
                    throw new IllegalStateException("Transaction was never started or was already released.");
                }
            } else {
                if (i != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                us9Var = (us9) this.b;
                try {
                    s38.b(obj);
                } catch (Throwable th4) {
                    th = th4;
                    roomDatabase.endTransaction();
                    throw th;
                }
            }
            roomDatabase.setTransactionSuccessful();
            roomDatabase.endTransaction();
            if (us9Var.b.decrementAndGet() >= 0) {
                return obj;
            }
            throw new IllegalStateException("Transaction was never started or was already released.");
        } catch (Throwable th5) {
            th = th5;
        }
    }
}
