package kc;

import com.google.android.gms.measurement.internal.u1;
import com.google.zxing.WriterException;
import com.google.zxing.qrcode.decoder.ErrorCorrectionLevel;
import java.util.Arrays;
import l2.h;

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

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public static final int[][] f29102a = {new int[]{1, 1, 1, 1, 1, 1, 1}, new int[]{1, 0, 0, 0, 0, 0, 1}, new int[]{1, 0, 1, 1, 1, 0, 1}, new int[]{1, 0, 1, 1, 1, 0, 1}, new int[]{1, 0, 1, 1, 1, 0, 1}, new int[]{1, 0, 0, 0, 0, 0, 1}, new int[]{1, 1, 1, 1, 1, 1, 1}};

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public static final int[][] f29103b = {new int[]{1, 1, 1, 1, 1}, new int[]{1, 0, 0, 0, 1}, new int[]{1, 0, 1, 0, 1}, new int[]{1, 0, 0, 0, 1}, new int[]{1, 1, 1, 1, 1}};

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public static final int[][] f29104c = {new int[]{-1, -1, -1, -1, -1, -1, -1}, new int[]{6, 18, -1, -1, -1, -1, -1}, new int[]{6, 22, -1, -1, -1, -1, -1}, new int[]{6, 26, -1, -1, -1, -1, -1}, new int[]{6, 30, -1, -1, -1, -1, -1}, new int[]{6, 34, -1, -1, -1, -1, -1}, new int[]{6, 22, 38, -1, -1, -1, -1}, new int[]{6, 24, 42, -1, -1, -1, -1}, new int[]{6, 26, 46, -1, -1, -1, -1}, new int[]{6, 28, 50, -1, -1, -1, -1}, new int[]{6, 30, 54, -1, -1, -1, -1}, new int[]{6, 32, 58, -1, -1, -1, -1}, new int[]{6, 34, 62, -1, -1, -1, -1}, new int[]{6, 26, 46, 66, -1, -1, -1}, new int[]{6, 26, 48, 70, -1, -1, -1}, new int[]{6, 26, 50, 74, -1, -1, -1}, new int[]{6, 30, 54, 78, -1, -1, -1}, new int[]{6, 30, 56, 82, -1, -1, -1}, new int[]{6, 30, 58, 86, -1, -1, -1}, new int[]{6, 34, 62, 90, -1, -1, -1}, new int[]{6, 28, 50, 72, 94, -1, -1}, new int[]{6, 26, 50, 74, 98, -1, -1}, new int[]{6, 30, 54, 78, 102, -1, -1}, new int[]{6, 28, 54, 80, 106, -1, -1}, new int[]{6, 32, 58, 84, 110, -1, -1}, new int[]{6, 30, 58, 86, 114, -1, -1}, new int[]{6, 34, 62, 90, 118, -1, -1}, new int[]{6, 26, 50, 74, 98, 122, -1}, new int[]{6, 30, 54, 78, 102, 126, -1}, new int[]{6, 26, 52, 78, 104, 130, -1}, new int[]{6, 30, 56, 82, 108, 134, -1}, new int[]{6, 34, 60, 86, 112, 138, -1}, new int[]{6, 30, 58, 86, 114, 142, -1}, new int[]{6, 34, 62, 90, 118, 146, -1}, new int[]{6, 30, 54, 78, 102, 126, 150}, new int[]{6, 24, 50, 76, 102, 128, 154}, new int[]{6, 28, 54, 80, 106, 132, 158}, new int[]{6, 32, 58, 84, 110, 136, 162}, new int[]{6, 26, 54, 82, 110, 138, 166}, new int[]{6, 30, 58, 86, 114, 142, 170}};

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public static final int[][] f29105d = {new int[]{8, 0}, new int[]{8, 1}, new int[]{8, 2}, new int[]{8, 3}, new int[]{8, 4}, new int[]{8, 5}, new int[]{8, 7}, new int[]{8, 8}, new int[]{7, 8}, new int[]{5, 8}, new int[]{4, 8}, new int[]{3, 8}, new int[]{2, 8}, new int[]{1, 8}, new int[]{0, 8}};

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:102:0x0250  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public static void a(tb.a aVar, ErrorCorrectionLevel errorCorrectionLevel, ic.d dVar, int i10, h hVar) {
        int i11;
        int i12;
        boolean z10;
        int i13;
        int i14;
        int i15;
        int i16;
        Object obj = hVar.f29998d;
        int i17 = 0;
        for (byte[] bArr : (byte[][]) obj) {
            Arrays.fill(bArr, (byte) -1);
        }
        int length = f29102a[0].length;
        d(0, 0, hVar);
        d(hVar.f29996b - length, 0, hVar);
        d(0, hVar.f29996b - length, hVar);
        c(0, 7, hVar);
        c(hVar.f29996b - 8, 7, hVar);
        c(0, hVar.f29996b - 8, hVar);
        e(7, 0, hVar);
        e(hVar.f29997c - 8, 0, hVar);
        e(7, hVar.f29997c - 7, hVar);
        if (hVar.d(8, hVar.f29997c - 8) == 0) {
            throw new WriterException();
        }
        hVar.e(8, hVar.f29997c - 8, 1);
        int i18 = dVar.f26616a;
        int i19 = 5;
        if (i18 >= 2) {
            int[] iArr = f29104c[i18 - 1];
            int length2 = iArr.length;
            int i20 = 0;
            while (i20 < length2) {
                int i21 = iArr[i20];
                if (i21 >= 0) {
                    int length3 = iArr.length;
                    int i22 = i17;
                    while (i22 < length3) {
                        int i23 = iArr[i22];
                        if (i23 >= 0 && f(hVar.d(i23, i21))) {
                            int i24 = i23 - 2;
                            int i25 = i21 - 2;
                            int i26 = i17;
                            while (i26 < i19) {
                                int[] iArr2 = f29103b[i26];
                                while (i17 < i19) {
                                    hVar.e(i24 + i17, i25 + i26, iArr2[i17]);
                                    i17++;
                                    i24 = i24;
                                    i19 = 5;
                                }
                                i26++;
                                i17 = 0;
                                i19 = 5;
                            }
                        }
                        i22++;
                        i17 = 0;
                        i19 = 5;
                    }
                }
                i20++;
                i17 = 0;
                i19 = 5;
            }
        }
        int i27 = 8;
        while (i27 < hVar.f29996b - 8) {
            int i28 = i27 + 1;
            int i29 = i28 % 2;
            if (f(hVar.d(i27, 6))) {
                hVar.e(i27, 6, i29);
            }
            if (f(hVar.d(6, i27))) {
                hVar.e(6, i27, i29);
            }
            i27 = i28;
        }
        tb.a aVar2 = new tb.a();
        if (i10 < 0 || i10 >= 8) {
            throw new WriterException("Invalid mask pattern");
        }
        int iA = (errorCorrectionLevel.a() << 3) | i10;
        aVar2.b(iA, 5);
        aVar2.b(b(iA, 1335), 10);
        tb.a aVar3 = new tb.a();
        aVar3.b(21522, 15);
        if (aVar2.f33004b != aVar3.f33004b) {
            throw new IllegalArgumentException("Sizes don't match");
        }
        int i30 = 0;
        while (true) {
            int[] iArr3 = aVar2.f33003a;
            if (i30 >= iArr3.length) {
                break;
            }
            iArr3[i30] = iArr3[i30] ^ aVar3.f33003a[i30];
            i30++;
        }
        if (aVar2.f33004b != 15) {
            throw new WriterException("should not happen but we got: " + aVar2.f33004b);
        }
        int i31 = 0;
        while (true) {
            int i32 = aVar2.f33004b;
            if (i31 >= i32) {
                break;
            }
            boolean zD = aVar2.d((i32 - 1) - i31);
            int[] iArr4 = f29105d[i31];
            int i33 = iArr4[0];
            byte[] bArr2 = ((byte[][]) obj)[iArr4[1]];
            byte b10 = zD ? (byte) 1 : (byte) 0;
            bArr2[i33] = b10;
            if (i31 < 8) {
                i16 = (hVar.f29996b - i31) - 1;
                i15 = 8;
            } else {
                i15 = (hVar.f29997c - 7) + (i31 - 8);
                i16 = 8;
            }
            ((byte[][]) obj)[i15][i16] = b10;
            i31++;
        }
        if (i18 >= 7) {
            tb.a aVar4 = new tb.a();
            aVar4.b(i18, 6);
            aVar4.b(b(i18, 7973), 12);
            if (aVar4.f33004b != 18) {
                throw new WriterException("should not happen but we got: " + aVar4.f33004b);
            }
            int i34 = 17;
            for (int i35 = 0; i35 < 6; i35++) {
                for (int i36 = 0; i36 < 3; i36++) {
                    boolean zD2 = aVar4.d(i34);
                    i34--;
                    int i37 = hVar.f29997c;
                    byte[] bArr3 = ((byte[][]) obj)[(i37 - 11) + i36];
                    byte b11 = zD2 ? (byte) 1 : (byte) 0;
                    bArr3[i35] = b11;
                    ((byte[][]) obj)[i35][(i37 - 11) + i36] = b11;
                }
            }
        }
        int i38 = hVar.f29996b - 1;
        int i39 = hVar.f29997c - 1;
        int i40 = 0;
        int i41 = -1;
        while (i38 > 0) {
            if (i38 == 6) {
                i38--;
            }
            while (i39 >= 0 && i39 < hVar.f29997c) {
                for (int i42 = 0; i42 < 2; i42++) {
                    int i43 = i38 - i42;
                    if (f(hVar.d(i43, i39))) {
                        if (i40 < aVar.f33004b) {
                            boolean zD3 = aVar.d(i40);
                            i40++;
                            i11 = zD3;
                        } else {
                            i11 = 0;
                        }
                        if (i10 != -1) {
                            switch (i10) {
                                case 0:
                                    i12 = (i39 + i43) & 1;
                                    if (i12 == 0) {
                                        i11 = ~i11;
                                    }
                                    break;
                                case 1:
                                    i12 = i39 & 1;
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 2:
                                    i12 = i43 % 3;
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 3:
                                    i12 = (i39 + i43) % 3;
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 4:
                                    i12 = ((i43 / 3) + (i39 / 2)) & 1;
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 5:
                                    int i44 = i39 * i43;
                                    i12 = (i44 % 3) + (i44 & 1);
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 6:
                                    z10 = true;
                                    int i45 = i39 * i43;
                                    i13 = i45 & 1;
                                    i14 = i45 % 3;
                                    i12 = (i14 + i13) & 1;
                                    if (i12 == 0) {
                                    }
                                    break;
                                case 7:
                                    i14 = (i39 * i43) % 3;
                                    z10 = true;
                                    i13 = (i39 + i43) & 1;
                                    i12 = (i14 + i13) & 1;
                                    if (i12 == 0) {
                                    }
                                    break;
                                default:
                                    throw new IllegalArgumentException(u1.g("Invalid mask pattern: ", i10));
                            }
                        }
                        ((byte[][]) obj)[i39][i43] = (byte) i11;
                    }
                }
                i39 += i41;
            }
            i41 = -i41;
            i39 += i41;
            i38 -= 2;
        }
        if (i40 == aVar.f33004b) {
            return;
        }
        throw new WriterException("Not all bits consumed: " + i40 + '/' + aVar.f33004b);
    }

    public static int b(int i10, int i11) {
        if (i11 == 0) {
            throw new IllegalArgumentException("0 polynomial");
        }
        int iNumberOfLeadingZeros = Integer.numberOfLeadingZeros(i11);
        int i12 = 32 - iNumberOfLeadingZeros;
        int iNumberOfLeadingZeros2 = i10 << (31 - iNumberOfLeadingZeros);
        while (32 - Integer.numberOfLeadingZeros(iNumberOfLeadingZeros2) >= i12) {
            iNumberOfLeadingZeros2 ^= i11 << ((32 - Integer.numberOfLeadingZeros(iNumberOfLeadingZeros2)) - i12);
        }
        return iNumberOfLeadingZeros2;
    }

    public static void c(int i10, int i11, h hVar) throws WriterException {
        for (int i12 = 0; i12 < 8; i12++) {
            int i13 = i10 + i12;
            if (!f(hVar.d(i13, i11))) {
                throw new WriterException();
            }
            hVar.e(i13, i11, 0);
        }
    }

    public static void d(int i10, int i11, h hVar) {
        for (int i12 = 0; i12 < 7; i12++) {
            int[] iArr = f29102a[i12];
            for (int i13 = 0; i13 < 7; i13++) {
                hVar.e(i10 + i13, i11 + i12, iArr[i13]);
            }
        }
    }

    public static void e(int i10, int i11, h hVar) throws WriterException {
        for (int i12 = 0; i12 < 7; i12++) {
            int i13 = i11 + i12;
            if (!f(hVar.d(i10, i13))) {
                throw new WriterException();
            }
            hVar.e(i10, i13, 0);
        }
    }

    public static boolean f(int i10) {
        return i10 == -1;
    }
}
