package p461;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.RandomAccess;
import kotlin.TypeCastException;
import kotlin.jvm.internal.DefaultConstructorMarker;
import p138.p176.p177.p242.p246.p251.C4303;
import p402.InterfaceC6540;
import p402.p403.AbstractC6553;
import p402.p411.p413.C6635;

/* JADX INFO: renamed from: ޑ.ތ, reason: contains not printable characters */
/* JADX INFO: loaded from: classes.dex */
@InterfaceC6540
public final class C7116 extends AbstractC6553<C7108> implements RandomAccess {

    /* JADX INFO: renamed from: ކ, reason: contains not printable characters */
    public static final C7117 f20652 = new C7117(null);

    /* JADX INFO: renamed from: ބ, reason: contains not printable characters */
    public final C7108[] f20653;

    /* JADX INFO: renamed from: ޅ, reason: contains not printable characters */
    public final int[] f20654;

    /* JADX INFO: renamed from: ޑ.ތ$֏, reason: contains not printable characters */
    public static final class C7117 {
        public C7117() {
        }

        public /* synthetic */ C7117(DefaultConstructorMarker defaultConstructorMarker) {
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final long m10468(C7103 c7103) {
            return c7103.f20630 / ((long) 4);
        }

        /* JADX WARN: Code restructure failed: missing block: B:80:0x0118, code lost:
        
            continue;
         */
        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        /*
            Code decompiled incorrectly, please refer to instructions dump.
        */
        public final C7116 m10469(C7108... c7108Arr) {
            int i;
            DefaultConstructorMarker defaultConstructorMarker = null;
            if (c7108Arr == null) {
                C6635.m9824("byteStrings");
                throw null;
            }
            int i2 = 0;
            int i3 = 1;
            if (c7108Arr.length == 0) {
                return new C7116(new C7108[0], new int[]{0, -1}, defaultConstructorMarker);
            }
            List<? extends C7108> listM7197 = C4303.m7197((Object[]) c7108Arr);
            ArrayList arrayList = (ArrayList) listM7197;
            if (arrayList.size() > 1) {
                Collections.sort(listM7197);
            }
            ArrayList arrayList2 = new ArrayList(c7108Arr.length);
            for (C7108 c7108 : c7108Arr) {
                arrayList2.add(-1);
            }
            Object[] array = arrayList2.toArray(new Integer[0]);
            if (array == null) {
                throw new TypeCastException("null cannot be cast to non-null type kotlin.Array<T>");
            }
            Integer[] numArr = (Integer[]) array;
            List<Integer> listM7192 = C4303.m7192(Arrays.copyOf(numArr, numArr.length));
            int length = c7108Arr.length;
            int i4 = 0;
            int i5 = 0;
            while (i4 < length) {
                C7108 c71082 = c7108Arr[i4];
                int i6 = i5 + 1;
                int size = arrayList.size();
                C4303.m7085(arrayList.size(), 0, size);
                int i7 = size - 1;
                int i8 = 0;
                while (true) {
                    if (i8 > i7) {
                        i = -(i8 + 1);
                        break;
                    }
                    i = (i8 + i7) >>> i3;
                    int iM6984 = C4303.m6984((C7108) arrayList.get(i), c71082);
                    if (iM6984 < 0) {
                        i8 = i + 1;
                    } else if (iM6984 > 0) {
                        i7 = i - 1;
                    }
                    i3 = 1;
                }
                listM7192.set(i, Integer.valueOf(i5));
                i4++;
                i5 = i6;
                i3 = 1;
            }
            if (!(((C7108) arrayList.get(0)).mo10450() > 0)) {
                throw new IllegalArgumentException("the empty byte string is not a supported option".toString());
            }
            int i9 = 0;
            while (i9 < arrayList.size()) {
                C7108 c71083 = (C7108) arrayList.get(i9);
                int i10 = i9 + 1;
                int i11 = i10;
                while (i11 < arrayList.size()) {
                    C7108 c71084 = (C7108) arrayList.get(i11);
                    if (!c71084.m10448(c71083)) {
                        break;
                    }
                    if (!(c71084.mo10450() != c71083.mo10450())) {
                        throw new IllegalArgumentException(("duplicate option: " + c71084).toString());
                    }
                    if (listM7192.get(i11).intValue() > listM7192.get(i9).intValue()) {
                        arrayList.remove(i11);
                        listM7192.remove(i11);
                    } else {
                        i11++;
                    }
                }
                i9 = i10;
            }
            C7103 c7103 = new C7103();
            m10470(0L, c7103, 0, listM7197, 0, arrayList.size(), listM7192);
            int[] iArr = new int[(int) m10468(c7103)];
            while (!c7103.mo10436()) {
                iArr[i2] = c7103.readInt();
                i2++;
            }
            Object[] objArrCopyOf = Arrays.copyOf(c7108Arr, c7108Arr.length);
            C6635.m9823((Object) objArrCopyOf, "java.util.Arrays.copyOf(this, size)");
            return new C7116((C7108[]) objArrCopyOf, iArr, defaultConstructorMarker);
        }

        /* JADX INFO: renamed from: ֏, reason: contains not printable characters */
        public final void m10470(long j, C7103 c7103, int i, List<? extends C7108> list, int i2, int i3, List<Integer> list2) {
            int i4;
            int i5;
            int i6;
            int i7;
            C7103 c71032;
            int i8 = i;
            if (!(i2 < i3)) {
                throw new IllegalArgumentException("Failed requirement.".toString());
            }
            for (int i9 = i2; i9 < i3; i9++) {
                if (!(list.get(i9).mo10450() >= i8)) {
                    throw new IllegalArgumentException("Failed requirement.".toString());
                }
            }
            C7108 c7108 = list.get(i2);
            C7108 c71082 = list.get(i3 - 1);
            if (i8 == c7108.mo10450()) {
                int iIntValue = list2.get(i2).intValue();
                int i10 = i2 + 1;
                C7108 c71083 = list.get(i10);
                i4 = i10;
                i5 = iIntValue;
                c7108 = c71083;
            } else {
                i4 = i2;
                i5 = -1;
            }
            if (c7108.mo10443(i8) == c71082.mo10443(i8)) {
                int iMin = Math.min(c7108.mo10450(), c71082.mo10450());
                int i11 = 0;
                for (int i12 = i8; i12 < iMin && c7108.mo10443(i12) == c71082.mo10443(i12); i12++) {
                    i11++;
                }
                long jM10468 = m10468(c7103) + j + ((long) 2) + ((long) i11) + 1;
                c7103.writeInt(-i11);
                c7103.writeInt(i5);
                int i13 = i8 + i11;
                while (i8 < i13) {
                    c7103.writeInt(c7108.mo10443(i8) & 255);
                    i8++;
                }
                if (i4 + 1 == i3) {
                    if (!(i13 == list.get(i4).mo10450())) {
                        throw new IllegalStateException("Check failed.".toString());
                    }
                    c7103.writeInt(list2.get(i4).intValue());
                    return;
                } else {
                    C7103 c71033 = new C7103();
                    c7103.writeInt(((int) (m10468(c71033) + jM10468)) * (-1));
                    m10470(jM10468, c71033, i13, list, i4, i3, list2);
                    c7103.mo10410((InterfaceC7129) c71033);
                    return;
                }
            }
            int i14 = 1;
            for (int i15 = i4 + 1; i15 < i3; i15++) {
                if (list.get(i15 - 1).mo10443(i8) != list.get(i15).mo10443(i8)) {
                    i14++;
                }
            }
            long jM104682 = m10468(c7103) + j + ((long) 2) + ((long) (i14 * 2));
            c7103.writeInt(i14);
            c7103.writeInt(i5);
            for (int i16 = i4; i16 < i3; i16++) {
                byte bMo10443 = list.get(i16).mo10443(i8);
                if (i16 == i4 || bMo10443 != list.get(i16 - 1).mo10443(i8)) {
                    c7103.writeInt(bMo10443 & 255);
                }
            }
            C7103 c71034 = new C7103();
            while (i4 < i3) {
                byte bMo104432 = list.get(i4).mo10443(i8);
                int i17 = i4 + 1;
                int i18 = i17;
                while (true) {
                    if (i18 >= i3) {
                        i6 = i3;
                        break;
                    } else {
                        if (bMo104432 != list.get(i18).mo10443(i8)) {
                            i6 = i18;
                            break;
                        }
                        i18++;
                    }
                }
                if (i17 == i6 && i8 + 1 == list.get(i4).mo10450()) {
                    c7103.writeInt(list2.get(i4).intValue());
                    i7 = i6;
                    c71032 = c71034;
                } else {
                    c7103.writeInt(((int) (m10468(c71034) + jM104682)) * (-1));
                    i7 = i6;
                    c71032 = c71034;
                    m10470(jM104682, c71034, i8 + 1, list, i4, i6, list2);
                }
                c71034 = c71032;
                i4 = i7;
            }
            c7103.mo10410((InterfaceC7129) c71034);
        }
    }

    public /* synthetic */ C7116(C7108[] c7108Arr, int[] iArr, DefaultConstructorMarker defaultConstructorMarker) {
        this.f20653 = c7108Arr;
        this.f20654 = iArr;
    }

    @Override // p402.p403.AbstractC6551, java.util.Collection
    public final boolean contains(Object obj) {
        if (obj instanceof C7108) {
            return super.contains((C7108) obj);
        }
        return false;
    }

    @Override // p402.p403.AbstractC6553, java.util.List
    public Object get(int i) {
        return this.f20653[i];
    }

    @Override // p402.p403.AbstractC6553, java.util.List
    public final int indexOf(Object obj) {
        if (obj instanceof C7108) {
            return super.indexOf((C7108) obj);
        }
        return -1;
    }

    @Override // p402.p403.AbstractC6553, java.util.List
    public final int lastIndexOf(Object obj) {
        if (obj instanceof C7108) {
            return super.lastIndexOf((C7108) obj);
        }
        return -1;
    }

    @Override // p402.p403.AbstractC6551
    /* JADX INFO: renamed from: ހ */
    public int mo9770() {
        return this.f20653.length;
    }
}
