package X6FRs_4.YghfZG_14.PGPF6hQ_2;

import X6FRs_4.YghfZG_14.PGPF6hQ_2.KQgRr5e_0;
import java.util.List;
/* compiled from: OpReorderer.java */
/* loaded from: classes.dex */
public class FSaI4_7 {
    public final KQgRr5e_0 KQgRr5e_0;

    /* compiled from: OpReorderer.java */
    /* loaded from: classes.dex */
    public interface KQgRr5e_0 {
        KQgRr5e_0.QxJ9d_1 KQgRr5e_0(int i, int i2, int i3, Object obj);

        void KQgRr5e_0(KQgRr5e_0.QxJ9d_1 qxJ9d_1);
    }

    public FSaI4_7(KQgRr5e_0 kQgRr5e_0) {
        this.KQgRr5e_0 = kQgRr5e_0;
    }

    /* renamed from: KQgRr5e_0  reason: collision with other method in class */
    public void m623KQgRr5e_0(List<KQgRr5e_0.QxJ9d_1> list) {
        while (true) {
            int KQgRr5e_02 = KQgRr5e_0(list);
            if (KQgRr5e_02 == -1) {
                return;
            }
            KQgRr5e_0(list, KQgRr5e_02, KQgRr5e_02 + 1);
        }
    }

    /* JADX WARN: Removed duplicated region for block: B:11:0x0027  */
    /* JADX WARN: Removed duplicated region for block: B:12:0x002b  */
    /* JADX WARN: Removed duplicated region for block: B:17:0x0048  */
    /* JADX WARN: Removed duplicated region for block: B:18:0x004c  */
    /* JADX WARN: Removed duplicated region for block: B:20:0x0056  */
    /* JADX WARN: Removed duplicated region for block: B:22:0x005b  */
    /* JADX WARN: Removed duplicated region for block: B:24:? A[RETURN, SYNTHETIC] */
    /*
        Code decompiled incorrectly, please refer to instructions dump.
    */
    public void PGPF6hQ_2(List<KQgRr5e_0.QxJ9d_1> list, int i, KQgRr5e_0.QxJ9d_1 qxJ9d_1, int i2, KQgRr5e_0.QxJ9d_1 qxJ9d_12) {
        KQgRr5e_0.QxJ9d_1 KQgRr5e_02;
        int i3;
        int i4;
        int i5 = qxJ9d_1.PGPF6hQ_2;
        int i6 = qxJ9d_12.QxJ9d_1;
        KQgRr5e_0.QxJ9d_1 qxJ9d_13 = null;
        if (i5 < i6) {
            qxJ9d_12.QxJ9d_1 = i6 - 1;
        } else {
            int i7 = qxJ9d_12.PGPF6hQ_2;
            if (i5 < i6 + i7) {
                qxJ9d_12.PGPF6hQ_2 = i7 - 1;
                KQgRr5e_02 = this.KQgRr5e_0.KQgRr5e_0(4, qxJ9d_1.QxJ9d_1, 1, qxJ9d_12.f1358KQgRr5e_0);
                i3 = qxJ9d_1.QxJ9d_1;
                i4 = qxJ9d_12.QxJ9d_1;
                if (i3 > i4) {
                    qxJ9d_12.QxJ9d_1 = i4 + 1;
                } else {
                    int i8 = qxJ9d_12.PGPF6hQ_2;
                    if (i3 < i4 + i8) {
                        int i9 = (i4 + i8) - i3;
                        qxJ9d_13 = this.KQgRr5e_0.KQgRr5e_0(4, i3 + 1, i9, qxJ9d_12.f1358KQgRr5e_0);
                        qxJ9d_12.PGPF6hQ_2 -= i9;
                    }
                }
                list.set(i2, qxJ9d_1);
                if (qxJ9d_12.PGPF6hQ_2 <= 0) {
                    list.set(i, qxJ9d_12);
                } else {
                    list.remove(i);
                    this.KQgRr5e_0.KQgRr5e_0(qxJ9d_12);
                }
                if (KQgRr5e_02 != null) {
                    list.add(i, KQgRr5e_02);
                }
                if (qxJ9d_13 == null) {
                    list.add(i, qxJ9d_13);
                    return;
                }
                return;
            }
        }
        KQgRr5e_02 = null;
        i3 = qxJ9d_1.QxJ9d_1;
        i4 = qxJ9d_12.QxJ9d_1;
        if (i3 > i4) {
        }
        list.set(i2, qxJ9d_1);
        if (qxJ9d_12.PGPF6hQ_2 <= 0) {
        }
        if (KQgRr5e_02 != null) {
        }
        if (qxJ9d_13 == null) {
        }
    }

