/*
 * Decompiled with CFR 0.152.
 */
import java.util.Enumeration;
import java.util.Vector;

public final class d
extends iy {
    private static final int[][] j = new int[][]{{0xFFFFFF, 0xFFFFFF, 0xFFFFFF}, {0xFFFFFF, 0xFFFFFF, iy.c[0]}, {0xFFFFFF, iy.c[0], iy.c[1]}};
    private final int[][] A;
    private final int h;
    private final int i;
    private final int k;
    private final int l;
    private final int m;
    private final int n;
    private final int[][] o;
    private final int[] w;
    private final int x;
    private final int y;
    private final int[] z;
    public final w a;
    private boolean B;
    private int C = 0;
    private int D = -1;
    private Vector E;
    private int F = 0;
    private int G;
    public int b;

    public final int a(nj nj2, int n, int n2) {
        this.D = -1;
        return super.a(nj2, n, n2);
    }

    /*
     * Enabled aggressive block sorting
     */
    public final int b(nj nj2, int n, int n2) {
        int n3;
        if (n2 >= this.i) return -1;
        if (nj2.j()) {
            if ((this.G == 1 || this.G == 2) && n < this.h / 2 + 4) {
                if (this.b > 0) {
                    --this.b;
                    this.s();
                    this.B();
                    return -2;
                }
            } else if ((this.G == 0 || this.G == 2) && n > this.r - this.h / 2 - 2 - 2) {
                if (this.b < this.E.size() - 1) {
                    ++this.b;
                    this.s();
                    this.B();
                    return -2;
                }
            } else {
                n2 = a.e(this.C);
                for (n3 = 0; n3 < this.E.size(); ++n3) {
                    if (n > (n2 += this.c(n3) + 4)) {
                        continue;
                    }
                    if (n3 == this.b) return -2;
                    this.b = n3;
                    this.s();
                    this.B();
                    return -2;
                }
            }
        }
        if (nj2.b() || nj2.f()) return -1;
        n2 = a.e(this.C);
        for (n3 = 0; n3 < this.E.size(); ++n3) {
            if (n > (n2 += this.c(n3) + 4)) continue;
            this.D = n3;
            return -2;
        }
        return -1;
    }

    /*
     * Enabled force condition propagation
     * Lifted jumps to return sites
     */
    public final int a(pb pb2) {
        int n = super.a(pb2);
        if (n != -1) return n;
        switch (pb2.c) {
            case 4: {
                if (this.b >= this.E.size() - 1) return -2;
                ++this.b;
                this.s();
                this.B();
                return -2;
            }
            case 3: {
                if (this.b <= 0) return -2;
                --this.b;
                this.s();
                this.B();
                return -2;
            }
        }
        return -1;
    }

    public final void b(ht ht2, int n, int n2) {
        int n3;
        int n4 = ht2.g();
        int n5 = ht2.f();
        int n6 = ht2.h();
        int n7 = ht2.d();
        ht2.b(n, n2, this.r + 1, this.s + 1);
        ht2.a(this.g[iy.d]);
        ht2.c(n, n2 + this.i, this.r, this.s - this.i);
        for (n3 = 0; n3 < iy.d; ++n3) {
            ht2.a(this.g[n3]);
            ht2.d(n + n3, n2 + n3 + this.i, this.r - n3 * 2, this.s - this.i - n3 * 2);
        }
        int n8 = n + a.e(this.C);
        for (int i = 0; i < this.E.size(); ++i) {
            int[] nArray;
            int[][] nArray2;
            int n9 = this.c(i);
            if (i != this.b) {
                if (i != this.D) {
                    ht2.a(this.y);
                    nArray2 = this.A;
                    nArray = this.z;
                } else {
                    ht2.a(this.n);
                    nArray2 = this.o;
                    nArray = this.w;
                }
            } else {
                ht2.a(-1);
                nArray2 = j;
                nArray = this.g;
            }
            ht2.c(n8, n2 + iy.d, n9, this.i - iy.d);
            if (i == this.b) {
                a.a(ht2, this.l, this.m, n8 + iy.d, n2, n9 - iy.d * 2, this.i / 2);
            } else {
                ht2.c(n8 + iy.d, n2, n9 - iy.d * 2, this.i);
            }
            int[] nArray3 = this.g;
            this.a(nArray);
            for (int k = 0; k < 3; ++k) {
                int n10;
                for (n3 = 0; n3 < 3; ++n3) {
                    n10 = nArray2[k][n3];
                    if (n10 == 0xFFFFFF) continue;
                    ht2.a(n10);
                    ht2.c(n8 + n3, n2 + k, 1, 1);
                    ht2.c(n8 + n9 - n3, n2 + k, 1, 1);
                }
                ht2.a(this.g[k]);
                n10 = n2 + iy.d;
                n3 = i == this.b ? 3 - k : 4;
                ht2.e(n8 + k, n10, n8 + k, n10 + this.i - n3);
                ht2.e(n8 + iy.d, n2 + k, n8 + n9 - iy.d, n2 + k);
                ht2.e(n8 + n9 - k, n10, n8 + n9 - k, n10 + this.i - n3);
            }
            if (i == this.b) {
                ht2.a(-1);
                ht2.c(n8 + iy.d, n2 + this.i, n9 - iy.d * 2 + 1, iy.d);
            }
            this.a(nArray3);
            n3 = i != this.b ? 11123394 : 13955839;
            ht2.a(n3);
            ht2.c(n8 + iy.d, n2 + 1, n9 - iy.d * 2, 1);
            n3 = i != this.b ? this.x : this.k;
            this.a.i(n3);
            ht2.a(n3);
            n3 = n8 + (n9 - ((ht)this.E.elementAt(i)).a()) / 2;
            ht2.a(this.a);
            ((ht)this.E.elementAt(i)).a(ht2, n3, n2 + 4);
            if (this.B) {
                if (i > 0 && i == this.b) {
                    this.a(ht2, n8, n2 + this.i, n9, false);
                }
                if (i + 1 < this.E.size() && i == this.b) {
                    this.a(ht2, n8, n2 + this.i, n9, true);
                }
            }
            n8 = n8 + n9 + 4;
        }
        switch (this.G) {
            case 2: {
                this.a(ht2, n, n2, true);
                this.a(ht2, n, n2, false);
                break;
            }
            case 1: {
                this.a(ht2, n, n2, false);
                break;
            }
            case 0: {
                this.a(ht2, n, n2, true);
            }
        }
        ht2.a(n4, n5, n6, n7);
        super.b(ht2, n, n2);
    }

    private void b(ht ht2, int n, int n2, boolean bl2) {
        int n3 = n + 2;
        ht2.a(-1);
        ht2.c(n, n2, this.h / 2 + 4, this.h + 4);
        ht2.a(-16777216);
        ht2.d(n, n2, this.h / 2 + 4, this.h + 4);
        ht2.a(this.g[1]);
        ht2.d(n + 1, n2 + 1, this.h / 2 + 4 - 2, this.h + 4 - 2);
        ht2.a(-14006936);
        int n4 = n2 + this.h / 2 + 2;
        for (n = 0; n < this.h / 2 - 1; ++n) {
            n2 = !bl2 ? n : -n;
            int n5 = n3 + n2;
            n2 = bl2 ? this.h / 2 : 0;
            int n6 = n5 + n2;
            ht2.e(n6, n4 + n, n6, n4 - n);
        }
    }

    private void a(ht ht2, int n, int n2, int n3, boolean bl2) {
        ht2.a(-16777216);
        n3 = !bl2 ? n + iy.d + 2 : n + n3 - iy.d - 2;
        n2 = n2 - this.a.l() / 2 - iy.d;
        for (int i = 0; i < 3; ++i) {
            n = bl2 ? -i : i;
            int n4 = n3 + n;
            ht2.e(n4, n2 + i, n4, n2 - i);
        }
    }

    private void s() {
        int n;
        gm gm2 = ((ht)this.E.elementAt((int)this.b)).a;
        this.j();
        this.d(gm2);
        int n2 = 0;
        int n3 = 0;
        for (n = 0; n < this.E.size(); ++n) {
            if (n < this.b) {
                n2 += 4 + this.c(n);
            }
            n3 += 4 + this.c(n);
        }
        n2 = (n2 + (n2 + this.c(this.b))) / 2;
        if ((n3 -= 4) >= this.r) {
            if (n2 + this.r / 2 < n3) {
                n = Math.max(0, n2 - this.r / 2);
                this.G = n == 0 ? 0 : 2;
            } else {
                n = n3 - this.r;
                this.G = 1;
            }
            n2 = 0;
            for (n3 = 0; n3 < this.E.size(); ++n3) {
                int n4 = this.c(n3);
                if (n < n2 || n >= n2 + n4 + 4) {
                    n2 = n2 + n4 + 4;
                    continue;
                }
                this.F = -n;
                break;
            }
        } else {
            this.F = 0;
            this.G = 3;
        }
        this.t();
    }

    public final void a(int n, int n2) {
        this.f(n, n2);
        for (n = 0; n < this.E.size(); ++n) {
            ((ht)this.E.elementAt((int)n)).a.a(this.x_(), this.c());
        }
    }

    private int c(int n) {
        int n2 = ((ht)this.E.elementAt(n)).a() + iy.d * 2 + 4;
        n = !this.B ? 0 : 8;
        return n2 + n;
    }

    public final Vector e() {
        Vector vector = new Vector();
        Enumeration enumeration = this.E.elements();
        while (enumeration.hasMoreElements()) {
            vector.addElement(enumeration.nextElement());
        }
        return vector;
    }

    public final void a(Vector vector) {
        Vector vector2 = new Vector();
        Enumeration enumeration = vector.elements();
        while (enumeration.hasMoreElements()) {
            vector2.addElement(enumeration.nextElement());
        }
        this.E = vector2;
    }

    private d(int n, int n2, int n3, int n4, w w2, boolean bl2, int n5, int n6, int n7, int n8, int n9, int n10, int n11) {
        super(n, n2, n3, n4);
        this.a = w2;
        this.i = w2.l() + iy.d * 2;
        this.h = this.i - 4;
        this.E = new Vector();
        this.B = bl2;
        this.k = n5;
        this.l = n6;
        this.m = n7;
        this.n = n8;
        this.w = new int[]{n11, n8, n8, n8};
        this.o = new int[][]{{0xFFFFFF, 0xFFFFFF, 0xFFFFFF}, {0xFFFFFF, 0xFFFFFF, this.w[0]}, {0xFFFFFF, this.w[0], this.w[1]}};
        this.x = n9;
        this.y = n10;
        this.z = new int[]{n11, n10, n10, n10};
        this.A = new int[][]{{0xFFFFFF, 0xFFFFFF, 0xFFFFFF}, {0xFFFFFF, 0xFFFFFF, this.z[0]}, {0xFFFFFF, this.z[0], this.z[1]}};
    }

    private void B() {
        gm gm2 = this.a();
        if (gm2 != null) {
            gm gm3 = gm2.r();
            if (gm3 == null) {
                gm2.o();
                return;
            }
            gm3.o();
        }
    }

    public final void c_(int n) {
        super.c_(n);
        int n2 = a.a(this.F);
        if (this.C != n2) {
            this.C = a.a(this.C, n2, n);
            this.t();
        }
    }

    private void a(ht ht2, int n, int n2, boolean bl2) {
        if (bl2) {
            this.b(ht2, n + this.r - this.h / 2 - 2 - 2, n2, bl2);
            return;
        }
        this.b(ht2, n, n2, bl2);
    }

    public final gm a() {
        if (this.m() > 0) {
            return this.h(0);
        }
        return null;
    }

    public final gm d() {
        return ((ht)this.E.elementAt((int)this.b)).a;
    }

    public final int f() {
        return iy.d + this.i;
    }

    public final int c() {
        return this.s - iy.d * 2 - this.i;
    }

    public final int g() {
        return 750;
    }

    public final void a_(int n) {
        this.b = n;
        this.s();
    }

    public d(int n, int n2, int n3, int n4, w w2, boolean bl2) {
        this(n, n2, n3, n4, w2, bl2, -16777216, -6710113, -1, -16621882, -1184275, -6710113, -14006936);
    }
}

