package ac;

import com.google.zxing.BarcodeFormat;
import com.google.zxing.DecodeHintType;
import com.google.zxing.NotFoundException;
import com.google.zxing.ResultMetadataType;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.Map;
import ob.f;
import ob.g;
import ob.h;
import zb.j;

/* JADX INFO: loaded from: classes.dex */
public final class e extends a {

    /* JADX INFO: renamed from: i, reason: collision with root package name */
    public static final int[] f433i = {1, 10, 34, 70, 126};

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public static final int[] f434j = {4, 20, 48, 81};

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public static final int[] f435k = {0, 161, 961, 2015, 2715};

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public static final int[] f436l = {0, 336, 1036, 1516};

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public static final int[] f437m = {8, 6, 4, 3, 1};

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public static final int[] f438n = {2, 4, 6, 8};

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

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final ArrayList f440g = new ArrayList();

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public final ArrayList f441h = new ArrayList();

    public static void k(ArrayList arrayList, d dVar) {
        if (dVar == null) {
            return;
        }
        Iterator it = arrayList.iterator();
        while (it.hasNext()) {
            d dVar2 = (d) it.next();
            if (dVar2.f426a == dVar.f426a) {
                dVar2.f432d++;
                return;
            }
        }
        arrayList.add(dVar);
    }

    @Override // zb.j
    public final f c(int i10, tb.a aVar, Map map) throws NotFoundException {
        d dVarM = m(aVar, false, i10, map);
        ArrayList<d> arrayList = this.f440g;
        k(arrayList, dVarM);
        aVar.i();
        d dVarM2 = m(aVar, true, i10, map);
        ArrayList<d> arrayList2 = this.f441h;
        k(arrayList2, dVarM2);
        aVar.i();
        for (d dVar : arrayList) {
            if (dVar.f432d > 1) {
                for (d dVar2 : arrayList2) {
                    if (dVar2.f432d > 1) {
                        int i11 = ((dVar2.f427b * 16) + dVar.f427b) % 79;
                        c cVar = dVar.f431c;
                        int i12 = cVar.f428a * 9;
                        c cVar2 = dVar2.f431c;
                        int i13 = i12 + cVar2.f428a;
                        if (i13 > 72) {
                            i13--;
                        }
                        if (i13 > 8) {
                            i13--;
                        }
                        if (i11 == i13) {
                            String strValueOf = String.valueOf((((long) dVar.f426a) * 4537077) + ((long) dVar2.f426a));
                            StringBuilder sb = new StringBuilder(14);
                            for (int length = 13 - strValueOf.length(); length > 0; length--) {
                                sb.append('0');
                            }
                            sb.append(strValueOf);
                            int i14 = 0;
                            for (int i15 = 0; i15 < 13; i15++) {
                                int iCharAt = sb.charAt(i15) - '0';
                                if ((i15 & 1) == 0) {
                                    iCharAt *= 3;
                                }
                                i14 += iCharAt;
                            }
                            int i16 = 10 - (i14 % 10);
                            if (i16 == 10) {
                                i16 = 0;
                            }
                            sb.append(i16);
                            String string = sb.toString();
                            g[] gVarArr = cVar.f430c;
                            g[] gVarArr2 = cVar2.f430c;
                            f fVar = new f(string, null, new g[]{gVarArr[0], gVarArr[1], gVarArr2[0], gVarArr2[1]}, BarcodeFormat.f24314m);
                            fVar.b(ResultMetadataType.f24344m, "]e0");
                            return fVar;
                        }
                    }
                }
            }
        }
        throw NotFoundException.a();
    }

