package y7;

import B6.k;
import B6.w;
import N1.C0215p;
import O6.p;
import P6.j;
import P6.l;
import P6.m;
import X6.n;
import com.google.android.gms.internal.measurement.X1;
import d3.C;
import d5.AbstractC0844a;
import java.io.IOException;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import x7.B;
import x7.C1731g;
import x7.E;
import x7.x;

/* JADX INFO: loaded from: classes.dex */
public abstract class b {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final char[] f19040a = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f'};

    public static final int a(char c3) {
        if ('0' <= c3 && c3 < ':') {
            return c3 - '0';
        }
        if ('a' <= c3 && c3 < 'g') {
            return c3 - 'W';
        }
        if ('A' <= c3 && c3 < 'G') {
            return c3 - '7';
        }
        throw new IllegalArgumentException("Unexpected hex digit: " + c3);
    }

    public static final LinkedHashMap b(ArrayList arrayList) {
        String str = x.f18797r;
        x xVarJ = C.j("/", false);
        LinkedHashMap linkedHashMapM0 = w.m0(new A6.h(xVarJ, new f(xVarJ, true, null, 0L, 0L, 0L, 0, 0L, 0, 0, null, null, null, 65532)));
        for (f fVar : k.u0(arrayList, new C0215p(9))) {
            if (((f) linkedHashMapM0.put(fVar.f19053a, fVar)) == null) {
                while (true) {
                    x xVar = fVar.f19053a;
                    x xVarC = xVar.c();
                    if (xVarC != null) {
                        f fVar2 = (f) linkedHashMapM0.get(xVarC);
                        if (fVar2 != null) {
                            fVar2.f19068q.add(xVar);
                            break;
                        }
                        f fVar3 = new f(xVarC, true, null, 0L, 0L, 0L, 0, 0L, 0, 0, null, null, null, 65532);
                        linkedHashMapM0.put(xVarC, fVar3);
                        fVar3.f19068q.add(xVar);
                        fVar = fVar3;
                    }
                }
            }
        }
        return linkedHashMapM0;
    }

    public static final String c(int i) {
        X1.f(16);
        String string = Integer.toString(i, 16);
        P6.g.d(string, "toString(...)");
        return "0x".concat(string);
    }

    public static final f d(B b8) throws IOException {
        int iN = b8.n();
        if (iN != 33639248) {
            throw new IOException("bad zip: expected " + c(33639248) + " but was " + c(iN));
        }
        b8.y(4L);
        short sA = b8.A();
        int i = sA & 65535;
        if ((sA & 1) != 0) {
            throw new IOException("unsupported zip: general purpose bit flag=" + c(i));
        }
        int iA = b8.A() & 65535;
        int iA2 = b8.A() & 65535;
        int iA3 = b8.A() & 65535;
        long jN = ((long) b8.n()) & 4294967295L;
        l lVar = new l();
        lVar.f5534q = ((long) b8.n()) & 4294967295L;
        l lVar2 = new l();
        lVar2.f5534q = ((long) b8.n()) & 4294967295L;
        int iA4 = b8.A() & 65535;
        int iA5 = b8.A() & 65535;
        int iA6 = 65535 & b8.A();
        b8.y(8L);
        l lVar3 = new l();
        lVar3.f5534q = ((long) b8.n()) & 4294967295L;
        String strH = b8.H(iA4);
        if (X6.e.N(strH, (char) 0)) {
            throw new IOException("bad zip: filename contains 0x00");
        }
        long j8 = lVar2.f5534q == 4294967295L ? 8 : 0L;
        if (lVar.f5534q == 4294967295L) {
            j8 += (long) 8;
        }
        if (lVar3.f5534q == 4294967295L) {
            j8 += (long) 8;
        }
        m mVar = new m();
        m mVar2 = new m();
        m mVar3 = new m();
        j jVar = new j();
        e(b8, iA5, new h(jVar, j8, lVar2, b8, lVar, lVar3, mVar, mVar2, mVar3));
        if (j8 > 0 && !jVar.f5532q) {
            throw new IOException("bad zip: zip64 extra required but absent");
        }
        String strH2 = b8.H(iA6);
        String str = x.f18797r;
        return new f(C.j("/", false).e(strH), n.H(strH, "/", false), strH2, jN, lVar.f5534q, lVar2.f5534q, iA, lVar3.f5534q, iA3, iA2, (Long) mVar.f5535q, (Long) mVar2.f5535q, (Long) mVar3.f5535q, 57344);
    }

    public static final void e(B b8, int i, p pVar) throws IOException {
        long j8 = i;
        while (j8 != 0) {
            if (j8 < 4) {
                throw new IOException("bad zip: truncated header in extra field");
            }
            int iA = b8.A() & 65535;
            long jA = ((long) b8.A()) & 65535;
            long j9 = j8 - ((long) 4);
            if (j9 < jA) {
                throw new IOException("bad zip: truncated value in extra field");
            }
            b8.O(jA);
            C1731g c1731g = b8.f18725r;
            long j10 = c1731g.f18765r;
            pVar.k(Integer.valueOf(iA), Long.valueOf(jA));
            long j11 = (c1731g.f18765r + jA) - j10;
            if (j11 < 0) {
                throw new IOException(AbstractC0844a.j("unsupported zip: too many bytes processed for ", iA));
            }
            if (j11 > 0) {
                c1731g.y(j11);
            }
            j8 = j9 - jA;
        }
    }

    public static final f f(B b8, f fVar) throws IOException {
        int iN = b8.n();
        if (iN != 67324752) {
            throw new IOException("bad zip: expected " + c(67324752) + " but was " + c(iN));
        }
        b8.y(2L);
        short sA = b8.A();
        int i = sA & 65535;
        if ((sA & 1) != 0) {
            throw new IOException("unsupported zip: general purpose bit flag=" + c(i));
        }
        b8.y(18L);
        long jA = ((long) b8.A()) & 65535;
        int iA = b8.A() & 65535;
        b8.y(jA);
        if (fVar == null) {
            b8.y(iA);
            return null;
        }
        m mVar = new m();
        m mVar2 = new m();
        m mVar3 = new m();
        e(b8, iA, new g(b8, mVar, mVar2, mVar3));
        return new f(fVar.f19053a, fVar.f19054b, fVar.f19055c, fVar.f19056d, fVar.f19057e, fVar.f19058f, fVar.f19059g, fVar.f19060h, fVar.i, fVar.f19061j, fVar.f19062k, fVar.f19063l, fVar.f19064m, (Integer) mVar.f5535q, (Integer) mVar2.f5535q, (Integer) mVar3.f5535q);
    }

    public static final int g(E e8, int i) {
        int i5;
        P6.g.e(e8, "<this>");
        int i8 = i + 1;
        int length = e8.f18737u.length;
        int[] iArr = e8.f18738v;
        P6.g.e(iArr, "<this>");
        int i9 = length - 1;
        int i10 = 0;
        while (true) {
            if (i10 <= i9) {
                i5 = (i10 + i9) >>> 1;
                int i11 = iArr[i5];
                if (i11 >= i8) {
                    if (i11 <= i8) {
                        break;
                    }
                    i9 = i5 - 1;
                } else {
                    i10 = i5 + 1;
                }
            } else {
                i5 = (-i10) - 1;
                break;
            }
        }
        return i5 >= 0 ? i5 : ~i5;
    }
}
