package androidx.datastore.core;

import java.util.concurrent.atomic.AtomicInteger;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.SuspendLambda;
import kotlin.jvm.functions.Function2;
import kotlin.jvm.internal.Ref$IntRef;

/* JADX INFO: loaded from: classes.dex */
@Metadata(d1 = {"\u0000\f\n\u0000\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0000\u0010\u0003\u001a\u00020\u0002\"\u0004\b\u0000\u0010\u0000*\b\u0012\u0004\u0012\u00028\u00000\u0001H\u008a@"}, d2 = {"T", "Landroidx/datastore/core/j0;", "Lkd/e;", "<anonymous>"}, k = 3, mv = {1, 8, 0})
@DebugMetadata(c = "androidx.datastore.core.DataStoreImpl$writeData$2", f = "DataStoreImpl.kt", i = {0}, l = {352, 353}, m = "invokeSuspend", n = {"$this$writeScope"}, s = {"L$0"})
final class DataStoreImpl$writeData$2 extends SuspendLambda implements Function2 {
    final /* synthetic */ Object $newData;
    final /* synthetic */ Ref$IntRef $newVersion;
    final /* synthetic */ boolean $updateCache;
    private /* synthetic */ Object L$0;
    Object L$1;
    int label;
    final /* synthetic */ n this$0;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public DataStoreImpl$writeData$2(Ref$IntRef ref$IntRef, n nVar, Object obj, boolean z10, Continuation continuation) {
        super(2, continuation);
        this.$newVersion = ref$IntRef;
        this.this$0 = nVar;
        this.$newData = obj;
        this.$updateCache = z10;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        DataStoreImpl$writeData$2 dataStoreImpl$writeData$2 = new DataStoreImpl$writeData$2(this.$newVersion, this.this$0, this.$newData, this.$updateCache, continuation);
        dataStoreImpl$writeData$2.L$0 = obj;
        return dataStoreImpl$writeData$2;
    }

    @Override // kotlin.jvm.functions.Function2
    public final Object invoke(Object obj, Object obj2) {
        return ((DataStoreImpl$writeData$2) create((j0) obj, (Continuation) obj2)).invokeSuspend(kd.e.f29109a);
    }

    /* JADX WARN: Removed duplicated region for block: B:19:0x006d  */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        Ref$IntRef ref$IntRef;
        j0 j0Var;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i10 = this.label;
        if (i10 == 0) {
            kotlin.a.d(obj);
            j0 j0Var2 = (j0) this.L$0;
            ref$IntRef = this.$newVersion;
            u uVarG = this.this$0.g();
            this.L$0 = j0Var2;
            this.L$1 = ref$IntRef;
            this.label = 1;
            Integer num = new Integer(((AtomicInteger) ((b0) uVarG).f1910b.f35758b).incrementAndGet());
            if (num == coroutineSingletons) {
                return coroutineSingletons;
            }
            j0Var = j0Var2;
            obj = num;
        } else {
            if (i10 != 1) {
                if (i10 != 2) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                kotlin.a.d(obj);
                if (this.$updateCache) {
                    o oVar = this.this$0.f1939h;
                    Object obj2 = this.$newData;
                    oVar.c(new d(obj2 != null ? obj2.hashCode() : 0, this.$newVersion.element, obj2));
                }
                return kd.e.f29109a;
            }
            ref$IntRef = (Ref$IntRef) this.L$1;
            j0Var = (j0) this.L$0;
            kotlin.a.d(obj);
        }
        ref$IntRef.element = ((Number) obj).intValue();
        Object obj3 = this.$newData;
        this.L$0 = null;
        this.L$1 = null;
        this.label = 2;
        if (((s) j0Var).b(obj3, this) == coroutineSingletons) {
            return coroutineSingletons;
        }
        if (this.$updateCache) {
        }
        return kd.e.f29109a;
    }
}
