package g0; import d0.t.c; import d0.t.k; import d0.t.n; import d0.t.q; import d0.z.d.m; import java.util.ArrayList; import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.RandomAccess; import kotlin.TypeCastException; import kotlin.jvm.internal.DefaultConstructorMarker; import okio.ByteString; /* compiled from: Options.kt */ /* loaded from: classes3.dex */ public final class o extends c implements RandomAccess { public static final a k = new a(null); public final ByteString[] l; public final int[] m; /* compiled from: Options.kt */ /* loaded from: classes3.dex */ public static final class a { public a(DefaultConstructorMarker defaultConstructorMarker) { } public final void a(long j, e eVar, int i, List list, int i2, int i3, List list2) { int i4; int i5; int i6; int i7 = i; if (i2 < i3) { for (int i8 = i2; i8 < i3; i8++) { if (!(((ByteString) list.get(i8)).j() >= i7)) { throw new IllegalArgumentException("Failed requirement.".toString()); } } ByteString byteString = (ByteString) list.get(i2); ByteString byteString2 = (ByteString) list.get(i3 - 1); if (i7 == byteString.j()) { i5 = list2.get(i2).intValue(); int i9 = i2 + 1; byteString = (ByteString) list.get(i9); i4 = i9; } else { i4 = i2; i5 = -1; } if (byteString.m(i7) != byteString2.m(i7)) { int i10 = 1; for (int i11 = i4 + 1; i11 < i3; i11++) { if (((ByteString) list.get(i11 - 1)).m(i7) != ((ByteString) list.get(i11)).m(i7)) { i10++; } } long b2 = b(eVar) + j + 2 + (i10 * 2); eVar.W(i10); eVar.W(i5); for (int i12 = i4; i12 < i3; i12++) { byte m = ((ByteString) list.get(i12)).m(i7); if (i12 == i4 || m != ((ByteString) list.get(i12 - 1)).m(i7)) { eVar.W(m & 255); } } e eVar2 = new e(); while (i4 < i3) { byte m2 = ((ByteString) list.get(i4)).m(i7); int i13 = i4 + 1; int i14 = i13; while (true) { if (i14 >= i3) { i6 = i3; break; } else if (m2 != ((ByteString) list.get(i14)).m(i7)) { i6 = i14; break; } else { i14++; } } if (i13 == i6 && i7 + 1 == ((ByteString) list.get(i4)).j()) { eVar.W(list2.get(i4).intValue()); i4 = i6; eVar2 = eVar2; } else { eVar.W(((int) (b(eVar2) + b2)) * (-1)); i4 = i6; eVar2 = eVar2; a(b2, eVar2, i7 + 1, list, i4, i6, list2); } } eVar.P(eVar2); return; } int min = Math.min(byteString.j(), byteString2.j()); int i15 = 0; for (int i16 = i7; i16 < min && byteString.m(i16) == byteString2.m(i16); i16++) { i15++; } long b3 = b(eVar) + j + 2 + i15 + 1; eVar.W(-i15); eVar.W(i5); int i17 = i7 + i15; while (i7 < i17) { eVar.W(byteString.m(i7) & 255); i7++; } if (i4 + 1 == i3) { if (i17 == ((ByteString) list.get(i4)).j()) { eVar.W(list2.get(i4).intValue()); return; } throw new IllegalStateException("Check failed.".toString()); } e eVar3 = new e(); eVar.W(((int) (b(eVar3) + b3)) * (-1)); a(b3, eVar3, i17, list, i4, i3, list2); eVar.P(eVar3); return; } throw new IllegalArgumentException("Failed requirement.".toString()); } public final long b(e eVar) { return eVar.k / 4; } /* JADX WARN: Code restructure failed: missing block: B:58:0x00fa, code lost: continue; */ /* Code decompiled incorrectly, please refer to instructions dump. */ public final o c(ByteString... byteStringArr) { m.checkParameterIsNotNull(byteStringArr, "byteStrings"); int i = 0; if (byteStringArr.length == 0) { return new o(new ByteString[0], new int[]{0, -1}, null); } List mutableList = k.toMutableList(byteStringArr); q.sort(mutableList); ArrayList arrayList = new ArrayList(byteStringArr.length); for (ByteString byteString : byteStringArr) { arrayList.add(-1); } Object[] array = arrayList.toArray(new Integer[0]); if (array != null) { Integer[] numArr = (Integer[]) array; List mutableListOf = n.mutableListOf((Integer[]) Arrays.copyOf(numArr, numArr.length)); int i2 = 0; for (ByteString byteString2 : byteStringArr) { i2++; mutableListOf.set(n.binarySearch$default(mutableList, byteString2, 0, 0, 6, null), Integer.valueOf(i2)); } if (((ByteString) mutableList.get(0)).j() > 0) { int i3 = 0; while (i3 < mutableList.size()) { ByteString byteString3 = (ByteString) mutableList.get(i3); int i4 = i3 + 1; int i5 = i4; while (i5 < mutableList.size()) { ByteString byteString4 = (ByteString) mutableList.get(i5); Objects.requireNonNull(byteString4); m.checkParameterIsNotNull(byteString3, "prefix"); if (!byteString4.n(0, byteString3, 0, byteString3.j())) { break; } if (!(byteString4.j() != byteString3.j())) { throw new IllegalArgumentException(("duplicate option: " + byteString4).toString()); } else if (mutableListOf.get(i5).intValue() > mutableListOf.get(i3).intValue()) { mutableList.remove(i5); mutableListOf.remove(i5); } else { i5++; } } i3 = i4; } e eVar = new e(); a(0L, eVar, 0, mutableList, 0, mutableList.size(), mutableListOf); int[] iArr = new int[(int) b(eVar)]; while (!eVar.w()) { i++; iArr[i] = eVar.readInt(); } Object[] copyOf = Arrays.copyOf(byteStringArr, byteStringArr.length); m.checkExpressionValueIsNotNull(copyOf, "java.util.Arrays.copyOf(this, size)"); return new o((ByteString[]) copyOf, iArr, null); } throw new IllegalArgumentException("the empty byte string is not a supported option".toString()); } throw new TypeCastException("null cannot be cast to non-null type kotlin.Array"); } } public o(ByteString[] byteStringArr, int[] iArr, DefaultConstructorMarker defaultConstructorMarker) { this.l = byteStringArr; this.m = iArr; } @Override // d0.t.a, java.util.Collection, java.util.List public final /* bridge */ boolean contains(Object obj) { if (obj instanceof ByteString) { return super.contains((ByteString) obj); } return false; } @Override // d0.t.c, java.util.List public Object get(int i) { return this.l[i]; } @Override // d0.t.a public int getSize() { return this.l.length; } @Override // d0.t.c, java.util.List public final /* bridge */ int indexOf(Object obj) { if (obj instanceof ByteString) { return super.indexOf((ByteString) obj); } return -1; } @Override // d0.t.c, java.util.List public final /* bridge */ int lastIndexOf(Object obj) { if (obj instanceof ByteString) { return super.lastIndexOf((ByteString) obj); } return -1; } }