package e0;

import android.content.res.AssetManager;
import android.media.MediaMetadataRetriever;
import android.os.Build;
import android.system.Os;
import android.system.OsConstants;
import android.util.Log;
import android.util.Pair;
import j$.util.DesugarTimeZone;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.EOFException;
import java.io.FileDescriptor;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.regex.Pattern;
import java.util.zip.CRC32;
import p0.AbstractC0928a;

/* JADX INFO: loaded from: classes.dex */
public final class h {

    /* JADX INFO: renamed from: A, reason: collision with root package name */
    public static final byte[] f6187A;

    /* JADX INFO: renamed from: B, reason: collision with root package name */
    public static final byte[] f6188B;

    /* JADX INFO: renamed from: C, reason: collision with root package name */
    public static final byte[] f6189C;

    /* JADX INFO: renamed from: D, reason: collision with root package name */
    public static final byte[] f6190D;

    /* JADX INFO: renamed from: E, reason: collision with root package name */
    public static final byte[] f6191E;

    /* JADX INFO: renamed from: F, reason: collision with root package name */
    public static final byte[] f6192F;

    /* JADX INFO: renamed from: G, reason: collision with root package name */
    public static final byte[] f6193G;

    /* JADX INFO: renamed from: H, reason: collision with root package name */
    public static final byte[] f6194H;
    public static final byte[] I;
    public static final byte[] J;
    public static final byte[] K;

    /* JADX INFO: renamed from: L, reason: collision with root package name */
    public static final byte[] f6195L;

    /* JADX INFO: renamed from: M, reason: collision with root package name */
    public static final byte[] f6196M;

    /* JADX INFO: renamed from: N, reason: collision with root package name */
    public static final byte[] f6197N;

    /* JADX INFO: renamed from: O, reason: collision with root package name */
    public static final byte[] f6198O;

    /* JADX INFO: renamed from: P, reason: collision with root package name */
    public static final byte[] f6199P;

    /* JADX INFO: renamed from: Q, reason: collision with root package name */
    public static final byte[] f6200Q;

    /* JADX INFO: renamed from: R, reason: collision with root package name */
    public static final String[] f6201R;

    /* JADX INFO: renamed from: S, reason: collision with root package name */
    public static final int[] f6202S;

    /* JADX INFO: renamed from: T, reason: collision with root package name */
    public static final byte[] f6203T;

    /* JADX INFO: renamed from: U, reason: collision with root package name */
    public static final e f6204U;

    /* JADX INFO: renamed from: V, reason: collision with root package name */
    public static final e[][] f6205V;

    /* JADX INFO: renamed from: W, reason: collision with root package name */
    public static final e[] f6206W;
    public static final HashMap[] X;

    /* JADX INFO: renamed from: Y, reason: collision with root package name */
    public static final HashMap[] f6207Y;

    /* JADX INFO: renamed from: Z, reason: collision with root package name */
    public static final Set f6208Z;

    /* JADX INFO: renamed from: a0, reason: collision with root package name */
    public static final HashMap f6209a0;

    /* JADX INFO: renamed from: b0, reason: collision with root package name */
    public static final Charset f6210b0;

    /* JADX INFO: renamed from: c0, reason: collision with root package name */
    public static final byte[] f6211c0;

    /* JADX INFO: renamed from: d0, reason: collision with root package name */
    public static final byte[] f6212d0;

    /* JADX INFO: renamed from: e0, reason: collision with root package name */
    public static final Pattern f6213e0;

    /* JADX INFO: renamed from: f0, reason: collision with root package name */
    public static final Pattern f6214f0;

    /* JADX INFO: renamed from: g0, reason: collision with root package name */
    public static final Pattern f6215g0;

    /* JADX INFO: renamed from: v, reason: collision with root package name */
    public static final boolean f6216v = Log.isLoggable("ExifInterface", 3);

    /* JADX INFO: renamed from: w, reason: collision with root package name */
    public static final int[] f6217w;

    /* JADX INFO: renamed from: x, reason: collision with root package name */
    public static final int[] f6218x;

    /* JADX INFO: renamed from: y, reason: collision with root package name */
    public static final byte[] f6219y;

    /* JADX INFO: renamed from: z, reason: collision with root package name */
    public static final byte[] f6220z;

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public final String f6221a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public final FileDescriptor f6222b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public final AssetManager.AssetInputStream f6223c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f6224d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public final boolean f6225e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final HashMap[] f6226f;

    /* JADX INFO: renamed from: g, reason: collision with root package name */
    public final HashSet f6227g;

    /* JADX INFO: renamed from: h, reason: collision with root package name */
    public ByteOrder f6228h;
    public boolean i;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public boolean f6229j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public boolean f6230k;

    /* JADX INFO: renamed from: l, reason: collision with root package name */
    public int f6231l;

    /* JADX INFO: renamed from: m, reason: collision with root package name */
    public int f6232m;

    /* JADX INFO: renamed from: n, reason: collision with root package name */
    public byte[] f6233n;

    /* JADX INFO: renamed from: o, reason: collision with root package name */
    public int f6234o;
    public int p;
    public int q;

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public int f6235r;

    /* JADX INFO: renamed from: s, reason: collision with root package name */
    public int f6236s;

    /* JADX INFO: renamed from: t, reason: collision with root package name */
    public d f6237t;

    /* JADX INFO: renamed from: u, reason: collision with root package name */
    public boolean f6238u;

