package wl;

import com.google.android.gms.maps.model.BitmapDescriptorFactory;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import yk.c;
import yk.s;

/* loaded from: classes3.dex */
public abstract class a {

    /* renamed from: a, reason: collision with root package name */
    private static final int[] f49534a = {0, 4, 1, 5};

    /* renamed from: b, reason: collision with root package name */
    private static final int[] f49535b = {6, 2, 7, 3};

    /* renamed from: c, reason: collision with root package name */
    private static final int[] f49536c = {8, 1, 1, 1, 1, 1, 1, 3};

    /* renamed from: d, reason: collision with root package name */
    private static final int[] f49537d = {7, 1, 1, 3, 1, 1, 1, 2, 1};

    private static void a(s[] sVarArr, s[] sVarArr2, int[] iArr) {
        for (int i10 = 0; i10 < iArr.length; i10++) {
            sVarArr[iArr[i10]] = sVarArr2[i10];
        }
    }

    /* JADX WARN: Code restructure failed: missing block: B:10:0x001d, code lost:
    
        if (r4 == 0) goto L31;
     */
    /* JADX WARN: Code restructure failed: missing block: B:11:0x001f, code lost:
    
        r3 = r0.iterator();
     */
    /* JADX WARN: Code restructure failed: missing block: B:13:0x0027, code lost:
    
        if (r3.hasNext() == false) goto L35;
     */
    /* JADX WARN: Code restructure failed: missing block: B:14:0x0029, code lost:
    
        r4 = (yk.s[]) r3.next();
        r7 = r4[1];
     */
    /* JADX WARN: Code restructure failed: missing block: B:15:0x0031, code lost:
    
        if (r7 == null) goto L17;
     */
    /* JADX WARN: Code restructure failed: missing block: B:16:0x0033, code lost:
    
        r2 = (int) java.lang.Math.max(r2, r7.d());
     */
    /* JADX WARN: Code restructure failed: missing block: B:17:0x003d, code lost:
    
        r4 = r4[3];
     */
    /* JADX WARN: Code restructure failed: missing block: B:18:0x003f, code lost:
    
        if (r4 == null) goto L38;
     */
    /* JADX WARN: Code restructure failed: missing block: B:20:0x0041, code lost:
    
        r2 = java.lang.Math.max(r2, (int) r4.d());
     */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private static List b(boolean z10, fl.b bVar) {
        int c10;
        float d10;
        ArrayList arrayList = new ArrayList();
        int i10 = 0;
        int i11 = 0;
        loop0: while (true) {
            int i12 = i11;
            while (true) {
                if (i10 >= bVar.j()) {
                    break loop0;
                }
                s[] f10 = f(bVar, i10, i11);
                if (f10[0] != null || f10[3] != null) {
                    arrayList.add(f10);
                    if (!z10) {
                        break loop0;
                    }
                    s sVar = f10[2];
                    if (sVar != null) {
                        c10 = (int) sVar.c();
                        d10 = f10[2].d();
                    } else {
                        c10 = (int) f10[4].c();
                        d10 = f10[4].d();
                    }
                    i10 = (int) d10;
                    i11 = c10;
                    i12 = 1;
                } else {
                    break;
                }
            }
            i10 += 5;
            i11 = 0;
        }
        return arrayList;
    }

    public static b c(c cVar, Map map, boolean z10) {
        fl.b a10 = cVar.a();
        List b10 = b(z10, a10);
        if (b10.isEmpty()) {
            a10 = a10.clone();
            a10.o();
            b10 = b(z10, a10);
        }
        return new b(a10, b10);
    }

    private static int[] d(fl.b bVar, int i10, int i11, int i12, int[] iArr, int[] iArr2) {
        Arrays.fill(iArr2, 0, iArr2.length, 0);
        int i13 = 0;
        while (bVar.f(i10, i11) && i10 > 0) {
            int i14 = i13 + 1;
            if (i13 >= 3) {
                break;
            }
            i10--;
            i13 = i14;
        }
        int length = iArr.length;
        int i15 = i10;
        int i16 = 0;
        boolean z10 = false;
        while (i10 < i12) {
            if (bVar.f(i10, i11) != z10) {
                iArr2[i16] = iArr2[i16] + 1;
            } else {
                if (i16 != length - 1) {
                    i16++;
                } else {
                    if (g(iArr2, iArr) < 0.42f) {
                        return new int[]{i15, i10};
                    }
                    i15 += iArr2[0] + iArr2[1];
                    int i17 = i16 - 1;
                    System.arraycopy(iArr2, 2, iArr2, 0, i17);
                    iArr2[i17] = 0;
                    iArr2[i16] = 0;
                    i16--;
                }
                iArr2[i16] = 1;
                z10 = !z10;
            }
            i10++;
        }
        if (i16 != length - 1 || g(iArr2, iArr) >= 0.42f) {
            return null;
        }
        return new int[]{i15, i10 - 1};
    }

