package androidx.compose.runtime.internal;

import F.C0171z;
import I2.C0334s;
import androidx.compose.runtime.Composer;
import androidx.compose.runtime.RecomposeScope;
import androidx.compose.runtime.RecomposeScopeImplKt;
import androidx.compose.runtime.ScopeUpdateScope;
import androidx.compose.runtime.Stable;
import java.util.ArrayList;
import java.util.List;
import kotlin.jvm.internal.o;
import w4.C3137A;
import x4.AbstractC3250p;

/* JADX INFO: loaded from: classes.dex */
@Stable
public final class ComposableLambdaNImpl implements ComposableLambdaN {
    public static final int $stable = 0;
    private Object _block;
    private final int arity;
    private final int key;
    private RecomposeScope scope;
    private List<RecomposeScope> scopes;
    private final boolean tracked;

    public ComposableLambdaNImpl(int i6, boolean z6, int i7) {
        this.key = i6;
        this.tracked = z6;
        this.arity = i7;
    }

    /* JADX INFO: Access modifiers changed from: private */
    public static final C3137A invoke$lambda$0(Object[] objArr, int i6, ComposableLambdaNImpl composableLambdaNImpl, Composer composer, int i7) {
        Object[] array = AbstractC3250p.V(objArr, L4.a.l0(0, i6)).toArray(new Object[0]);
        Object obj = objArr[i6 + 1];
        o.f(obj, "null cannot be cast to non-null type kotlin.Int");
        int iUpdateChangedFlags = RecomposeScopeImplKt.updateChangedFlags(((Integer) obj).intValue());
        int length = (objArr.length - i6) - 2;
        Object[] objArr2 = new Object[length];
        for (int i8 = 0; i8 < length; i8++) {
            Object obj2 = objArr[i6 + 2 + i8];
            o.f(obj2, "null cannot be cast to non-null type kotlin.Int");
            objArr2[i8] = Integer.valueOf(RecomposeScopeImplKt.updateChangedFlags(((Integer) obj2).intValue()));
        }
        C0334s c0334s = new C0334s(4);
        c0334s.f(array);
        c0334s.b(composer);
        c0334s.b(Integer.valueOf(iUpdateChangedFlags | 1));
        c0334s.f(objArr2);
        ArrayList arrayList = c0334s.f2658b;
        composableLambdaNImpl.invoke(arrayList.toArray(new Object[arrayList.size()]));
        return C3137A.f25453a;
    }

    private final int realParamCount(int i6) {
        int i7 = i6 - 2;
        for (int i8 = 1; i8 * 10 < i7; i8++) {
            i7--;
        }
        return i7;
    }

    private final void trackRead(Composer composer) {
        RecomposeScope recomposeScope;
        if (!this.tracked || (recomposeScope = composer.getRecomposeScope()) == null) {
            return;
        }
        composer.recordUsed(recomposeScope);
        if (ComposableLambdaKt.replacableWith(this.scope, recomposeScope)) {
            this.scope = recomposeScope;
            return;
        }
        List<RecomposeScope> list = this.scopes;
        if (list == null) {
            ArrayList arrayList = new ArrayList();
            this.scopes = arrayList;
            arrayList.add(recomposeScope);
            return;
        }
        int size = list.size();
        for (int i6 = 0; i6 < size; i6++) {
            if (ComposableLambdaKt.replacableWith(list.get(i6), recomposeScope)) {
                list.set(i6, recomposeScope);
                return;
            }
        }
        list.add(recomposeScope);
    }

    private final void trackWrite() {
        if (this.tracked) {
            RecomposeScope recomposeScope = this.scope;
            if (recomposeScope != null) {
                recomposeScope.invalidate();
                this.scope = null;
            }
            List<RecomposeScope> list = this.scopes;
            if (list != null) {
                int size = list.size();
                for (int i6 = 0; i6 < size; i6++) {
                    list.get(i6).invalidate();
                }
                list.clear();
            }
        }
    }

    @Override // androidx.compose.runtime.internal.ComposableLambdaN, kotlin.jvm.internal.j
    public int getArity() {
        return this.arity;
    }

    public final int getKey() {
        return this.key;
    }

    @Override // androidx.compose.runtime.internal.ComposableLambdaN
    public Object invoke(Object... objArr) {
        int iRealParamCount = realParamCount(objArr.length);
        Object obj = objArr[iRealParamCount];
        o.f(obj, "null cannot be cast to non-null type androidx.compose.runtime.Composer");
        Object[] array = AbstractC3250p.V(objArr, L4.a.l0(0, objArr.length - 1)).toArray(new Object[0]);
        Object obj2 = objArr[objArr.length - 1];
        o.f(obj2, "null cannot be cast to non-null type kotlin.Int");
        int iIntValue = ((Integer) obj2).intValue();
        Composer composerStartRestartGroup = ((Composer) obj).startRestartGroup(this.key);
        trackRead(composerStartRestartGroup);
        int iDifferentBits = iIntValue | (composerStartRestartGroup.changed(this) ? ComposableLambdaKt.differentBits(iRealParamCount) : ComposableLambdaKt.sameBits(iRealParamCount));
        Object obj3 = this._block;
        o.f(obj3, "null cannot be cast to non-null type kotlin.jvm.functions.FunctionN<*>");
        C0334s c0334s = new C0334s(2);
        c0334s.f(array);
        c0334s.b(Integer.valueOf(iDifferentBits));
        ArrayList arrayList = c0334s.f2658b;
        Object objInvoke = ((ComposableLambdaN) obj3).invoke(arrayList.toArray(new Object[arrayList.size()]));
        ScopeUpdateScope scopeUpdateScopeEndRestartGroup = composerStartRestartGroup.endRestartGroup();
        if (scopeUpdateScopeEndRestartGroup != null) {
            scopeUpdateScopeEndRestartGroup.updateScope(new C0171z(objArr, iRealParamCount, this, 18));
        }
        return objInvoke;
    }

    public final void update(Object obj) {
        if (o.c(obj, this._block)) {
            return;
        }
        boolean z6 = this._block == null;
        o.f(obj, "null cannot be cast to non-null type kotlin.jvm.functions.FunctionN<*>");
        this._block = (ComposableLambdaN) obj;
        if (z6) {
            return;
        }
        trackWrite();
    }
}
