package androidx.compose.runtime.tooling;

import S4.w;
import androidx.compose.runtime.Anchor;
import androidx.compose.runtime.Composer;
import androidx.compose.runtime.GroupSourceInformation;
import androidx.compose.runtime.internal.StabilityInferred;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.o;

/* JADX INFO: loaded from: classes.dex */
@StabilityInferred(parameters = 0)
public abstract class ComposeStackTraceBuilder {
    public static final int $stable = 8;
    private final List<ComposeStackTraceFrame> _trace = new ArrayList();

    private final boolean appendGroupSourceInformation(int i6, GroupSourceInformation groupSourceInformation, Object obj) {
        ArrayList<Object> groups = groupSourceInformation.getGroups();
        boolean z6 = false;
        if (groups == null) {
            if (!groupSourceInformation.getClosed()) {
                appendTraceFrame(i6, groupSourceInformation, null);
                return true;
            }
            int dataStartOffset = groupSourceInformation.getDataStartOffset();
            int dataEndOffset = groupSourceInformation.getDataEndOffset();
            if (obj instanceof Integer) {
                Number number = (Number) obj;
                int iIntValue = number.intValue();
                if ((dataStartOffset <= iIntValue && iIntValue < dataEndOffset) || (dataStartOffset == dataEndOffset && (obj instanceof Integer) && dataStartOffset == number.intValue())) {
                    z6 = true;
                }
                if (z6) {
                    appendTraceFrame(groupSourceInformation.getKey(), groupSourceInformation, null);
                }
            }
            return z6;
        }
        int size = groups.size();
        for (int i7 = 0; i7 < size; i7++) {
            Object obj2 = groups.get(i7);
            if (obj2 instanceof Anchor) {
                if (o.c(obj2, obj)) {
                    appendTraceFrame(groupSourceInformation.getKey(), groupSourceInformation, obj2);
                    return true;
                }
            } else {
                if (!(obj2 instanceof GroupSourceInformation)) {
                    throw new IllegalStateException(("Unexpected child source info " + obj2).toString());
                }
                if (appendGroupSourceInformation(i6, (GroupSourceInformation) obj2, obj)) {
                    appendTraceFrame(groupSourceInformation.getKey(), groupSourceInformation, obj2);
                    return true;
                }
            }
        }
        return false;
    }

    private final void appendTraceFrame(int i6, GroupSourceInformation groupSourceInformation, Object obj) {
        ComposeStackTraceFrame composeStackTraceFrameExtractTraceFrame = extractTraceFrame(i6, groupSourceInformation, obj);
        if (composeStackTraceFrameExtractTraceFrame != null) {
            this._trace.add(composeStackTraceFrameExtractTraceFrame);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:43:0x0081  */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    private final ComposeStackTraceFrame extractTraceFrame(int i6, GroupSourceInformation groupSourceInformation, Object obj) {
        ArrayList<Object> groups;
        String sourceInformation;
        SourceInformation sourceInformation2 = (groupSourceInformation == null || (sourceInformation = groupSourceInformation.getSourceInformation()) == null) ? null : SourceInformationKt.parseSourceInformation(sourceInformation);
        if (sourceInformation2 == null) {
            return new ComposeStackTraceFrame(i6, null, null);
        }
        if (obj == null) {
            return new ComposeStackTraceFrame(i6, sourceInformation2, null);
        }
        ArrayList<Object> groups2 = groupSourceInformation.getGroups();
        int i7 = 0;
        if (groups2 != null) {
            int size = groups2.size();
            int i8 = 0;
            for (int i9 = 0; i9 < size; i9++) {
                Object obj2 = groups2.get(i9);
                if (o.c(obj2, obj)) {
                    break;
                }
                GroupSourceInformation groupSourceInformationSourceInformationOf = sourceInformationOf(obj2);
                if (groupSourceInformationSourceInformationOf != null && (groupSourceInformationSourceInformationOf.getKey() == -127 || (groupSourceInformationSourceInformationOf.getKey() == 0 && (obj2 instanceof Anchor) && groupKeyOf((Anchor) obj2) == -127))) {
                    if ((groupSourceInformationSourceInformationOf != null ? groupSourceInformationSourceInformationOf.getSourceInformation() : null) == null) {
                        if (groupSourceInformationSourceInformationOf != null && (groups = groupSourceInformationSourceInformationOf.getGroups()) != null) {
                            int size2 = groups.size();
                            for (int i10 = 0; i10 < size2; i10++) {
                                GroupSourceInformation groupSourceInformationSourceInformationOf2 = sourceInformationOf(groups.get(i10));
                                if (groupSourceInformationSourceInformationOf2 != null && isCall(groupSourceInformationSourceInformationOf2)) {
                                    i8++;
                                }
                            }
                        }
                    }
                } else if (groupSourceInformationSourceInformationOf != null && isCall(groupSourceInformationSourceInformationOf)) {
                    i8++;
                }
            }
            i7 = i8;
        }
        return new ComposeStackTraceFrame(i6, sourceInformation2, Integer.valueOf(i7));
    }

    private final boolean isCall(GroupSourceInformation groupSourceInformation) {
        String sourceInformation = groupSourceInformation.getSourceInformation();
        return sourceInformation != null && w.A0(sourceInformation, "C", false);
    }

    private final GroupSourceInformation sourceInformationOf(Object obj) {
        if (obj instanceof Anchor) {
            return sourceInformationOf((Anchor) obj);
        }
        if (obj instanceof GroupSourceInformation) {
            return (GroupSourceInformation) obj;
        }
        throw new IllegalStateException(("Unexpected child source info " + obj).toString());
    }

    public abstract int groupKeyOf(Anchor anchor);

    public final void processEdge(int i6, Object obj, GroupSourceInformation groupSourceInformation, Object obj2) {
        if (groupSourceInformation != null || o.c(obj, Composer.Companion.getEmpty())) {
            if (obj2 == null || groupSourceInformation == null) {
                appendTraceFrame(i6, groupSourceInformation, null);
            } else {
                if (appendGroupSourceInformation(i6, groupSourceInformation, obj2) || groupSourceInformation.getClosed()) {
                    return;
                }
                appendTraceFrame(i6, groupSourceInformation, obj2);
            }
        }
    }

    public abstract GroupSourceInformation sourceInformationOf(Anchor anchor);

    public final List<ComposeStackTraceFrame> trace() {
        return this._trace;
    }
}
