package g.i.a.c.o;

import android.content.Context;
import android.content.res.AssetManager;
import android.text.TextUtils;
import g.h.a.i;
import g.i.a.c.j.c;
import g.i.a.c.j.d;
import io.netty.handler.codec.dns.DnsRecord;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Locale;

/* JADX INFO: loaded from: classes.dex */
public class a {
    public static g.i.a.c.l.e.a a(int i2, InputStream inputStream, long j2) throws IOException {
        inputStream.skip(j2);
        if (i2 <= 3) {
            return new c(inputStream);
        }
        if (i2 == 4 || i2 == 6 || i2 == 7 || i2 == 8) {
            return new g.i.a.c.j.b(inputStream);
        }
        if (i2 == 11 || i2 == 10 || i2 == 13) {
            return new g.i.a.c.j.a(inputStream);
        }
        if (i2 == 5 || i2 == 9 || i2 == 12) {
            return new d(inputStream);
        }
        i.U3(String.format("not support icType=0x%02X", Integer.valueOf(i2)));
        return null;
    }

    public static g.i.a.c.q.a b(String str, String str2) throws g.i.a.c.g.b {
        if (TextUtils.isEmpty(str)) {
            throw new g.i.a.c.g.b("invalid path: ", 4098);
        }
        String strI1 = i.I1(str);
        if (strI1 == null || !strI1.equalsIgnoreCase(str2)) {
            i.W3("invalid suffix: " + strI1);
            throw new g.i.a.c.g.b("invalid suffix", 4099);
        }
        File file = new File(str);
        if (!file.exists()) {
            throw new g.i.a.c.g.b("image file not exist", 4100);
        }
        g.i.a.c.q.a aVar = new g.i.a.c.q.a();
        aVar.a = file.getPath();
        aVar.f5644b = file.getName();
        aVar.f5645c = file.length();
        return aVar;
    }

    public static boolean c(int i2, int i3) {
        return i3 <= 3 ? i2 <= 3 : (i3 == 4 || i3 == 8 || i3 == 6) ? i2 == 4 || i2 == 8 || i2 == 6 : i3 == i2;
    }

    public static g.i.a.c.q.a d(String str, String str2) throws g.i.a.c.g.b {
        if (TextUtils.isEmpty(str)) {
            throw new g.i.a.c.g.b("invalid path", 4098);
        }
        String strI1 = i.I1(str);
        if (strI1 != null && strI1.equalsIgnoreCase(str2)) {
            g.i.a.c.q.a aVar = new g.i.a.c.q.a();
            aVar.a = str;
            aVar.f5644b = g.i.a.c.a0.d.c(str);
            return aVar;
        }
        i.W3("the file suffix is not right, suffix=" + strI1);
        throw new g.i.a.c.g.b("invalid suffix", 4099);
    }

