package Q1;

import O1.InterfaceC0561a;
import O1.N;
import O1.Y;
import O1.a0;
import java.io.IOException;
import kotlin.jvm.internal.o;
import m3.AbstractC2467b;
import n2.AbstractC2613d;
import p5.AbstractC2749t;
import p5.G;
import w4.C3137A;

/* JADX INFO: loaded from: classes.dex */
public final class i implements InterfaceC0561a {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final AbstractC2749t f5897a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final G f5898b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final Y f5899c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public final e f5900d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final a f5901e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final e5.c f5902f;

    public i(AbstractC2749t fileSystem, G path, Y coordinator, e eVar) {
        o.h(fileSystem, "fileSystem");
        o.h(path, "path");
        o.h(coordinator, "coordinator");
        this.f5897a = fileSystem;
        this.f5898b = path;
        this.f5899c = coordinator;
        this.f5900d = eVar;
        this.f5901e = new a();
        this.f5902f = e5.d.a();
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:30:0x0074  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x007c A[Catch: all -> 0x007d, TRY_ENTER, TRY_LEAVE, TryCatch #2 {all -> 0x007d, blocks: (B:33:0x007c, B:42:0x008d, B:41:0x008a, B:38:0x0085), top: B:54:0x0020, inners: #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0095  */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0013  */
    /* JADX WARN: Type inference failed for: r0v10 */
    /* JADX WARN: Type inference failed for: r0v11 */
    /* JADX WARN: Type inference failed for: r0v12, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r0v13, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r0v16 */
    /* JADX WARN: Type inference failed for: r0v17 */
    /* JADX WARN: Type inference failed for: r0v18 */
    /* JADX WARN: Type inference failed for: r0v2, types: [Q1.g, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r0v3 */
    /* JADX WARN: Type inference failed for: r0v4, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r0v6 */
    /* JADX WARN: Type inference failed for: r0v8 */
    /* JADX WARN: Type inference failed for: r8v0, types: [O1.a0] */
    /* JADX WARN: Type inference failed for: r8v1 */
    /* JADX WARN: Type inference failed for: r8v10 */
    /* JADX WARN: Type inference failed for: r8v11 */
    /* JADX WARN: Type inference failed for: r8v12 */
    /* JADX WARN: Type inference failed for: r8v15, types: [boolean] */
    /* JADX WARN: Type inference failed for: r8v16 */
    /* JADX WARN: Type inference failed for: r8v2 */
    /* JADX WARN: Type inference failed for: r8v6 */
    /* JADX WARN: Type inference failed for: r8v8 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object a(a0 a0Var, C4.c cVar) throws Throwable {
        ?? gVar;
        Throwable th;
        c cVar2;
        ?? r8;
        ?? r02;
        if (cVar instanceof g) {
            g gVar2 = (g) cVar;
            int i6 = gVar2.f5889f;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                gVar2.f5889f = i6 - Integer.MIN_VALUE;
                gVar = gVar2;
            } else {
                gVar = new g(this, cVar);
            }
        }
        Object obj = gVar.f5887d;
        B4.a aVar = B4.a.f492a;
        int i7 = gVar.f5889f;
        try {
            if (i7 != 0) {
                if (i7 != 1) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
                a0Var = gVar.f5886c;
                cVar2 = gVar.f5885b;
                gVar = gVar.f5884a;
                try {
                    AbstractC2467b.l(obj);
                    r02 = gVar;
                    r8 = a0Var;
                    try {
                        cVar2.close();
                        th = null;
                    } catch (Throwable th2) {
                        th = th2;
                    }
                    if (th == null) {
                        throw th;
                    }
                    if (r8 != 0) {
                        r02.f5902f.g(null);
                    }
                    return obj;
                } catch (Throwable th3) {
                    th = th3;
                    try {
                        cVar2.close();
                    } catch (Throwable th4) {
                        AbstractC2613d.b(th, th4);
                    }
                    throw th;
                }
            }
            AbstractC2467b.l(obj);
            if (this.f5901e.f5866a.get()) {
                throw new IllegalStateException("StorageConnection has already been disposed.");
            }
            boolean zF = this.f5902f.f();
            try {
                c cVar3 = new c(this.f5897a, this.f5898b);
                try {
                    Boolean boolValueOf = Boolean.valueOf(zF);
                    gVar.f5884a = this;
                    gVar.f5885b = cVar3;
                    gVar.f5886c = zF;
                    gVar.f5889f = 1;
                    Object objInvoke = a0Var.invoke(cVar3, boolValueOf, gVar);
                    if (objInvoke == aVar) {
                        return aVar;
                    }
                    obj = objInvoke;
                    r8 = zF;
                    r02 = this;
                    cVar2 = cVar3;
                    cVar2.close();
                    th = null;
                    if (th == null) {
                    }
                } catch (Throwable th5) {
                    th = th5;
                    a0Var = zF;
                    gVar = this;
                    cVar2 = cVar3;
                    cVar2.close();
                    throw th;
                }
            } catch (Throwable th6) {
                th = th6;
                a0Var = zF;
                gVar = this;
                if (a0Var != 0) {
                }
                throw th;
            }
        } catch (Throwable th7) {
            th = th7;
            if (a0Var != 0) {
                gVar.f5902f.g(null);
            }
            throw th;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:40:0x00ba A[Catch: all -> 0x00ca, IOException -> 0x00cd, TRY_ENTER, TryCatch #9 {IOException -> 0x00cd, all -> 0x00ca, blocks: (B:40:0x00ba, B:42:0x00c2, B:50:0x00d9, B:57:0x00e7, B:56:0x00e4, B:53:0x00df), top: B:86:0x0024, inners: #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:50:0x00d9 A[Catch: all -> 0x00ca, IOException -> 0x00cd, TRY_ENTER, TRY_LEAVE, TryCatch #9 {IOException -> 0x00cd, all -> 0x00ca, blocks: (B:40:0x00ba, B:42:0x00c2, B:50:0x00d9, B:57:0x00e7, B:56:0x00e4, B:53:0x00df), top: B:86:0x0024, inners: #1 }] */
    /* JADX WARN: Removed duplicated region for block: B:76:0x00f3 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:7:0x0015  */
    /* JADX WARN: Type inference failed for: r0v0, types: [java.lang.String] */
    /* JADX WARN: Type inference failed for: r0v1 */
    /* JADX WARN: Type inference failed for: r0v2, types: [p5.G] */
    /* JADX WARN: Type inference failed for: r0v4, types: [p5.G] */
    /* JADX WARN: Type inference failed for: r0v5 */
    /* JADX WARN: Type inference failed for: r0v6, types: [p5.G] */
    /* JADX WARN: Type inference failed for: r0v7, types: [p5.G] */
    /* JADX WARN: Type inference failed for: r0v8 */
    /* JADX WARN: Type inference failed for: r0v9 */
    /* JADX WARN: Type inference failed for: r11v19, types: [p5.t] */
    /* JADX WARN: Type inference failed for: r11v22, types: [p5.t] */
    /* JADX WARN: Type inference failed for: r11v26 */
    /* JADX WARN: Type inference failed for: r11v30 */
    /* JADX WARN: Type inference failed for: r11v8, types: [J4.e] */
    /* JADX WARN: Type inference failed for: r12v15, types: [e5.c, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v16, types: [java.lang.Object] */
    /* JADX WARN: Type inference failed for: r12v2 */
    /* JADX WARN: Type inference failed for: r12v20 */
    /* JADX WARN: Type inference failed for: r12v23 */
    /* JADX WARN: Type inference failed for: r12v3 */
    /* JADX WARN: Type inference failed for: r12v4 */
    /* JADX WARN: Type inference failed for: r12v6 */
    /* JADX WARN: Type inference failed for: r12v7 */
    /* JADX WARN: Type inference failed for: r1v10, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r1v11, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r1v14 */
    /* JADX WARN: Type inference failed for: r1v15 */
    /* JADX WARN: Type inference failed for: r1v16 */
    /* JADX WARN: Type inference failed for: r1v2, types: [A4.d, Q1.h, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r1v3 */
    /* JADX WARN: Type inference failed for: r1v4, types: [p5.t] */
    /* JADX WARN: Type inference failed for: r1v6, types: [p5.t] */
    /* JADX WARN: Type inference failed for: r1v7 */
    /* JADX WARN: Type inference failed for: r1v8 */
    /* JADX WARN: Type inference failed for: r1v9 */
    /* JADX WARN: Type inference failed for: r2v0, types: [B4.a, java.lang.Object] */
    /* JADX WARN: Type inference failed for: r2v1 */
    /* JADX WARN: Type inference failed for: r2v12 */
    /* JADX WARN: Type inference failed for: r2v2 */
    /* JADX WARN: Type inference failed for: r2v3 */
    /* JADX WARN: Type inference failed for: r2v4 */
    /* JADX WARN: Type inference failed for: r2v5 */
    /* JADX WARN: Type inference failed for: r2v6 */
    /* JADX WARN: Type inference failed for: r2v9, types: [e5.a] */
    /* JADX WARN: Type inference failed for: r8v0 */
    /* JADX WARN: Type inference failed for: r8v1, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r8v2 */
    /* JADX WARN: Type inference failed for: r8v3, types: [Q1.i] */
    /* JADX WARN: Type inference failed for: r8v5 */
    /* JADX WARN: Type inference failed for: r9v0, types: [p5.t] */
    /* JADX WARN: Type inference fix 'apply assigned field type' failed
    java.lang.UnsupportedOperationException: ArgType.getObject(), call class: class jadx.core.dex.instructions.args.ArgType$UnknownArg
    	at jadx.core.dex.instructions.args.ArgType.getObject(ArgType.java:593)
    	at jadx.core.dex.attributes.nodes.ClassTypeVarsAttr.getTypeVarsMapFor(ClassTypeVarsAttr.java:35)
    	at jadx.core.dex.nodes.utils.TypeUtils.replaceClassGenerics(TypeUtils.java:177)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.insertExplicitUseCast(FixTypesVisitor.java:397)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.tryFieldTypeWithNewCasts(FixTypesVisitor.java:359)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.applyFieldType(FixTypesVisitor.java:309)
    	at jadx.core.dex.visitors.typeinference.FixTypesVisitor.visit(FixTypesVisitor.java:94)
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object b(N n6, C4.c cVar) throws Throwable {
        ?? hVar;
        ?? r12;
        ?? r8;
        G gC;
        ?? r11;
        ?? r9;
        k kVar;
        Throwable th;
        InterfaceC0561a interfaceC0561a;
        ?? r22;
        ?? r13;
        ?? r02;
        ?? E5 = ".tmp";
        if (cVar instanceof h) {
            h hVar2 = (h) cVar;
            int i6 = hVar2.f5896j;
            if ((i6 & Integer.MIN_VALUE) != 0) {
                hVar2.f5896j = i6 - Integer.MIN_VALUE;
                hVar = hVar2;
            } else {
                hVar = new h(this, cVar);
            }
        }
        Object obj = hVar.f5894e;
        ?? r23 = B4.a.f492a;
        int i7 = hVar.f5896j;
        try {
            try {
                try {
                    try {
                        if (i7 == 0) {
                            AbstractC2467b.l(obj);
                            if (this.f5901e.f5866a.get()) {
                                throw new IllegalStateException("StorageConnection has already been disposed.");
                            }
                            gC = this.f5898b.c();
                            if (gC == null) {
                                throw new IllegalStateException("must have a parent path");
                            }
                            this.f5897a.createDirectories(gC, false);
                            hVar.f5890a = this;
                            hVar.f5891b = n6;
                            hVar.f5892c = gC;
                            ?? r122 = this.f5902f;
                            hVar.f5893d = r122;
                            hVar.f5896j = 1;
                            if (r122.e(hVar) != r23) {
                                r8 = this;
                                r11 = n6;
                                r12 = r122;
                            }
                            return r23;
                        }
                        if (i7 != 1) {
                            if (i7 != 2) {
                                throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                            }
                            interfaceC0561a = (InterfaceC0561a) hVar.f5893d;
                            E5 = hVar.f5892c;
                            r23 = (e5.a) hVar.f5891b;
                            hVar = hVar.f5890a;
                            try {
                                AbstractC2467b.l(obj);
                                r02 = E5;
                                r13 = hVar;
                                r22 = r23;
                                try {
                                    interfaceC0561a.close();
                                    th = null;
                                } catch (Throwable th2) {
                                    th = th2;
                                }
                                if (th == null) {
                                    throw th;
                                }
                                if (r13.f5897a.exists(r02)) {
                                    r13.f5897a.atomicMove(r02, r13.f5898b);
                                }
                                ((e5.c) r22).g(null);
                                return C3137A.f25453a;
                            } catch (Throwable th3) {
                                th = th3;
                                try {
                                    interfaceC0561a.close();
                                } catch (Throwable th4) {
                                    AbstractC2613d.b(th, th4);
                                }
                                throw th;
                            }
                        }
                        e5.a aVar = (e5.a) hVar.f5893d;
                        gC = hVar.f5892c;
                        J4.e eVar = (J4.e) hVar.f5891b;
                        i iVar = hVar.f5890a;
                        AbstractC2467b.l(obj);
                        r12 = aVar;
                        r11 = eVar;
                        r8 = iVar;
                        hVar.f5890a = r8;
                        hVar.f5891b = r12;
                        hVar.f5892c = E5;
                        hVar.f5893d = kVar;
                        hVar.f5896j = 2;
                        if (r11.invoke(kVar, hVar) != r23) {
                            r22 = r12;
                            interfaceC0561a = kVar;
                            r13 = r8;
                            r02 = E5;
                            interfaceC0561a.close();
                            th = null;
                            if (th == null) {
                            }
                        }
                        return r23;
                    } catch (Throwable th5) {
                        r23 = r12;
                        hVar = r8;
                        th = th5;
                        interfaceC0561a = kVar;
                        interfaceC0561a.close();
                        throw th;
                    }
                    r9.delete(E5, false);
                    kVar = new k(r9, E5);
                } catch (IOException e6) {
                    e = e6;
                    if (r8.f5897a.exists(E5)) {
                        try {
                            r8.f5897a.delete(E5);
                        } catch (IOException unused) {
                        }
                    }
                    throw e;
                }
                G g6 = r8.f5898b;
                r9 = r8.f5897a;
                E5 = gC.e(g6.b().concat(".tmp"));
            } catch (Throwable th6) {
                th = th6;
                ((e5.c) r12).g(null);
                throw th;
            }
        } catch (IOException e7) {
            e = e7;
            r8 = hVar;
            r12 = r23;
            if (r8.f5897a.exists(E5)) {
            }
            throw e;
        } catch (Throwable th7) {
            th = th7;
            r12 = r23;
            ((e5.c) r12).g(null);
            throw th;
        }
    }

    @Override // O1.InterfaceC0561a
    public final void close() {
        this.f5901e.f5866a.set(true);
        this.f5900d.invoke();
    }
}