    public void QxJ9d_1(List<KQgRr5e_0.QxJ9d_1> list, int i, KQgRr5e_0.QxJ9d_1 qxJ9d_1, int i2, KQgRr5e_0.QxJ9d_1 qxJ9d_12) {
        boolean z;
        int i3 = qxJ9d_1.QxJ9d_1;
        int i4 = qxJ9d_1.PGPF6hQ_2;
        boolean z2 = false;
        if (i3 < i4) {
            if (qxJ9d_12.QxJ9d_1 == i3 && qxJ9d_12.PGPF6hQ_2 == i4 - i3) {
                z = false;
                z2 = true;
            } else {
                z = false;
            }
        } else if (qxJ9d_12.QxJ9d_1 == i4 + 1 && qxJ9d_12.PGPF6hQ_2 == i3 - i4) {
            z = true;
            z2 = true;
        } else {
            z = true;
        }
        int i5 = qxJ9d_1.PGPF6hQ_2;
        int i6 = qxJ9d_12.QxJ9d_1;
        if (i5 < i6) {
            qxJ9d_12.QxJ9d_1 = i6 - 1;
        } else {
            int i7 = qxJ9d_12.PGPF6hQ_2;
            if (i5 < i6 + i7) {
                qxJ9d_12.PGPF6hQ_2 = i7 - 1;
                qxJ9d_1.KQgRr5e_0 = 2;
                qxJ9d_1.PGPF6hQ_2 = 1;
                if (qxJ9d_12.PGPF6hQ_2 == 0) {
                    list.remove(i2);
                    this.KQgRr5e_0.KQgRr5e_0(qxJ9d_12);
                    return;
                }
                return;
            }
        }
        int i8 = qxJ9d_1.QxJ9d_1;
        int i9 = qxJ9d_12.QxJ9d_1;
        KQgRr5e_0.QxJ9d_1 qxJ9d_13 = null;
        if (i8 <= i9) {
            qxJ9d_12.QxJ9d_1 = i9 + 1;
        } else {
            int i10 = qxJ9d_12.PGPF6hQ_2;
            if (i8 < i9 + i10) {
                qxJ9d_13 = this.KQgRr5e_0.KQgRr5e_0(2, i8 + 1, (i9 + i10) - i8, null);
                qxJ9d_12.PGPF6hQ_2 = qxJ9d_1.QxJ9d_1 - qxJ9d_12.QxJ9d_1;
            }
        }
        if (z2) {
            list.set(i, qxJ9d_12);
            list.remove(i2);
            this.KQgRr5e_0.KQgRr5e_0(qxJ9d_1);
            return;
        }
        if (z) {
            if (qxJ9d_13 != null) {
                int i11 = qxJ9d_1.QxJ9d_1;
                if (i11 > qxJ9d_13.QxJ9d_1) {
                    qxJ9d_1.QxJ9d_1 = i11 - qxJ9d_13.PGPF6hQ_2;
                }
                int i12 = qxJ9d_1.PGPF6hQ_2;
                if (i12 > qxJ9d_13.QxJ9d_1) {
                    qxJ9d_1.PGPF6hQ_2 = i12 - qxJ9d_13.PGPF6hQ_2;
                }
            }
            int i13 = qxJ9d_1.QxJ9d_1;
            if (i13 > qxJ9d_12.QxJ9d_1) {
                qxJ9d_1.QxJ9d_1 = i13 - qxJ9d_12.PGPF6hQ_2;
            }
            int i14 = qxJ9d_1.PGPF6hQ_2;
            if (i14 > qxJ9d_12.QxJ9d_1) {
                qxJ9d_1.PGPF6hQ_2 = i14 - qxJ9d_12.PGPF6hQ_2;
            }
        } else {
            if (qxJ9d_13 != null) {
                int i15 = qxJ9d_1.QxJ9d_1;
                if (i15 >= qxJ9d_13.QxJ9d_1) {
                    qxJ9d_1.QxJ9d_1 = i15 - qxJ9d_13.PGPF6hQ_2;
                }
                int i16 = qxJ9d_1.PGPF6hQ_2;
                if (i16 >= qxJ9d_13.QxJ9d_1) {
                    qxJ9d_1.PGPF6hQ_2 = i16 - qxJ9d_13.PGPF6hQ_2;
                }
            }
            int i17 = qxJ9d_1.QxJ9d_1;
            if (i17 >= qxJ9d_12.QxJ9d_1) {
                qxJ9d_1.QxJ9d_1 = i17 - qxJ9d_12.PGPF6hQ_2;
            }
            int i18 = qxJ9d_1.PGPF6hQ_2;
            if (i18 >= qxJ9d_12.QxJ9d_1) {
                qxJ9d_1.PGPF6hQ_2 = i18 - qxJ9d_12.PGPF6hQ_2;
            }
        }
        list.set(i, qxJ9d_12);
        if (qxJ9d_1.QxJ9d_1 != qxJ9d_1.PGPF6hQ_2) {
            list.set(i2, qxJ9d_1);
        } else {
            list.remove(i2);
        }
        if (qxJ9d_13 != null) {
            list.add(i, qxJ9d_13);
        }
    }