    /* JADX WARN: Can't fix incorrect switch cases order, some code will duplicate */
    /* JADX WARN: Removed duplicated region for block: B:27:0x003f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static int e(int r11, g.i.a.c.l.e.a r12, g.i.a.c.q.i r13) {
        /*
            Method dump skipped, instruction units count: 668
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.o.a.e(int, g.i.a.c.l.e.a, g.i.a.c.q.i):int");
    }

    /* JADX WARN: Removed duplicated region for block: B:37:0x006d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static int f(g.i.a.c.l.e.a r14, g.i.a.c.q.i r15) {
        /*
            Method dump skipped, instruction units count: 378
            To view this dump add '--comments-level debug' option
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.o.a.f(g.i.a.c.l.e.a, g.i.a.c.q.i):int");
    }

    public static int g(int i2, int i3, int i4, int i5, int i6) {
        i.U3(String.format(Locale.US, "checkVersion: bin=%08X(%d) %s, soc=%08X(%d) %s", Integer.valueOf(i2), Integer.valueOf(i2), g.i.a.c.a0.d.b(i3, i2, i6), Integer.valueOf(i4), Integer.valueOf(i4), g.i.a.c.a0.d.b(i5, i4, i6)));
        if (i3 <= 0) {
            return i.g(i2, i.h(i4, i5, i6));
        }
        if (i5 <= 0) {
            return i.g(i.h(i2, i3, i6), i4);
        }
        if (i6 == 1) {
            int i7 = i2 & DnsRecord.CLASS_ANY;
            int i8 = (i2 >> 8) & DnsRecord.CLASS_ANY;
            int i9 = (i2 >> 16) & DnsRecord.CLASS_ANY;
            int i10 = (i2 >> 24) & DnsRecord.CLASS_ANY;
            int i11 = i4 & DnsRecord.CLASS_ANY;
            int i12 = (i4 >> 8) & DnsRecord.CLASS_ANY;
            int i13 = (i4 >> 16) & DnsRecord.CLASS_ANY;
            int i14 = (i4 >> 24) & DnsRecord.CLASS_ANY;
            if (i7 <= i11) {
                if (i7 >= i11) {
                    if (i8 <= i12) {
                        if (i8 >= i12) {
                            if (i9 <= i13) {
                                if (i9 >= i13) {
                                    if (i10 <= i14) {
                                        if (i10 == i14) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        if (i6 == 515) {
            int i15 = (i2 >> 24) & DnsRecord.CLASS_ANY;
            int i16 = (i2 >> 16) & DnsRecord.CLASS_ANY;
            int i17 = (i2 >> 8) & DnsRecord.CLASS_ANY;
            int i18 = i2 & DnsRecord.CLASS_ANY;
            int i19 = (i4 >> 24) & DnsRecord.CLASS_ANY;
            int i20 = (i4 >> 16) & DnsRecord.CLASS_ANY;
            int i21 = (i4 >> 8) & DnsRecord.CLASS_ANY;
            int i22 = i4 & DnsRecord.CLASS_ANY;
            if (i15 <= i19) {
                if (i15 >= i19) {
                    if (i16 <= i20) {
                        if (i16 >= i20) {
                            if (i17 <= i21) {
                                if (i17 >= i21) {
                                    if (i18 <= i22) {
                                        if (i18 == i22) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        if (i6 == 2) {
            int i23 = (i2 >> 24) & DnsRecord.CLASS_ANY;
            int i24 = (i2 >> 16) & DnsRecord.CLASS_ANY;
            int i25 = (i2 >> 8) & DnsRecord.CLASS_ANY;
            int i26 = i2 & DnsRecord.CLASS_ANY;
            int i27 = (i4 >> 24) & DnsRecord.CLASS_ANY;
            int i28 = (i4 >> 16) & DnsRecord.CLASS_ANY;
            int i29 = (i4 >> 8) & DnsRecord.CLASS_ANY;
            int i30 = i4 & DnsRecord.CLASS_ANY;
            if (i23 <= i27) {
                if (i23 >= i27) {
                    if (i24 <= i28) {
                        if (i24 >= i28) {
                            if (i25 <= i29) {
                                if (i25 >= i29) {
                                    if (i26 <= i30) {
                                        if (i26 == i30) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        if (i6 == 3) {
            int i31 = i2 & 15;
            int i32 = (i2 >> 4) & DnsRecord.CLASS_ANY;
            int i33 = (i2 >> 12) & 32767;
            int i34 = (i2 >> 27) & 31;
            int i35 = i4 & 15;
            int i36 = (i4 >> 4) & DnsRecord.CLASS_ANY;
            int i37 = (i4 >> 12) & 32767;
            int i38 = (i4 >> 27) & 31;
            if (i31 <= i35) {
                if (i31 >= i35) {
                    if (i32 <= i36) {
                        if (i32 >= i36) {
                            if (i33 <= i37) {
                                if (i33 >= i37) {
                                    if (i34 <= i38) {
                                        if (i34 == i38) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        if (i6 == 5) {
            int i39 = i2 & 15;
            int i40 = (i2 >> 4) & DnsRecord.CLASS_ANY;
            int i41 = (i2 >> 12) & 511;
            int i42 = (i2 >> 21) & 32767;
            int i43 = i4 & 15;
            int i44 = (i4 >> 4) & DnsRecord.CLASS_ANY;
            int i45 = (i4 >> 12) & 511;
            int i46 = (i4 >> 21) & 32767;
            if (i39 <= i43) {
                if (i39 >= i43) {
                    if (i40 <= i44) {
                        if (i40 >= i44) {
                            if (i41 <= i45) {
                                if (i41 >= i45) {
                                    if (i42 <= i46) {
                                        if (i42 == i46) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        if (i6 != 4 && i6 != 7 && i6 == 514) {
            int i47 = (i2 >> 8) & DnsRecord.CLASS_ANY;
            int i48 = i2 & DnsRecord.CLASS_ANY;
            int i49 = (i2 >> 24) & DnsRecord.CLASS_ANY;
            int i50 = (i2 >> 16) & DnsRecord.CLASS_ANY;
            int i51 = (i4 >> 8) & DnsRecord.CLASS_ANY;
            int i52 = i4 & DnsRecord.CLASS_ANY;
            int i53 = (i4 >> 24) & DnsRecord.CLASS_ANY;
            int i54 = (i4 >> 16) & DnsRecord.CLASS_ANY;
            if (i47 <= i51) {
                if (i47 >= i51) {
                    if (i48 <= i52) {
                        if (i48 >= i52) {
                            if (i49 <= i53) {
                                if (i49 >= i53) {
                                    if (i50 <= i54) {
                                        if (i50 == i54) {
                                            return 0;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
                return -1;
            }
            return 1;
        }
        return i.g(i2, i4);
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x007f  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct add '--show-bad-code' argument
    */
    public static int h(int r16, int r17, int r18, int r19, int r20, int r21, int r22, int r23) {
        /*
            r0 = r16
            r1 = r17
            r2 = r18
            r3 = r19
            r4 = r21
            r5 = r22
            r6 = r23
            java.util.Locale r7 = java.util.Locale.US
            r8 = 3
            java.lang.Object[] r9 = new java.lang.Object[r8]
            java.lang.Integer r10 = java.lang.Integer.valueOf(r18)
            r11 = 0
            r9[r11] = r10
            java.lang.Integer r10 = java.lang.Integer.valueOf(r18)
            r12 = 1
            r9[r12] = r10
            java.lang.String r10 = g.i.a.c.a0.d.b(r3, r2, r6)
            r13 = 2
            r9[r13] = r10
            java.lang.String r10 = "checkVersion: bin=%08X(%d) %s"
            java.lang.String r9 = java.lang.String.format(r7, r10, r9)
            g.h.a.i.U3(r9)
            r9 = 516(0x204, float:7.23E-43)
            r10 = 1040(0x410, float:1.457E-42)
            if (r3 != r13) goto L3b
            if (r1 != r10) goto L3b
            r14 = r9
            goto L3c
        L3b:
            r14 = r6
        L3c:
            r15 = 7
            if (r3 > 0) goto L40
            r14 = r15
        L40:
            g.i.a.c.e.a r2 = g.i.a.c.e.a.b(r14, r2)
            java.lang.Object[] r3 = new java.lang.Object[r8]
            java.lang.Integer r8 = java.lang.Integer.valueOf(r21)
            r3[r11] = r8
            java.lang.Integer r8 = java.lang.Integer.valueOf(r21)
            r3[r12] = r8
            java.lang.String r8 = g.i.a.c.a0.d.b(r5, r4, r6)
            r3[r13] = r8
            java.lang.String r8 = "checkVersion: soc=%08X(%d) %s"
            java.lang.String r3 = java.lang.String.format(r7, r8, r3)
            g.h.a.i.U3(r3)
            r3 = 11
            if (r0 == r3) goto L7c
            r3 = 13
            if (r0 == r3) goto L7c
            r3 = 10
            if (r0 != r3) goto L6e
            goto L7c
        L6e:
            r0 = 20
            r1 = r20
            if (r1 != r0) goto L78
            r0 = 514(0x202, float:7.2E-43)
            r9 = r0
            goto L80
        L78:
            if (r5 > 0) goto L7f
            r9 = r15
            goto L80
        L7c:
            if (r1 != r10) goto L7f
            goto L80
        L7f:
            r9 = r6
        L80:
            g.i.a.c.e.a r0 = g.i.a.c.e.a.b(r9, r4)
            int r0 = r2.a(r0)
            return r0
        */
        throw new UnsupportedOperationException("Method not decompiled: g.i.a.c.o.a.h(int, int, int, int, int, int, int, int):int");
    }

    public static g.i.a.c.l.e.a i(Context context, int i2, String str, long j2) throws IOException {
        i.V3(false, String.format(Locale.US, "fileName=%s, icType=%d", str, Integer.valueOf(i2)));
        AssetManager assets = context.getAssets();
        if (assets == null) {
            i.W3("assetManager is null");
            return null;
        }
        InputStream inputStreamOpen = assets.open(str);
        if (inputStreamOpen != null) {
            return a(i2, inputStreamOpen, j2);
        }
        i.w0("open asset file failed");
        return null;
    }

    public static g.i.a.c.l.e.a j(int i2, String str, long j2) {
        return a(i2, new FileInputStream(str), j2);
    }

    public static int k(int i2, int i3) {
        return i3 == 0 ? i2 : i2 % i3;
    }

    public static int l(int i2, int i3, int i4) {
        int i5 = (i3 >> (i2 * 2)) & 3;
        if (i5 == 0) {
            if (i4 != 2) {
                return i2;
            }
        } else if (i5 != 1) {
            return i2;
        }
        return i2 + 16;
    }
}
