package androidx.profileinstaller;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import d3.c;
import d3.n;
import defpackage.e;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.BitSet;
import java.util.Iterator;
import java.util.Map;
import java.util.TreeMap;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final byte[] f3654a = {112, 114, 111, 0};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final byte[] f3655b = {112, 114, 109, 0};

    public static byte[] a(d3.b[] bVarArr, byte[] bArr) throws IOException {
        int i10 = 0;
        int length = 0;
        for (d3.b bVar : bVarArr) {
            length += ((((bVar.f24952g * 2) + 7) & (-8)) / 8) + (bVar.f24950e * 2) + b(bArr, bVar.f24946a, bVar.f24947b).getBytes(StandardCharsets.UTF_8).length + 16 + bVar.f24951f;
        }
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(length);
        if (Arrays.equals(bArr, n.f24972c)) {
            int length2 = bVarArr.length;
            while (i10 < length2) {
                d3.b bVar2 = bVarArr[i10];
                m(byteArrayOutputStream, bVar2, b(bArr, bVar2.f24946a, bVar2.f24947b));
                l(byteArrayOutputStream, bVar2);
                i10++;
            }
        } else {
            for (d3.b bVar3 : bVarArr) {
                m(byteArrayOutputStream, bVar3, b(bArr, bVar3.f24946a, bVar3.f24947b));
            }
            int length3 = bVarArr.length;
            while (i10 < length3) {
                l(byteArrayOutputStream, bVarArr[i10]);
                i10++;
            }
        }
        if (byteArrayOutputStream.size() == length) {
            return byteArrayOutputStream.toByteArray();
        }
        throw c.error("The bytes saved do not match expectation. actual=" + byteArrayOutputStream.size() + " expected=" + length);
    }

    public static String b(byte[] bArr, String str, String str2) {
        byte[] bArr2 = n.f24974e;
        boolean zEquals = Arrays.equals(bArr, bArr2);
        byte[] bArr3 = n.f24973d;
        String str3 = (zEquals || Arrays.equals(bArr, bArr3)) ? ":" : "!";
        if (str.length() <= 0) {
            return "!".equals(str3) ? str2.replace(":", "!") : ":".equals(str3) ? str2.replace("!", ":") : str2;
        }
        if (str2.equals("classes.dex")) {
            return str;
        }
        if (str2.contains("!") || str2.contains(":")) {
            return "!".equals(str3) ? str2.replace(":", "!") : ":".equals(str3) ? str2.replace("!", ":") : str2;
        }
        if (str2.endsWith(".apk")) {
            return str2;
        }
        return e.o(u.a.c(str), (Arrays.equals(bArr, bArr2) || Arrays.equals(bArr, bArr3)) ? ":" : "!", str2);
    }

    public static int c(int i10, int i11, int i12) {
        if (i10 == 1) {
            throw c.error("HOT methods are not stored in the bitmap");
        }
        if (i10 == 2) {
            return i11;
        }
        if (i10 == 4) {
            return i11 + i12;
        }
        throw c.error("Unexpected flag: " + i10);
    }

    public static int[] d(ByteArrayInputStream byteArrayInputStream, int i10) {
        int[] iArr = new int[i10];
        int iD = 0;
        for (int i11 = 0; i11 < i10; i11++) {
            iD += (int) c.d(byteArrayInputStream, 2);
            iArr[i11] = iD;
        }
        return iArr;
    }

    public static d3.b[] e(InputStream inputStream, byte[] bArr, byte[] bArr2, d3.b[] bVarArr) throws IOException {
        byte[] bArr3 = n.f24975f;
        if (!Arrays.equals(bArr, bArr3)) {
            if (!Arrays.equals(bArr, n.f24976g)) {
                throw c.error("Unsupported meta version");
            }
            int iD = (int) c.d(inputStream, 2);
            byte[] bArrC = c.c(inputStream, (int) c.d(inputStream, 4), (int) c.d(inputStream, 4));
            if (inputStream.read() > 0) {
                throw c.error("Content found after the end of file");
            }
            ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArrC);
            try {
                d3.b[] bVarArrG = g(byteArrayInputStream, bArr2, iD, bVarArr);
                byteArrayInputStream.close();
                return bVarArrG;
            } catch (Throwable th) {
                try {
                    byteArrayInputStream.close();
                } catch (Throwable th2) {
                    th.addSuppressed(th2);
                }
                throw th;
            }
        }
        if (Arrays.equals(n.f24970a, bArr2)) {
            throw c.error("Requires new Baseline Profile Metadata. Please rebuild the APK with Android Gradle Plugin 7.2 Canary 7 or higher");
        }
        if (!Arrays.equals(bArr, bArr3)) {
            throw c.error("Unsupported meta version");
        }
        int iD2 = (int) c.d(inputStream, 1);
        byte[] bArrC2 = c.c(inputStream, (int) c.d(inputStream, 4), (int) c.d(inputStream, 4));
        if (inputStream.read() > 0) {
            throw c.error("Content found after the end of file");
        }
        ByteArrayInputStream byteArrayInputStream2 = new ByteArrayInputStream(bArrC2);
        try {
            d3.b[] bVarArrF = f(byteArrayInputStream2, iD2, bVarArr);
            byteArrayInputStream2.close();
            return bVarArrF;
        } catch (Throwable th3) {
            try {
                byteArrayInputStream2.close();
            } catch (Throwable th4) {
                th3.addSuppressed(th4);
            }
            throw th3;
        }
    }

    public static d3.b[] f(ByteArrayInputStream byteArrayInputStream, int i10, d3.b[] bVarArr) {
        if (byteArrayInputStream.available() == 0) {
            return new d3.b[0];
        }
        if (i10 != bVarArr.length) {
            throw c.error("Mismatched number of dex files found in metadata");
        }
        String[] strArr = new String[i10];
        int[] iArr = new int[i10];
        for (int i11 = 0; i11 < i10; i11++) {
            int iD = (int) c.d(byteArrayInputStream, 2);
            iArr[i11] = (int) c.d(byteArrayInputStream, 2);
            strArr[i11] = new String(c.b(byteArrayInputStream, iD), StandardCharsets.UTF_8);
        }
        for (int i12 = 0; i12 < i10; i12++) {
            d3.b bVar = bVarArr[i12];
            if (!bVar.f24947b.equals(strArr[i12])) {
                throw c.error("Order of dexfiles in metadata did not match baseline");
            }
            int i13 = iArr[i12];
            bVar.f24950e = i13;
            bVar.f24953h = d(byteArrayInputStream, i13);
        }
        return bVarArr;
    }

    @Nullable
    private static d3.b findByDexName(@NonNull d3.b[] bVarArr, @NonNull String str) {
        if (bVarArr.length <= 0) {
            return null;
        }
        int iIndexOf = str.indexOf("!");
        if (iIndexOf < 0) {
            iIndexOf = str.indexOf(":");
        }
        if (iIndexOf > 0) {
            str = str.substring(iIndexOf + 1);
        }
        for (int i10 = 0; i10 < bVarArr.length; i10++) {
            if (bVarArr[i10].f24947b.equals(str)) {
                return bVarArr[i10];
            }
        }
        return null;
    }

    public static d3.b[] g(ByteArrayInputStream byteArrayInputStream, byte[] bArr, int i10, d3.b[] bVarArr) throws IOException {
        if (byteArrayInputStream.available() == 0) {
            return new d3.b[0];
        }
        if (i10 != bVarArr.length) {
            throw c.error("Mismatched number of dex files found in metadata");
        }
        for (int i11 = 0; i11 < i10; i11++) {
            c.d(byteArrayInputStream, 2);
            String str = new String(c.b(byteArrayInputStream, (int) c.d(byteArrayInputStream, 2)), StandardCharsets.UTF_8);
            long jD = c.d(byteArrayInputStream, 4);
            int iD = (int) c.d(byteArrayInputStream, 2);
            d3.b bVarFindByDexName = findByDexName(bVarArr, str);
            if (bVarFindByDexName == null) {
                throw c.error("Missing profile key: ".concat(str));
            }
            bVarFindByDexName.f24949d = jD;
            int[] iArrD = d(byteArrayInputStream, iD);
            if (Arrays.equals(bArr, n.f24974e)) {
                bVarFindByDexName.f24950e = iD;
                bVarFindByDexName.f24953h = iArrD;
            }
        }
        return bVarArr;
    }

    public static d3.b[] h(InputStream inputStream, byte[] bArr, String str) throws IOException {
        if (!Arrays.equals(bArr, n.f24971b)) {
            throw c.error("Unsupported version");
        }
        int iD = (int) c.d(inputStream, 1);
        byte[] bArrC = c.c(inputStream, (int) c.d(inputStream, 4), (int) c.d(inputStream, 4));
        if (inputStream.read() > 0) {
            throw c.error("Content found after the end of file");
        }
        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bArrC);
        try {
            d3.b[] bVarArrI = i(byteArrayInputStream, str, iD);
            byteArrayInputStream.close();
            return bVarArrI;
        } catch (Throwable th) {
            try {
                byteArrayInputStream.close();
            } catch (Throwable th2) {
                th.addSuppressed(th2);
            }
            throw th;
        }
    }

    public static d3.b[] i(ByteArrayInputStream byteArrayInputStream, String str, int i10) throws IOException {
        TreeMap treeMap;
        if (byteArrayInputStream.available() == 0) {
            return new d3.b[0];
        }
        d3.b[] bVarArr = new d3.b[i10];
        for (int i11 = 0; i11 < i10; i11++) {
            int iD = (int) c.d(byteArrayInputStream, 2);
            int iD2 = (int) c.d(byteArrayInputStream, 2);
            bVarArr[i11] = new d3.b(str, new String(c.b(byteArrayInputStream, iD), StandardCharsets.UTF_8), c.d(byteArrayInputStream, 4), iD2, (int) c.d(byteArrayInputStream, 4), (int) c.d(byteArrayInputStream, 4), new int[iD2], new TreeMap());
        }
        for (int i12 = 0; i12 < i10; i12++) {
            d3.b bVar = bVarArr[i12];
            int iAvailable = byteArrayInputStream.available() - bVar.f24951f;
            int iD3 = 0;
            while (true) {
                int iAvailable2 = byteArrayInputStream.available();
                treeMap = bVar.f24954i;
                if (iAvailable2 <= iAvailable) {
                    break;
                }
                iD3 += (int) c.d(byteArrayInputStream, 2);
                treeMap.put(Integer.valueOf(iD3), 1);
                for (int iD4 = (int) c.d(byteArrayInputStream, 2); iD4 > 0; iD4--) {
                    c.d(byteArrayInputStream, 2);
                    int iD5 = (int) c.d(byteArrayInputStream, 1);
                    if (iD5 != 6 && iD5 != 7) {
                        while (iD5 > 0) {
                            c.d(byteArrayInputStream, 1);
                            for (int iD6 = (int) c.d(byteArrayInputStream, 1); iD6 > 0; iD6--) {
                                c.d(byteArrayInputStream, 2);
                            }
                            iD5--;
                        }
                    }
                }
            }
            if (byteArrayInputStream.available() != iAvailable) {
                throw c.error("Read too much data during profile line parse");
            }
            bVar.f24953h = d(byteArrayInputStream, bVar.f24950e);
            int i13 = bVar.f24952g;
            BitSet bitSetValueOf = BitSet.valueOf(c.b(byteArrayInputStream, (((i13 * 2) + 7) & (-8)) / 8));
            for (int i14 = 0; i14 < i13; i14++) {
                int i15 = bitSetValueOf.get(c(2, i14, i13)) ? 2 : 0;
                if (bitSetValueOf.get(c(4, i14, i13))) {
                    i15 |= 4;
                }
                if (i15 != 0) {
                    Integer num = (Integer) treeMap.get(Integer.valueOf(i14));
                    if (num == null) {
                        num = 0;
                    }
                    treeMap.put(Integer.valueOf(i14), Integer.valueOf(i15 | num.intValue()));
                }
            }
        }
        return bVarArr;
    }

    /* JADX WARN: Finally extract failed */
    public static boolean j(ByteArrayOutputStream byteArrayOutputStream, byte[] bArr, d3.b[] bVarArr) throws IOException {
        ArrayList arrayList;
        int length;
        byte[] bArr2 = n.f24970a;
        int i10 = 0;
        if (!Arrays.equals(bArr, bArr2)) {
            byte[] bArr3 = n.f24971b;
            if (Arrays.equals(bArr, bArr3)) {
                byte[] bArrA = a(bVarArr, bArr3);
                c.e(byteArrayOutputStream, bVarArr.length, 1);
                c.e(byteArrayOutputStream, bArrA.length, 4);
                byte[] bArrA2 = c.a(bArrA);
                c.e(byteArrayOutputStream, bArrA2.length, 4);
                byteArrayOutputStream.write(bArrA2);
                return true;
            }
            byte[] bArr4 = n.f24973d;
            if (Arrays.equals(bArr, bArr4)) {
                c.e(byteArrayOutputStream, bVarArr.length, 1);
                for (d3.b bVar : bVarArr) {
                    int size = bVar.f24954i.size() * 4;
                    String strB = b(bArr4, bVar.f24946a, bVar.f24947b);
                    Charset charset = StandardCharsets.UTF_8;
                    c.f(byteArrayOutputStream, strB.getBytes(charset).length);
                    c.f(byteArrayOutputStream, bVar.f24953h.length);
                    c.e(byteArrayOutputStream, size, 4);
                    c.e(byteArrayOutputStream, bVar.f24948c, 4);
                    byteArrayOutputStream.write(strB.getBytes(charset));
                    Iterator it = bVar.f24954i.keySet().iterator();
                    while (it.hasNext()) {
                        c.f(byteArrayOutputStream, ((Integer) it.next()).intValue());
                        c.f(byteArrayOutputStream, 0);
                    }
                    for (int i11 : bVar.f24953h) {
                        c.f(byteArrayOutputStream, i11);
                    }
                }
                return true;
            }
            byte[] bArr5 = n.f24972c;
            if (Arrays.equals(bArr, bArr5)) {
                byte[] bArrA3 = a(bVarArr, bArr5);
                c.e(byteArrayOutputStream, bVarArr.length, 1);
                c.e(byteArrayOutputStream, bArrA3.length, 4);
                byte[] bArrA4 = c.a(bArrA3);
                c.e(byteArrayOutputStream, bArrA4.length, 4);
                byteArrayOutputStream.write(bArrA4);
                return true;
            }
            byte[] bArr6 = n.f24974e;
            if (!Arrays.equals(bArr, bArr6)) {
                return false;
            }
            c.f(byteArrayOutputStream, bVarArr.length);
            for (d3.b bVar2 : bVarArr) {
                String strB2 = b(bArr6, bVar2.f24946a, bVar2.f24947b);
                Charset charset2 = StandardCharsets.UTF_8;
                c.f(byteArrayOutputStream, strB2.getBytes(charset2).length);
                TreeMap treeMap = bVar2.f24954i;
                c.f(byteArrayOutputStream, treeMap.size());
                c.f(byteArrayOutputStream, bVar2.f24953h.length);
                c.e(byteArrayOutputStream, bVar2.f24948c, 4);
                byteArrayOutputStream.write(strB2.getBytes(charset2));
                Iterator it2 = treeMap.keySet().iterator();
                while (it2.hasNext()) {
                    c.f(byteArrayOutputStream, ((Integer) it2.next()).intValue());
                }
                for (int i12 : bVar2.f24953h) {
                    c.f(byteArrayOutputStream, i12);
                }
            }
            return true;
        }
        ArrayList arrayList2 = new ArrayList(3);
        ArrayList arrayList3 = new ArrayList(3);
        ByteArrayOutputStream byteArrayOutputStream2 = new ByteArrayOutputStream();
        try {
            c.f(byteArrayOutputStream2, bVarArr.length);
            int i13 = 2;
            int i14 = 2;
            for (d3.b bVar3 : bVarArr) {
                c.e(byteArrayOutputStream2, bVar3.f24948c, 4);
                c.e(byteArrayOutputStream2, bVar3.f24949d, 4);
                c.e(byteArrayOutputStream2, bVar3.f24952g, 4);
                String strB3 = b(bArr2, bVar3.f24946a, bVar3.f24947b);
                Charset charset3 = StandardCharsets.UTF_8;
                int length2 = strB3.getBytes(charset3).length;
                c.f(byteArrayOutputStream2, length2);
                i14 = i14 + 14 + length2;
                byteArrayOutputStream2.write(strB3.getBytes(charset3));
            }
            byte[] byteArray = byteArrayOutputStream2.toByteArray();
            if (i14 != byteArray.length) {
                throw c.error("Expected size " + i14 + ", does not match actual size " + byteArray.length);
            }
            b bVar4 = new b(FileSectionType.f3650a, byteArray, false);
            byteArrayOutputStream2.close();
            arrayList2.add(bVar4);
            ByteArrayOutputStream byteArrayOutputStream3 = new ByteArrayOutputStream();
            int i15 = 0;
            for (int i16 = 0; i16 < bVarArr.length; i16++) {
                try {
                    d3.b bVar5 = bVarArr[i16];
                    c.f(byteArrayOutputStream3, i16);
                    c.f(byteArrayOutputStream3, bVar5.f24950e);
                    i15 = i15 + 4 + (bVar5.f24950e * 2);
                    k(byteArrayOutputStream3, bVar5);
                } catch (Throwable th) {
                }
            }
            byte[] byteArray2 = byteArrayOutputStream3.toByteArray();
            if (i15 != byteArray2.length) {
                throw c.error("Expected size " + i15 + ", does not match actual size " + byteArray2.length);
            }
            b bVar6 = new b(FileSectionType.f3651b, byteArray2, true);
            byteArrayOutputStream3.close();
            arrayList2.add(bVar6);
            byteArrayOutputStream3 = new ByteArrayOutputStream();
            int i17 = 0;
            int i18 = 0;
            while (i17 < bVarArr.length) {
                try {
                    d3.b bVar7 = bVarArr[i17];
                    Iterator it3 = bVar7.f24954i.entrySet().iterator();
                    int iIntValue = i10;
                    while (it3.hasNext()) {
                        iIntValue |= ((Integer) ((Map.Entry) it3.next()).getValue()).intValue();
                    }
                    ByteArrayOutputStream byteArrayOutputStream4 = new ByteArrayOutputStream();
                    try {
                        n(byteArrayOutputStream4, iIntValue, bVar7);
                        byte[] byteArray3 = byteArrayOutputStream4.toByteArray();
                        byteArrayOutputStream4.close();
                        byteArrayOutputStream4 = new ByteArrayOutputStream();
                        try {
                            o(byteArrayOutputStream4, bVar7);
                            byte[] byteArray4 = byteArrayOutputStream4.toByteArray();
                            byteArrayOutputStream4.close();
                            c.f(byteArrayOutputStream3, i17);
                            int length3 = byteArray3.length + i13 + byteArray4.length;
                            int i19 = i18 + 6;
                            ArrayList arrayList4 = arrayList3;
                            c.e(byteArrayOutputStream3, length3, 4);
                            c.f(byteArrayOutputStream3, iIntValue);
                            byteArrayOutputStream3.write(byteArray3);
                            byteArrayOutputStream3.write(byteArray4);
                            i18 = i19 + length3;
                            i17++;
                            arrayList3 = arrayList4;
                            i10 = 0;
                            i13 = 2;
                        } finally {
                        }
                    } finally {
                    }
                } finally {
                    try {
                        byteArrayOutputStream3.close();
                        throw th;
                    } catch (Throwable th2) {
                        th.addSuppressed(th2);
                    }
                }
            }
            ArrayList arrayList5 = arrayList3;
            byte[] byteArray5 = byteArrayOutputStream3.toByteArray();
            if (i18 != byteArray5.length) {
                throw c.error("Expected size " + i18 + ", does not match actual size " + byteArray5.length);
            }
            b bVar8 = new b(FileSectionType.f3652c, byteArray5, true);
            byteArrayOutputStream3.close();
            arrayList2.add(bVar8);
            long j10 = 4;
            long size2 = j10 + j10 + 4 + ((long) (arrayList2.size() * 16));
            c.e(byteArrayOutputStream, arrayList2.size(), 4);
            int i20 = 0;
            while (i20 < arrayList2.size()) {
                b bVar9 = (b) arrayList2.get(i20);
                c.e(byteArrayOutputStream, bVar9.f3656a.a(), 4);
                c.e(byteArrayOutputStream, size2, 4);
                boolean z10 = bVar9.f3658c;
                byte[] bArr7 = bVar9.f3657b;
                if (z10) {
                    long length4 = bArr7.length;
                    byte[] bArrA5 = c.a(bArr7);
                    arrayList = arrayList5;
                    arrayList.add(bArrA5);
                    c.e(byteArrayOutputStream, bArrA5.length, 4);
                    c.e(byteArrayOutputStream, length4, 4);
                    length = bArrA5.length;
                } else {
                    arrayList = arrayList5;
                    arrayList.add(bArr7);
                    c.e(byteArrayOutputStream, bArr7.length, 4);
                    c.e(byteArrayOutputStream, 0L, 4);
                    length = bArr7.length;
                }
                size2 += (long) length;
                i20++;
                arrayList5 = arrayList;
            }
            ArrayList arrayList6 = arrayList5;
            for (int i21 = 0; i21 < arrayList6.size(); i21++) {
                byteArrayOutputStream.write((byte[]) arrayList6.get(i21));
            }
            return true;
        } catch (Throwable th3) {
            try {
                byteArrayOutputStream2.close();
                throw th3;
            } catch (Throwable th4) {
                th3.addSuppressed(th4);
                throw th3;
            }
        }
    }

    public static void k(ByteArrayOutputStream byteArrayOutputStream, d3.b bVar) throws IOException {
        int iIntValue = 0;
        for (int i10 : bVar.f24953h) {
            Integer numValueOf = Integer.valueOf(i10);
            c.f(byteArrayOutputStream, numValueOf.intValue() - iIntValue);
            iIntValue = numValueOf.intValue();
        }
    }

    public static void l(ByteArrayOutputStream byteArrayOutputStream, d3.b bVar) throws IOException {
        o(byteArrayOutputStream, bVar);
        k(byteArrayOutputStream, bVar);
        int i10 = bVar.f24952g;
        byte[] bArr = new byte[(((i10 * 2) + 7) & (-8)) / 8];
        for (Map.Entry entry : bVar.f24954i.entrySet()) {
            int iIntValue = ((Integer) entry.getKey()).intValue();
            int iIntValue2 = ((Integer) entry.getValue()).intValue();
            if ((iIntValue2 & 2) != 0) {
                int iC = c(2, iIntValue, i10);
                int i11 = iC / 8;
                bArr[i11] = (byte) ((1 << (iC % 8)) | bArr[i11]);
            }
            if ((iIntValue2 & 4) != 0) {
                int iC2 = c(4, iIntValue, i10);
                int i12 = iC2 / 8;
                bArr[i12] = (byte) ((1 << (iC2 % 8)) | bArr[i12]);
            }
        }
        byteArrayOutputStream.write(bArr);
    }

    public static void m(ByteArrayOutputStream byteArrayOutputStream, d3.b bVar, String str) throws IOException {
        Charset charset = StandardCharsets.UTF_8;
        c.f(byteArrayOutputStream, str.getBytes(charset).length);
        c.f(byteArrayOutputStream, bVar.f24950e);
        c.e(byteArrayOutputStream, bVar.f24951f, 4);
        c.e(byteArrayOutputStream, bVar.f24948c, 4);
        c.e(byteArrayOutputStream, bVar.f24952g, 4);
        byteArrayOutputStream.write(str.getBytes(charset));
    }

    public static void n(ByteArrayOutputStream byteArrayOutputStream, int i10, d3.b bVar) throws IOException {
        int iBitCount = Integer.bitCount(i10 & (-2));
        int i11 = bVar.f24952g;
        byte[] bArr = new byte[(((iBitCount * i11) + 7) & (-8)) / 8];
        for (Map.Entry entry : bVar.f24954i.entrySet()) {
            int iIntValue = ((Integer) entry.getKey()).intValue();
            int iIntValue2 = ((Integer) entry.getValue()).intValue();
            int i12 = 0;
            for (int i13 = 1; i13 <= 4; i13 <<= 1) {
                if (i13 != 1 && (i13 & i10) != 0) {
                    if ((i13 & iIntValue2) == i13) {
                        int i14 = (i12 * i11) + iIntValue;
                        int i15 = i14 / 8;
                        bArr[i15] = (byte) ((1 << (i14 % 8)) | bArr[i15]);
                    }
                    i12++;
                }
            }
        }
        byteArrayOutputStream.write(bArr);
    }

    public static void o(ByteArrayOutputStream byteArrayOutputStream, d3.b bVar) throws IOException {
        int i10 = 0;
        for (Map.Entry entry : bVar.f24954i.entrySet()) {
            int iIntValue = ((Integer) entry.getKey()).intValue();
            if ((((Integer) entry.getValue()).intValue() & 1) != 0) {
                c.f(byteArrayOutputStream, iIntValue - i10);
                c.f(byteArrayOutputStream, 0);
                i10 = iIntValue;
            }
        }
    }
}
