content: package kotlin.collections;
  
  import java.util.Collection;
  import java.util.Iterator;
  import java.util.NoSuchElementException;
  import kotlin.Metadata;
  import kotlin.jvm.functions.Function1;
  import kotlin.jvm.internal.DefaultConstructorMarker;
  import kotlin.jvm.internal.Intrinsics;
  import kotlin.ranges.RangesKt;
  
  @Metadata(d1 = {"\u0000L\n\u0002\u0018\u0002\n\u0000\n\u0002\u0018\u0002\n\u0000\n\u0002\u0010\b\n\u0002\b\u0003\n\u0002\u0010\u001e\n\u0002\b\u0002\n\u0002\u0010\u0011\n\u0002\u0010\u0000\n\u0002\b\u0007\n\u0002\u0010\u000b\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0002\b\u0011\n\u0002\u0018\u0002\n\u0002\b\u000b\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u001b\b\u0007\u0018\u0000 P*\u0004\b\u0000\u0010\u00012\b\u0012\u0004\u0012\u0002H\u00010\u0002:\u0001PB\u000f\b\u0016\u0012\u0006\u0010\u0003\u001a\u00020\u0004¢\u0006\u0002\u0010\u0005B\u0007\b\u0016¢\u0006\u0002\u0010\u0006B\u0015\b\u0016\u0012\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\b¢\u0006\u0002\u0010\tJ\u0015\u0010\u0013\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010\u0016J\u001d\u0010\u0013\u001a\u00020\u00172\u0006\u0010\u0018\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010\u0019J\u001e\u0010\u001a\u001a\u00020\u00142\u0006\u0010\u0018\u001a\u00020\u00042\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\bH\u0016J\u0016\u0010\u001a\u001a\u00020\u00142\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\bH\u0016J\u0013\u0010\u001b\u001a\u00020\u00172\u0006\u0010\u0015\u001a\u00028\u0000¢\u0006\u0002\u0010\u001cJ\u0013\u0010\u001d\u001a\u00020\u00172\u0006\u0010\u0015\u001a\u00028\u0000¢\u0006\u0002\u0010\u001cJ\b\u0010\u001e\u001a\u00020\u0017H\u0016J\u0016\u0010\u001f\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00028\u0000H\u0002¢\u0006\u0002\u0010\u0016J\u001e\u0010 \u001a\u00020\u00172\u0006\u0010!\u001a\u00020\u00042\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\bH\u0002J\u0010\u0010\"\u001a\u00020\u00172\u0006\u0010#\u001a\u00020\u0004H\u0002J\u0010\u0010$\u001a\u00020\u00042\u0006\u0010\u0018\u001a\u00020\u0004H\u0002J\u0010\u0010%\u001a\u00020\u00172\u0006\u0010&\u001a\u00020\u0004H\u0002J\u001d\u0010'\u001a\u00020\u00142\u0012\u0010(\u001a\u000e\u0012\u0004\u0012\u00028\u0000\u0012\u0004\u0012\u00020\u00140)H\bJ\u000b\u0010*\u001a\u00028\u0000¢\u0006\u0002\u0010+J\r\u0010,\u001a\u0004\u0018\u00018\u0000¢\u0006\u0002\u0010+J\u0016\u0010-\u001a\u00028\u00002\u0006\u0010\u0018\u001a\u00020\u0004H\u0002¢\u0006\u0002\u0010.J\u0010\u0010/\u001a\u00020\u00042\u0006\u0010\u0018\u001a\u00020\u0004H\u0002J\u0015\u00100\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00028\u0000H\u0016¢\u0006\u0002\u00101J\u0016\u00102\u001a\u00028\u00002\u0006\u0010!\u001a\u00020\u0004H\b¢\u0006\u0002\u0010.J\u0011\u0010!\u001a\u00020\u00042\u0006\u0010\u0018\u001a\u00020\u0004H\bJM\u00103\u001a\u00020\u00172>\u00104\u001a:\u0012\u0013\u0012\u00110\u0004¢\u0006\f\b6\u0012\b\b7\u0012\u0004\b\b(\u000e\u0012\u001b\u0012\u0019\u0012\u0006\u0012\u0004\u0018\u00010\f0\u000b¢\u0006\f\b6\u0012\b\b7\u0012\u0004\b\b(\u0007\u0012\u0004\u0012\u00020\u001705H\u0000¢\u0006\u0002\b8J\b\u00109\u001a\u00020\u0014H\u0016J\u000b\u0010:\u001a\u00028\u0000¢\u0006\u0002\u0010+J\u0015\u0010;\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00028\u0000H\u0016¢\u0006\u0002\u00101J\r\u0010<\u001a\u0004\u0018\u00018\u0000¢\u0006\u0002\u0010+J\u0010\u0010=\u001a\u00020\u00042\u0006\u0010\u0018\u001a\u00020\u0004H\u0002J\u0010\u0010>\u001a\u00020\u00042\u0006\u0010\u0018\u001a\u00020\u0004H\u0002J\u0015\u0010?\u001a\u00020\u00142\u0006\u0010\u0015\u001a\u00028\u0000H\u0016¢\u0006\u0002\u0010\u0016J\u0016\u0010@\u001a\u00020\u00142\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\bH\u0016J\u0015\u0010A\u001a\u00028\u00002\u0006\u0010\u0018\u001a\u00020\u0004H\u0016¢\u0006\u0002\u0010.J\u000b\u0010B\u001a\u00028\u0000¢\u0006\u0002\u0010+J\r\u0010C\u001a\u0004\u0018\u00018\u0000¢\u0006\u0002\u0010+J\u000b\u0010D\u001a\u00028\u0000¢\u0006\u0002\u0010+J\r\u0010E\u001a\u0004\u0018\u00018\u0000¢\u0006\u0002\u0010+J\u0016\u0010F\u001a\u00020\u00142\f\u0010\u0007\u001a\b\u0012\u0004\u0012\u00028\u00000\bH\u0016J\u001e\u0010G\u001a\u00028\u00002\u0006\u0010\u0018\u001a\u00020\u00042\u0006\u0010\u0015\u001a\u00028\u0000H\u0002¢\u0006\u0002\u0010HJ\u0017\u0010I\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\f0\u000bH\u0000¢\u0006\u0004\bJ\u0010KJ)\u0010I\u001a\b\u0012\u0004\u0012\u0002HL0\u000b\"\u0004\b\u0001\u0010L2\f\u0010M\u001a\b\u0012\u0004\u0012\u0002HL0\u000bH\u0000¢\u0006\u0004\bJ\u0010NJ\u0015\u0010O\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\f0\u000bH\u0016¢\u0006\u0002\u0010KJ'\u0010O\u001a\b\u0012\u0004\u0012\u0002HL0\u000b\"\u0004\b\u0001\u0010L2\f\u0010M\u001a\b\u0012\u0004\u0012\u0002HL0\u000bH\u0016¢\u0006\u0002\u0010NR\u0018\u0010\n\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\f0\u000bX\u000e¢\u0006\u0004\n\u0002\u0010\rR\u000e\u0010\u000e\u001a\u00020\u0004X\u000e¢\u0006\u0002\n\u0000R\u001e\u0010\u0010\u001a\u00020\u00042\u0006\u0010\u000f\u001a\u00020\u0004@RX\u000e¢\u0006\b\n\u0000\u001a\u0004\b\u0011\u0010\u0012¨\u0006Q"}, d2 = {"Lkotlin/collections/ArrayDeque;", "E", "Lkotlin/collections/AbstractMutableList;", "initialCapacity", "", "(I)V", "()V", "elements", "", "(Ljava/util/Collection;)V", "elementData", "", "", "[Ljava/lang/Object;", "head", "<set-?>", "size", "getSize", "()I", "add", "", "element", "(Ljava/lang/Object;)Z", "", "index", "(ILjava/lang/Object;)V", "addAll", "addFirst", "(Ljava/lang/Object;)V", "addLast", "clear", "contains", "copyCollectionElements", "internalIndex", "copyElements", "newCapacity", "decremented", "ensureCapacity", "minCapacity", "filterInPlace", "predicate", "Lkotlin/Function1;", "first", "()Ljava/lang/Object;", "firstOrNull", "get", "(I)Ljava/lang/Object;", "incremented", "indexOf", "(Ljava/lang/Object;)I", "internalGet", "internalStructure", "structure", "Lkotlin/Function2;", "Lkotlin/ParameterName;", "name", "internalStructure$kotlin_stdlib", "isEmpty", "last", "lastIndexOf", "lastOrNull", "negativeMod", "positiveMod", "remove", "removeAll", "removeAt", "removeFirst", "removeFirstOrNull", "removeLast", "removeLastOrNull", "retainAll", "set", "(ILjava/lang/Object;)Ljava/lang/Object;", "testToArray", "testToArray$kotlin_stdlib", "()[Ljava/lang/Object;", "T", "array", "([Ljava/lang/Object;)[Ljava/lang/Object;", "toArray", "Companion", "kotlin-stdlib"}, k = 1, mv = {1, 7, 1}, xi = 48)
  /* compiled from: ArrayDeque.kt */
  public final class ArrayDeque<E> extends AbstractMutableList<E> {
      public static final Companion Companion = new Companion((DefaultConstructorMarker) null);
      private static final int defaultMinCapacity = 10;
      private static final Object[] emptyElementData = new Object[0];
      private static final int maxArraySize = 2147483639;
      private Object[] elementData;
      private int head;
      private int size;
  
      @Metadata(d1 = {"\u0000\u001a\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\b\n\u0000\n\u0002\u0010\u0011\n\u0002\b\u0007\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002J\u001d\u0010\t\u001a\u00020\u00042\u0006\u0010\n\u001a\u00020\u00042\u0006\u0010\u000b\u001a\u00020\u0004H\u0000¢\u0006\u0002\b\fR\u000e\u0010\u0003\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000R\u0018\u0010\u0005\u001a\n\u0012\u0006\u0012\u0004\u0018\u00010\u00010\u0006X\u0004¢\u0006\u0004\n\u0002\u0010\u0007R\u000e\u0010\b\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000¨\u0006\r"}, d2 = {"Lkotlin/collections/ArrayDeque$Companion;", "", "()V", "defaultMinCapacity", "", "emptyElementData", "", "[Ljava/lang/Object;", "maxArraySize", "newCapacity", "oldCapacity", "minCapacity", "newCapacity$kotlin_stdlib", "kotlin-stdlib"}, k = 1, mv = {1, 7, 1}, xi = 48)
      /* compiled from: ArrayDeque.kt */
      public static final class Companion {
          private Companion() {
          }
  
          public /* synthetic */ Companion(DefaultConstructorMarker defaultConstructorMarker) {
              this();
          }
  
          public final int newCapacity$kotlin_stdlib(int oldCapacity, int minCapacity) {
              int i = (oldCapacity >> 1) + oldCapacity;
              if (i - minCapacity < 0) {
                  i = minCapacity;
              }
              int i2 = ArrayDeque.maxArraySize;
              if (i - ArrayDeque.maxArraySize <= 0) {
                  return i;
              }
              if (minCapacity > ArrayDeque.maxArraySize) {
                  i2 = Integer.MAX_VALUE;
              }
              return i2;
          }
      }
  
      public ArrayDeque() {
          this.elementData = emptyElementData;
      }
  
      public ArrayDeque(int initialCapacity) {
          Object[] objArr;
          if (initialCapacity == 0) {
              objArr = emptyElementData;
          } else if (initialCapacity > 0) {
              objArr = new Object[initialCapacity];
          } else {
              throw new IllegalArgumentException("Illegal Capacity: " + initialCapacity);
          }
          this.elementData = objArr;
      }
  
      public ArrayDeque(Collection<? extends E> elements) {
          Intrinsics.checkNotNullParameter(elements, "elements");
          boolean z = false;
          Object[] array = elements.toArray(new Object[0]);
          Intrinsics.checkNotNull(array, "null cannot be cast to non-null type kotlin.Array<T of kotlin.collections.ArraysKt__ArraysJVMKt.toTypedArray>");
          this.elementData = array;
          this.size = array.length;
          if (array.length == 0 ? true : z) {
              this.elementData = emptyElementData;
          }
      }
  
      private final void copyCollectionElements(int internalIndex, Collection<? extends E> elements) {
          Iterator<? extends E> it = elements.iterator();
          int length = this.elementData.length;
          for (int i = internalIndex; i < length && it.hasNext(); i++) {
              this.elementData[i] = it.next();
          }
          int i2 = this.head;
          for (int i3 = 0; i3 < i2 && it.hasNext(); i3++) {
              this.elementData[i3] = it.next();
          }
          this.size = size() + elements.size();
      }
  
      private final void copyElements(int newCapacity) {
          Object[] objArr = new Object[newCapacity];
          Object[] objArr2 = this.elementData;
          ArraysKt.copyInto((T[]) objArr2, (T[]) objArr, 0, this.head, objArr2.length);
          Object[] objArr3 = this.elementData;
          int length = objArr3.length;
          int i = this.head;
          ArraysKt.copyInto((T[]) objArr3, (T[]) objArr, length - i, 0, i);
          this.head = 0;
          this.elementData = objArr;
      }
  
      private final int decremented(int index) {
          return index == 0 ? ArraysKt.getLastIndex((T[]) this.elementData) : index - 1;
      }
  
      private final void ensureCapacity(int minCapacity) {
          if (minCapacity >= 0) {
              Object[] objArr = this.elementData;
              if (minCapacity > objArr.length) {
                  if (objArr == emptyElementData) {
                      this.elementData = new Object[RangesKt.coerceAtLeast(minCapacity, 10)];
                  } else {
                      copyElements(Companion.newCapacity$kotlin_stdlib(objArr.length, minCapacity));
                  }
              }
          } else {
              throw new IllegalStateException("Deque is too big.");
          }
      }
  
      private final boolean filterInPlace(Function1<? super E, Boolean> predicate) {
          if (!isEmpty()) {
              if (!(this.elementData.length == 0)) {
                  int positiveMod = positiveMod(this.head + size());
                  int i = this.head;
                  boolean z = false;
                  if (this.head < positiveMod) {
                      for (int i2 = this.head; i2 < positiveMod; i2++) {
                          Object obj = this.elementData[i2];
                          if (predicate.invoke(obj).booleanValue()) {
                              this.elementData[i] = obj;
                              i++;
                          } else {
                              z = true;
                          }
                      }
                      ArraysKt.fill((T[]) this.elementData, null, i, positiveMod);
                  } else {
                      int length = this.elementData.length;
                      for (int i3 = this.head; i3 < length; i3++) {
                          Object[] objArr = this.elementData;
                          Object obj2 = objArr[i3];
                          objArr[i3] = null;
                          if (predicate.invoke(obj2).booleanValue()) {
                              this.elementData[i] = obj2;
                              i++;
                          } else {
                              z = true;
                          }
                      }
                      i = positiveMod(i);
                      for (int i4 = 0; i4 < positiveMod; i4++) {
                          Object[] objArr2 = this.elementData;
                          Object obj3 = objArr2[i4];
                          objArr2[i4] = null;
                          if (predicate.invoke(obj3).booleanValue()) {
                              this.elementData[i] = obj3;
                              i = incremented(i);
                          } else {
                              z = true;
                          }
                      }
                  }
                  if (z) {
                      this.size = negativeMod(i - this.head);
                  }
                  return z;
              }
          }
          return false;
      }
  
      private final int incremented(int index) {
          if (index == ArraysKt.getLastIndex((T[]) this.elementData)) {
              return 0;
          }
          return index + 1;
      }
  
      private final E internalGet(int internalIndex) {
          return this.elementData[internalIndex];
      }
  
      private final int internalIndex(int index) {
          return positiveMod(this.head + index);
      }
  
      private final int negativeMod(int index) {
          return index < 0 ? this.elementData.length + index : index;
      }
  
      private final int positiveMod(int index) {
          Object[] objArr = this.elementData;
          return index >= objArr.length ? index - objArr.length : index;
      }
  
      public void add(int index, E element) {
          AbstractList.Companion.checkPositionIndex$kotlin_stdlib(index, size());
          if (index == size()) {
              addLast(element);
          } else if (index == 0) {
              addFirst(element);
          } else {
              ensureCapacity(size() + 1);
              int positiveMod = positiveMod(this.head + index);
              if (index < ((size() + 1) >> 1)) {
                  int decremented = decremented(positiveMod);
                  int decremented2 = decremented(this.head);
                  int i = this.head;
                  if (decremented >= i) {
                      Object[] objArr = this.elementData;
                      objArr[decremented2] = objArr[i];
                      ArraysKt.copyInto((T[]) objArr, (T[]) objArr, i, i + 1, decremented + 1);
                  } else {
                      Object[] objArr2 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr2, (T[]) objArr2, i - 1, i, objArr2.length);
                      Object[] objArr3 = this.elementData;
                      objArr3[objArr3.length - 1] = objArr3[0];
                      ArraysKt.copyInto((T[]) objArr3, (T[]) objArr3, 0, 1, decremented + 1);
                  }
                  this.elementData[decremented] = element;
                  this.head = decremented2;
              } else {
                  int positiveMod2 = positiveMod(this.head + size());
                  if (positiveMod < positiveMod2) {
                      Object[] objArr4 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr4, (T[]) objArr4, positiveMod + 1, positiveMod, positiveMod2);
                  } else {
                      Object[] objArr5 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr5, (T[]) objArr5, 1, 0, positiveMod2);
                      Object[] objArr6 = this.elementData;
                      objArr6[0] = objArr6[objArr6.length - 1];
                      ArraysKt.copyInto((T[]) objArr6, (T[]) objArr6, positiveMod + 1, positiveMod, objArr6.length - 1);
                  }
                  this.elementData[positiveMod] = element;
              }
              this.size = size() + 1;
          }
      }
  
      public boolean add(E element) {
          addLast(element);
          return true;
      }
  
      public boolean addAll(int index, Collection<? extends E> elements) {
          Intrinsics.checkNotNullParameter(elements, "elements");
          AbstractList.Companion.checkPositionIndex$kotlin_stdlib(index, size());
          if (elements.isEmpty()) {
              return false;
          }
          if (index == size()) {
              return addAll(elements);
          }
          ensureCapacity(size() + elements.size());
          int positiveMod = positiveMod(this.head + size());
          int positiveMod2 = positiveMod(this.head + index);
          int size2 = elements.size();
          if (index < ((size() + 1) >> 1)) {
              int i = this.head;
              int i2 = i - size2;
              if (positiveMod2 < i) {
                  Object[] objArr = this.elementData;
                  ArraysKt.copyInto((T[]) objArr, (T[]) objArr, i2, i, objArr.length);
                  if (size2 >= positiveMod2) {
                      Object[] objArr2 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr2, (T[]) objArr2, objArr2.length - size2, 0, positiveMod2);
                  } else {
                      Object[] objArr3 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr3, (T[]) objArr3, objArr3.length - size2, 0, size2);
                      Object[] objArr4 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr4, (T[]) objArr4, 0, size2, positiveMod2);
                  }
              } else if (i2 >= 0) {
                  Object[] objArr5 = this.elementData;
                  ArraysKt.copyInto((T[]) objArr5, (T[]) objArr5, i2, i, positiveMod2);
              } else {
                  Object[] objArr6 = this.elementData;
                  i2 += objArr6.length;
                  int i3 = positiveMod2 - i;
                  int length = objArr6.length - i2;
                  if (length >= i3) {
                      ArraysKt.copyInto((T[]) objArr6, (T[]) objArr6, i2, i, positiveMod2);
                  } else {
                      ArraysKt.copyInto((T[]) objArr6, (T[]) objArr6, i2, i, i + length);
                      Object[] objArr7 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr7, (T[]) objArr7, 0, this.head + length, positiveMod2);
                  }
              }
              this.head = i2;
              copyCollectionElements(negativeMod(positiveMod2 - size2), elements);
          } else {
              int i4 = positiveMod2 + size2;
              if (positiveMod2 < positiveMod) {
                  int i5 = positiveMod + size2;
                  Object[] objArr8 = this.elementData;
                  if (i5 <= objArr8.length) {
                      ArraysKt.copyInto((T[]) objArr8, (T[]) objArr8, i4, positiveMod2, positiveMod);
                  } else if (i4 >= objArr8.length) {
                      ArraysKt.copyInto((T[]) objArr8, (T[]) objArr8, i4 - objArr8.length, positiveMod2, positiveMod);
                  } else {
                      int length2 = (positiveMod + size2) - objArr8.length;
                      ArraysKt.copyInto((T[]) objArr8, (T[]) objArr8, 0, positiveMod - length2, positiveMod);
                      Object[] objArr9 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr9, (T[]) objArr9, i4, positiveMod2, positiveMod - length2);
                  }
              } else {
                  Object[] objArr10 = this.elementData;
                  ArraysKt.copyInto((T[]) objArr10, (T[]) objArr10, size2, 0, positiveMod);
                  Object[] objArr11 = this.elementData;
                  if (i4 >= objArr11.length) {
                      ArraysKt.copyInto((T[]) objArr11, (T[]) objArr11, i4 - objArr11.length, positiveMod2, objArr11.length);
                  } else {
                      ArraysKt.copyInto((T[]) objArr11, (T[]) objArr11, 0, objArr11.length - size2, objArr11.length);
                      Object[] objArr12 = this.elementData;
                      ArraysKt.copyInto((T[]) objArr12, (T[]) objArr12, i4, positiveMod2, objArr12.length - size2);
                  }
              }
              copyCollectionElements(positiveMod2, elements);
          }
          return true;
      }
  
      public boolean addAll(Collection<? extends E> elements) {
          Intrinsics.checkNotNullParameter(elements, "elements");
          if (elements.isEmpty()) {
              return false;
          }
          ensureCapacity(size() + elements.size());
          copyCollectionElements(positiveMod(this.head + size()), elements);
          return true;
      }
  
      public final void addFirst(E element) {
          ensureCapacity(size() + 1);
          int decremented = decremented(this.head);
          this.head = decremented;
          this.elementData[decremented] = element;
          this.size = size() + 1;
      }
  
      public final void addLast(E element) {
          ensureCapacity(size() + 1);
          this.elementData[positiveMod(this.head + size())] = element;
          this.size = size() + 1;
      }
  
      public void clear() {
          int positiveMod = positiveMod(this.head + size());
          int i = this.head;
          if (i < positiveMod) {
              ArraysKt.fill((T[]) this.elementData, null, i, positiveMod);
          } else if (!isEmpty()) {
              Object[] objArr = this.elementData;
              ArraysKt.fill((T[]) objArr, null, this.head, objArr.length);
              ArraysKt.fill((T[]) this.elementData, null, 0, positiveMod);
          }
          this.head = 0;
          this.size = 0;
      }
  
      public boolean contains(Object element) {
          return indexOf(element) != -1;
      }
  
      public final E first() {
          if (!isEmpty()) {
              return this.elementData[this.head];
          }
          throw new NoSuchElementException("ArrayDeque is empty.");
      }
  
      public final E firstOrNull() {
          if (isEmpty()) {
              return null;
          }
          return this.elementData[this.head];
      }
  
      public E get(int index) {
          AbstractList.Companion.checkElementIndex$kotlin_stdlib(index, size());
          return this.elementData[positiveMod(this.head + index)];
      }
  
      public int getSize() {
          return this.size;
      }
  
      public int indexOf(Object element) {
          int positiveMod = positiveMod(this.head + size());
          int i = this.head;
          if (i < positiveMod) {
              for (int i2 = this.head; i2 < positiveMod; i2++) {
                  if (Intrinsics.areEqual(element, this.elementData[i2])) {
                      return i2 - this.head;
                  }
              }
              return -1;
          } else if (i < positiveMod) {
              return -1;
          } else {
              int length = this.elementData.length;
              for (int i3 = this.head; i3 < length; i3++) {
                  if (Intrinsics.areEqual(element, this.elementData[i3])) {
                      return i3 - this.head;
                  }
              }
              for (int i4 = 0; i4 < positiveMod; i4++) {
                  if (Intrinsics.areEqual(element, this.elementData[i4])) {
                      return (this.elementData.length + i4) - this.head;
                  }
              }
              return -1;
          }
      }
  
      /* JADX WARNING: Code restructure failed: missing block: B:2:0x0017, code lost:
          r1 = r4.head;
       */
      /* Code decompiled incorrectly, please refer to instructions dump. */
      public final void internalStructure$kotlin_stdlib(kotlin.jvm.functions.Function2<? super java.lang.Integer, ? super java.lang.Object[], kotlin.Unit> r5) {
          /*
              r4 = this;
              java.lang.String r0 = "structure"
              kotlin.jvm.internal.Intrinsics.checkNotNullParameter(r5, r0)
              int r0 = r4.head
              int r1 = r4.size()
              int r0 = r0 + r1
              int r0 = r4.positiveMod(r0)
              boolean r1 = r4.isEmpty()
              if (r1 != 0) goto L_0x0021
              int r1 = r4.head
              if (r1 >= r0) goto L_0x001c
              goto L_0x0021
          L_0x001c:
              java.lang.Object[] r2 = r4.elementData
              int r2 = r2.length
              int r1 = r1 - r2
              goto L_0x0023
          L_0x0021:
              int r1 = r4.head
          L_0x0023:
              java.lang.Integer r2 = java.lang.Integer.valueOf(r1)
              java.lang.Object[] r3 = r4.toArray()
              r5.invoke(r2, r3)
              return
          */
          throw new UnsupportedOperationException("Method not decompiled: kotlin.collections.ArrayDeque.internalStructure$kotlin_stdlib(kotlin.jvm.functions.Function2):void");
      }
  
      public boolean isEmpty() {
          return size() == 0;
      }
  
      public final E last() {
          if (!isEmpty()) {
              return this.elementData[positiveMod(this.head + CollectionsKt.getLastIndex(this))];
          }
          throw new NoSuchElementException("ArrayDeque is empty.");
      }
  
      public int lastIndexOf(Object element) {
          int positiveMod = positiveMod(this.head + size());
          int i = this.head;
          if (i < positiveMod) {
              int i2 = positiveMod - 1;
              if (i <= i2) {
                  while (!Intrinsics.areEqual(element, this.elementData[i2])) {
                      if (i2 != i) {
                          i2--;
                      }
                  }
                  return i2 - this.head;
              }
          } else if (i > positiveMod) {
              for (int i3 = positiveMod - 1; -1 < i3; i3--) {
                  if (Intrinsics.areEqual(element, this.elementData[i3])) {
                      return (this.elementData.length + i3) - this.head;
                  }
              }
              int lastIndex = ArraysKt.getLastIndex((T[]) this.elementData);
              int i4 = this.head;
              if (i4 <= lastIndex) {
                  while (!Intrinsics.areEqual(element, this.elementData[lastIndex])) {
                      if (lastIndex != i4) {
                          lastIndex--;
                      }
                  }
                  return lastIndex - this.head;
              }
          }
          return -1;
      }
  
      public final E lastOrNull() {
          if (isEmpty()) {
              return null;
          }
          return this.elementData[positiveMod(this.head + CollectionsKt.getLastIndex(this))];
      }
  
      public boolean remove(Object element) {
          int indexOf = indexOf(element);
          if (indexOf == -1) {
              return false;
          }
          remove(indexOf);
          return true;
      }
  
      public boolean removeAll(Collection<? extends Object> elements) {
          int i;
          Intrinsics.checkNotNullParameter(elements, "elements");
          boolean z = false;
          if (!isEmpty()) {
              if (!(this.elementData.length == 0)) {
                  int positiveMod = positiveMod(this.head + size());
                  int i2 = this.head;
                  boolean z2 = false;
                  if (this.head < positiveMod) {
                      for (int i3 = this.head; i3 < positiveMod; i3++) {
                          Object obj = this.elementData[i3];
                          if (!elements.contains(obj)) {
                              this.elementData[i2] = obj;
                              i2++;
                          } else {
                              z2 = true;
                          }
                      }
                      ArraysKt.fill((T[]) this.elementData, null, i2, positiveMod);
                      i = i2;
                      z = z2;
                  } else {
                      int length = this.elementData.length;
                      for (int i4 = this.head; i4 < length; i4++) {
                          Object[] objArr = this.elementData;
                          Object obj2 = objArr[i4];
                          objArr[i4] = null;
                          if (!elements.contains(obj2)) {
                              this.elementData[i2] = obj2;
                              i2++;
                          } else {
                              z2 = true;
                          }
                      }
                      int positiveMod2 = positiveMod(i2);
                      for (int i5 = 0; i5 < positiveMod; i5++) {
                          Object[] objArr2 = this.elementData;
                          Object obj3 = objArr2[i5];
                          objArr2[i5] = null;
                          if (!elements.contains(obj3)) {
                              this.elementData[positiveMod2] = obj3;
                              positiveMod2 = incremented(positiveMod2);
                          } else {
                              z2 = true;
                          }
                      }
                      i = positiveMod2;
                      z = z2;
                  }
                  if (z) {
                      this.size = negativeMod(i - this.head);
                  }
              }
          }
          return z;
      }
  
      public E removeAt(int index) {
          AbstractList.Companion.checkElementIndex$kotlin_stdlib(index, size());
          if (index == CollectionsKt.getLastIndex(this)) {
              return removeLast();
          }
          if (index == 0) {
              return removeFirst();
          }
          int positiveMod = positiveMod(this.head + index);
          E e = this.elementData[positiveMod];
          if (index < (size() >> 1)) {
              int i = this.head;
              if (positiveMod >= i) {
                  Object[] objArr = this.elementData;
                  ArraysKt.copyInto((T[]) objArr, (T[]) objArr, i + 1, i, positiveMod);
              } else {
                  Object[] objArr2 = this.elementData;
                  ArraysKt.copyInto((T[]) objArr2, (T[]) objArr2, 1, 0, positiveMod);
                  Object[] objArr3 = this.elementData;
                  objArr3[0] = objArr3[objArr3.length - 1];
                  int i2 = this.head;
                  ArraysKt.copyInto((T[]) objArr3, (T[]) objArr3, i2 + 1, i2, objArr3.length - 1);
              }
              Object[] objArr4 = this.elementData;
              int i3 = this.head;
              objArr4[i3] = null;
              this.head = incremented(i3);
          } else {
              int positiveMod2 = positiveMod(this.head + CollectionsKt.getLastIndex(this));
              if (positiveMod <= positiveMod2) {
                  Object[] objArr5 = this.elementData;
                  ArraysKt.copyInto((T[]) objArr5, (T[]) objArr5, positiveMod, positiveMod + 1, positiveMod2 + 1);
              } else {
                  Object[] objArr6 = this.elementData;
                  ArraysKt.copyInto((T[]) objArr6, (T[]) objArr6, positiveMod, positiveMod + 1, objArr6.length);
                  Object[] objArr7 = this.elementData;
                  objArr7[objArr7.length - 1] = objArr7[0];
                  ArraysKt.copyInto((T[]) objArr7, (T[]) objArr7, 0, 1, positiveMod2 + 1);
              }
              this.elementData[positiveMod2] = null;
          }
          this.size = size() - 1;
          return e;
      }
  
      public final E removeFirst() {
          if (!isEmpty()) {
              E[] eArr = this.elementData;
              int i = this.head;
              E e = eArr[i];
              eArr[i] = null;
              this.head = incremented(i);
              this.size = size() - 1;
              return e;
          }
          throw new NoSuchElementException("ArrayDeque is empty.");
      }
  
      public final E removeFirstOrNull() {
          if (isEmpty()) {
              return null;
          }
          return removeFirst();
      }
  
      public final E removeLast() {
          if (!isEmpty()) {
              int positiveMod = positiveMod(this.head + CollectionsKt.getLastIndex(this));
              E[] eArr = this.elementData;
              E e = eArr[positiveMod];
              eArr[positiveMod] = null;
              this.size = size() - 1;
              return e;
          }
          throw new NoSuchElementException("ArrayDeque is empty.");
      }
  
      public final E removeLastOrNull() {
          if (isEmpty()) {
              return null;
          }
          return removeLast();
      }
  
      public boolean retainAll(Collection<? extends Object> elements) {
          int i;
          Intrinsics.checkNotNullParameter(elements, "elements");
          boolean z = false;
          if (!isEmpty()) {
              if (!(this.elementData.length == 0)) {
                  int positiveMod = positiveMod(this.head + size());
                  int i2 = this.head;
                  boolean z2 = false;
                  if (this.head < positiveMod) {
                      for (int i3 = this.head; i3 < positiveMod; i3++) {
                          Object obj = this.elementData[i3];
                          if (elements.contains(obj)) {
                              this.elementData[i2] = obj;
                              i2++;
                          } else {
                              z2 = true;
                          }
                      }
                      ArraysKt.fill((T[]) this.elementData, null, i2, positiveMod);
                      boolean z3 = z2;
                      i = i2;
                      z = z3;
                  } else {
                      int length = this.elementData.length;
                      for (int i4 = this.head; i4 < length; i4++) {
                          Object[] objArr = this.elementData;
                          Object obj2 = objArr[i4];
                          objArr[i4] = null;
                          if (elements.contains(obj2)) {
                              this.elementData[i2] = obj2;
                              i2++;
                          } else {
                              z2 = true;
                          }
                      }
                      int positiveMod2 = positiveMod(i2);
                      for (int i5 = 0; i5 < positiveMod; i5++) {
                          Object[] objArr2 = this.elementData;
                          Object obj3 = objArr2[i5];
                          objArr2[i5] = null;
                          if (elements.contains(obj3)) {
                              this.elementData[positiveMod2] = obj3;
                              positiveMod2 = incremented(positiveMod2);
                          } else {
                              z2 = true;
                          }
                      }
                      boolean z4 = z2;
                      i = positiveMod2;
                      z = z4;
                  }
                  if (z) {
                      this.size = negativeMod(i - this.head);
                  }
              }
          }
          return z;
      }
  
      public E set(int index, E element) {
          AbstractList.Companion.checkElementIndex$kotlin_stdlib(index, size());
          int positiveMod = positiveMod(this.head + index);
          E[] eArr = this.elementData;
          E e = eArr[positiveMod];
          eArr[positiveMod] = element;
          return e;
      }
  
      public final Object[] testToArray$kotlin_stdlib() {
          return toArray();
      }
  
      public final <T> T[] testToArray$kotlin_stdlib(T[] array) {
          Intrinsics.checkNotNullParameter(array, "array");
          return toArray(array);
      }
  
      public Object[] toArray() {
          return toArray(new Object[size()]);
      }
  
      public <T> T[] toArray(T[] array) {
          Intrinsics.checkNotNullParameter(array, "array");
          T[] arrayOfNulls = array.length >= size() ? array : ArraysKt.arrayOfNulls(array, size());
          Intrinsics.checkNotNull(arrayOfNulls, "null cannot be cast to non-null type kotlin.Array<kotlin.Any?>");
          int positiveMod = positiveMod(this.head + size());
          int i = this.head;
          if (i < positiveMod) {
              ArraysKt.copyInto$default(this.elementData, (Object[]) arrayOfNulls, 0, i, positiveMod, 2, (Object) null);
          } else if (!isEmpty()) {
              Object[] objArr = this.elementData;
              ArraysKt.copyInto((T[]) objArr, arrayOfNulls, 0, this.head, objArr.length);
              Object[] objArr2 = this.elementData;
              ArraysKt.copyInto((T[]) objArr2, arrayOfNulls, objArr2.length - this.head, 0, positiveMod);
          }
          if (arrayOfNulls.length > size()) {
              arrayOfNulls[size()] = null;
          }
          return arrayOfNulls;
      }
  }
  