    private static s[] e(fl.b bVar, int i10, int i11, int i12, int i13, int[] iArr) {
        boolean z10;
        int i14;
        s[] sVarArr = new s[4];
        int[] iArr2 = new int[iArr.length];
        int i15 = i12;
        while (true) {
            if (i15 >= i10) {
                z10 = false;
                break;
            }
            int[] d10 = d(bVar, i13, i15, i11, iArr, iArr2);
            if (d10 != null) {
                int i16 = i15;
                int[] iArr3 = d10;
                int i17 = i16;
                while (true) {
                    if (i17 <= 0) {
                        i14 = i17;
                        break;
                    }
                    int i18 = i17 - 1;
                    int[] d11 = d(bVar, i13, i18, i11, iArr, iArr2);
                    if (d11 == null) {
                        i14 = i18 + 1;
                        break;
                    }
                    iArr3 = d11;
                    i17 = i18;
                }
                float f10 = i14;
                sVarArr[0] = new s(iArr3[0], f10);
                sVarArr[1] = new s(iArr3[1], f10);
                z10 = true;
                i15 = i14;
            } else {
                i15 += 5;
            }
        }
        int i19 = i15 + 1;
        if (z10) {
            int[] iArr4 = {(int) sVarArr[0].c(), (int) sVarArr[1].c()};
            int i20 = i19;
            int i21 = 0;
            while (i20 < i10) {
                int[] d12 = d(bVar, iArr4[0], i20, i11, iArr, iArr2);
                if (d12 != null && Math.abs(iArr4[0] - d12[0]) < 5 && Math.abs(iArr4[1] - d12[1]) < 5) {
                    iArr4 = d12;
                    i21 = 0;
                } else {
                    if (i21 > 25) {
                        break;
                    }
                    i21++;
                }
                i20++;
            }
            i19 = i20 - (i21 + 1);
            float f11 = i19;
            sVarArr[2] = new s(iArr4[0], f11);
            sVarArr[3] = new s(iArr4[1], f11);
        }
        if (i19 - i15 < 10) {
            Arrays.fill(sVarArr, (Object) null);
        }
        return sVarArr;
    }

    private static s[] f(fl.b bVar, int i10, int i11) {
        int j10 = bVar.j();
        int n10 = bVar.n();
        s[] sVarArr = new s[8];
        a(sVarArr, e(bVar, j10, n10, i10, i11, f49536c), f49534a);
        s sVar = sVarArr[4];
        if (sVar != null) {
            i11 = (int) sVar.c();
            i10 = (int) sVarArr[4].d();
        }
        a(sVarArr, e(bVar, j10, n10, i10, i11, f49537d), f49535b);
        return sVarArr;
    }

    private static float g(int[] iArr, int[] iArr2) {
        int length = iArr.length;
        int i10 = 0;
        int i11 = 0;
        for (int i12 = 0; i12 < length; i12++) {
            i10 += iArr[i12];
            i11 += iArr2[i12];
        }
        if (i10 < i11) {
            return Float.POSITIVE_INFINITY;
        }
        float f10 = i10;
        float f11 = f10 / i11;
        float f12 = 0.8f * f11;
        float f13 = BitmapDescriptorFactory.HUE_RED;
        for (int i13 = 0; i13 < length; i13++) {
            float f14 = iArr2[i13] * f11;
            float f15 = iArr[i13];
            float f16 = f15 > f14 ? f15 - f14 : f14 - f15;
            if (f16 > f12) {
                return Float.POSITIVE_INFINITY;
            }
            f13 += f16;
        }
        return f13 / f10;
    }
}