    static {
        Arrays.asList(1, 6, 3, 8);
        Arrays.asList(2, 7, 4, 5);
        f6217w = new int[]{8, 8, 8};
        f6218x = new int[]{8};
        f6219y = new byte[]{-1, -40, -1};
        f6220z = new byte[]{102, 116, 121, 112};
        f6187A = new byte[]{109, 105, 102, 49};
        f6188B = new byte[]{104, 101, 105, 99};
        f6189C = new byte[]{97, 118, 105, 102};
        f6190D = new byte[]{97, 118, 105, 115};
        f6191E = new byte[]{79, 76, 89, 77, 80, 0};
        f6192F = new byte[]{79, 76, 89, 77, 80, 85, 83, 0, 73, 73};
        f6193G = new byte[]{-119, 80, 78, 71, 13, 10, 26, 10};
        f6194H = "XML:com.adobe.xmp\u0000\u0000\u0000\u0000\u0000".getBytes(StandardCharsets.UTF_8);
        I = new byte[]{82, 73, 70, 70};
        J = new byte[]{87, 69, 66, 80};
        K = new byte[]{69, 88, 73, 70};
        f6195L = new byte[]{-99, 1, 42};
        f6196M = "VP8X".getBytes(Charset.defaultCharset());
        f6197N = "VP8L".getBytes(Charset.defaultCharset());
        f6198O = "VP8 ".getBytes(Charset.defaultCharset());
        f6199P = "ANIM".getBytes(Charset.defaultCharset());
        f6200Q = "ANMF".getBytes(Charset.defaultCharset());
        f6201R = new String[]{"", "BYTE", "STRING", "USHORT", "ULONG", "URATIONAL", "SBYTE", "UNDEFINED", "SSHORT", "SLONG", "SRATIONAL", "SINGLE", "DOUBLE", "IFD"};
        f6202S = new int[]{0, 1, 1, 2, 4, 8, 1, 1, 2, 4, 8, 4, 8, 1};
        f6203T = new byte[]{65, 83, 67, 73, 73, 0, 0, 0};
        e[] eVarArr = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ImageWidth", 256, 3, 4), new e("ImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("Orientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("SensorTopBorder", 4, 4), new e("SensorLeftBorder", 5, 4), new e("SensorBottomBorder", 6, 4), new e("SensorRightBorder", 7, 4), new e("ISO", 23, 3), new e("JpgFromRaw", 46, 7), new e("Xmp", 700, 1)};
        e[] eVarArr2 = {new e("ExposureTime", 33434, 5), new e("FNumber", 33437, 5), new e("ExposureProgram", 34850, 3), new e("SpectralSensitivity", 34852, 2), new e("PhotographicSensitivity", 34855, 3), new e("OECF", 34856, 7), new e("SensitivityType", 34864, 3), new e("StandardOutputSensitivity", 34865, 4), new e("RecommendedExposureIndex", 34866, 4), new e("ISOSpeed", 34867, 4), new e("ISOSpeedLatitudeyyy", 34868, 4), new e("ISOSpeedLatitudezzz", 34869, 4), new e("ExifVersion", 36864, 2), new e("DateTimeOriginal", 36867, 2), new e("DateTimeDigitized", 36868, 2), new e("OffsetTime", 36880, 2), new e("OffsetTimeOriginal", 36881, 2), new e("OffsetTimeDigitized", 36882, 2), new e("ComponentsConfiguration", 37121, 7), new e("CompressedBitsPerPixel", 37122, 5), new e("ShutterSpeedValue", 37377, 10), new e("ApertureValue", 37378, 5), new e("BrightnessValue", 37379, 10), new e("ExposureBiasValue", 37380, 10), new e("MaxApertureValue", 37381, 5), new e("SubjectDistance", 37382, 5), new e("MeteringMode", 37383, 3), new e("LightSource", 37384, 3), new e("Flash", 37385, 3), new e("FocalLength", 37386, 5), new e("SubjectArea", 37396, 3), new e("MakerNote", 37500, 7), new e("UserComment", 37510, 7), new e("SubSecTime", 37520, 2), new e("SubSecTimeOriginal", 37521, 2), new e("SubSecTimeDigitized", 37522, 2), new e("FlashpixVersion", 40960, 7), new e("ColorSpace", 40961, 3), new e("PixelXDimension", 40962, 3, 4), new e("PixelYDimension", 40963, 3, 4), new e("RelatedSoundFile", 40964, 2), new e("InteroperabilityIFDPointer", 40965, 4), new e("FlashEnergy", 41483, 5), new e("SpatialFrequencyResponse", 41484, 7), new e("FocalPlaneXResolution", 41486, 5), new e("FocalPlaneYResolution", 41487, 5), new e("FocalPlaneResolutionUnit", 41488, 3), new e("SubjectLocation", 41492, 3), new e("ExposureIndex", 41493, 5), new e("SensingMethod", 41495, 3), new e("FileSource", 41728, 7), new e("SceneType", 41729, 7), new e("CFAPattern", 41730, 7), new e("CustomRendered", 41985, 3), new e("ExposureMode", 41986, 3), new e("WhiteBalance", 41987, 3), new e("DigitalZoomRatio", 41988, 5), new e("FocalLengthIn35mmFilm", 41989, 3), new e("SceneCaptureType", 41990, 3), new e("GainControl", 41991, 3), new e("Contrast", 41992, 3), new e("Saturation", 41993, 3), new e("Sharpness", 41994, 3), new e("DeviceSettingDescription", 41995, 7), new e("SubjectDistanceRange", 41996, 3), new e("ImageUniqueID", 42016, 2), new e("CameraOwnerName", 42032, 2), new e("BodySerialNumber", 42033, 2), new e("LensSpecification", 42034, 5), new e("LensMake", 42035, 2), new e("LensModel", 42036, 2), new e("Gamma", 42240, 5), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        e[] eVarArr3 = {new e("GPSVersionID", 0, 1), new e("GPSLatitudeRef", 1, 2), new e("GPSLatitude", 2, 5, 10), new e("GPSLongitudeRef", 3, 2), new e("GPSLongitude", 4, 5, 10), new e("GPSAltitudeRef", 5, 1), new e("GPSAltitude", 6, 5), new e("GPSTimeStamp", 7, 5), new e("GPSSatellites", 8, 2), new e("GPSStatus", 9, 2), new e("GPSMeasureMode", 10, 2), new e("GPSDOP", 11, 5), new e("GPSSpeedRef", 12, 2), new e("GPSSpeed", 13, 5), new e("GPSTrackRef", 14, 2), new e("GPSTrack", 15, 5), new e("GPSImgDirectionRef", 16, 2), new e("GPSImgDirection", 17, 5), new e("GPSMapDatum", 18, 2), new e("GPSDestLatitudeRef", 19, 2), new e("GPSDestLatitude", 20, 5), new e("GPSDestLongitudeRef", 21, 2), new e("GPSDestLongitude", 22, 5), new e("GPSDestBearingRef", 23, 2), new e("GPSDestBearing", 24, 5), new e("GPSDestDistanceRef", 25, 2), new e("GPSDestDistance", 26, 5), new e("GPSProcessingMethod", 27, 7), new e("GPSAreaInformation", 28, 7), new e("GPSDateStamp", 29, 2), new e("GPSDifferential", 30, 3), new e("GPSHPositioningError", 31, 5)};
        e[] eVarArr4 = {new e("InteroperabilityIndex", 1, 2)};
        e[] eVarArr5 = {new e("NewSubfileType", 254, 4), new e("SubfileType", 255, 4), new e("ThumbnailImageWidth", 256, 3, 4), new e("ThumbnailImageLength", 257, 3, 4), new e("BitsPerSample", 258, 3), new e("Compression", 259, 3), new e("PhotometricInterpretation", 262, 3), new e("ImageDescription", 270, 2), new e("Make", 271, 2), new e("Model", 272, 2), new e("StripOffsets", 273, 3, 4), new e("ThumbnailOrientation", 274, 3), new e("SamplesPerPixel", 277, 3), new e("RowsPerStrip", 278, 3, 4), new e("StripByteCounts", 279, 3, 4), new e("XResolution", 282, 5), new e("YResolution", 283, 5), new e("PlanarConfiguration", 284, 3), new e("ResolutionUnit", 296, 3), new e("TransferFunction", 301, 3), new e("Software", 305, 2), new e("DateTime", 306, 2), new e("Artist", 315, 2), new e("WhitePoint", 318, 5), new e("PrimaryChromaticities", 319, 5), new e("SubIFDPointer", 330, 4), new e("JPEGInterchangeFormat", 513, 4), new e("JPEGInterchangeFormatLength", 514, 4), new e("YCbCrCoefficients", 529, 5), new e("YCbCrSubSampling", 530, 3), new e("YCbCrPositioning", 531, 3), new e("ReferenceBlackWhite", 532, 5), new e("Copyright", 33432, 2), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("DNGVersion", 50706, 1), new e("DefaultCropSize", 50720, 3, 4)};
        f6204U = new e("StripOffsets", 273, 3);
        f6205V = new e[][]{eVarArr, eVarArr2, eVarArr3, eVarArr4, eVarArr5, eVarArr, new e[]{new e("ThumbnailImage", 256, 7), new e("CameraSettingsIFDPointer", 8224, 4), new e("ImageProcessingIFDPointer", 8256, 4)}, new e[]{new e("PreviewImageStart", 257, 4), new e("PreviewImageLength", 258, 4)}, new e[]{new e("AspectFrame", 4371, 3)}, new e[]{new e("ColorSpace", 55, 3)}};
        f6206W = new e[]{new e("SubIFDPointer", 330, 4), new e("ExifIFDPointer", 34665, 4), new e("GPSInfoIFDPointer", 34853, 4), new e("InteroperabilityIFDPointer", 40965, 4), new e("CameraSettingsIFDPointer", 8224, 1), new e("ImageProcessingIFDPointer", 8256, 1)};
        X = new HashMap[10];
        f6207Y = new HashMap[10];
        f6208Z = Collections.unmodifiableSet(new HashSet(Arrays.asList("FNumber", "DigitalZoomRatio", "ExposureTime", "SubjectDistance")));
        f6209a0 = new HashMap();
        Charset charsetForName = Charset.forName("US-ASCII");
        f6210b0 = charsetForName;
        f6211c0 = "Exif\u0000\u0000".getBytes(charsetForName);
        f6212d0 = "http://ns.adobe.com/xap/1.0/\u0000".getBytes(charsetForName);
        Locale locale = Locale.US;
        new SimpleDateFormat("yyyy:MM:dd HH:mm:ss", locale).setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        new SimpleDateFormat("yyyy-MM-dd HH:mm:ss", locale).setTimeZone(DesugarTimeZone.getTimeZone("UTC"));
        int i = 0;
        while (true) {
            e[][] eVarArr6 = f6205V;
            if (i >= eVarArr6.length) {
                HashMap map = f6209a0;
                e[] eVarArr7 = f6206W;
                map.put(Integer.valueOf(eVarArr7[0].f6181a), 5);
                map.put(Integer.valueOf(eVarArr7[1].f6181a), 1);
                map.put(Integer.valueOf(eVarArr7[2].f6181a), 2);
                map.put(Integer.valueOf(eVarArr7[3].f6181a), 3);
                map.put(Integer.valueOf(eVarArr7[4].f6181a), 7);
                map.put(Integer.valueOf(eVarArr7[5].f6181a), 8);
                Pattern.compile(".*[1-9].*");
                f6213e0 = Pattern.compile("^(\\d{2}):(\\d{2}):(\\d{2})$");
                f6214f0 = Pattern.compile("^(\\d{4}):(\\d{2}):(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                f6215g0 = Pattern.compile("^(\\d{4})-(\\d{2})-(\\d{2})\\s(\\d{2}):(\\d{2}):(\\d{2})$");
                return;
            }
            X[i] = new HashMap();
            f6207Y[i] = new HashMap();
            for (e eVar : eVarArr6[i]) {
                X[i].put(Integer.valueOf(eVar.f6181a), eVar);
                f6207Y[i].put(eVar.f6182b, eVar);
            }
            i++;
        }
    }

    public h(String str) throws Throwable {
        FileInputStream fileInputStream;
        boolean z5;
        e[][] eVarArr = f6205V;
        this.f6226f = new HashMap[eVarArr.length];
        this.f6227g = new HashSet(eVarArr.length);
        this.f6228h = ByteOrder.BIG_ENDIAN;
        if (str == null) {
            throw new NullPointerException("filename cannot be null");
        }
        FileInputStream fileInputStream2 = null;
        this.f6223c = null;
        this.f6221a = str;
        try {
            fileInputStream = new FileInputStream(str);
        } catch (Throwable th) {
            th = th;
        }
        try {
            try {
                Os.lseek(fileInputStream.getFD(), 0L, OsConstants.SEEK_CUR);
                z5 = true;
            } catch (Exception unused) {
                if (f6216v) {
                    Log.d("ExifInterface", "The file descriptor for the given input is not seekable");
                }
                z5 = false;
            }
            if (z5) {
                this.f6222b = fileInputStream.getFD();
            } else {
                this.f6222b = null;
            }
            r(fileInputStream);
            b5.a.f(fileInputStream);
        } catch (Throwable th2) {
            th = th2;
            fileInputStream2 = fileInputStream;
            b5.a.f(fileInputStream2);
            throw th;
        }
    }

    public static Pair o(String str) {
        if (str.contains(",")) {
            String[] strArrSplit = str.split(",", -1);
            Pair pairO = o(strArrSplit[0]);
            if (((Integer) pairO.first).intValue() == 2) {
                return pairO;
            }
            for (int i = 1; i < strArrSplit.length; i++) {
                Pair pairO2 = o(strArrSplit[i]);
                int iIntValue = (((Integer) pairO2.first).equals(pairO.first) || ((Integer) pairO2.second).equals(pairO.first)) ? ((Integer) pairO.first).intValue() : -1;
                int iIntValue2 = (((Integer) pairO.second).intValue() == -1 || !(((Integer) pairO2.first).equals(pairO.second) || ((Integer) pairO2.second).equals(pairO.second))) ? -1 : ((Integer) pairO.second).intValue();
                if (iIntValue == -1 && iIntValue2 == -1) {
                    return new Pair(2, -1);
                }
                if (iIntValue == -1) {
                    pairO = new Pair(Integer.valueOf(iIntValue2), -1);
                } else if (iIntValue2 == -1) {
                    pairO = new Pair(Integer.valueOf(iIntValue), -1);
                }
            }
            return pairO;
        }
        if (!str.contains("/")) {
            try {
                try {
                    long j5 = Long.parseLong(str);
                    return (j5 < 0 || j5 > 65535) ? j5 < 0 ? new Pair(9, -1) : new Pair(4, -1) : new Pair(3, 4);
                } catch (NumberFormatException unused) {
                    return new Pair(2, -1);
                }
            } catch (NumberFormatException unused2) {
                Double.parseDouble(str);
                return new Pair(12, -1);
            }
        }
        String[] strArrSplit2 = str.split("/", -1);
        if (strArrSplit2.length == 2) {
            try {
                long j6 = (long) Double.parseDouble(strArrSplit2[0]);
                long j7 = (long) Double.parseDouble(strArrSplit2[1]);
                if (j6 >= 0 && j7 >= 0) {
                    if (j6 <= 2147483647L && j7 <= 2147483647L) {
                        return new Pair(10, 5);
                    }
                    return new Pair(5, -1);
                }
                return new Pair(10, -1);
            } catch (NumberFormatException unused3) {
            }
        }
        return new Pair(2, -1);
    }

    public static ByteOrder u(C0555b c0555b) throws IOException {
        short s5 = c0555b.readShort();
        boolean z5 = f6216v;
        if (s5 == 18761) {
            if (z5) {
                Log.d("ExifInterface", "readExifSegment: Byte Align II");
            }
            return ByteOrder.LITTLE_ENDIAN;
        }
        if (s5 == 19789) {
            if (z5) {
                Log.d("ExifInterface", "readExifSegment: Byte Align MM");
            }
            return ByteOrder.BIG_ENDIAN;
        }
        throw new IOException("Invalid byte order: " + Integer.toHexString(s5));
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0043 A[ADDED_TO_REGION] */
    /* JADX WARN: Removed duplicated region for block: B:42:0x0077 A[SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:46:0x0057 A[SYNTHETIC] */
    /* JADX WARN: Unsupported multi-entry loop pattern (BACK_EDGE: B:25:0x0075 -> B:10:0x0041). Please report as a decompilation issue!!! */
    /*  JADX ERROR: JadxOverflowException in pass: RegionMakerVisitor
        jadx.core.utils.exceptions.JadxOverflowException: Regions count limit reached
        	at jadx.core.utils.ErrorsCounter.addError(ErrorsCounter.java:59)
        	at jadx.core.utils.ErrorsCounter.error(ErrorsCounter.java:31)
        	at jadx.core.dex.attributes.nodes.NotificationAttrNode.addError(NotificationAttrNode.java:19)
        */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void A(java.io.BufferedInputStream r9, java.io.BufferedOutputStream r10) {
        /*
            r8 = this;
            boolean r0 = e0.h.f6216v
            if (r0 == 0) goto L24
            java.lang.StringBuilder r0 = new java.lang.StringBuilder
            java.lang.String r1 = "savePngAttributes starting with (inputStream: "
            r0.<init>(r1)
            r0.append(r9)
            java.lang.String r1 = ", outputStream: "
            r0.append(r1)
            r0.append(r10)
            java.lang.String r1 = ")"
            r0.append(r1)
            java.lang.String r0 = r0.toString()
            java.lang.String r1 = "ExifInterface"
            android.util.Log.d(r1, r0)
        L24:
            e0.b r0 = new e0.b
            r0.<init>(r9)
            e0.c r9 = new e0.c
            java.nio.ByteOrder r1 = java.nio.ByteOrder.BIG_ENDIAN
            r9.<init>(r10, r1)
            byte[] r10 = e0.h.f6193G
            int r10 = r10.length
            b5.a.h(r0, r9, r10)
            e0.d r10 = r8.f6237t
            r1 = 1
            r2 = 0
            if (r10 != 0) goto L40
            boolean r10 = r8.f6238u
            if (r10 == 0) goto L75
        L40:
            r10 = r1
        L41:
            if (r1 != 0) goto L4a
            if (r10 == 0) goto L46
            goto L4a
        L46:
            b5.a.i(r0, r9)
            return
        L4a:
            int r3 = r0.readInt()
            int r4 = r0.readInt()
            r5 = 1229472850(0x49484452, float:820293.1)
            if (r4 != r5) goto L77
            r9.e(r3)
            r9.e(r4)
            int r3 = r3 + 4
            b5.a.h(r0, r9, r3)
            int r3 = r8.p
            if (r3 != 0) goto L6a
            r8.H(r9)
            r1 = r2
        L6a:
            e0.d r3 = r8.f6237t
            if (r3 == 0) goto L41
            boolean r3 = r8.f6238u
            if (r3 != 0) goto L41
            r8.I(r9)
        L75:
            r10 = r2
            goto L41
        L77:
            r5 = 1700284774(0x65584966, float:6.383657E22)
            if (r4 != r5) goto L88
            if (r1 == 0) goto L88
            r8.H(r9)
            int r3 = r3 + 4
            r0.a(r3)
            r1 = r2
            goto L41
        L88:
            r5 = 1767135348(0x69545874, float:1.6044374E25)
            if (r4 != r5) goto Lba
            byte[] r5 = e0.h.f6194H
            int r6 = r5.length
            if (r3 < r6) goto Lba
            int r6 = r5.length
            byte[] r7 = new byte[r6]
            r0.readFully(r7)
            int r6 = r3 - r6
            int r6 = r6 + 4
            boolean r5 = java.util.Arrays.equals(r7, r5)
            if (r5 == 0) goto Lad
            e0.d r10 = r8.f6237t
            if (r10 == 0) goto La9
            r8.I(r9)
        La9:
            r0.a(r6)
            goto L75
        Lad:
            r9.e(r3)
            r9.e(r4)
            r9.write(r7)
            b5.a.h(r0, r9, r6)
            goto L41
        Lba:
            r9.e(r3)
            r9.e(r4)
            int r3 = r3 + 4
            b5.a.h(r0, r9, r3)
            goto L41
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.A(java.io.BufferedInputStream, java.io.BufferedOutputStream):void");
    }

    /* JADX WARN: Can't wrap try/catch for region: R(18:0|2|(1:4)|5|139|6|(4:149|7|8|143)|(4:10|(1:12)|13|14)(3:20|21|(7:23|(1:25)(1:26)|27|(1:29)|30|(4:32|(3:33|(1:35)|36)|(5:39|141|40|41|(1:152)(3:45|(2:47|153)(1:154)|48))|44)(2:(4:49|(1:51)|52|(1:157)(2:160|158))|57)|58)(6:59|60|(22:66|(1:68)(1:70)|69|71|72|(2:74|(1:76)(2:77|78))(3:79|80|(2:82|(3:84|(1:86)(1:87)|88)(2:89|90))(1:91))|92|(1:94)(1:96)|97|98|147|99|(1:101)(2:107|(2:109|110))|111|112|113|(1:115)|116|145|117|118|119)(1:65)|123|135|136))|15|112|113|(0)|116|145|117|118|119|(1:(0))) */
    /* JADX WARN: Code restructure failed: missing block: B:120:0x0290, code lost:
    
        r0 = th;
     */
    /* JADX WARN: Code restructure failed: missing block: B:122:0x0293, code lost:
    
        r0 = e;
     */
    /* JADX WARN: Removed duplicated region for block: B:115:0x027b A[Catch: all -> 0x0243, Exception -> 0x0248, TRY_ENTER, TRY_LEAVE, TryCatch #12 {Exception -> 0x0248, all -> 0x0243, blocks: (B:115:0x027b, B:101:0x0239, B:110:0x0254), top: B:143:0x0056 }] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void B(java.io.BufferedInputStream r23, java.io.BufferedOutputStream r24) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 691
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.B(java.io.BufferedInputStream, java.io.BufferedOutputStream):void");
    }

    public final void C(C0555b c0555b) throws Throwable {
        String str;
        d dVar;
        int i;
        HashMap map = this.f6226f[4];
        d dVar2 = (d) map.get("Compression");
        if (dVar2 == null) {
            this.f6234o = 6;
            p(c0555b, map);
            return;
        }
        int i5 = dVar2.i(this.f6228h);
        this.f6234o = i5;
        int i6 = 1;
        if (i5 != 1) {
            if (i5 == 6) {
                p(c0555b, map);
                return;
            } else if (i5 != 7) {
                return;
            }
        }
        d dVar3 = (d) map.get("BitsPerSample");
        String str2 = "ExifInterface";
        if (dVar3 != null) {
            int[] iArr = (int[]) dVar3.k(this.f6228h);
            int[] iArr2 = f6217w;
            if (Arrays.equals(iArr2, iArr) || (this.f6224d == 3 && (dVar = (d) map.get("PhotometricInterpretation")) != null && (((i = dVar.i(this.f6228h)) == 1 && Arrays.equals(iArr, f6218x)) || (i == 6 && Arrays.equals(iArr, iArr2))))) {
                d dVar4 = (d) map.get("StripOffsets");
                d dVar5 = (d) map.get("StripByteCounts");
                if (dVar4 == null || dVar5 == null) {
                    return;
                }
                long[] jArrG = b5.a.g(dVar4.k(this.f6228h));
                long[] jArrG2 = b5.a.g(dVar5.k(this.f6228h));
                if (jArrG == null || jArrG.length == 0) {
                    Log.w("ExifInterface", "stripOffsets should not be null or have zero length.");
                    return;
                }
                if (jArrG2 == null || jArrG2.length == 0) {
                    Log.w("ExifInterface", "stripByteCounts should not be null or have zero length.");
                    return;
                }
                if (jArrG.length != jArrG2.length) {
                    Log.w("ExifInterface", "stripOffsets and stripByteCounts should have same length.");
                    return;
                }
                long j5 = 0;
                for (long j6 : jArrG2) {
                    j5 += j6;
                }
                int i7 = (int) j5;
                byte[] bArr = new byte[i7];
                this.f6230k = true;
                this.f6229j = true;
                this.i = true;
                int i8 = 0;
                int i9 = 0;
                int i10 = 0;
                while (i8 < jArrG.length) {
                    int i11 = (int) jArrG[i8];
                    int i12 = (int) jArrG2[i8];
                    if (i8 < jArrG.length - i6) {
                        str = str2;
                        if (i11 + i12 != jArrG[i8 + 1]) {
                            this.f6230k = false;
                        }
                    } else {
                        str = str2;
                    }
                    int i13 = i11 - i9;
                    if (i13 < 0) {
                        Log.d(str, "Invalid strip offset value");
                        return;
                    }
                    String str3 = str;
                    try {
                        c0555b.a(i13);
                        int i14 = i9 + i13;
                        byte[] bArr2 = new byte[i12];
                        try {
                            c0555b.readFully(bArr2);
                            i9 = i14 + i12;
                            System.arraycopy(bArr2, 0, bArr, i10, i12);
                            i10 += i12;
                            i8++;
                            str2 = str3;
                            i6 = 1;
                        } catch (EOFException unused) {
                            Log.d(str3, "Failed to read " + i12 + " bytes.");
                            return;
                        }
                    } catch (EOFException unused2) {
                        Log.d(str3, "Failed to skip " + i13 + " bytes.");
                        return;
                    }
                }
                this.f6233n = bArr;
                if (this.f6230k) {
                    this.f6231l = (int) jArrG[0];
                    this.f6232m = i7;
                    return;
                }
                return;
            }
        }
        if (f6216v) {
            Log.d("ExifInterface", "Unsupported data type value");
        }
    }

    public final void D(int i, int i5) throws Throwable {
        HashMap[] mapArr = this.f6226f;
        boolean zIsEmpty = mapArr[i].isEmpty();
        boolean z5 = f6216v;
        if (zIsEmpty || mapArr[i5].isEmpty()) {
            if (z5) {
                Log.d("ExifInterface", "Cannot perform swap since only one image data exists");
                return;
            }
            return;
        }
        d dVar = (d) mapArr[i].get("ImageLength");
        d dVar2 = (d) mapArr[i].get("ImageWidth");
        d dVar3 = (d) mapArr[i5].get("ImageLength");
        d dVar4 = (d) mapArr[i5].get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            if (z5) {
                Log.d("ExifInterface", "First image does not contain valid size information");
                return;
            }
            return;
        }
        if (dVar3 == null || dVar4 == null) {
            if (z5) {
                Log.d("ExifInterface", "Second image does not contain valid size information");
                return;
            }
            return;
        }
        int i6 = dVar.i(this.f6228h);
        int i7 = dVar2.i(this.f6228h);
        int i8 = dVar3.i(this.f6228h);
        int i9 = dVar4.i(this.f6228h);
        if (i6 >= i8 || i7 >= i9) {
            return;
        }
        HashMap map = mapArr[i];
        mapArr[i] = mapArr[i5];
        mapArr[i5] = map;
    }

    public final void E(g gVar, int i) throws Throwable {
        d dVarF;
        d dVarF2;
        HashMap[] mapArr = this.f6226f;
        d dVar = (d) mapArr[i].get("DefaultCropSize");
        d dVar2 = (d) mapArr[i].get("SensorTopBorder");
        d dVar3 = (d) mapArr[i].get("SensorLeftBorder");
        d dVar4 = (d) mapArr[i].get("SensorBottomBorder");
        d dVar5 = (d) mapArr[i].get("SensorRightBorder");
        if (dVar != null) {
            if (dVar.f6177a == 5) {
                f[] fVarArr = (f[]) dVar.k(this.f6228h);
                if (fVarArr == null || fVarArr.length != 2) {
                    Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(fVarArr));
                    return;
                } else {
                    dVarF = d.e(new f[]{fVarArr[0]}, this.f6228h);
                    dVarF2 = d.e(new f[]{fVarArr[1]}, this.f6228h);
                }
            } else {
                int[] iArr = (int[]) dVar.k(this.f6228h);
                if (iArr == null || iArr.length != 2) {
                    Log.w("ExifInterface", "Invalid crop size values. cropSize=" + Arrays.toString(iArr));
                    return;
                }
                dVarF = d.f(iArr[0], this.f6228h);
                dVarF2 = d.f(iArr[1], this.f6228h);
            }
            mapArr[i].put("ImageWidth", dVarF);
            mapArr[i].put("ImageLength", dVarF2);
            return;
        }
        if (dVar2 != null && dVar3 != null && dVar4 != null && dVar5 != null) {
            int i5 = dVar2.i(this.f6228h);
            int i6 = dVar4.i(this.f6228h);
            int i7 = dVar5.i(this.f6228h);
            int i8 = dVar3.i(this.f6228h);
            if (i6 <= i5 || i7 <= i8) {
                return;
            }
            d dVarF3 = d.f(i6 - i5, this.f6228h);
            d dVarF4 = d.f(i7 - i8, this.f6228h);
            mapArr[i].put("ImageLength", dVarF3);
            mapArr[i].put("ImageWidth", dVarF4);
            return;
        }
        d dVar6 = (d) mapArr[i].get("ImageLength");
        d dVar7 = (d) mapArr[i].get("ImageWidth");
        if (dVar6 == null || dVar7 == null) {
            d dVar8 = (d) mapArr[i].get("JPEGInterchangeFormat");
            d dVar9 = (d) mapArr[i].get("JPEGInterchangeFormatLength");
            if (dVar8 == null || dVar9 == null) {
                return;
            }
            int i9 = dVar8.i(this.f6228h);
            int i10 = dVar8.i(this.f6228h);
            gVar.e(i9);
            byte[] bArr = new byte[i10];
            gVar.readFully(bArr);
            e(new C0555b(bArr), i9, i);
        }
    }

    public final void F() throws Throwable {
        D(0, 5);
        D(0, 4);
        D(5, 4);
        HashMap[] mapArr = this.f6226f;
        d dVar = (d) mapArr[1].get("PixelXDimension");
        d dVar2 = (d) mapArr[1].get("PixelYDimension");
        if (dVar != null && dVar2 != null) {
            mapArr[0].put("ImageWidth", dVar);
            mapArr[0].put("ImageLength", dVar2);
        }
        if (mapArr[4].isEmpty() && q(mapArr[5])) {
            mapArr[4] = mapArr[5];
            mapArr[5] = new HashMap();
        }
        if (!q(mapArr[4])) {
            Log.d("ExifInterface", "No image meets the size requirements of a thumbnail image.");
        }
        y(0, "ThumbnailOrientation", "Orientation");
        y(0, "ThumbnailImageLength", "ImageLength");
        y(0, "ThumbnailImageWidth", "ImageWidth");
        y(5, "ThumbnailOrientation", "Orientation");
        y(5, "ThumbnailImageLength", "ImageLength");
        y(5, "ThumbnailImageWidth", "ImageWidth");
        y(4, "Orientation", "ThumbnailOrientation");
        y(4, "ImageLength", "ThumbnailImageLength");
        y(4, "ImageWidth", "ThumbnailImageWidth");
    }

    public final int G(c cVar) throws IOException {
        HashMap[] mapArr;
        int i;
        int i5;
        char c6;
        char c7;
        int[] iArr;
        int i6;
        e[][] eVarArr = f6205V;
        int[] iArr2 = new int[eVarArr.length];
        int[] iArr3 = new int[eVarArr.length];
        e[] eVarArr2 = f6206W;
        for (e eVar : eVarArr2) {
            x(eVar.f6182b);
        }
        if (this.i) {
            if (this.f6229j) {
                x("StripOffsets");
                x("StripByteCounts");
            } else {
                x("JPEGInterchangeFormat");
                x("JPEGInterchangeFormatLength");
            }
        }
        int i7 = 0;
        while (true) {
            int length = eVarArr.length;
            mapArr = this.f6226f;
            if (i7 >= length) {
                break;
            }
            Iterator it = mapArr[i7].entrySet().iterator();
            while (it.hasNext()) {
                if (((Map.Entry) it.next()).getValue() == null) {
                    it.remove();
                }
            }
            i7++;
        }
        if (mapArr[1].isEmpty()) {
            i = 1;
            i5 = 0;
        } else {
            i = 1;
            i5 = 0;
            mapArr[0].put(eVarArr2[1].f6182b, d.c(0L, this.f6228h));
        }
        if (mapArr[2].isEmpty()) {
            c6 = 2;
        } else {
            c6 = 2;
            mapArr[i5].put(eVarArr2[2].f6182b, d.c(0L, this.f6228h));
        }
        if (mapArr[3].isEmpty()) {
            c7 = 3;
        } else {
            c7 = 3;
            mapArr[i].put(eVarArr2[3].f6182b, d.c(0L, this.f6228h));
        }
        int i8 = 4;
        if (this.i) {
            if (this.f6229j) {
                mapArr[4].put("StripOffsets", d.f(i5, this.f6228h));
                mapArr[4].put("StripByteCounts", d.f(this.f6232m, this.f6228h));
            } else {
                mapArr[4].put("JPEGInterchangeFormat", d.c(0L, this.f6228h));
                mapArr[4].put("JPEGInterchangeFormatLength", d.c(this.f6232m, this.f6228h));
            }
        }
        int i9 = 0;
        while (true) {
            int length2 = eVarArr.length;
            iArr = f6202S;
            if (i9 >= length2) {
                break;
            }
            Iterator it2 = mapArr[i9].entrySet().iterator();
            int i10 = 0;
            while (it2.hasNext()) {
                d dVar = (d) ((Map.Entry) it2.next()).getValue();
                dVar.getClass();
                int i11 = iArr[dVar.f6177a] * dVar.f6178b;
                if (i11 > 4) {
                    i10 += i11;
                }
            }
            iArr3[i9] = iArr3[i9] + i10;
            i9++;
        }
        int size = 8;
        for (int i12 = 0; i12 < eVarArr.length; i12++) {
            if (!mapArr[i12].isEmpty()) {
                iArr2[i12] = size;
                size = (mapArr[i12].size() * 12) + 6 + iArr3[i12] + size;
            }
        }
        if (this.i) {
            if (this.f6229j) {
                mapArr[4].put("StripOffsets", d.f(size, this.f6228h));
            } else {
                mapArr[4].put("JPEGInterchangeFormat", d.c(size, this.f6228h));
            }
            this.f6231l = size;
            size += this.f6232m;
        }
        if (this.f6224d == 4) {
            size += 8;
        }
        if (f6216v) {
            for (int i13 = 0; i13 < eVarArr.length; i13++) {
                Log.d("ExifInterface", String.format("index: %d, offsets: %d, tag count: %d, data sizes: %d, total size: %d", Integer.valueOf(i13), Integer.valueOf(iArr2[i13]), Integer.valueOf(mapArr[i13].size()), Integer.valueOf(iArr3[i13]), Integer.valueOf(size)));
            }
        }
        if (!mapArr[i].isEmpty()) {
            mapArr[0].put(eVarArr2[i].f6182b, d.c(iArr2[i], this.f6228h));
        }
        if (!mapArr[c6].isEmpty()) {
            mapArr[0].put(eVarArr2[c6].f6182b, d.c(iArr2[c6], this.f6228h));
        }
        if (!mapArr[c7].isEmpty()) {
            mapArr[i].put(eVarArr2[c7].f6182b, d.c(iArr2[c7], this.f6228h));
        }
        int i14 = this.f6224d;
        if (i14 == 4) {
            if (size > 65535) {
                throw new IllegalStateException(AbstractC0928a.j(size, "Size of exif data (", " bytes) exceeds the max size of a JPEG APP1 segment (65536 bytes)"));
            }
            cVar.k(size);
            cVar.write(f6211c0);
        } else if (i14 == 13) {
            cVar.e(size);
            cVar.e(1700284774);
        } else if (i14 == 14) {
            cVar.write(K);
            cVar.e(size);
        }
        int size2 = cVar.f6175k.size();
        cVar.f(this.f6228h == ByteOrder.BIG_ENDIAN ? (short) 19789 : (short) 18761);
        cVar.f6176l = this.f6228h;
        cVar.k(42);
        cVar.h(8L);
        int i15 = 0;
        while (i15 < eVarArr.length) {
            if (mapArr[i15].isEmpty()) {
                i6 = i8;
            } else {
                cVar.k(mapArr[i15].size());
                int size3 = (mapArr[i15].size() * 12) + iArr2[i15] + 2 + i8;
                for (Map.Entry entry : mapArr[i15].entrySet()) {
                    int i16 = ((e) f6207Y[i15].get(entry.getKey())).f6181a;
                    d dVar2 = (d) entry.getValue();
                    dVar2.getClass();
                    int i17 = dVar2.f6177a;
                    int i18 = iArr[i17];
                    int i19 = dVar2.f6178b;
                    int i20 = i18 * i19;
                    cVar.k(i16);
                    cVar.k(i17);
                    cVar.e(i19);
                    if (i20 > 4) {
                        cVar.h(size3);
                        size3 += i20;
                    } else {
                        cVar.write(dVar2.f6180d);
                        if (i20 < 4) {
                            while (i20 < 4) {
                                cVar.a(0);
                                i20++;
                            }
                        }
                    }
                    i8 = 4;
                }
                int i21 = i8;
                if (i15 != 0 || mapArr[i21].isEmpty()) {
                    cVar.h(0L);
                } else {
                    cVar.h(iArr2[i21]);
                }
                Iterator it3 = mapArr[i15].entrySet().iterator();
                while (it3.hasNext()) {
                    byte[] bArr = ((d) ((Map.Entry) it3.next()).getValue()).f6180d;
                    if (bArr.length > 4) {
                        cVar.write(bArr, 0, bArr.length);
                    }
                }
                i6 = 4;
            }
            i15++;
            i8 = i6;
        }
        if (this.i) {
            cVar.write(m());
        }
        if (this.f6224d == 14 && size % 2 == i) {
            cVar.a(0);
        }
        cVar.f6176l = ByteOrder.BIG_ENDIAN;
        return size2;
    }

    public final void H(c cVar) throws IOException {
        ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
        this.p = cVar.f6175k.size() + G(new c(byteArrayOutputStream, ByteOrder.BIG_ENDIAN));
        byte[] byteArray = byteArrayOutputStream.toByteArray();
        cVar.write(byteArray);
        CRC32 crc32 = new CRC32();
        crc32.update(byteArray, 4, byteArray.length - 4);
        cVar.e((int) crc32.getValue());
    }

    public final void I(c cVar) throws IOException {
        cVar.e(this.f6237t.f6180d.length + 22);
        CRC32 crc32 = new CRC32();
        cVar.e(1767135348);
        crc32.update(105);
        crc32.update(26964);
        crc32.update(6902872);
        crc32.update(1767135348);
        byte[] bArr = f6194H;
        cVar.write(bArr);
        crc32.update(bArr);
        cVar.write(this.f6237t.f6180d);
        crc32.update(this.f6237t.f6180d);
        cVar.e((int) crc32.getValue());
        this.f6238u = true;
    }

    public final void a() {
        String strB = b("DateTimeOriginal");
        HashMap[] mapArr = this.f6226f;
        if (strB != null && b("DateTime") == null) {
            mapArr[0].put("DateTime", d.b(strB));
        }
        if (b("ImageWidth") == null) {
            mapArr[0].put("ImageWidth", d.c(0L, this.f6228h));
        }
        if (b("ImageLength") == null) {
            mapArr[0].put("ImageLength", d.c(0L, this.f6228h));
        }
        if (b("Orientation") == null) {
            mapArr[0].put("Orientation", d.c(0L, this.f6228h));
        }
        if (b("LightSource") == null) {
            mapArr[1].put("LightSource", d.c(0L, this.f6228h));
        }
    }

    public final String b(String str) {
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        d dVarC = c(str);
        if (dVarC != null) {
            if (str.equals("GPSTimeStamp")) {
                int i = dVarC.f6177a;
                if (i != 5 && i != 10) {
                    Log.w("ExifInterface", "GPS Timestamp format is not rational. format=" + i);
                    return null;
                }
                f[] fVarArr = (f[]) dVarC.k(this.f6228h);
                if (fVarArr == null || fVarArr.length != 3) {
                    Log.w("ExifInterface", "Invalid GPS Timestamp array. array=" + Arrays.toString(fVarArr));
                    return null;
                }
                f fVar = fVarArr[0];
                Integer numValueOf = Integer.valueOf((int) (fVar.f6185a / fVar.f6186b));
                f fVar2 = fVarArr[1];
                Integer numValueOf2 = Integer.valueOf((int) (fVar2.f6185a / fVar2.f6186b));
                f fVar3 = fVarArr[2];
                return String.format("%02d:%02d:%02d", numValueOf, numValueOf2, Integer.valueOf((int) (fVar3.f6185a / fVar3.f6186b)));
            }
            if (!f6208Z.contains(str)) {
                return dVarC.j(this.f6228h);
            }
            try {
                return Double.toString(dVarC.h(this.f6228h));
            } catch (NumberFormatException unused) {
            }
        }
        return null;
    }

    public final d c(String str) {
        d dVar;
        int i;
        d dVar2;
        if (str == null) {
            throw new NullPointerException("tag shouldn't be null");
        }
        if ("ISOSpeedRatings".equals(str)) {
            if (f6216v) {
                Log.d("ExifInterface", "getExifAttribute: Replacing TAG_ISO_SPEED_RATINGS with TAG_PHOTOGRAPHIC_SENSITIVITY.");
            }
            str = "PhotographicSensitivity";
        }
        if ("Xmp".equals(str) && (i = this.f6224d) != 4 && ((i == 9 || i == 15 || i == 12 || i == 13) && (dVar2 = this.f6237t) != null)) {
            return dVar2;
        }
        for (int i5 = 0; i5 < f6205V.length; i5++) {
            d dVar3 = (d) this.f6226f[i5].get(str);
            if (dVar3 != null) {
                return dVar3;
            }
        }
        if (!"Xmp".equals(str) || (dVar = this.f6237t) == null) {
            return null;
        }
        return dVar;
    }

    public final void d(g gVar, int i) {
        String strExtractMetadata;
        String strExtractMetadata2;
        String strExtractMetadata3;
        int i5 = Build.VERSION.SDK_INT;
        if (i5 < 28) {
            throw new UnsupportedOperationException("Reading EXIF from HEIC files is supported from SDK 28 and above");
        }
        if (i == 15 && i5 < 31) {
            throw new UnsupportedOperationException("Reading EXIF from AVIF files is supported from SDK 31 and above");
        }
        MediaMetadataRetriever mediaMetadataRetriever = new MediaMetadataRetriever();
        try {
            try {
                mediaMetadataRetriever.setDataSource(new C0554a(gVar));
                String strExtractMetadata4 = mediaMetadataRetriever.extractMetadata(33);
                String strExtractMetadata5 = mediaMetadataRetriever.extractMetadata(34);
                String strExtractMetadata6 = mediaMetadataRetriever.extractMetadata(26);
                String strExtractMetadata7 = mediaMetadataRetriever.extractMetadata(17);
                if ("yes".equals(strExtractMetadata6)) {
                    strExtractMetadata = mediaMetadataRetriever.extractMetadata(29);
                    strExtractMetadata3 = mediaMetadataRetriever.extractMetadata(30);
                    strExtractMetadata2 = mediaMetadataRetriever.extractMetadata(31);
                } else if ("yes".equals(strExtractMetadata7)) {
                    strExtractMetadata = mediaMetadataRetriever.extractMetadata(18);
                    strExtractMetadata3 = mediaMetadataRetriever.extractMetadata(19);
                    strExtractMetadata2 = mediaMetadataRetriever.extractMetadata(24);
                } else {
                    strExtractMetadata = null;
                    strExtractMetadata2 = null;
                    strExtractMetadata3 = null;
                }
                HashMap[] mapArr = this.f6226f;
                if (strExtractMetadata != null) {
                    mapArr[0].put("ImageWidth", d.f(Integer.parseInt(strExtractMetadata), this.f6228h));
                }
                if (strExtractMetadata3 != null) {
                    mapArr[0].put("ImageLength", d.f(Integer.parseInt(strExtractMetadata3), this.f6228h));
                }
                if (strExtractMetadata2 != null) {
                    int i6 = Integer.parseInt(strExtractMetadata2);
                    mapArr[0].put("Orientation", d.f(i6 != 90 ? i6 != 180 ? i6 != 270 ? 1 : 8 : 3 : 6, this.f6228h));
                }
                if (strExtractMetadata4 != null && strExtractMetadata5 != null) {
                    int i7 = Integer.parseInt(strExtractMetadata4);
                    int i8 = Integer.parseInt(strExtractMetadata5);
                    if (i8 <= 6) {
                        throw new IOException("Invalid exif length");
                    }
                    gVar.e(i7);
                    byte[] bArr = new byte[6];
                    gVar.readFully(bArr);
                    int i9 = i7 + 6;
                    int i10 = i8 - 6;
                    if (!Arrays.equals(bArr, f6211c0)) {
                        throw new IOException("Invalid identifier");
                    }
                    byte[] bArr2 = new byte[i10];
                    gVar.readFully(bArr2);
                    this.p = i9;
                    v(0, bArr2);
                }
                String strExtractMetadata8 = mediaMetadataRetriever.extractMetadata(41);
                String strExtractMetadata9 = mediaMetadataRetriever.extractMetadata(42);
                if (strExtractMetadata8 != null && strExtractMetadata9 != null) {
                    int i11 = Integer.parseInt(strExtractMetadata8);
                    int i12 = Integer.parseInt(strExtractMetadata9);
                    long j5 = i11;
                    gVar.e(j5);
                    byte[] bArr3 = new byte[i12];
                    gVar.readFully(bArr3);
                    this.f6237t = new d(j5, bArr3, 1, i12);
                    this.f6238u = true;
                }
                if (f6216v) {
                    Log.d("ExifInterface", "Heif meta: " + strExtractMetadata + "x" + strExtractMetadata3 + ", rotation " + strExtractMetadata2);
                }
                try {
                    mediaMetadataRetriever.release();
                } catch (IOException unused) {
                }
            } catch (RuntimeException e2) {
                throw new UnsupportedOperationException("Failed to read EXIF from HEIF file. Given stream is either malformed or unsupported.", e2);
            }
        } catch (Throwable th) {
            try {
                mediaMetadataRetriever.release();
            } catch (IOException unused2) {
            }
            throw th;
        }
    }

    /*  JADX ERROR: UnsupportedOperationException in pass: RegionMakerVisitor
        java.lang.UnsupportedOperationException
        	at java.base/java.util.Collections$UnmodifiableCollection.add(Collections.java:1091)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker$1.leaveRegion(SwitchRegionMaker.java:390)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:70)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverse(DepthRegionTraversal.java:23)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.insertBreaksForCase(SwitchRegionMaker.java:370)
        	at jadx.core.dex.visitors.regions.maker.SwitchRegionMaker.insertBreaks(SwitchRegionMaker.java:85)
        	at jadx.core.dex.visitors.regions.PostProcessRegions.leaveRegion(PostProcessRegions.java:33)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:70)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at java.base/java.util.Collections$UnmodifiableCollection.forEach(Collections.java:1116)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.lambda$traverseInternal$0(DepthRegionTraversal.java:68)
        	at java.base/java.util.ArrayList.forEach(ArrayList.java:1596)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverseInternal(DepthRegionTraversal.java:68)
        	at jadx.core.dex.visitors.regions.DepthRegionTraversal.traverse(DepthRegionTraversal.java:19)
        	at jadx.core.dex.visitors.regions.PostProcessRegions.process(PostProcessRegions.java:23)
        	at jadx.core.dex.visitors.regions.RegionMakerVisitor.visit(RegionMakerVisitor.java:31)
        */
    public final void e(e0.C0555b r22, int r23, int r24) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 484
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.e(e0.b, int, int):void");
    }

    /* JADX WARN: Removed duplicated region for block: B:168:0x00f1 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Removed duplicated region for block: B:16:0x004a  */
    /* JADX WARN: Removed duplicated region for block: B:74:0x00f0 A[RETURN] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final int f(java.io.BufferedInputStream r18) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 445
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.f(java.io.BufferedInputStream):int");
    }

    public final void g(g gVar) throws Throwable {
        int i;
        int i5;
        j(gVar);
        HashMap[] mapArr = this.f6226f;
        d dVar = (d) mapArr[1].get("MakerNote");
        if (dVar != null) {
            g gVar2 = new g(dVar.f6180d);
            gVar2.f6172m = this.f6228h;
            byte[] bArr = f6191E;
            byte[] bArr2 = new byte[bArr.length];
            gVar2.readFully(bArr2);
            gVar2.e(0L);
            byte[] bArr3 = f6192F;
            byte[] bArr4 = new byte[bArr3.length];
            gVar2.readFully(bArr4);
            if (Arrays.equals(bArr2, bArr)) {
                gVar2.e(8L);
            } else if (Arrays.equals(bArr4, bArr3)) {
                gVar2.e(12L);
            }
            w(gVar2, 6);
            d dVar2 = (d) mapArr[7].get("PreviewImageStart");
            d dVar3 = (d) mapArr[7].get("PreviewImageLength");
            if (dVar2 != null && dVar3 != null) {
                mapArr[5].put("JPEGInterchangeFormat", dVar2);
                mapArr[5].put("JPEGInterchangeFormatLength", dVar3);
            }
            d dVar4 = (d) mapArr[8].get("AspectFrame");
            if (dVar4 != null) {
                int[] iArr = (int[]) dVar4.k(this.f6228h);
                if (iArr == null || iArr.length != 4) {
                    Log.w("ExifInterface", "Invalid aspect frame values. frame=" + Arrays.toString(iArr));
                    return;
                }
                int i6 = iArr[2];
                int i7 = iArr[0];
                if (i6 <= i7 || (i = iArr[3]) <= (i5 = iArr[1])) {
                    return;
                }
                int i8 = (i6 - i7) + 1;
                int i9 = (i - i5) + 1;
                if (i8 < i9) {
                    int i10 = i8 + i9;
                    i9 = i10 - i9;
                    i8 = i10 - i9;
                }
                d dVarF = d.f(i8, this.f6228h);
                d dVarF2 = d.f(i9, this.f6228h);
                mapArr[0].put("ImageWidth", dVarF);
                mapArr[0].put("ImageLength", dVarF2);
            }
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:19:0x0057, code lost:
    
        r18.f6238u = r5;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0059, code lost:
    
        return;
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void h(e0.C0555b r19) throws java.lang.Throwable {
        /*
            Method dump skipped, instruction units count: 255
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.h(e0.b):void");
    }

    public final void i(C0555b c0555b) throws Throwable {
        boolean z5 = f6216v;
        if (z5) {
            Log.d("ExifInterface", "getRafAttributes starting with: " + c0555b);
        }
        c0555b.a(84);
        byte[] bArr = new byte[4];
        byte[] bArr2 = new byte[4];
        byte[] bArr3 = new byte[4];
        c0555b.readFully(bArr);
        c0555b.readFully(bArr2);
        c0555b.readFully(bArr3);
        int i = ByteBuffer.wrap(bArr).getInt();
        int i5 = ByteBuffer.wrap(bArr2).getInt();
        int i6 = ByteBuffer.wrap(bArr3).getInt();
        byte[] bArr4 = new byte[i5];
        c0555b.a(i - c0555b.f6171l);
        c0555b.readFully(bArr4);
        e(new C0555b(bArr4), i, 5);
        c0555b.a(i6 - c0555b.f6171l);
        c0555b.f6172m = ByteOrder.BIG_ENDIAN;
        int i7 = c0555b.readInt();
        if (z5) {
            Log.d("ExifInterface", "numberOfDirectoryEntry: " + i7);
        }
        for (int i8 = 0; i8 < i7; i8++) {
            int unsignedShort = c0555b.readUnsignedShort();
            int unsignedShort2 = c0555b.readUnsignedShort();
            if (unsignedShort == f6204U.f6181a) {
                short s5 = c0555b.readShort();
                short s6 = c0555b.readShort();
                d dVarF = d.f(s5, this.f6228h);
                d dVarF2 = d.f(s6, this.f6228h);
                HashMap[] mapArr = this.f6226f;
                mapArr[0].put("ImageLength", dVarF);
                mapArr[0].put("ImageWidth", dVarF2);
                if (z5) {
                    Log.d("ExifInterface", "Updated to length: " + ((int) s5) + ", width: " + ((int) s6));
                    return;
                }
                return;
            }
            c0555b.a(unsignedShort2);
        }
    }

    public final void j(g gVar) throws Throwable {
        s(gVar);
        w(gVar, 0);
        E(gVar, 0);
        E(gVar, 5);
        E(gVar, 4);
        F();
        if (this.f6224d == 8) {
            HashMap[] mapArr = this.f6226f;
            d dVar = (d) mapArr[1].get("MakerNote");
            if (dVar != null) {
                g gVar2 = new g(dVar.f6180d);
                gVar2.f6172m = this.f6228h;
                gVar2.a(6);
                w(gVar2, 9);
                d dVar2 = (d) mapArr[9].get("ColorSpace");
                if (dVar2 != null) {
                    mapArr[1].put("ColorSpace", dVar2);
                }
            }
        }
    }

    public final void k(g gVar) throws Throwable {
        if (f6216v) {
            Log.d("ExifInterface", "getRw2Attributes starting with: " + gVar);
        }
        j(gVar);
        HashMap[] mapArr = this.f6226f;
        d dVar = (d) mapArr[0].get("JpgFromRaw");
        if (dVar != null) {
            e(new C0555b(dVar.f6180d), (int) dVar.f6179c, 5);
        }
        d dVar2 = (d) mapArr[0].get("ISO");
        d dVar3 = (d) mapArr[1].get("PhotographicSensitivity");
        if (dVar2 == null || dVar3 != null) {
            return;
        }
        mapArr[1].put("PhotographicSensitivity", dVar2);
    }

    public final boolean l(g gVar) throws IOException {
        byte[] bArr = f6211c0;
        byte[] bArr2 = new byte[bArr.length];
        gVar.readFully(bArr2);
        if (!Arrays.equals(bArr2, bArr)) {
            Log.w("ExifInterface", "Given data is not EXIF-only.");
            return false;
        }
        byte[] bArrCopyOf = new byte[1024];
        int i = 0;
        while (true) {
            if (i == bArrCopyOf.length) {
                bArrCopyOf = Arrays.copyOf(bArrCopyOf, bArrCopyOf.length * 2);
            }
            int i5 = gVar.f6170k.read(bArrCopyOf, i, bArrCopyOf.length - i);
            if (i5 == -1) {
                byte[] bArrCopyOf2 = Arrays.copyOf(bArrCopyOf, i);
                this.p = bArr.length;
                v(0, bArrCopyOf2);
                return true;
            }
            i += i5;
            gVar.f6171l += i5;
        }
    }

    /* JADX WARN: Multi-variable type inference failed */
    /* JADX WARN: Removed duplicated region for block: B:72:0x0078 A[EXC_TOP_SPLITTER, SYNTHETIC] */
    /* JADX WARN: Type inference failed for: r3v1, types: [byte[]] */
    /* JADX WARN: Type inference failed for: r3v13 */
    /* JADX WARN: Type inference failed for: r3v14 */
    /* JADX WARN: Type inference failed for: r3v16 */
    /* JADX WARN: Type inference failed for: r3v17 */
    /* JADX WARN: Type inference failed for: r3v18 */
    /* JADX WARN: Type inference failed for: r3v2 */
    /* JADX WARN: Type inference failed for: r3v3 */
    /* JADX WARN: Type inference failed for: r3v5 */
    /* JADX WARN: Type inference failed for: r3v6, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r3v7, types: [android.content.res.AssetManager$AssetInputStream, java.io.Closeable, java.io.InputStream] */
    /* JADX WARN: Type inference failed for: r3v8, types: [java.io.Closeable, java.io.InputStream] */
    /* JADX WARN: Type inference failed for: r3v9 */
    /* JADX WARN: Type inference failed for: r4v0 */
    /* JADX WARN: Type inference failed for: r4v1 */
    /* JADX WARN: Type inference failed for: r4v2, types: [java.io.Closeable] */
    /* JADX WARN: Type inference failed for: r4v3 */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final byte[] m() throws java.lang.Throwable {
        /*
            r10 = this;
            java.lang.String r0 = "Error closing fd."
            java.lang.String r1 = "ExifInterfaceUtils"
            java.lang.String r2 = "ExifInterface"
            boolean r3 = r10.i
            r4 = 0
            if (r3 != 0) goto Ld
            goto L9e
        Ld:
            byte[] r3 = r10.f6233n
            if (r3 == 0) goto L12
            return r3
        L12:
            android.content.res.AssetManager$AssetInputStream r3 = r10.f6223c     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            if (r3 == 0) goto L34
            boolean r5 = r3.markSupported()     // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L26
            if (r5 == 0) goto L2b
            r3.reset()     // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L26
        L1f:
            r5 = r4
            goto L5d
        L21:
            r2 = move-exception
            r5 = r4
        L23:
            r4 = r3
            goto L9f
        L26:
            r5 = move-exception
            r6 = r5
            r5 = r4
            goto L8c
        L2b:
            java.lang.String r5 = "Cannot read thumbnail from inputstream without mark/reset support"
            android.util.Log.d(r2, r5)     // Catch: java.lang.Throwable -> L21 java.lang.Exception -> L26
            b5.a.f(r3)
            return r4
        L34:
            java.lang.String r3 = r10.f6221a     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            if (r3 == 0) goto L48
            java.io.FileInputStream r3 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            java.lang.String r5 = r10.f6221a     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            r3.<init>(r5)     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            goto L1f
        L40:
            r2 = move-exception
            r5 = r4
            goto L9f
        L43:
            r5 = move-exception
            r3 = r4
            r6 = r5
            r5 = r3
            goto L8c
        L48:
            java.io.FileDescriptor r3 = r10.f6222b     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            java.io.FileDescriptor r3 = android.system.Os.dup(r3)     // Catch: java.lang.Throwable -> L40 java.lang.Exception -> L43
            int r5 = android.system.OsConstants.SEEK_SET     // Catch: java.lang.Throwable -> L85 java.lang.Exception -> L88
            r6 = 0
            android.system.Os.lseek(r3, r6, r5)     // Catch: java.lang.Throwable -> L85 java.lang.Exception -> L88
            java.io.FileInputStream r5 = new java.io.FileInputStream     // Catch: java.lang.Throwable -> L85 java.lang.Exception -> L88
            r5.<init>(r3)     // Catch: java.lang.Throwable -> L85 java.lang.Exception -> L88
            r9 = r5
            r5 = r3
            r3 = r9
        L5d:
            e0.b r6 = new e0.b     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            r6.<init>(r3)     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            int r7 = r10.f6231l     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            int r8 = r10.p     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            int r7 = r7 + r8
            r6.a(r7)     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            int r7 = r10.f6232m     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            byte[] r7 = new byte[r7]     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            r6.readFully(r7)     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            r10.f6233n = r7     // Catch: java.lang.Throwable -> L81 java.lang.Exception -> L83
            b5.a.f(r3)
            if (r5 == 0) goto L80
            android.system.Os.close(r5)     // Catch: android.system.ErrnoException -> L7c
            return r7
        L7c:
            r2 = move-exception
            android.util.Log.e(r1, r0, r2)
        L80:
            return r7
        L81:
            r2 = move-exception
            goto L23
        L83:
            r6 = move-exception
            goto L8c
        L85:
            r2 = move-exception
            r5 = r3
            goto L9f
        L88:
            r5 = move-exception
            r6 = r5
            r5 = r3
            r3 = r4
        L8c:
            java.lang.String r7 = "Encountered exception while getting thumbnail"
            android.util.Log.d(r2, r7, r6)     // Catch: java.lang.Throwable -> L81
            b5.a.f(r3)
            if (r5 == 0) goto L9e
            android.system.Os.close(r5)     // Catch: android.system.ErrnoException -> L9a
            goto L9e
        L9a:
            r2 = move-exception
            android.util.Log.e(r1, r0, r2)
        L9e:
            return r4
        L9f:
            b5.a.f(r4)
            if (r5 == 0) goto Lac
            android.system.Os.close(r5)     // Catch: android.system.ErrnoException -> La8
            goto Lac
        La8:
            r3 = move-exception
            android.util.Log.e(r1, r0, r3)
        Lac:
            throw r2
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.m():byte[]");
    }

    public final void n(C0555b c0555b) throws Throwable {
        if (f6216v) {
            Log.d("ExifInterface", "getWebpAttributes starting with: " + c0555b);
        }
        c0555b.f6172m = ByteOrder.LITTLE_ENDIAN;
        c0555b.a(I.length);
        int i = c0555b.readInt() + 8;
        byte[] bArr = J;
        c0555b.a(bArr.length);
        int length = bArr.length + 8;
        while (true) {
            try {
                byte[] bArr2 = new byte[4];
                c0555b.readFully(bArr2);
                int i5 = c0555b.readInt();
                int i6 = length + 8;
                if (Arrays.equals(K, bArr2)) {
                    byte[] bArrCopyOfRange = new byte[i5];
                    c0555b.readFully(bArrCopyOfRange);
                    byte[] bArr3 = f6211c0;
                    if (b5.a.G(bArrCopyOfRange, bArr3)) {
                        bArrCopyOfRange = Arrays.copyOfRange(bArrCopyOfRange, bArr3.length, i5);
                    }
                    this.p = i6;
                    v(0, bArrCopyOfRange);
                    C(new C0555b(bArrCopyOfRange));
                    return;
                }
                if (i5 % 2 == 1) {
                    i5++;
                }
                length = i6 + i5;
                if (length == i) {
                    return;
                }
                if (length > i) {
                    throw new IOException("Encountered WebP file with invalid chunk size");
                }
                c0555b.a(i5);
            } catch (EOFException e2) {
                throw new IOException("Encountered corrupt WebP file.", e2);
            }
        }
    }

    public final void p(C0555b c0555b, HashMap map) throws Throwable {
        d dVar = (d) map.get("JPEGInterchangeFormat");
        d dVar2 = (d) map.get("JPEGInterchangeFormatLength");
        if (dVar == null || dVar2 == null) {
            return;
        }
        int i = dVar.i(this.f6228h);
        int i5 = dVar2.i(this.f6228h);
        if (this.f6224d == 7) {
            i += this.q;
        }
        if (i > 0 && i5 > 0) {
            this.i = true;
            if (this.f6221a == null && this.f6223c == null && this.f6222b == null) {
                byte[] bArr = new byte[i5];
                c0555b.a(i);
                c0555b.readFully(bArr);
                this.f6233n = bArr;
            }
            this.f6231l = i;
            this.f6232m = i5;
        }
        if (f6216v) {
            Log.d("ExifInterface", "Setting thumbnail attributes with offset: " + i + ", length: " + i5);
        }
    }

    public final boolean q(HashMap map) {
        d dVar = (d) map.get("ImageLength");
        d dVar2 = (d) map.get("ImageWidth");
        if (dVar == null || dVar2 == null) {
            return false;
        }
        return dVar.i(this.f6228h) <= 512 && dVar2.i(this.f6228h) <= 512;
    }

    public final void r(InputStream inputStream) {
        boolean z5 = f6216v;
        for (int i = 0; i < f6205V.length; i++) {
            try {
                try {
                    this.f6226f[i] = new HashMap();
                } finally {
                    a();
                    if (z5) {
                        t();
                    }
                }
            } catch (IOException | UnsupportedOperationException e2) {
                if (z5) {
                    Log.w("ExifInterface", "Invalid image: ExifInterface got an unsupported image format file (ExifInterface supports JPEG and some RAW image formats only) or a corrupted JPEG file to ExifInterface.", e2);
                }
                a();
                if (z5) {
                    t();
                    return;
                }
                return;
            }
        }
        boolean z6 = this.f6225e;
        if (!z6) {
            BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream, 5000);
            this.f6224d = f(bufferedInputStream);
            inputStream = bufferedInputStream;
        }
        int i5 = this.f6224d;
        if (i5 == 4 || i5 == 9 || i5 == 13 || i5 == 14) {
            C0555b c0555b = new C0555b(inputStream);
            int i6 = this.f6224d;
            if (i6 == 4) {
                e(c0555b, 0, 0);
            } else if (i6 == 13) {
                h(c0555b);
            } else if (i6 == 9) {
                i(c0555b);
            } else if (i6 == 14) {
                n(c0555b);
            }
        } else {
            g gVar = new g(inputStream);
            if (!z6) {
                int i7 = this.f6224d;
                if (i7 == 12 || i7 == 15) {
                    d(gVar, i7);
                } else if (i7 == 7) {
                    g(gVar);
                } else if (i7 == 10) {
                    k(gVar);
                } else {
                    j(gVar);
                }
            } else if (!l(gVar)) {
                if (z5) {
                    return;
                } else {
                    return;
                }
            }
            gVar.e(this.p);
            C(gVar);
        }
        a();
        if (z5) {
            t();
        }
    }

    public final void s(g gVar) throws IOException {
        ByteOrder byteOrderU = u(gVar);
        this.f6228h = byteOrderU;
        gVar.f6172m = byteOrderU;
        int unsignedShort = gVar.readUnsignedShort();
        int i = this.f6224d;
        if (i != 7 && i != 10 && unsignedShort != 42) {
            throw new IOException("Invalid start code: " + Integer.toHexString(unsignedShort));
        }
        int i5 = gVar.readInt();
        if (i5 < 8) {
            throw new IOException(AbstractC0928a.i(i5, "Invalid first Ifd offset: "));
        }
        int i6 = i5 - 8;
        if (i6 > 0) {
            gVar.a(i6);
        }
    }

    public final void t() {
        int i = 0;
        while (true) {
            HashMap[] mapArr = this.f6226f;
            if (i >= mapArr.length) {
                return;
            }
            StringBuilder sbM = AbstractC0928a.m(i, "The size of tag group[", "]: ");
            sbM.append(mapArr[i].size());
            Log.d("ExifInterface", sbM.toString());
            for (Map.Entry entry : mapArr[i].entrySet()) {
                d dVar = (d) entry.getValue();
                Log.d("ExifInterface", "tagName: " + ((String) entry.getKey()) + ", tagType: " + dVar.toString() + ", tagValue: '" + dVar.j(this.f6228h) + "'");
            }
            i++;
        }
    }

    public final void v(int i, byte[] bArr) throws IOException {
        g gVar = new g(bArr);
        s(gVar);
        w(gVar, i);
    }

    /* JADX WARN: Removed duplicated region for block: B:112:0x022f  */
    /* JADX WARN: Removed duplicated region for block: B:119:0x0253  */
    /* JADX WARN: Removed duplicated region for block: B:126:0x028f  */
    /* JADX WARN: Removed duplicated region for block: B:71:0x0148  */
    /* JADX WARN: Removed duplicated region for block: B:72:0x014d  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
        To view partially-correct code enable 'Show inconsistent code' option in preferences
    */
    public final void w(e0.g r27, int r28) throws java.io.IOException {
        /*
            Method dump skipped, instruction units count: 935
            To view this dump change 'Code comments level' option to 'DEBUG'
        */
        throw new UnsupportedOperationException("Method not decompiled: e0.h.w(e0.g, int):void");
    }

    public final void x(String str) {
        for (int i = 0; i < f6205V.length; i++) {
            this.f6226f[i].remove(str);
        }
    }

    public final void y(int i, String str, String str2) {
        HashMap[] mapArr = this.f6226f;
        if (mapArr[i].isEmpty() || mapArr[i].get(str) == null) {
            return;
        }
        HashMap map = mapArr[i];
        map.put(str2, (d) map.get(str));
        mapArr[i].remove(str);
    }

    public final void z(BufferedInputStream bufferedInputStream, BufferedOutputStream bufferedOutputStream) throws IOException {
        byte b2;
        if (f6216v) {
            Log.d("ExifInterface", "saveJpegAttributes starting with (inputStream: " + bufferedInputStream + ", outputStream: " + bufferedOutputStream + ")");
        }
        C0555b c0555b = new C0555b(bufferedInputStream);
        c cVar = new c(bufferedOutputStream, ByteOrder.BIG_ENDIAN);
        if (c0555b.readByte() != -1) {
            throw new IOException("Invalid marker");
        }
        cVar.a(-1);
        if (c0555b.readByte() != -40) {
            throw new IOException("Invalid marker");
        }
        cVar.a(-40);
        cVar.a(-1);
        cVar.a(-31);
        this.p = G(cVar);
        d dVar = this.f6237t;
        byte[] bArr = f6212d0;
        if (dVar != null) {
            cVar.write(-1);
            cVar.a(-31);
            cVar.k(bArr.length + 2 + this.f6237t.f6180d.length);
            cVar.write(bArr);
            cVar.write(this.f6237t.f6180d);
            this.f6238u = true;
        }
        byte[] bArr2 = new byte[4096];
        while (c0555b.readByte() == -1) {
            do {
                b2 = c0555b.readByte();
            } while (b2 == -1);
            if (b2 == -39 || b2 == -38) {
                cVar.a(-1);
                cVar.a(b2);
                b5.a.i(c0555b, cVar);
                return;
            }
            if (b2 != -31) {
                cVar.a(-1);
                cVar.a(b2);
                int unsignedShort = c0555b.readUnsignedShort();
                cVar.k(unsignedShort);
                int i = unsignedShort - 2;
                if (i < 0) {
                    throw new IOException("Invalid length");
                }
                while (i > 0) {
                    int i5 = c0555b.read(bArr2, 0, Math.min(i, 4096));
                    if (i5 >= 0) {
                        cVar.write(bArr2, 0, i5);
                        i -= i5;
                    }
                }
            } else {
                int unsignedShort2 = c0555b.readUnsignedShort();
                int length = unsignedShort2 - 2;
                if (length < 0) {
                    throw new IOException("Invalid length");
                }
                int length2 = bArr.length;
                byte[] bArr3 = f6211c0;
                byte[] bArr4 = length >= length2 ? new byte[bArr.length] : length >= bArr3.length ? new byte[bArr3.length] : null;
                if (bArr4 != null) {
                    c0555b.readFully(bArr4);
                    if (b5.a.G(bArr4, bArr3) || b5.a.G(bArr4, bArr)) {
                        c0555b.a(length - bArr4.length);
                    }
                }
                cVar.a(-1);
                cVar.a(b2);
                cVar.k(unsignedShort2);
                if (bArr4 != null) {
                    length -= bArr4.length;
                    cVar.write(bArr4);
                }
                while (length > 0) {
                    int i6 = c0555b.read(bArr2, 0, Math.min(length, 4096));
                    if (i6 >= 0) {
                        cVar.write(bArr2, 0, i6);
                        length -= i6;
                    }
                }
            }
        }
        throw new IOException("Invalid marker");
    }

    public h(ByteArrayInputStream byteArrayInputStream) {
        e[][] eVarArr = f6205V;
        this.f6226f = new HashMap[eVarArr.length];
        this.f6227g = new HashSet(eVarArr.length);
        this.f6228h = ByteOrder.BIG_ENDIAN;
        this.f6221a = null;
        this.f6225e = false;
        this.f6223c = null;
        this.f6222b = null;
        r(byteArrayInputStream);
    }
}
