package o;

import com.google.android.gms.common.api.Api;
import java.io.IOException;
import java.net.ProtocolException;
import java.util.Iterator;
import java.util.List;
import java.util.regex.Pattern;
import javax.net.ssl.SSLSocketFactory;

/* compiled from: r8-map-id-3b7cc9102578c509342fa2f0fabed2bfc72239cd258d579fc679bfcbc198b048 */
/* renamed from: o.Ee, reason: case insensitive filesystem */
/* loaded from: classes.dex */
public final class C0108Ee implements InterfaceC2229qI {
    public final /* synthetic */ int a;
    public final Object b;

    public /* synthetic */ C0108Ee(int i, Object obj) {
        this.a = i;
        this.b = obj;
    }

    public static int d(C20 c20, int i) {
        String strA = c20.q.a("Retry-After");
        if (strA == null) {
            strA = null;
        }
        return strA == null ? i : Pattern.compile("\\d+").matcher(strA).matches() ? Integer.valueOf(strA).intValue() : Api.BaseClientBuilder.API_PRIORITY_OTHER;
    }

    @Override // o.InterfaceC2229qI
    public final C20 a(A00 a00) {
        AbstractC3081zG abstractC3081zG;
        SSLSocketFactory sSLSocketFactory;
        C2240qT c2240qT;
        C0395Pg c0395Pg;
        switch (this.a) {
            case 0:
                ME me = (ME) this.b;
                U7 u7 = a00.e;
                Q1 q1T = u7.t();
                ZF zf = (ZF) u7.m;
                LE le = (LE) u7.f352o;
                AbstractC0752ap abstractC0752ap = (AbstractC0752ap) u7.p;
                if (abstractC0752ap != null) {
                    C2804wO c2804wOA = abstractC0752ap.A();
                    if (c2804wOA != null) {
                        q1T.t("Content-Type", c2804wOA.a);
                    }
                    long jZ = abstractC0752ap.z();
                    if (jZ != -1) {
                        q1T.t("Content-Length", String.valueOf(jZ));
                        q1T.z("Transfer-Encoding");
                    } else {
                        q1T.t("Transfer-Encoding", "chunked");
                        q1T.z("Content-Length");
                    }
                }
                boolean z = false;
                if (le.a("Host") == null) {
                    q1T.t("Host", AbstractC2264qi0.v(zf, false));
                }
                if (le.a("Connection") == null) {
                    q1T.t("Connection", "Keep-Alive");
                }
                if (le.a("Accept-Encoding") == null && le.a("Range") == null) {
                    q1T.t("Accept-Encoding", "gzip");
                    z = true;
                }
                me.getClass();
                if (le.a("User-Agent") == null) {
                    q1T.t("User-Agent", "okhttp/4.12.0");
                }
                C20 c20B = a00.b(q1T.g());
                LE le2 = c20B.q;
                TF.b(me, zf, le2);
                B20 b20C = c20B.c();
                b20C.a = u7;
                if (z) {
                    String strA = le2.a("Content-Encoding");
                    if (strA == null) {
                        strA = null;
                    }
                    if ("gzip".equalsIgnoreCase(strA) && TF.a(c20B) && (abstractC3081zG = c20B.r) != null) {
                        C2794wE c2794wE = new C2794wE(abstractC3081zG.f());
                        KE keC = le2.c();
                        keC.o("Content-Encoding");
                        keC.o("Content-Length");
                        b20C.f = keC.d().c();
                        String strA2 = le2.a("Content-Type");
                        b20C.g = new D00(strA2 != null ? strA2 : null, -1L, new C1822m00(c2794wE));
                    }
                }
                return b20C.a();
            default:
                U7 u72 = a00.e;
                C2202q00 c2202q00 = a00.a;
                List listM0 = C0332Mv.l;
                C20 c20 = null;
                int i = 0;
                U7 u7B = u72;
                while (true) {
                    boolean z2 = true;
                    while (c2202q00.t == null) {
                        synchronized (c2202q00) {
                            try {
                                if (c2202q00.v) {
                                    throw new IllegalStateException("cannot make a new request because the previous response is still open: please call response.close()");
                                }
                                if (c2202q00.u) {
                                    throw new IllegalStateException("Check failed.");
                                }
                            } catch (Throwable th) {
                                throw th;
                            }
                        }
                        if (z2) {
                            C1715kt c1715kt = c2202q00.n;
                            ZF zf2 = (ZF) u7B.m;
                            C2429sT c2429sT = c2202q00.l;
                            if (zf2.i) {
                                SSLSocketFactory sSLSocketFactory2 = c2429sT.z;
                                if (sSLSocketFactory2 == null) {
                                    throw new IllegalStateException("CLEARTEXT-only client");
                                }
                                C2240qT c2240qT2 = c2429sT.D;
                                c0395Pg = c2429sT.E;
                                sSLSocketFactory = sSLSocketFactory2;
                                c2240qT = c2240qT2;
                            } else {
                                sSLSocketFactory = null;
                                c2240qT = null;
                                c0395Pg = null;
                            }
                            c2202q00.r = new C1414hl(c1715kt, new U1(zf2.d, zf2.e, c2429sT.v, c2429sT.y, sSLSocketFactory, c2240qT, c0395Pg, c2429sT.x, c2429sT.C, c2429sT.B, c2429sT.w), c2202q00);
                        }
                        try {
                            if (c2202q00.x) {
                                throw new IOException("Canceled");
                            }
                            try {
                                try {
                                    C20 c20B2 = a00.b(u7B);
                                    if (c20 != null) {
                                        B20 b20C2 = c20B2.c();
                                        B20 b20C3 = c20.c();
                                        b20C3.g = null;
                                        C20 c20A = b20C3.a();
                                        if (c20A.r != null) {
                                            throw new IllegalArgumentException("priorResponse.body != null");
                                        }
                                        b20C2.j = c20A;
                                        c20B2 = b20C2.a();
                                    }
                                    c20 = c20B2;
                                    u7B = b(c20, c2202q00.t);
                                    if (u7B == null) {
                                        c2202q00.f(false);
                                        return c20;
                                    }
                                    AbstractC3081zG abstractC3081zG2 = c20.r;
                                    if (abstractC3081zG2 != null) {
                                        AbstractC2264qi0.d(abstractC3081zG2);
                                    }
                                    i++;
                                    if (i > 20) {
                                        throw new ProtocolException("Too many follow-up requests: " + i);
                                    }
                                    c2202q00.f(true);
                                } catch (IOException e) {
                                    if (!c(e, c2202q00, u7B, !(e instanceof C1699kl))) {
                                        Iterator it = listM0.iterator();
                                        while (it.hasNext()) {
                                            C80.i(e, (Exception) it.next());
                                        }
                                        throw e;
                                    }
                                    listM0 = AbstractC3117zi.m0(listM0, e);
                                    c2202q00.f(true);
                                    z2 = false;
                                }
                            } catch (C2682v30 e2) {
                                if (!c(e2.m, c2202q00, u7B, false)) {
                                    IOException iOException = e2.l;
                                    Iterator it2 = listM0.iterator();
                                    while (it2.hasNext()) {
                                        C80.i(iOException, (Exception) it2.next());
                                    }
                                    throw iOException;
                                }
                                listM0 = AbstractC3117zi.m0(listM0, e2.l);
                                c2202q00.f(true);
                                z2 = false;
                            }
                        } catch (Throwable th2) {
                            c2202q00.f(true);
                            throw th2;
                        }
                    }
                    throw new IllegalStateException("Check failed.");
                }
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:66:0x00c2  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public o.U7 b(o.C20 r12, o.C2398s4 r13) throws java.net.ProtocolException {
        /*
            Method dump skipped, instructions count: 368
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C0108Ee.b(o.C20, o.s4):o.U7");
    }

    /* JADX WARN: Removed duplicated region for block: B:33:0x0046  */
    /* JADX WARN: Removed duplicated region for block: B:36:0x004d  */
    /* JADX WARN: Removed duplicated region for block: B:63:0x0088  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public boolean c(java.io.IOException r4, o.C2202q00 r5, o.U7 r6, boolean r7) {
        /*
            r3 = this;
            java.lang.Object r6 = r3.b
            o.sT r6 = (o.C2429sT) r6
            boolean r6 = r6.q
            r0 = 0
            if (r6 != 0) goto Lb
            goto La4
        Lb:
            if (r7 == 0) goto L12
            boolean r6 = r4 instanceof java.io.FileNotFoundException
            if (r6 == 0) goto L12
            return r0
        L12:
            boolean r6 = r4 instanceof java.net.ProtocolException
            if (r6 == 0) goto L17
            return r0
        L17:
            boolean r6 = r4 instanceof java.io.InterruptedIOException
            if (r6 == 0) goto L22
            boolean r4 = r4 instanceof java.net.SocketTimeoutException
            if (r4 == 0) goto La4
            if (r7 != 0) goto La4
            goto L35
        L22:
            boolean r6 = r4 instanceof javax.net.ssl.SSLHandshakeException
            if (r6 == 0) goto L30
            java.lang.Throwable r6 = r4.getCause()
            boolean r6 = r6 instanceof java.security.cert.CertificateException
            if (r6 == 0) goto L30
            goto La4
        L30:
            boolean r4 = r4 instanceof javax.net.ssl.SSLPeerUnverifiedException
            if (r4 == 0) goto L35
            return r0
        L35:
            o.hl r4 = r5.r
            int r5 = r4.a
            r6 = 1
            if (r5 != 0) goto L46
            int r7 = r4.b
            if (r7 != 0) goto L46
            int r7 = r4.c
            if (r7 != 0) goto L46
            r4 = r0
            goto La2
        L46:
            java.lang.Object r7 = r4.i
            o.u30 r7 = (o.C2587u30) r7
            if (r7 == 0) goto L4d
            goto L9d
        L4d:
            r7 = 0
            if (r5 > r6) goto L84
            int r5 = r4.b
            if (r5 > r6) goto L84
            int r5 = r4.c
            if (r5 <= 0) goto L59
            goto L84
        L59:
            java.lang.Object r5 = r4.f
            o.q00 r5 = (o.C2202q00) r5
            o.t00 r5 = r5.s
            if (r5 != 0) goto L62
            goto L84
        L62:
            monitor-enter(r5)
            int r1 = r5.l     // Catch: java.lang.Throwable -> L81
            if (r1 == 0) goto L69
            monitor-exit(r5)
            goto L84
        L69:
            o.u30 r1 = r5.b     // Catch: java.lang.Throwable -> L81
            o.U1 r1 = r1.a     // Catch: java.lang.Throwable -> L81
            o.ZF r1 = r1.h     // Catch: java.lang.Throwable -> L81
            java.lang.Object r2 = r4.e     // Catch: java.lang.Throwable -> L81
            o.U1 r2 = (o.U1) r2     // Catch: java.lang.Throwable -> L81
            o.ZF r2 = r2.h     // Catch: java.lang.Throwable -> L81
            boolean r1 = o.AbstractC2264qi0.a(r1, r2)     // Catch: java.lang.Throwable -> L81
            if (r1 != 0) goto L7d
            monitor-exit(r5)
            goto L84
        L7d:
            o.u30 r7 = r5.b     // Catch: java.lang.Throwable -> L81
            monitor-exit(r5)
            goto L84
        L81:
            r4 = move-exception
            monitor-exit(r5)
            throw r4
        L84:
            if (r7 == 0) goto L8a
            r4.i = r7
        L88:
            r4 = r6
            goto La2
        L8a:
            java.lang.Object r5 = r4.g
            o.g30 r5 = (o.C1257g30) r5
            if (r5 == 0) goto L97
            boolean r5 = r5.a()
            if (r5 != r6) goto L97
            goto L9d
        L97:
            java.lang.Object r4 = r4.h
            o.v7 r4 = (o.C2689v7) r4
            if (r4 != 0) goto L9e
        L9d:
            goto L88
        L9e:
            boolean r4 = r4.l()
        La2:
            if (r4 != 0) goto La5
        La4:
            return r0
        La5:
            return r6
        */
        throw new UnsupportedOperationException("Method not decompiled: o.C0108Ee.c(java.io.IOException, o.q00, o.U7, boolean):boolean");
    }
}
