package X6;

import O6.p;
import Z6.C0379t;
import Z6.InterfaceC0372l;
import Z6.d0;
import Z6.k0;
import d7.w;
import e7.q;
import java.util.Iterator;
import java.util.List;
import java.util.NoSuchElementException;
import n4.u0;

/* JADX INFO: loaded from: classes.dex */
public final /* synthetic */ class o implements p {

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

    /* JADX INFO: renamed from: r, reason: collision with root package name */
    public final /* synthetic */ Object f7252r;

    public /* synthetic */ o(int i, Object obj) {
        this.f7251q = i;
        this.f7252r = obj;
    }

    /* JADX WARN: Removed duplicated region for block: B:39:0x00e0  */
    /* JADX WARN: Removed duplicated region for block: B:8:0x002a  */
    @Override // O6.p
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public final Object k(Object obj, Object obj2) {
        int i;
        int i5;
        int i8;
        Object next;
        A6.h hVar;
        Object next2;
        switch (this.f7251q) {
            case u0.f15495q /* 0 */:
                CharSequence charSequence = (CharSequence) obj;
                int iIntValue = ((Integer) obj2).intValue();
                P6.g.e(charSequence, "$this$DelimitedRangesSequence");
                List list = (List) this.f7252r;
                if (list.size() == 1) {
                    int size = list.size();
                    if (size == 0) {
                        throw new NoSuchElementException("List is empty.");
                    }
                    if (size != 1) {
                        throw new IllegalArgumentException("List has more than one element.");
                    }
                    String str = (String) list.get(0);
                    int iT = e.T(charSequence, str, iIntValue, 4);
                    hVar = iT < 0 ? null : new A6.h(Integer.valueOf(iT), str);
                } else {
                    if (iIntValue < 0) {
                        iIntValue = 0;
                    }
                    U6.c cVar = new U6.c(iIntValue, charSequence.length(), 1);
                    boolean z8 = charSequence instanceof String;
                    int i9 = cVar.f6799s;
                    int i10 = cVar.f6798r;
                    if (z8) {
                        if ((i9 > 0 && iIntValue <= i10) || (i9 < 0 && i10 <= iIntValue)) {
                            int i11 = iIntValue;
                            while (true) {
                                Iterator it = list.iterator();
                                while (true) {
                                    if (it.hasNext()) {
                                        next2 = it.next();
                                        String str2 = (String) next2;
                                        if (n.J(0, i11, str2.length(), str2, (String) charSequence, false)) {
                                        }
                                    } else {
                                        next2 = null;
                                    }
                                }
                                String str3 = (String) next2;
                                if (str3 != null) {
                                    hVar = new A6.h(Integer.valueOf(i11), str3);
                                } else if (i11 != i10) {
                                    i11 += i9;
                                }
                            }
                        }
                    } else if ((i9 > 0 && iIntValue <= i10) || (i9 < 0 && i10 <= iIntValue)) {
                        while (true) {
                            Iterator it2 = list.iterator();
                            while (true) {
                                if (it2.hasNext()) {
                                    next = it2.next();
                                    int i12 = i10;
                                    String str4 = (String) next;
                                    int i13 = i9;
                                    i = iIntValue;
                                    i5 = i13;
                                    i8 = i12;
                                    if (!e.Y(str4, 0, charSequence, i, str4.length(), false)) {
                                        i9 = i5;
                                        iIntValue = i;
                                        i10 = i8;
                                    }
                                } else {
                                    int i14 = i9;
                                    i = iIntValue;
                                    i5 = i14;
                                    i8 = i10;
                                    next = null;
                                }
                            }
                            String str5 = (String) next;
                            if (str5 != null) {
                                hVar = new A6.h(Integer.valueOf(i), str5);
                            } else if (i != i8) {
                                int i15 = i + i5;
                                i9 = i5;
                                iIntValue = i15;
                                i10 = i8;
                            }
                        }
                    }
                }
                if (hVar != null) {
                    return new A6.h(hVar.f446q, Integer.valueOf(((String) hVar.f447r).length()));
                }
                return null;
            case 1:
                CharSequence charSequence2 = (CharSequence) obj;
                int iIntValue2 = ((Integer) obj2).intValue();
                P6.g.e(charSequence2, "$this$DelimitedRangesSequence");
                int iU = e.U(charSequence2, (char[]) this.f7252r, iIntValue2, false);
                if (iU < 0) {
                    return null;
                }
                return new A6.h(Integer.valueOf(iU), 1);
            default:
                int iIntValue3 = ((Integer) obj).intValue();
                E6.g gVar = (E6.g) obj2;
                E6.h key = gVar.getKey();
                E6.g gVarK = ((w) this.f7252r).f12389u.K(key);
                if (key != C0379t.f7546r) {
                    iIntValue3 = gVar != gVarK ? Integer.MIN_VALUE : iIntValue3 + 1;
                } else {
                    d0 d0Var = (d0) gVarK;
                    d0 parent = (d0) gVar;
                    while (true) {
                        if (parent == null) {
                            parent = null;
                        } else if (parent != d0Var && (parent instanceof q)) {
                            InterfaceC0372l interfaceC0372l = (InterfaceC0372l) k0.f7530r.get((q) parent);
                            parent = interfaceC0372l != null ? interfaceC0372l.getParent() : null;
                        }
                    }
                    if (parent != d0Var) {
                        throw new IllegalStateException(("Flow invariant is violated:\n\t\tEmission from another coroutine is detected.\n\t\tChild of " + parent + ", expected child of " + d0Var + ".\n\t\tFlowCollector is not thread-safe and concurrent emissions are prohibited.\n\t\tTo mitigate this restriction please use 'channelFlow' builder instead of 'flow'").toString());
                    }
                    if (d0Var != null) {
                    }
                }
                return Integer.valueOf(iIntValue3);
        }
    }
}
