package x4;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import m3.AbstractC2467b;
import w4.C3137A;

/* JADX INFO: renamed from: x4.K, reason: case insensitive filesystem */
/* JADX INFO: loaded from: classes3.dex */
public final class C3234K extends C4.i implements J4.e {

    /* JADX INFO: renamed from: a, reason: collision with root package name */
    public Object f26046a;

    /* JADX INFO: renamed from: b, reason: collision with root package name */
    public Iterator f26047b;

    /* JADX INFO: renamed from: c, reason: collision with root package name */
    public int f26048c;

    /* JADX INFO: renamed from: d, reason: collision with root package name */
    public int f26049d;

    /* JADX INFO: renamed from: e, reason: collision with root package name */
    public /* synthetic */ Object f26050e;

    /* JADX INFO: renamed from: f, reason: collision with root package name */
    public final /* synthetic */ int f26051f;

    /* JADX INFO: renamed from: j, reason: collision with root package name */
    public final /* synthetic */ int f26052j;

    /* JADX INFO: renamed from: k, reason: collision with root package name */
    public final /* synthetic */ Iterator f26053k;

    /* JADX WARN: 'super' call moved to the top of the method (can break code semantics) */
    public C3234K(int i6, int i7, Iterator it, A4.d dVar) {
        super(2, dVar);
        this.f26051f = i6;
        this.f26052j = i7;
        this.f26053k = it;
    }

    @Override // C4.a
    public final A4.d create(Object obj, A4.d dVar) {
        C3234K c3234k = new C3234K(this.f26051f, this.f26052j, this.f26053k, dVar);
        c3234k.f26050e = obj;
        return c3234k;
    }

    @Override // J4.e
    public final Object invoke(Object obj, Object obj2) {
        return ((C3234K) create((R4.m) obj, (A4.d) obj2)).invokeSuspend(C3137A.f25453a);
    }

    /* 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:0x00c7  */
    /* JADX WARN: Removed duplicated region for block: B:59:0x013b  */
    /* JADX WARN: Removed duplicated region for block: B:61:0x014e  */
    @Override // C4.a
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object invokeSuspend(Object obj) {
        R4.m mVar;
        int i6;
        C3232I c3232i;
        Iterator it;
        R4.m mVar2;
        ArrayList arrayList;
        Iterator it2;
        int i7;
        R4.m mVar3;
        C3232I c3232i2;
        Object[] array;
        B4.a aVar = B4.a.f492a;
        int i8 = this.f26049d;
        int i9 = this.f26052j;
        int i10 = this.f26051f;
        if (i8 == 0) {
            AbstractC2467b.l(obj);
            mVar = (R4.m) this.f26050e;
            int i11 = i10 <= 1024 ? i10 : 1024;
            i6 = i9 - i10;
            Iterator it3 = this.f26053k;
            if (i6 >= 0) {
                mVar2 = mVar;
                arrayList = new ArrayList(i11);
                it2 = it3;
                i7 = 0;
                while (it2.hasNext()) {
                }
                if (!arrayList.isEmpty()) {
                }
            } else {
                c3232i = new C3232I(new Object[i11], 0);
                it = it3;
                while (it.hasNext()) {
                }
                mVar3 = mVar;
                c3232i2 = c3232i;
                if (c3232i2.size() > i9) {
                }
            }
        } else if (i8 != 1) {
            if (i8 != 2) {
                if (i8 == 3) {
                    it = this.f26047b;
                    c3232i = (C3232I) this.f26046a;
                    R4.m mVar4 = (R4.m) this.f26050e;
                    AbstractC2467b.l(obj);
                    c3232i.g(i9);
                    mVar = mVar4;
                    while (it.hasNext()) {
                        Object next = it.next();
                        int size = c3232i.size();
                        int i12 = c3232i.f26043b;
                        if (size == i12) {
                            throw new IllegalStateException("ring buffer is full");
                        }
                        int size2 = (c3232i.size() + c3232i.f26044c) % i12;
                        Object[] objArr = c3232i.f26042a;
                        objArr[size2] = next;
                        c3232i.f26045d = c3232i.size() + 1;
                        if (c3232i.size() == i12) {
                            if (c3232i.size() >= i10) {
                                ArrayList arrayList2 = new ArrayList(c3232i);
                                this.f26050e = mVar;
                                this.f26046a = c3232i;
                                this.f26047b = it;
                                this.f26049d = 3;
                                mVar.a(this, arrayList2);
                                B4.a aVar2 = B4.a.f492a;
                                return aVar;
                            }
                            int i13 = i12 + (i12 >> 1) + 1;
                            if (i13 > i10) {
                                i13 = i10;
                            }
                            if (c3232i.f26044c == 0) {
                                array = Arrays.copyOf(objArr, i13);
                                kotlin.jvm.internal.o.g(array, "copyOf(...)");
                            } else {
                                array = c3232i.toArray(new Object[i13]);
                            }
                            c3232i = new C3232I(array, c3232i.size());
                        }
                    }
                    mVar3 = mVar;
                    c3232i2 = c3232i;
                    if (c3232i2.size() > i9) {
                    }
                } else if (i8 == 4) {
                    c3232i2 = (C3232I) this.f26046a;
                    mVar3 = (R4.m) this.f26050e;
                    AbstractC2467b.l(obj);
                    c3232i2.g(i9);
                    if (c3232i2.size() > i9) {
                        ArrayList arrayList3 = new ArrayList(c3232i2);
                        this.f26050e = mVar3;
                        this.f26046a = c3232i2;
                        this.f26047b = null;
                        this.f26049d = 4;
                        mVar3.a(this, arrayList3);
                        B4.a aVar3 = B4.a.f492a;
                        return aVar;
                    }
                    if (!c3232i2.isEmpty()) {
                        this.f26050e = null;
                        this.f26046a = null;
                        this.f26047b = null;
                        this.f26049d = 5;
                        mVar3.a(this, c3232i2);
                        B4.a aVar4 = B4.a.f492a;
                        return aVar;
                    }
                } else if (i8 != 5) {
                    throw new IllegalStateException("call to 'resume' before 'invoke' with coroutine");
                }
            }
            AbstractC2467b.l(obj);
        } else {
            i7 = this.f26048c;
            it2 = this.f26047b;
            mVar2 = (R4.m) this.f26050e;
            AbstractC2467b.l(obj);
            arrayList = new ArrayList(i10);
            i6 = i7;
            while (it2.hasNext()) {
                Object next2 = it2.next();
                if (i7 > 0) {
                    i7--;
                } else {
                    arrayList.add(next2);
                    if (arrayList.size() == i10) {
                        this.f26050e = mVar2;
                        this.f26046a = arrayList;
                        this.f26047b = it2;
                        this.f26048c = i6;
                        this.f26049d = 1;
                        mVar2.a(this, arrayList);
                        B4.a aVar5 = B4.a.f492a;
                        return aVar;
                    }
                }
            }
            if (!arrayList.isEmpty()) {
                this.f26050e = null;
                this.f26046a = null;
                this.f26047b = null;
                this.f26049d = 2;
                mVar2.a(this, arrayList);
                B4.a aVar6 = B4.a.f492a;
                return aVar;
            }
        }
        return C3137A.f25453a;
    }
}
