package defpackage;

import androidx.media3.container.NalUnitUtil;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import kotlin.Metadata;
import kotlin.coroutines.Continuation;
import kotlin.coroutines.jvm.internal.DebugMetadata;
import kotlin.coroutines.jvm.internal.RestrictedSuspendLambda;

/* JADX INFO: renamed from: iw8, reason: from Kotlin metadata and case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
@Metadata(d1 = {"\u0000\u0012\n\u0000\n\u0002\u0018\u0002\n\u0002\u0010 \n\u0002\u0018\u0002\n\u0002\b\u0002\u0010\u0004\u001a\u00020\u0003\"\u0004\b\u0000\u0010\u0000*\u000e\u0012\n\u0012\b\u0012\u0004\u0012\u00028\u00000\u00020\u0001H\n¢\u0006\u0004\b\u0004\u0010\u0005"}, d2 = {"T", "Lrg8;", "", "Le6a;", "<anonymous>", "(Lrg8;)V"}, k = 3, mv = {2, 1, 0})
@DebugMetadata(c = "kotlin.collections.SlidingWindowKt$windowedIterator$1", f = "SlidingWindow.kt", i = {0, 0, 0, 2, 2, 3, 3}, l = {34, NalUnitUtil.H265_NAL_UNIT_TYPE_SUFFIX_SEI, 49, 55, 58}, m = "invokeSuspend", n = {"$this$iterator", "buffer", "gap", "$this$iterator", "buffer", "$this$iterator", "buffer"}, s = {"L$0", "L$1", "I$0", "L$0", "L$1", "L$0", "L$1"})
final class C0577iw8 extends RestrictedSuspendLambda implements gr3<rg8<? super List<Object>>, Continuation<? super e6a>, Object> {
    public Object a;
    public Iterator b;
    public int c;
    public int d;
    public /* synthetic */ Object e;
    public final /* synthetic */ int f;
    public final /* synthetic */ int i;
    public final /* synthetic */ Iterator j;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C0577iw8(int i, int i2, Iterator it, Continuation continuation) {
        super(2, continuation);
        this.f = i;
        this.i = i2;
        this.j = it;
    }

    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    public final Continuation create(Object obj, Continuation continuation) {
        C0577iw8 c0577iw8 = new C0577iw8(this.f, this.i, this.j, continuation);
        c0577iw8.e = obj;
        return c0577iw8;
    }

    @Override // defpackage.gr3
    public final Object invoke(Object obj, Object obj2) {
        return ((C0577iw8) create((rg8) obj, (Continuation) obj2)).invokeSuspend(e6a.a);
    }

    /* JADX WARN: Removed duplicated region for block: B:24:0x0083  */
    /* JADX WARN: Removed duplicated region for block: B:33:0x00ab  */
    /* JADX WARN: Removed duplicated region for block: B:38:0x00cc  */
    /* JADX WARN: Removed duplicated region for block: B:68:0x0130 A[SYNTHETIC] */
    @Override // kotlin.coroutines.jvm.internal.BaseContinuationImpl
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        int i;
        a58 a58Var;
        rg8 rg8Var;
        Iterator it;
        ArrayList arrayList;
        rg8 rg8Var2;
        Iterator it2;
        int i2;
        a58 a58Var2;
        rg8 rg8Var3;
        Object[] array;
        ck1 ck1Var = ck1.a;
        int i3 = this.d;
        int i4 = this.i;
        boolean z = true;
        int i5 = this.f;
        if (i3 == 0) {
            s38.b(obj);
            rg8 rg8Var4 = (rg8) this.e;
            int i6 = i5 <= 1024 ? i5 : 1024;
            i = i4 - i5;
            Iterator it3 = this.j;
            if (i >= 0) {
                arrayList = new ArrayList(i6);
                rg8Var2 = rg8Var4;
                it2 = it3;
                i2 = 0;
                while (it2.hasNext()) {
                }
                if (!arrayList.isEmpty()) {
                }
            } else {
                a58Var = new a58(new Object[i6], 0);
                rg8Var = rg8Var4;
                it = it3;
                while (true) {
                    int i7 = a58Var.b;
                    Object[] objArr = a58Var.a;
                    if (it.hasNext()) {
                    }
                    z = z;
                }
            }
        } else if (i3 != 1) {
            if (i3 != 2) {
                if (i3 == 3) {
                    it = this.b;
                    a58Var = (a58) this.a;
                    rg8Var = (rg8) this.e;
                    s38.b(obj);
                    a58Var.b(i4);
                    while (true) {
                        int i72 = a58Var.b;
                        Object[] objArr2 = a58Var.a;
                        if (it.hasNext()) {
                            a58Var2 = a58Var;
                            rg8Var3 = rg8Var;
                            break;
                        }
                        Object next = it.next();
                        if (a58Var.getD() == i72) {
                            throw new IllegalStateException("ring buffer is full");
                        }
                        int i8 = a58Var.c;
                        boolean z2 = z;
                        int i9 = a58Var.d;
                        objArr2[(i8 + i9) % i72] = next;
                        a58Var.d = i9 + 1;
                        if (a58Var.getD() == i72) {
                            if (a58Var.d >= i5) {
                                ArrayList arrayList2 = new ArrayList(a58Var);
                                this.e = rg8Var;
                                this.a = a58Var;
                                this.b = it;
                                this.d = 3;
                                rg8Var.a(arrayList2, this);
                                ck1 ck1Var2 = ck1.a;
                                return ck1Var;
                            }
                            int i10 = i72 + (i72 >> 1) + 1;
                            if (i10 > i5) {
                                i10 = i5;
                            }
                            if (a58Var.c == 0) {
                                array = Arrays.copyOf(objArr2, i10);
                                cr4.f(array, "copyOf(...)");
                            } else {
                                array = a58Var.toArray(new Object[i10]);
                            }
                            a58Var = new a58(array, a58Var.d);
                        }
                        z = z2;
                    }
                } else if (i3 == 4) {
                    a58Var2 = (a58) this.a;
                    rg8Var3 = (rg8) this.e;
                    s38.b(obj);
                    a58Var2.b(i4);
                    if (a58Var2.d > i4) {
                        ArrayList arrayList3 = new ArrayList(a58Var2);
                        this.e = rg8Var3;
                        this.a = a58Var2;
                        this.b = null;
                        this.d = 4;
                        rg8Var3.a(arrayList3, this);
                        ck1 ck1Var3 = ck1.a;
                        return ck1Var;
                    }
                    if (!a58Var2.isEmpty()) {
                        this.e = null;
                        this.a = null;
                        this.b = null;
                        this.d = 5;
                        rg8Var3.a(a58Var2, this);
                        ck1 ck1Var4 = ck1.a;
                        return ck1Var;
                    }
                } else if (i3 != 5) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
            }
            s38.b(obj);
        } else {
            i2 = this.c;
            it2 = this.b;
            rg8Var2 = (rg8) this.e;
            s38.b(obj);
            arrayList = new ArrayList(i5);
            i = i2;
            while (it2.hasNext()) {
                Object next2 = it2.next();
                if (i2 > 0) {
                    i2--;
                } else {
                    arrayList.add(next2);
                    if (arrayList.size() == i5) {
                        this.e = rg8Var2;
                        this.a = arrayList;
                        this.b = it2;
                        this.c = i;
                        this.d = 1;
                        rg8Var2.a(arrayList, this);
                        ck1 ck1Var5 = ck1.a;
                        return ck1Var;
                    }
                }
            }
            if (!arrayList.isEmpty()) {
                this.e = null;
                this.a = null;
                this.b = null;
                this.d = 2;
                rg8Var2.a(arrayList, this);
                ck1 ck1Var6 = ck1.a;
                return ck1Var;
            }
        }
        return e6a.a;
    }
}
