package androidx.datastore.core;

import java.io.Closeable;
import java.io.FileOutputStream;
import java.io.IOException;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.intrinsics.CoroutineSingletons;

/* JADX INFO: loaded from: classes.dex */
public final class s extends p implements j0 {
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(Object obj, Continuation continuation) throws IOException {
        FileWriteScope$writeData$1 fileWriteScope$writeData$1;
        Closeable closeable;
        FileOutputStream fileOutputStream;
        if (continuation instanceof FileWriteScope$writeData$1) {
            fileWriteScope$writeData$1 = (FileWriteScope$writeData$1) continuation;
            int i10 = fileWriteScope$writeData$1.label;
            if ((i10 & Integer.MIN_VALUE) != 0) {
                fileWriteScope$writeData$1.label = i10 - Integer.MIN_VALUE;
            } else {
                fileWriteScope$writeData$1 = new FileWriteScope$writeData$1(this, continuation);
            }
        }
        Object obj2 = fileWriteScope$writeData$1.result;
        CoroutineSingletons coroutineSingletons = CoroutineSingletons.f29226a;
        int i11 = fileWriteScope$writeData$1.label;
        kd.e eVar = kd.e.f29109a;
        if (i11 == 0) {
            kotlin.a.d(obj2);
            if (!(!this.f1947c.get())) {
                throw new IllegalStateException("This scope has already been closed.".toString());
            }
            FileOutputStream fileOutputStream2 = new FileOutputStream(this.f1945a);
            try {
                z zVar = this.f1946b;
                g0 g0Var = new g0(fileOutputStream2);
                fileWriteScope$writeData$1.L$0 = fileOutputStream2;
                fileWriteScope$writeData$1.L$1 = fileOutputStream2;
                fileWriteScope$writeData$1.label = 1;
                zVar.c(obj, g0Var);
                if (eVar == coroutineSingletons) {
                    return coroutineSingletons;
                }
                fileOutputStream = fileOutputStream2;
                closeable = fileOutputStream;
            } catch (Throwable th) {
                th = th;
                closeable = fileOutputStream2;
                throw th;
            }
        } else {
            if (i11 != 1) {
                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
            }
            fileOutputStream = (FileOutputStream) fileWriteScope$writeData$1.L$1;
            closeable = (Closeable) fileWriteScope$writeData$1.L$0;
            try {
                kotlin.a.d(obj2);
            } catch (Throwable th2) {
                th = th2;
                try {
                    throw th;
                } catch (Throwable th3) {
                    ua.b.g(closeable, th);
                    throw th3;
                }
            }
        }
        fileOutputStream.getFD().sync();
        ua.b.g(closeable, null);
        return eVar;
    }
}
