/*
 * Decompiled with CFR 0.152.
 */
/*
 * Duplicate member names - consider using --renamedupmembers true
 */
public final class hx
extends fs {
    private final gh A;
    private final gh B;
    private final gh C;
    private final gh D;
    private final gh E;
    private final gh F;
    private final gh G;
    private final gh H;
    private final gh I;
    private final gh J;
    public final ij c;
    private int a = Integer.MAX_VALUE;
    private int i;
    private int j;
    private int k;
    private boolean k = Integer.MAX_VALUE;
    private boolean m = false;
    private boolean n = false;
    private boolean o = false;
    private boolean w = true;
    private int x;
    private int y;
    private int z;
    public int b;
    public int c;
    public int d = -16777216;
    public int e = -1184275;
    public int f = -3618616;
    public int g = -3618616;
    public int h = 14;

    private void a(int n) {
        this.n(n);
    }

    public final void a(gm gm2, boolean bl2) {
        int n = gm2.p;
        super.d(gm2);
        if (bl2) {
            gm2.j(n);
        }
    }

    private int[] D() {
        ij ij2 = this.c;
        int n = ij2.a.a() - ij2.b.a();
        int n2 = ij2.b.f() - ij2.a.f();
        int n3 = ij2.b.f();
        return new int[]{n, n2, n3};
    }

    public final void d() {
        gh gh2 = this.c.b;
        this.b = gh2.e() << 8;
        this.c = gh2.f() << 8;
    }

    public final int g() {
        return 750;
    }

    private static int f(int n, int n2, int n3, int n4) {
        return n * (n2 - n4) / (n3 - n2);
    }

    private void a(gh gh2, gh gh3) {
        hx.a(gh2, gh3, this.z);
    }

    private void b(gh gh2, gh gh3) {
        hx.a(gh2, gh3, -this.z);
    }

    public final void b(int n, int n2) {
        this.D();
    }

    public String toString() {
        return super.toString();
    }

    public final int h() {
        return this.a;
    }

    public final int i() {
        return this.k;
    }

    public final int a() {
        return Math.max(0, this.c.b.d() - this.h) - this.i * 2;
    }

    public final int r_() {
        return -(this.b >> 8);
    }

    public final int f() {
        return -(this.c >> 8);
    }

    public final boolean a(gh gh2) {
        return this.c.b(gh2);
    }

    public final boolean c(gm gm2) {
        gh gh2 = this.A;
        this.a(gm2, gh2);
        return this.a(gh2);
    }

    public final void b(gm gm2) {
        gh gh2 = this.H;
        this.a(gm2, gh2);
        this.c.a(gh2);
    }

    private void a(ht ht2, int n, int n2, int n3, int n4) {
        ht2.a(this.d);
        ht2.c(n, n2, n3, n4);
    }

    public hx(int n, int n2, int n3, int n4, boolean bl2) {
        this(n, n2, n3, n4, bl2, false);
        this.i = 1;
        this.j = 1;
    }

    public hx(int n, int n2, int n3, int n4, boolean bl2, boolean bl3) {
        super(n, n2, n3, n4);
        this.A = new gh();
        this.B = new gh();
        this.C = new gh();
        this.D = new gh();
        this.E = new gh();
        this.F = new gh();
        this.G = new gh();
        this.H = new gh();
        this.I = new gh();
        this.J = new gh();
        this.c = new ij(1, 2, 3, 4);
        this.c.a(n3, n4);
        n = !bl2 ? 0 : 40;
        this.z = n;
    }

    private int r(int n) {
        int n2 = 0;
        int n3 = this.m();
        for (int i = 0; i < n3; ++i) {
            gm gm2 = this.h(i);
            gm2.a(Math.max(0, n - gm2.p), Integer.MAX_VALUE);
            n2 = Math.max(n2, gm2.w());
        }
        return n2;
    }

    public final void B() {
        if (this.n().w() + this.j < this.s) {
            this.m(this.n().w() + this.j);
        }
    }

    private void C() {
        gm gm2 = this.r();
        if (gm2 != null && gm2 != this) {
            this.b(gm2);
        }
    }

    public final boolean l(gm gm2) {
        this.b(gm2);
        if (!gm2.z()) {
            this.b_();
            return false;
        }
        return true;
    }

    public final int a(nj nj2) {
        if (nj2.d() && this.w) {
            gh gh2 = this.c.b;
            this.x = gh2.e();
            this.y = gh2.f();
            this.o = true;
            return -2;
        }
        return -1;
    }

    public final boolean a(int n, int n2, int n3, int n4) {
        int n5;
        gh gh2 = this.c.b;
        int n6 = n + gh2.e();
        if (this.c.c(n6, n5 = n2 + gh2.f(), n3, n4)) {
            return super.a(n, n2, n3, n4);
        }
        return false;
    }

    private static void a(gh gh2, gh gh3, int n) {
        int n2 = gh2.e() + gh2.d() / 2;
        int n3 = gh2.f() + gh2.b() / 2;
        int n4 = gh2.e() - n;
        int n5 = gh2.f() - n;
        int n6 = gh2.c() + n;
        n = gh2.a() + n;
        n4 = Math.min(n4, n2);
        n2 = Math.max(n6, n2) - n4;
        int n7 = Math.min(n5, n3);
        gh3.a(n4, n7, n2, Math.max(n, n3) - n7);
    }

    private void a(gm gm2, gh gh2) {
        gh2.a = gm2.j(this);
        gh2.b = gm2.k(this);
        gh2.c = gm2.r;
        gh2.d = gm2.s;
        this.d(gh2);
    }

    private void d(gh gh2) {
        gh2.a -= this.r_();
        gh2.b -= this.f();
    }

    public final void b_() {
        gh gh2 = this.J;
        gh2.a(this.c.b);
        gh gh3 = gh2;
        gh3.a += this.r_();
        gh3.b += this.f();
        if (!this.a(gh3.a + gh3.c / 2, gh3.b + gh3.d / 2, false)) {
            this.o();
        }
    }

    public final void d(int n) {
        this.o();
        this.c.b(0, 0);
        this.d();
        gh gh2 = new gh();
        if (this.a(n, gh2, false) && this.a(gh2)) {
            this.a(n, null, true);
        }
    }

    public final void c_(int n) {
        gh gh2 = this.c.b;
        int n2 = gh2.e() << 8;
        int n3 = gh2.f() << 8;
        if (this.b != n2 || this.c != n3) {
            this.b = a.a(this.b, n2, n);
            this.c = a.a(this.c, n3, n);
            this.t();
        }
        super.c_(n);
    }

    public final int c(int n) {
        int n2;
        if (!this.c.a(n)) {
            n2 = this.c.c;
            this.c.c = 20;
            this.c.b(n);
            gh gh2 = this.B;
            this.b(gh2);
            this.d(gh2);
            hx.a(gh2, this.C, -this.z);
            if (!this.a(gh2)) {
                this.b_();
            }
            return -2;
        }
        return -1;
        finally {
            this.c.c = n2;
        }
    }

    public final void a(int n, int n2) {
        if (false && this.r(n) > n2 && this.h != 0) {
            this.r(n - this.h);
        }
        this.f(Math.min(n, this.a), Math.min(n2, this.k));
        this.a();
        this.D();
    }

    public final void s() {
        for (int i = 0; i < this.m(); ++i) {
            gm gm2 = this.h(i);
            if (!gm2.b()) {
                continue;
            }
            this.l(gm2);
            break;
        }
    }

    private void p(int n) {
        this.k = true;
        gm gm2 = this.h(n);
        gm2.j(this.i);
        ++n;
        int n2 = this.m();
        while (true) {
            int n3 = n;
            gm gm3 = gm2;
            if (n3 >= n2) break;
            n = n3 + 1;
            gm2 = this.h(n3);
            gm2.d(this.i, gm3.w() + this.j, gm2.r, gm2.s);
        }
        this.k = false;
    }

    public final void a(gm gm2) {
        if (!this.k) {
            int n = this.g(gm2);
            if (n < this.m() - 1) {
                gm gm3 = this.h(n + 1);
                if (gm2.w() + this.j - gm3.q != 0) {
                    this.p(n);
                }
            }
            this.C();
            this.a();
        }
    }

    public final boolean a(gm gm2, int n) {
        if (n >= 0 && n <= this.m()) {
            if (!this.h(gm2)) {
                if (n > 0) {
                    gm2.k(this.h(n - 1).w() + this.j);
                } else {
                    gm2.k(0);
                }
                gm2.j(this.i);
                if (n < this.m()) {
                    this.h(n).k(gm2.w() + this.j);
                    this.p(n);
                }
                this.C();
                if (super.a(gm2, n)) {
                    this.a();
                }
                if (this.t_() && this.r() == null && this.c(gm2)) {
                    this.l(gm2);
                }
                return true;
            }
            return false;
        }
        throw new IndexOutOfBoundsException();
    }

    public final boolean b_(int n) {
        gm gm2 = this.h(n);
        if (n >= 0) {
            this.k = true;
            int n2 = this.m();
            for (int i = n; i < n2; ++i) {
                gm gm3 = this.h(i);
                gm3.k(gm3.q - (gm2.s + this.j));
            }
            this.k = false;
            gm gm4 = this.r();
            if (super.b_(n)) {
                this.a();
            }
            if (gm4 == gm2) {
                if (this.l()) {
                    this.l(this.h(Math.min(n, this.m() - 1)));
                    return true;
                }
            } else if (gm4 != null && gm4 != this) {
                this.b(gm4);
            }
            return true;
        }
        return false;
    }

    private void D() {
        gh gh2 = this.c.a;
        int n = gh2.d();
        int n2 = gh2.b();
        n = n > this.r ? 1 : 0;
        n2 = n2 > this.s ? 1 : 0;
        if (this.c.a(n2 = n2 != 0 && this.h != 0 ? Math.max(0, this.r - this.h) : this.r, n = n != 0 && this.h != 0 ? Math.max(0, this.s - this.h) : this.s)) {
            n2 = this.c.b.d();
            for (n = 0; n < this.m(); ++n) {
                gm gm2 = this.h(n);
                if (!false) {
                    if (!gm2.u || gm2.r <= this.a()) continue;
                    gm2.l(this.a());
                    continue;
                }
                gm2.l(n2 - gm2.p);
            }
        }
    }

    private void a() {
        int n;
        int n2 = 0;
        int n3 = 0;
        int n4 = 0;
        int n5 = 0;
        for (n = 0; n < this.m(); ++n) {
            gm gm2 = this.h(n);
            n5 = Math.min(n5, gm2.p);
            n4 = Math.min(n4, gm2.q);
            n3 = Math.max(n3, gm2.v());
            n2 = Math.max(n2, gm2.w());
        }
        gh gh2 = this.c.a;
        n = n2 - n4;
        if (gh2.e() != n5 || gh2.f() != n4 || gh2.d() != (n3 -= n5) || gh2.b() != n) {
            this.c.a(n5, n4, n3, n);
            this.D();
        }
    }

    /*
     * WARNING - void declaration
     */
    private void a(ht ht2, int n, int n2, int n3, int n4, boolean bl2) {
        if (bl2) {
            void var6_9;
            int n5;
            int n6 = n2 + 1;
            int n7 = Math.max(1, n4 - 2);
            if (n3 <= 2) {
                n5 = n;
                boolean bl3 = true;
            } else {
                int n8 = n3 - 2;
                n5 = n + 1;
            }
            a.a(ht2, this.e, this.f, n5, n6, (int)var6_9, n7);
        } else {
            void var6_12;
            int n9;
            int n10 = n + 1;
            int n11 = Math.max(1, n3 - 2);
            if (n4 > 2) {
                int n12 = n2 + 1;
                n9 = n4 - 2;
            } else {
                int n13 = n2;
                n9 = 1;
            }
            a.b(ht2, this.e, this.f, n10, (int)var6_12, n11, n9);
        }
        ht2.a(this.g);
        ht2.d(n, n2, n3 - 1, n4 - 1);
    }

    private void a(gm gm2, int[] nArray) {
        ij ij2 = this.c;
        int n = nArray[0];
        int n2 = nArray[1];
        int n3 = nArray[2];
        gm gm3 = this.r();
        if (gm2 != null && gm3 != null) {
            int n4 = gm3.k(this) >= gm2.k(this) ? 0 : 1;
            int n5 = ij2.b.e();
            int n6 = ij2.b.d();
            int n7 = ij2.b.b();
            n4 = n4 == 0 ? ij2.a.f() + n2 : ij2.a.a() - n - n7;
            int n8 = Math.max(Math.min(n4, ij2.a.a() - n7), ij2.a.f());
            ij2.b(n5, n8, n6, n7);
            this.c = (n8 - n3 << 8) + this.c;
            this.b(gm3);
        }
    }

    private void b(oa oa2) {
        gh gh2 = this.D;
        gh gh3 = this.c.b;
        gh gh4 = this.c.a;
        int n = gh3.d();
        int n2 = gh3.b();
        int n3 = gh4.d();
        int n4 = gh4.b();
        gh2.a = gh3.e();
        gh2.b = gh3.f();
        gh2.c = n;
        gh2.d = n2;
        if (this.m) {
            gh2.b = (oa2.b << 8) / n2 * (n4 - n2) >> 8;
        }
        if (this.n) {
            gh2.a = (oa2.a << 8) / n * (n3 - n) >> 8;
        }
        this.c.a(gh2);
    }

    public final void b(ht ht2, int n, int n2) {
        gh gh2 = this.c.b;
        gh gh3 = this.c.a;
        int n3 = gh2.e();
        int n4 = gh2.f();
        int n5 = gh2.d();
        int n6 = gh2.b();
        int n7 = gh3.d();
        int n8 = gh3.b();
        int n9 = ht2.g();
        int n10 = ht2.f();
        int n11 = ht2.h();
        int n12 = ht2.d();
        ht2.b(n, n2, n5, n6);
        super.b(ht2, n, n2);
        ht2.a(n9, n10, n11, n12);
        if (this.h != 0) {
            if (n8 > n6) {
                int n13 = n + this.r - this.h;
                this.a(ht2, n13, n2, this.h, this.s);
                n9 = n13;
                n10 = n6 * n6 / n8;
                this.a(ht2, n9, n2 + hx.f(n4, n6, n8, n10), this.h, n10, false);
            }
            if (n7 > n5) {
                n2 = n2 + this.s - this.h;
                this.a(ht2, n, n2, this.r, this.h);
                n4 = n5 * n5 / n7;
                this.a(ht2, n + hx.f(n3, n5, n7, n4), n2, n4, this.h, true);
            }
        }
    }

    /*
     * Enabled aggressive block sorting
     */
    public final int b(nj nj2, int n, int n2) {
        oa oa2;
        block20: {
            block17: {
                block18: {
                    block19: {
                        oa2 = new oa(n, n2);
                        if (nj2.d()) break block18;
                        if (!nj2.c()) break block19;
                        if (!this.l()) break block17;
                        if (this.h == 0 || !this.n && !this.m) {
                            if (this.o) {
                                oa2 = nj2.d;
                                gh gh2 = this.c.b;
                                this.I.a = this.x + oa2.a;
                                this.I.b = this.y + oa2.b;
                                this.I.c = gh2.d();
                                this.I.d = gh2.b();
                                this.c.a(this.I);
                            }
                            break block17;
                        } else {
                            this.b(oa2);
                            return -2;
                        }
                    }
                    if (!nj2.e()) {
                        if (nj2.k()) {
                            return this.c(1);
                        }
                        if (nj2.l()) {
                            return this.c(2);
                        }
                        break block17;
                    } else {
                        this.m = false;
                        this.n = false;
                        this.o = false;
                    }
                    break block17;
                }
                this.m = false;
                this.n = false;
                this.o = false;
                if (!this.l() || this.h == 0) break block17;
                if (n > this.r - this.h && this.c.k()) {
                    this.m = true;
                } else if (n2 > this.s - this.h && this.c.h()) {
                    this.n = true;
                }
                if (this.n || this.m) break block20;
            }
            if (nj2.i()) {
                gm gm2 = this.r();
                int[] nArray = this.D();
                this.a(n, n2, true);
                if (gm2 != this.r()) {
                    this.a(gm2, nArray);
                }
            }
            return -1;
        }
        this.b(oa2);
        return -2;
    }

    public final int a(pb pb2) {
        int n;
        int[] nArray;
        gm gm2;
        block25: {
            gm2 = this.r();
            nArray = this.D();
            n = super.a(pb2);
            if (n == -1) {
                int n2 = !false ? pb2.c : pb2.d;
                switch (n2) {
                    case 10: {
                        n2 = !this.c.a(4) ? 4 : 2;
                        n = 0;
                        break;
                    }
                    case 9: {
                        n2 = this.c.a(3) ? 1 : 3;
                        n = 0;
                        break;
                    }
                    case 18: {
                        n = 1;
                        n2 = 4;
                        break;
                    }
                    case 17: {
                        n2 = 3;
                        n = 1;
                        break;
                    }
                    case 16: {
                        n2 = 2;
                        n = 1;
                        break;
                    }
                    case 15: {
                        n = 1;
                        n2 = 1;
                        break;
                    }
                    default: {
                        n = -1;
                        break block25;
                    }
                    case 1: 
                    case 2: 
                    case 3: 
                    case 4: {
                        n = 0;
                    }
                }
                if (n == 0) {
                    gh gh2 = this.E;
                    gh gh3 = this.F;
                    gh gh4 = this.G;
                    this.b(gh2);
                    this.d(gh2);
                    if (!this.c.b(gh2)) {
                        this.b_();
                        this.b(gh2);
                        this.d(gh2);
                    }
                    this.b(gh2, gh4);
                    if (!this.c.a(gh4, n2)) {
                        if (this.a(n2, gh2)) {
                            this.b(gh2, gh4);
                            this.a(gh2, gh3);
                            if (!this.c.b(gh4)) {
                                if (this.c.a(gh4, n2)) {
                                    this.c.a(n2, gh3);
                                    if (!this.c.a(gh4, n2)) {
                                        this.a(n2);
                                    }
                                } else {
                                    this.c.a(gh3);
                                    this.a(n2);
                                }
                            } else {
                                this.c.a(n2, gh3);
                                this.a(n2);
                            }
                            n = -2;
                        } else if (!this.c.a(n2)) {
                            n = -2;
                            this.c.b(n2);
                        } else {
                            n = -1;
                        }
                    } else {
                        n = -2;
                        this.a(gh2, gh3);
                        this.c.a(n2, gh3);
                    }
                } else {
                    n = this.c(n2);
                }
            }
        }
        if (gm2 != this.r()) {
            this.a(gm2, nArray);
        }
        return n;
    }
}