    public final void KQgRr5e_0(List<KQgRr5e_0.QxJ9d_1> list, int i, int i2) {
        KQgRr5e_0.QxJ9d_1 qxJ9d_1 = list.get(i);
        KQgRr5e_0.QxJ9d_1 qxJ9d_12 = list.get(i2);
        int i3 = qxJ9d_12.KQgRr5e_0;
        if (i3 == 1) {
            KQgRr5e_0(list, i, qxJ9d_1, i2, qxJ9d_12);
        } else if (i3 == 2) {
            QxJ9d_1(list, i, qxJ9d_1, i2, qxJ9d_12);
        } else if (i3 != 4) {
        } else {
            PGPF6hQ_2(list, i, qxJ9d_1, i2, qxJ9d_12);
        }
    }

    public final void KQgRr5e_0(List<KQgRr5e_0.QxJ9d_1> list, int i, KQgRr5e_0.QxJ9d_1 qxJ9d_1, int i2, KQgRr5e_0.QxJ9d_1 qxJ9d_12) {
        int i3 = qxJ9d_1.PGPF6hQ_2 < qxJ9d_12.QxJ9d_1 ? -1 : 0;
        if (qxJ9d_1.QxJ9d_1 < qxJ9d_12.QxJ9d_1) {
            i3++;
        }
        int i4 = qxJ9d_12.QxJ9d_1;
        int i5 = qxJ9d_1.QxJ9d_1;
        if (i4 <= i5) {
            qxJ9d_1.QxJ9d_1 = i5 + qxJ9d_12.PGPF6hQ_2;
        }
        int i6 = qxJ9d_12.QxJ9d_1;
        int i7 = qxJ9d_1.PGPF6hQ_2;
        if (i6 <= i7) {
            qxJ9d_1.PGPF6hQ_2 = i7 + qxJ9d_12.PGPF6hQ_2;
        }
        qxJ9d_12.QxJ9d_1 += i3;
        list.set(i, qxJ9d_12);
        list.set(i2, qxJ9d_1);
    }

    public final int KQgRr5e_0(List<KQgRr5e_0.QxJ9d_1> list) {
        boolean z = false;
        for (int size = list.size() - 1; size >= 0; size--) {
            if (list.get(size).KQgRr5e_0 != 8) {
                z = true;
            } else if (z) {
                return size;
            }
        }
        return -1;
    }
}