    /* JADX WARN: Removed duplicated region for block: B:35:0x0095 A[PHI: r14 r15
      0x0095: PHI (r14v7 boolean) = (r14v4 boolean), (r14v15 boolean) binds: [B:46:0x00b1, B:34:0x0093] A[DONT_GENERATE, DONT_INLINE]
      0x0095: PHI (r15v5 boolean) = (r15v2 boolean), (r15v13 boolean) binds: [B:46:0x00b1, B:34:0x0093] A[DONT_GENERATE, DONT_INLINE]] */
    /* JADX WARN: Removed duplicated region for block: B:36:0x009a A[PHI: r14 r15
      0x009a: PHI (r14v6 boolean) = (r14v4 boolean), (r14v15 boolean) binds: [B:46:0x00b1, B:34:0x0093] A[DONT_GENERATE, DONT_INLINE]
      0x009a: PHI (r15v4 boolean) = (r15v2 boolean), (r15v13 boolean) binds: [B:46:0x00b1, B:34:0x0093] A[DONT_GENERATE, DONT_INLINE]] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final b l(tb.a aVar, c cVar, boolean z10) throws NotFoundException {
        float[] fArr;
        float[] fArr2;
        int[] iArr;
        int[] iArr2;
        boolean z11;
        boolean z12;
        boolean z13;
        boolean z14;
        int[] iArr3 = this.f421b;
        Arrays.fill(iArr3, 0);
        int[] iArr4 = cVar.f429b;
        if (z10) {
            j.g(iArr4[0], aVar, iArr3);
        } else {
            j.f(iArr4[1], aVar, iArr3);
            int i10 = 0;
            for (int length = iArr3.length - 1; i10 < length; length--) {
                int i11 = iArr3[i10];
                iArr3[i10] = iArr3[length];
                iArr3[length] = i11;
                i10++;
            }
        }
        int i12 = z10 ? 16 : 15;
        float fT = nb.g.T(iArr3) / i12;
        int i13 = 0;
        while (true) {
            int length2 = iArr3.length;
            fArr = this.f423d;
            fArr2 = this.f422c;
            iArr = this.f425f;
            iArr2 = this.f424e;
            if (i13 >= length2) {
                break;
            }
            float f10 = iArr3[i13] / fT;
            int i14 = (int) (0.5f + f10);
            if (i14 < 1) {
                i14 = 1;
            } else if (i14 > 8) {
                i14 = 8;
            }
            int i15 = i13 / 2;
            if ((i13 & 1) == 0) {
                iArr2[i15] = i14;
                fArr2[i15] = f10 - i14;
            } else {
                iArr[i15] = i14;
                fArr[i15] = f10 - i14;
            }
            i13++;
        }
        int iT = nb.g.T(iArr2);
        int iT2 = nb.g.T(iArr);
        if (z10) {
            if (iT > 12) {
                z11 = false;
                z12 = true;
            } else if (iT < 4) {
                z12 = false;
                z11 = true;
            } else {
                z11 = false;
                z12 = false;
            }
            if (iT2 <= 12) {
                if (iT2 < 4) {
                    z14 = false;
                    z13 = true;
                } else {
                    z13 = false;
                    z14 = false;
                }
            }
            z13 = false;
            z14 = true;
        } else {
            if (iT > 11) {
                z11 = false;
                z12 = true;
            } else if (iT < 5) {
                z12 = false;
                z11 = true;
            } else {
                z11 = false;
                z12 = false;
            }
            if (iT2 <= 10) {
                if (iT2 < 4) {
                }
            }
            z13 = false;
            z14 = true;
        }
        int i16 = (iT + iT2) - i12;
        boolean z15 = (iT & 1) == z10;
        boolean z16 = (iT2 & 1) == 1;
        if (i16 != -1) {
            if (i16 != 0) {
                if (i16 != 1) {
                    throw NotFoundException.a();
                }
                if (z15) {
                    if (z16) {
                        throw NotFoundException.a();
                    }
                    z12 = true;
                } else {
                    if (!z16) {
                        throw NotFoundException.a();
                    }
                    z14 = true;
                }
            } else if (z15) {
                if (!z16) {
                    throw NotFoundException.a();
                }
                if (iT < iT2) {
                    z11 = true;
                    z14 = true;
                } else {
                    z12 = true;
                    z13 = true;
                }
            } else if (z16) {
                throw NotFoundException.a();
            }
        } else if (z15) {
            if (z16) {
                throw NotFoundException.a();
            }
            z11 = true;
        } else {
            if (!z16) {
                throw NotFoundException.a();
            }
            z13 = true;
        }
        if (z11) {
            if (z12) {
                throw NotFoundException.a();
            }
            a.i(fArr2, iArr2);
        }
        if (z12) {
            a.h(fArr2, iArr2);
        }
        if (z13) {
            if (z14) {
                throw NotFoundException.a();
            }
            a.i(fArr2, iArr);
        }
        if (z14) {
            a.h(fArr, iArr);
        }
        int i17 = 0;
        int i18 = 0;
        for (int length3 = iArr2.length - 1; length3 >= 0; length3--) {
            int i19 = iArr2[length3];
            i17 = (i17 * 9) + i19;
            i18 += i19;
        }
        int i20 = 0;
        int i21 = 0;
        for (int length4 = iArr.length - 1; length4 >= 0; length4--) {
            int i22 = iArr[length4];
            i20 = (i20 * 9) + i22;
            i21 += i22;
        }
        int i23 = (i20 * 3) + i17;
        if (!z10) {
            if ((i21 & 1) != 0 || i21 > 10 || i21 < 4) {
                throw NotFoundException.a();
            }
            int i24 = (10 - i21) / 2;
            int i25 = f438n[i24];
            return new b((ua.b.y(iArr, 9 - i25, false) * f434j[i24]) + ua.b.y(iArr2, i25, true) + f436l[i24], i23);
        }
        if ((i18 & 1) != 0 || i18 > 12 || i18 < 4) {
            throw NotFoundException.a();
        }
        int i26 = (12 - i18) / 2;
        int i27 = f437m[i26];
        return new b((ua.b.y(iArr2, i27, false) * f433i[i26]) + ua.b.y(iArr, 9 - i27, true) + f435k[i26], i23);
    }

    public final d m(tb.a aVar, boolean z10, int i10, Map map) {
        try {
            c cVarO = o(aVar, i10, z10, n(aVar, z10));
            h hVar = map == null ? null : (h) map.get(DecodeHintType.f24324i);
            if (hVar != null) {
                int[] iArr = cVarO.f429b;
                float f10 = ((iArr[0] + iArr[1]) - 1) / 2.0f;
                if (z10) {
                    f10 = (aVar.f33004b - 1) - f10;
                }
                hVar.a(new g(f10, i10));
            }
            b bVarL = l(aVar, cVarO, true);
            b bVarL2 = l(aVar, cVarO, false);
            return new d((bVarL.f426a * 1597) + bVarL2.f426a, (bVarL2.f427b * 4) + bVarL.f427b, cVarO);
        } catch (NotFoundException unused) {
            return null;
        }
    }

    public final int[] n(tb.a aVar, boolean z10) throws NotFoundException {
        int[] iArr = this.f420a;
        iArr[0] = 0;
        iArr[1] = 0;
        iArr[2] = 0;
        iArr[3] = 0;
        int i10 = aVar.f33004b;
        int i11 = 0;
        boolean z11 = false;
        while (i11 < i10) {
            z11 = !aVar.d(i11);
            if (z10 == z11) {
                break;
            }
            i11++;
        }
        int i12 = 0;
        int i13 = i11;
        while (i11 < i10) {
            if (aVar.d(i11) != z11) {
                iArr[i12] = iArr[i12] + 1;
            } else {
                if (i12 != 3) {
                    i12++;
                } else {
                    if (a.j(iArr)) {
                        return new int[]{i13, i11};
                    }
                    i13 += iArr[0] + iArr[1];
                    iArr[0] = iArr[2];
                    iArr[1] = iArr[3];
                    iArr[2] = 0;
                    iArr[3] = 0;
                    i12--;
                }
                iArr[i12] = 1;
                z11 = !z11;
            }
            i11++;
        }
        throw NotFoundException.a();
    }

    public final c o(tb.a aVar, int i10, boolean z10, int[] iArr) throws NotFoundException {
        int i11;
        int i12;
        boolean zD = aVar.d(iArr[0]);
        int i13 = iArr[0] - 1;
        while (i13 >= 0 && zD != aVar.d(i13)) {
            i13--;
        }
        int i14 = i13 + 1;
        int i15 = iArr[0] - i14;
        int[] iArr2 = this.f420a;
        System.arraycopy(iArr2, 0, iArr2, 1, iArr2.length - 1);
        iArr2[0] = i15;
        int[][] iArr3 = f439o;
        for (int i16 = 0; i16 < 9; i16++) {
            if (j.e(iArr2, iArr3[i16], 0.45f) < 0.2f) {
                int i17 = iArr[1];
                if (z10) {
                    int i18 = aVar.f33004b - 1;
                    i11 = i18 - i17;
                    i12 = i18 - i14;
                } else {
                    i11 = i17;
                    i12 = i14;
                }
                return new c(i16, i12, i11, i10, new int[]{i14, i17});
            }
        }
        throw NotFoundException.a();
    }

    @Override // zb.j, ob.e
    public final void reset() {
        this.f440g.clear();
        this.f441h.clear();
    }
}
