package p7;

import B6.t;
import P6.g;
import X6.e;
import X6.n;
import com.google.android.gms.internal.measurement.C1;
import d3.E;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Pattern;
import k7.C;
import k7.k;
import k7.l;
import k7.o;
import k7.q;
import okhttp3.internal.publicsuffix.PublicSuffixDatabase;
import x7.C1734j;

/* JADX INFO: loaded from: classes.dex */
public abstract class c {
    static {
        C1734j c1734j = C1734j.f18766t;
        E.h("\"\\");
        E.h("\t ,=");
    }

    public static final boolean a(C c3) {
        if (g.a(c3.f14010q.f14203b, "HEAD")) {
            return false;
        }
        int i = c3.f14013t;
        return (((i >= 100 && i < 200) || i == 204 || i == 304) && l7.b.k(c3) == -1 && !"chunked".equalsIgnoreCase(C.a("Transfer-Encoding", c3))) ? false : true;
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:21:0x0080  */
    /* JADX WARN: Type inference failed for: r25v3 */
    /* JADX WARN: Type inference failed for: r26v2 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static final void b(l lVar, q qVar, o oVar) {
        List list;
        int i;
        k kVar;
        int i5;
        k kVar2;
        int i8 = 1;
        g.e(lVar, "<this>");
        g.e(qVar, "url");
        g.e(oVar, "headers");
        if (lVar == l.f14102q) {
            return;
        }
        Pattern pattern = k.f14090j;
        int size = oVar.size();
        int i9 = 0;
        ArrayList arrayList = null;
        for (int i10 = 0; i10 < size; i10++) {
            if ("Set-Cookie".equalsIgnoreCase(oVar.c(i10))) {
                if (arrayList == null) {
                    arrayList = new ArrayList(2);
                }
                arrayList.add(oVar.g(i10));
            }
        }
        List listUnmodifiableList = t.f1032q;
        if (arrayList != null) {
            List listUnmodifiableList2 = Collections.unmodifiableList(arrayList);
            g.d(listUnmodifiableList2, "{\n      Collections.unmodifiableList(result)\n    }");
            list = listUnmodifiableList2;
        } else {
            list = listUnmodifiableList;
        }
        int size2 = list.size();
        int i11 = 0;
        ArrayList arrayList2 = null;
        while (i11 < size2) {
            String str = (String) list.get(i11);
            g.e(str, "setCookie");
            long jCurrentTimeMillis = System.currentTimeMillis();
            byte[] bArr = l7.b.f14412a;
            char c3 = ';';
            int iF = l7.b.f(str, ';', i9, str.length());
            char c8 = '=';
            int iF2 = l7.b.f(str, '=', i9, iF);
            if (iF2 == iF) {
                i = i8;
                i5 = i9;
                kVar2 = null;
            } else {
                String strZ = l7.b.z(i9, iF2, str);
                if (strZ.length() != 0) {
                    i = i8;
                    if (l7.b.m(strZ) == -1) {
                        String strZ2 = l7.b.z(iF2 + 1, iF, str);
                        if (l7.b.m(strZ2) == -1) {
                            int i12 = iF + 1;
                            int length = str.length();
                            long j8 = 253402300799999L;
                            int i13 = i9;
                            int i14 = i13;
                            int i15 = i14 == true ? 1 : 0;
                            long jI = 253402300799999L;
                            boolean z8 = i;
                            String str2 = null;
                            String str3 = null;
                            long j9 = -1;
                            boolean z9 = i14;
                            while (true) {
                                if (i12 < length) {
                                    int iF3 = l7.b.f(str, c3, i12, length);
                                    int iF4 = l7.b.f(str, c8, i12, iF3);
                                    String strZ3 = l7.b.z(i12, iF4, str);
                                    String strZ4 = iF4 < iF3 ? l7.b.z(iF4 + 1, iF3, str) : "";
                                    if (strZ3.equalsIgnoreCase("expires")) {
                                        try {
                                            jI = U2.a.I(strZ4.length(), strZ4);
                                            z9 = i;
                                        } catch (NumberFormatException | IllegalArgumentException unused) {
                                        }
                                    } else if (strZ3.equalsIgnoreCase("max-age")) {
                                        try {
                                            long j10 = Long.parseLong(strZ4);
                                            j9 = j10 <= 0 ? Long.MIN_VALUE : j10;
                                        } catch (NumberFormatException e8) {
                                            Pattern patternCompile = Pattern.compile("-?\\d+");
                                            g.d(patternCompile, "compile(...)");
                                            if (!patternCompile.matcher(strZ4).matches()) {
                                                throw e8;
                                            }
                                            j9 = n.M(strZ4, "-", false) ? Long.MIN_VALUE : Long.MAX_VALUE;
                                        }
                                        z9 = i;
                                    } else if (strZ3.equalsIgnoreCase("domain")) {
                                        if (n.H(strZ4, ".", false)) {
                                            throw new IllegalArgumentException("Failed requirement.");
                                        }
                                        String strO = C1.O(e.Z(strZ4, "."));
                                        if (strO == null) {
                                            throw new IllegalArgumentException();
                                        }
                                        str2 = strO;
                                        z8 = 0;
                                    } else if (strZ3.equalsIgnoreCase("path")) {
                                        str3 = strZ4;
                                    } else if (strZ3.equalsIgnoreCase("secure")) {
                                        i15 = i;
                                    } else if (strZ3.equalsIgnoreCase("httponly")) {
                                        i13 = i;
                                    }
                                    i12 = iF3 + 1;
                                    c3 = ';';
                                    c8 = '=';
                                    z9 = z9;
                                    z8 = z8;
                                } else {
                                    if (j9 == Long.MIN_VALUE) {
                                        j8 = Long.MIN_VALUE;
                                    } else if (j9 != -1) {
                                        long j11 = jCurrentTimeMillis + (j9 <= 9223372036854775L ? j9 * ((long) 1000) : Long.MAX_VALUE);
                                        if (j11 >= jCurrentTimeMillis && j11 <= 253402300799999L) {
                                            j8 = j11;
                                        }
                                    } else {
                                        j8 = jI;
                                    }
                                    String str4 = qVar.f14124d;
                                    if (str2 == null) {
                                        str2 = str4;
                                    } else if (!g.a(str4, str2)) {
                                        if (n.H(str4, str2, false) && str4.charAt((str4.length() - str2.length()) - 1) == '.') {
                                            X6.d dVar = l7.b.f14417f;
                                            dVar.getClass();
                                            if (!dVar.f7248q.matcher(str4).matches()) {
                                            }
                                        }
                                        i5 = 0;
                                        kVar = null;
                                        kVar2 = kVar;
                                    }
                                    if (str4.length() == str2.length() || PublicSuffixDatabase.f16002g.a(str2) != null) {
                                        String strSubstring = "/";
                                        i5 = 0;
                                        if (str3 == null || !n.M(str3, "/", false)) {
                                            String strB = qVar.b();
                                            int iW = e.W(strB, '/', 0, 6);
                                            if (iW != 0) {
                                                strSubstring = strB.substring(0, iW);
                                                g.d(strSubstring, "this as java.lang.String…ing(startIndex, endIndex)");
                                            }
                                            str3 = strSubstring;
                                        }
                                        kVar = new k(strZ, strZ2, j8, str2, str3, i15 == true ? 1 : 0, i13, z9, z8);
                                    } else {
                                        i5 = 0;
                                        kVar = null;
                                    }
                                    kVar2 = kVar;
                                }
                            }
                        }
                    }
                }
                i5 = i9;
                kVar2 = null;
            }
            if (kVar2 != null) {
                if (arrayList2 == null) {
                    arrayList2 = new ArrayList();
                }
                arrayList2.add(kVar2);
            }
            i11++;
            i9 = i5;
            i8 = i;
        }
        if (arrayList2 != null) {
            listUnmodifiableList = Collections.unmodifiableList(arrayList2);
            g.d(listUnmodifiableList, "{\n        Collections.un…ableList(cookies)\n      }");
        }
        listUnmodifiableList.isEmpty();
    }
}
