// File: /workspace/github_cpp_makefile_star2_O1/phillip-h[P]fractal-gen/fractalgen.cpp
// Function: main
int main(int argc, char** argv)
{
    if (argc < 4) {
        cout << "too few arguments!\n";
        cout << "usage: fractal-gen <width> <height> <scale>\n";
        cout << "                   ";
        cout << "[color A] [color B] [color C]\n";
        cout << "                   ";
        cout << "[cr+ci] [color depth] [offx] [offy]\n";
        return -1;
    }
    
    unsigned width = atoi(argv[1]);
    unsigned height = atoi(argv[2]);
    double size = atof(argv[3]); 
    unsigned color_depth = 255;
    double offx = -0.5;
    double offy = 0.0;
    bool mandel = true;
    complex c_arg(0, 0);
    auto file = "fractal.png";

    auto A_R = 0;
    auto A_G = 0;
    auto A_B = 0;

    auto B_R = 255;
    auto B_G = 255;
    auto B_B = 255;

    auto D_R = 0;
    auto D_G = 0;
    auto D_B = 0;

    if (argc > 4) {
        std::string str(argv[4]);
        if (str.at(0) == '#')
            str = str.substr(1, str.size() - 1);
        if (str.size() != 6) {
            cout << "error -- invalid color!\n";
            cout << "express colors as '#RRGGBB'.\n";
            return -1;
        }

        std::string sub_str = str.substr(0, 2);
        A_R = htoi(sub_str);

        sub_str = str.substr(2, 2);
        A_G = htoi(sub_str);
        
        sub_str = str.substr(4, 2);
        A_B = htoi(sub_str);
    }

    if (argc > 5) {
        std::string str(argv[5]);
        if (str.at(0) == '#')
            str = str.substr(1, str.size() - 1);
        if (str.size() != 6) {
            cout << "error -- invalid color!\n";
            cout << "express colors as '#RRGGBB'.\n";
            return -1;
        }

        std::string sub_str = str.substr(0, 2);
        B_R = htoi(sub_str);

        sub_str = str.substr(2, 2);
        B_G = htoi(sub_str);
        
        sub_str = str.substr(4, 2);
        B_B = htoi(sub_str);
    }
    
    if (argc > 6) {
        std::string str(argv[6]);
        if (str.at(0) == '#')
            str = str.substr(1, str.size() - 1);
        if (str.size() != 6) {
            cout << "error -- invalid color!\n";
            cout << "express colors as '#RRGGBB'.\n";
            return -1;
        }

        std::string sub_str = str.substr(0, 2);
        D_R = htoi(sub_str);

        sub_str = str.substr(2, 2);
        D_G = htoi(sub_str);
        
        sub_str = str.substr(4, 2);
        D_B = htoi(sub_str);
    }

    if (argc > 7 && std::string(argv[7]) != "mandelbrot") {
        mandel = false;
        offx = 0;
        offy = 0;
        std::string str(argv[7]);
        unsigned pos = 0;
        for (unsigned i = 0; i < str.size(); i++)
        {
            if (str.at(i) == '+') {
                pos = i + 1;
                break;
            }
        }
        if (pos == 0) {
            cout << "invalid complex argument!\n";
            return -1;
        }
        double real = atof(str.substr(0, pos - 1).c_str());
        double imag = atof(str.substr(pos, str.size() - pos).c_str());
        c_arg = complex(real, imag);
    }

    if (argc > 8)
        color_depth = atof(argv[8]);
    if (argc > 9)
        offx = atof(argv[9]);
    if (argc > 10)
        offy = atof(argv[10]);
    if (argc > 11)
        cout << "warning -- extra arguments, ignoring them.\n";

    cout << "fractal information:\n\n";
    
    if (mandel) {
        cout << "fractal type -- mandelbrot\n";
    } else {
        cout << "fractal type -- julia\n";
        cout << "complex argument -- " << c_arg.to_str() << "\n";
    }

    cout << "\n";
    cout << "width       -- " << width << "\n";
    cout << "height      -- " << height << "\n";
    cout << "pixels      -- " << (width * height * 4) << "\n";
    cout << "scale       -- " << size << "\n";
    cout << "color A     -- (";
    cout << A_R << ", " << A_G << ", " << A_B << ")\n";
    cout << "color B     -- (";
    cout << B_R << ", " << B_G << ", " << B_B << ")\n";
    cout << "color C     -- (";
    cout << D_R << ", " << D_G << ", " << D_B << ")\n";
    cout << "color depth -- " << color_depth << "\n";
    cout << "offx        -- " << offx << "\n";
    cout << "offy        -- " << offy << "\n";

    vector<unsigned char> image(width * height * 4);

    auto lerp = [&] (double x0, double y0,
                    double x1, double y1,
                    double t)
    {
        double m = (y1 - y0) / (x1 - x0);
        return y0 + t * m;
    };

    auto comp_color_r = [&] (unsigned val)
    {
        if (val == color_depth)
            return D_R;
        double rat = (double) val / color_depth;
        double dc = lerp(0, A_R, 1, B_R, rat);
        return (int) dc;
    };

    auto comp_color_g = [&] (unsigned val)
    {
        if (val == color_depth)
            return D_G;
        double rat = (double) val / color_depth;
        double dc = lerp(0, A_G, 1, B_G, rat);
        return (int) dc;
    };

    auto comp_color_b = [&] (unsigned val)
    {
        if (val == color_depth)
            return D_B;
        double rat = (double) val / color_depth;
        double dc = lerp(0, A_B, 1, B_B, rat);
        return (int) dc;
    };

    double r;
    double i;
    complex c;
    unsigned color;
    for (unsigned x = 0; x < width; x++)
    {
        for (unsigned y = 0; y < height; y++)
        {
            r = offx - size / 2 + size * x / width;
            i = offy - size / 2 + size * y / height;
            c = complex(r, i);
            if (mandel)
                color = eval(c, color_depth, c);
            else
                color = eval(c, color_depth, c_arg);
            set_pixel(comp_color_r(color),
                      comp_color_g(color),
                      comp_color_b(color), 
                      x, y, image, height);
        }
    }

    unsigned error = lodepng::encode(file, image, width, height);
    if (error)
        cout << "error -- " << lodepng_error_text(error) << std::endl;
    
    return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
cmpl $0x3, %edi
jg 0x2776
movq 0x148e4(%rip), %rbx     # 0x16fd8
leaq 0xe940(%rip), %rsi      # 0x1103b
movl $0x13, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0xe940(%rip), %rsi      # 0x1104f
movl $0x2c, %edx
movq %rbx, %rdi
callq 0x2190
leaq 0xe959(%rip), %r14      # 0x1107c
movl $0x13, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xe956(%rip), %rsi      # 0x11090
movl $0x1e, %edx
movq %rbx, %rdi
callq 0x2190
movl $0x13, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xe951(%rip), %rsi      # 0x110af
movl $0x24, %edx
movq %rbx, %rdi
callq 0x2190
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
jmp 0x3a20
movq %rsi, %rbx
movl %edi, %r13d
movq 0x8(%rsi), %rdi
callq 0x2230
movl %eax, 0x3c(%rsp)
movq 0x10(%rbx), %rdi
callq 0x2230
movl %eax, 0x2c(%rsp)
movq %rbx, 0x30(%rsp)
movq 0x18(%rbx), %rdi
callq 0x21d0
vmovsd %xmm0, 0xd8(%rsp)
movl $0x0, 0x68(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
vmovapd %xmm0, 0xf0(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, 0x58(%rsp)
movl $0x0, %r14d
cmpl $0x4, %r13d
je 0x2a6a
movq 0x30(%rsp), %rax
movq 0x20(%rax), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2080
movq 0x78(%rsp), %rcx
testq %rcx, %rcx
je 0x3a35
movq 0x70(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x284d
decq %rcx
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x2160
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x21c0
movq (%rbx), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x284d
callq 0x2120
movq 0x78(%rsp), %r12
cmpq $0x6, %r12
jne 0x29fc
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %ecx
xorl %edx, %edx
callq 0x2160
leaq 0x248(%rsp), %r14
movq %r14, -0x10(%r14)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x238(%rsp), %rdi
callq 0x3f4a
leaq 0x238(%rsp), %rdi
callq 0x25a7
movl %eax, %ebx
movq 0x238(%rsp), %rdi
cmpq %r14, %rdi
je 0x28b9
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %edx
movl $0x2, %ecx
callq 0x2160
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r14
movq %r14, %rsi
callq 0x21c0
movq (%r14), %rdi
leaq 0xc0(%rsp), %rbp
cmpq %rbp, %rdi
je 0x28ff
callq 0x2120
leaq 0x228(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x218(%rsp), %rdi
callq 0x3f4a
leaq 0x218(%rsp), %rdi
callq 0x25a7
movl %eax, %r14d
movq 0x218(%rsp), %rdi
cmpq %r15, %rdi
je 0x2947
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x4, %edx
movl $0x2, %ecx
callq 0x2160
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x21c0
movq (%r15), %rdi
cmpq %rbp, %rdi
je 0x2985
callq 0x2120
leaq 0x208(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1f8(%rsp), %rdi
callq 0x3f4a
leaq 0x1f8(%rsp), %rdi
callq 0x25a7
movl %eax, %r15d
movq 0x1f8(%rsp), %rdi
cmpq %rbp, %rdi
je 0x29cd
callq 0x2120
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x29e0
callq 0x2120
movzbl %bl, %eax
movl %eax, 0x58(%rsp)
movzbl %r14b, %eax
movl %eax, 0x60(%rsp)
movzbl %r15b, %eax
movl %eax, 0x68(%rsp)
xorl %r14d, %r14d
jmp 0x2a4a
movq 0x145d5(%rip), %rdi     # 0x16fd8
leaq 0xe6d6(%rip), %rsi      # 0x110e0
movl $0x18, %edx
callq 0x2190
movq 0x145bd(%rip), %rdi     # 0x16fd8
leaq 0xe6d7(%rip), %rsi      # 0x110f9
movl $0x1d, %edx
callq 0x2190
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x0, 0x68(%rsp)
movl $0x0, 0x60(%rsp)
movl $0x0, 0x58(%rsp)
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2a60
callq 0x2120
cmpq $0x6, %r12
jne 0x3a20
movl $0xff, 0x40(%rsp)
cmpl $0x6, %r13d
jl 0x2ca2
movq 0x30(%rsp), %rax
movq 0x28(%rax), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2080
movq 0x78(%rsp), %rcx
testq %rcx, %rcx
je 0x3a48
movq 0x70(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x2ae7
decq %rcx
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x2160
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x21c0
movq (%rbx), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2ae7
callq 0x2120
movq 0x78(%rsp), %rbx
cmpq $0x6, %rbx
jne 0x2cba
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %ecx
xorl %edx, %edx
callq 0x2160
leaq 0x1e8(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1d8(%rsp), %rdi
callq 0x3f4a
leaq 0x1d8(%rsp), %rdi
callq 0x25a7
movl %eax, %ebp
movq 0x1d8(%rsp), %rdi
cmpq %r15, %rdi
je 0x2b53
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %edx
movl $0x2, %ecx
callq 0x2160
movb %bpl, 0x40(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x21c0
movq (%r15), %rdi
leaq 0xc0(%rsp), %rbp
cmpq %rbp, %rdi
je 0x2b9e
callq 0x2120
leaq 0x1c8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1b8(%rsp), %rdi
callq 0x3f4a
leaq 0x1b8(%rsp), %rdi
callq 0x25a7
movl %eax, %r15d
movq 0x1b8(%rsp), %rdi
cmpq %r12, %rdi
je 0x2be7
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x4, %edx
movl $0x2, %ecx
callq 0x2160
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r12
movq %r12, %rsi
callq 0x21c0
movq (%r12), %rdi
cmpq %rbp, %rdi
je 0x2c26
callq 0x2120
leaq 0x1a8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x3f4a
leaq 0x198(%rsp), %rdi
callq 0x25a7
movl %eax, %r12d
movq 0x198(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2c6e
callq 0x2120
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2c81
callq 0x2120
movzbl 0x40(%rsp), %eax
movl %eax, 0xa0(%rsp)
movzbl %r15b, %eax
movl %eax, 0xa8(%rsp)
movzbl %r12b, %eax
movl %eax, 0x40(%rsp)
jmp 0x2d0e
movl $0xff, 0xa8(%rsp)
movl $0xff, 0xa0(%rsp)
jmp 0x2d2e
movq 0x14317(%rip), %rdi     # 0x16fd8
leaq 0xe418(%rip), %rsi      # 0x110e0
movl $0x18, %edx
callq 0x2190
movq 0x142ff(%rip), %rdi     # 0x16fd8
leaq 0xe419(%rip), %rsi      # 0x110f9
movl $0x1d, %edx
callq 0x2190
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0xff, 0x40(%rsp)
movl $0xff, 0xa8(%rsp)
movl $0xff, 0xa0(%rsp)
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2d24
callq 0x2120
cmpq $0x6, %rbx
jne 0x3a20
movl $0x0, 0x28(%rsp)
cmpl $0x7, %r13d
jl 0x2f60
movq 0x30(%rsp), %rax
movq 0x30(%rax), %rsi
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rdx
callq 0x2080
movq 0x78(%rsp), %rcx
testq %rcx, %rcx
je 0x3a5b
movq 0x70(%rsp), %rax
cmpb $0x23, (%rax)
jne 0x2dab
decq %rcx
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x1, %edx
callq 0x2160
leaq 0x70(%rsp), %rdi
leaq 0x8(%rsp), %rbx
movq %rbx, %rsi
callq 0x21c0
movq (%rbx), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x2dab
callq 0x2120
movq 0x78(%rsp), %rbx
cmpq $0x6, %rbx
jne 0x2f72
leaq 0x8(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %ecx
xorl %edx, %edx
callq 0x2160
leaq 0x188(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x178(%rsp), %rdi
callq 0x3f4a
leaq 0x178(%rsp), %rdi
callq 0x25a7
movl %eax, %ebp
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x2e17
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x2, %edx
movl $0x2, %ecx
callq 0x2160
movb %bpl, 0x28(%rsp)
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r15
movq %r15, %rsi
callq 0x21c0
movq (%r15), %rdi
leaq 0xc0(%rsp), %rbp
cmpq %rbp, %rdi
je 0x2e62
callq 0x2120
leaq 0x168(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x158(%rsp), %rdi
callq 0x3f4a
leaq 0x158(%rsp), %rdi
callq 0x25a7
movl %eax, %r15d
movq 0x158(%rsp), %rdi
cmpq %r12, %rdi
je 0x2eab
callq 0x2120
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
movl $0x4, %edx
movl $0x2, %ecx
callq 0x2160
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %r12
movq %r12, %rsi
callq 0x21c0
movq (%r12), %rdi
cmpq %rbp, %rdi
je 0x2eea
callq 0x2120
leaq 0x148(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
addq %rsi, %rdx
leaq 0x138(%rsp), %rdi
callq 0x3f4a
leaq 0x138(%rsp), %rdi
callq 0x25a7
movl %eax, %r12d
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x2f32
callq 0x2120
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2f45
callq 0x2120
movzbl 0x28(%rsp), %eax
movl %eax, 0x4c(%rsp)
movzbl %r15b, %eax
movl %eax, 0x50(%rsp)
movzbl %r12b, %eax
movl %eax, 0x28(%rsp)
jmp 0x2fc0
movl $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
jmp 0x2fe0
movq 0x1405f(%rip), %rdi     # 0x16fd8
leaq 0xe160(%rip), %rsi      # 0x110e0
movl $0x18, %edx
callq 0x2190
movq 0x14047(%rip), %rdi     # 0x16fd8
leaq 0xe161(%rip), %rsi      # 0x110f9
movl $0x1d, %edx
callq 0x2190
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movl $0x0, 0x28(%rsp)
movl $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x2fd6
callq 0x2120
cmpq $0x6, %rbx
jne 0x3a20
cmpl $0x8, %r13d
jl 0x301e
movq 0x30(%rsp), %rax
movq 0x38(%rax), %rsi
leaq 0x70(%rsp), %r12
leaq 0x97(%rsp), %rdx
movq %r12, %rdi
callq 0x2080
leaq 0xe10c(%rip), %rsi      # 0x11117
movq %r12, %rdi
callq 0x2050
testl %eax, %eax
setne %al
movl %eax, 0x54(%rsp)
jmp 0x3026
movl $0x0, 0x54(%rsp)
cmpl $0x8, %r13d
jl 0x3042
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3042
callq 0x2120
cmpb $0x0, 0x54(%rsp)
je 0x3143
movq 0x30(%rsp), %rax
movq 0x38(%rax), %rsi
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
callq 0x2080
movq 0x10(%rsp), %rax
testq %rax, %rax
je 0x308d
movl $0x1, %ebx
movq 0x8(%rsp), %rcx
xorl %edx, %edx
cmpb $0x2b, (%rcx,%rdx)
je 0x308f
movl %ebx, %edx
incl %ebx
cmpq %rdx, %rax
ja 0x307e
xorl %ebx, %ebx
testl %ebx, %ebx
je 0x3156
leal -0x1(%rbx), %ecx
leaq 0xb0(%rsp), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x2160
leaq 0xc0(%rsp), %r15
movq -0x10(%r15), %r12
movq %r12, %rdi
callq 0x21d0
vmovsd %xmm0, 0xe8(%rsp)
cmpq %r15, %r12
je 0x30d8
movq %r12, %rdi
callq 0x2120
movl %ebx, %edx
leaq 0x8(%rsp), %rsi
movq 0x8(%rsi), %rcx
subq %rdx, %rcx
leaq 0xb0(%rsp), %rdi
callq 0x2160
movq 0xb0(%rsp), %r12
movq %r12, %rdi
callq 0x21d0
vmovapd %xmm0, %xmm1
cmpq %r15, %r12
je 0x3126
movq %r12, %rdi
vmovsd %xmm1, 0xe0(%rsp)
callq 0x2120
vmovsd 0xe0(%rsp), %xmm1
vmovsd 0xe8(%rsp), %xmm0
vmovsd %xmm0, 0xf0(%rsp)
vmovsd %xmm1, 0xf8(%rsp)
jmp 0x3174
vmovsd 0xdec5(%rip), %xmm0     # 0x11010
vmovsd %xmm0, 0x98(%rsp)
jmp 0x319c
movl $0xffffffff, %r14d      # imm = 0xFFFFFFFF
movq 0x13e75(%rip), %rdi     # 0x16fd8
leaq 0xdfb8(%rip), %rsi      # 0x11122
movl $0x1a, %edx
callq 0x2190
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3187
callq 0x2120
vxorpd %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0x98(%rsp)
testl %ebx, %ebx
je 0x3a20
movl $0xff, %r15d
cmpl $0x9, %r13d
movq 0x30(%rsp), %r14
jl 0x31bc
movq 0x40(%r14), %rdi
callq 0x21d0
vcvttsd2usi %xmm0, %r15d
cmpl $0xa, %r13d
movl 0x3c(%rsp), %ebx
movl 0x2c(%rsp), %ebp
jl 0x31dc
movq 0x48(%r14), %rdi
callq 0x21d0
vmovsd %xmm0, 0x98(%rsp)
vxorpd %xmm0, %xmm0, %xmm0
vmovsd %xmm0, 0xd0(%rsp)
cmpl $0xb, %r13d
jl 0x3201
movq 0x50(%r14), %rdi
callq 0x21d0
vmovsd %xmm0, 0xd0(%rsp)
cmpl $0xc, %r13d
jl 0x321f
movq 0x13dca(%rip), %rdi     # 0x16fd8
leaq 0xdf28(%rip), %rsi      # 0x1113d
movl $0x2b, %edx
callq 0x2190
movq 0x13db2(%rip), %rdi     # 0x16fd8
leaq 0xdf3c(%rip), %rsi      # 0x11169
movl $0x16, %edx
callq 0x2190
cmpb $0x0, 0x54(%rsp)
je 0x32c8
movq 0x13d8f(%rip), %r14     # 0x16fd8
leaq 0xdf4c(%rip), %rsi      # 0x1119c
movl $0x16, %edx
movq %r14, %rdi
callq 0x2190
leaq 0xdf4f(%rip), %rsi      # 0x111b3
movl $0x14, %edx
movq %r14, %rdi
callq 0x2190
leaq 0x8(%rsp), %r12
leaq 0xf0(%rsp), %rsi
movq %r12, %rdi
callq 0x3bc0
movq (%r12), %rsi
movq 0x8(%r12), %rdx
movq %r14, %rdi
callq 0x2190
leaq 0xdee0(%rip), %rsi      # 0x1117e
movl $0x1, %edx
movq %rax, %rdi
callq 0x2190
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movl 0x3c(%rsp), %ebx
movl 0x2c(%rsp), %ebp
je 0x32e0
callq 0x2120
jmp 0x32e0
movq 0x13d09(%rip), %rdi     # 0x16fd8
leaq 0xdeaa(%rip), %rsi      # 0x11180
movl $0x1b, %edx
callq 0x2190
movq 0x13cf1(%rip), %r13     # 0x16fd8
leaq 0xde90(%rip), %r14      # 0x1117e
movl $0x1, %edx
movq %r13, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xdec3(%rip), %rsi      # 0x111c8
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movl %ebx, %esi
movq %r13, %rdi
callq 0x20c0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xdea5(%rip), %rsi      # 0x111d8
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movl %ebp, %esi
movq %r13, %rdi
callq 0x20c0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xde87(%rip), %rsi      # 0x111e8
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movl %ebx, %esi
imull %ebp, %esi
shll $0x2, %esi
movq %rsi, 0x30(%rsp)
movq %r13, %rdi
callq 0x20c0
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xde5e(%rip), %rsi      # 0x111f8
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
vmovsd 0xd8(%rsp), %xmm0
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xde39(%rip), %rsi      # 0x11208
movl $0x10, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
movl 0x58(%rsp), %esi
callq 0x2280
movq %rax, %r14
leaq 0xde27(%rip), %r12      # 0x11219
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0x60(%rsp), %esi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0x68(%rsp), %esi
callq 0x2280
leaq 0xdde8(%rip), %rbp      # 0x1121c
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
leaq 0xddd4(%rip), %rsi      # 0x1121f
movl $0x10, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
movl 0xa0(%rsp), %esi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0xa8(%rsp), %esi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0x40(%rsp), %esi
callq 0x2280
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
leaq 0xdd71(%rip), %rsi      # 0x11230
movl $0x10, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
movl 0x4c(%rsp), %esi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0x50(%rsp), %esi
callq 0x2280
movq %rax, %r14
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x2190
movq %r14, %rdi
movl 0x28(%rsp), %esi
callq 0x2280
movl $0x2, %edx
movq %rax, %rdi
movq %rbp, %rsi
callq 0x2190
leaq 0xdd14(%rip), %rsi      # 0x11241
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movl %r15d, %esi
movq %r13, %rdi
callq 0x20c0
movl $0x1, %edx
movq %rax, %rdi
leaq 0xdc2a(%rip), %r14      # 0x1117e
movq %r14, %rsi
callq 0x2190
leaq 0xdcee(%rip), %rsi      # 0x11251
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
vmovsd 0x98(%rsp), %xmm0
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xdcc9(%rip), %rsi      # 0x11261
movl $0xf, %edx
movq %r13, %rdi
callq 0x2190
movq %r13, %rdi
vmovsd 0xd0(%rsp), %xmm0
callq 0x2240
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x2190
leaq 0xb0(%rsp), %rdi
leaq 0x8(%rsp), %rdx
movq 0x30(%rsp), %rsi
callq 0x3e2e
testl %ebx, %ebx
je 0x3923
vcvtusi2sdl 0x3c(%rsp), %xmm1, %xmm0
vmovsd %xmm0, 0x110(%rsp)
vcvtusi2sdl 0x2c(%rsp), %xmm1, %xmm0
vmovsd %xmm0, 0xe8(%rsp)
vcvtusi2sd %r15d, %xmm1, %xmm0
vmovsd %xmm0, 0xe0(%rsp)
movl 0x58(%rsp), %eax
vcvtsi2sd %eax, %xmm1, %xmm0
vmovsd %xmm0, 0x130(%rsp)
movl 0xa0(%rsp), %ecx
subl %eax, %ecx
vcvtsi2sd %ecx, %xmm1, %xmm0
vmovsd %xmm0, 0xa0(%rsp)
vmovsd 0xd8(%rsp), %xmm0
vmulsd 0xd9ca(%rip), %xmm0, %xmm0 # 0x11018
movl 0x60(%rsp), %eax
vcvtsi2sd %eax, %xmm1, %xmm1
vmovsd %xmm1, 0x128(%rsp)
movl 0xa8(%rsp), %ecx
subl %eax, %ecx
vcvtsi2sd %ecx, %xmm2, %xmm1
vmovsd %xmm1, 0x120(%rsp)
vmovsd 0x98(%rsp), %xmm1
vsubsd %xmm0, %xmm1, %xmm1
vmovsd %xmm1, 0x108(%rsp)
movl 0x68(%rsp), %eax
vcvtsi2sd %eax, %xmm2, %xmm1
vmovsd %xmm1, 0x98(%rsp)
movl 0x40(%rsp), %ecx
subl %eax, %ecx
vcvtsi2sd %ecx, %xmm2, %xmm1
vmovsd %xmm1, 0x118(%rsp)
vmovsd 0xd0(%rsp), %xmm1
vsubsd %xmm0, %xmm1, %xmm0
vmovsd %xmm0, 0xd0(%rsp)
xorl %r14d, %r14d
movl $0xff, %ebp
leaq 0xb0(%rsp), %r13
cmpl $0x0, 0x2c(%rsp)
je 0x3915
vcvtusi2sd %r14d, %xmm6, %xmm0
vmulsd 0xd8(%rsp), %xmm0, %xmm0
vdivsd 0x110(%rsp), %xmm0, %xmm0
vaddsd 0x108(%rsp), %xmm0, %xmm0
vmovsd %xmm0, 0x68(%rsp)
xorl %r12d, %r12d
vcvtusi2sd %r12d, %xmm6, %xmm0
vmulsd 0xd8(%rsp), %xmm0, %xmm0
vdivsd 0xe8(%rsp), %xmm0, %xmm0
vaddsd 0xd0(%rsp), %xmm0, %xmm2
cmpb $0x0, 0x54(%rsp)
je 0x37ed
testl %r15d, %r15d
je 0x3882
vmovsd 0xf0(%rsp), %xmm3
vmovsd 0xf8(%rsp), %xmm4
xorl %ebx, %ebx
vmovsd 0x68(%rsp), %xmm1
vmovsd %xmm3, 0x40(%rsp)
vmovsd %xmm4, 0xa8(%rsp)
vmulsd %xmm2, %xmm2, %xmm5
vmovapd %xmm1, %xmm0
vfmadd213sd %xmm5, %xmm1, %xmm0 # xmm0 = (xmm1 * xmm0) + xmm5
vucomisd 0xd8a3(%rip), %xmm0     # 0x11020
jb 0x3785
vsqrtsd %xmm0, %xmm0, %xmm0
jmp 0x37bd
vmovsd %xmm2, 0x30(%rsp)
vmovsd %xmm1, 0x60(%rsp)
vmovsd %xmm5, 0x58(%rsp)
callq 0x20f0
vmovsd 0x58(%rsp), %xmm5
vmovsd 0x60(%rsp), %xmm1
vmovsd 0xa8(%rsp), %xmm4
vmovsd 0x40(%rsp), %xmm3
vmovsd 0x30(%rsp), %xmm2
vucomisd 0xd843(%rip), %xmm0     # 0x11008
ja 0x3884
vfmsub231sd %xmm1, %xmm1, %xmm5 # xmm5 = (xmm1 * xmm1) - xmm5
vmulsd %xmm1, %xmm2, %xmm0
vfmadd231sd %xmm1, %xmm2, %xmm0 # xmm0 = (xmm2 * xmm1) + xmm0
vaddsd %xmm5, %xmm3, %xmm1
vaddsd %xmm0, %xmm4, %xmm2
incl %ebx
cmpl %ebx, %r15d
jne 0x3768
jmp 0x387d
testl %r15d, %r15d
je 0x3882
xorl %ebx, %ebx
vmovapd %xmm2, %xmm1
vmovsd 0x68(%rsp), %xmm3
vmovsd %xmm2, 0x30(%rsp)
vmulsd %xmm1, %xmm1, %xmm4
vmovapd %xmm3, %xmm0
vfmadd213sd %xmm4, %xmm3, %xmm0 # xmm0 = (xmm3 * xmm0) + xmm4
vucomisd 0xd803(%rip), %xmm0     # 0x11020
jb 0x3825
vsqrtsd %xmm0, %xmm0, %xmm0
jmp 0x3854
vmovsd %xmm1, 0x60(%rsp)
vmovsd %xmm3, 0x58(%rsp)
vmovsd %xmm4, 0x40(%rsp)
callq 0x20f0
vmovsd 0x40(%rsp), %xmm4
vmovsd 0x58(%rsp), %xmm3
vmovsd 0x60(%rsp), %xmm1
vmovsd 0x30(%rsp), %xmm2
vucomisd 0xd7ac(%rip), %xmm0     # 0x11008
ja 0x3884
vfmsub231sd %xmm3, %xmm3, %xmm4 # xmm4 = (xmm3 * xmm3) - xmm4
vmulsd %xmm3, %xmm1, %xmm0
vfmadd231sd %xmm3, %xmm1, %xmm0 # xmm0 = (xmm1 * xmm3) + xmm0
vaddsd 0x68(%rsp), %xmm4, %xmm3
vaddsd %xmm0, %xmm2, %xmm1
incl %ebx
cmpl %ebx, %r15d
jne 0x3808
movl %r15d, %ebx
jmp 0x3884
xorl %ebx, %ebx
cmpl %r15d, %ebx
cmovael %r15d, %ebx
vcvtusi2sd %ebx, %xmm6, %xmm0
vdivsd 0xe0(%rsp), %xmm0, %xmm0
vmovsd 0xa0(%rsp), %xmm1
vfmadd213sd 0x130(%rsp), %xmm0, %xmm1 # xmm1 = (xmm0 * xmm1) + mem
vcvttsd2si %xmm1, %edi
cmovael 0x4c(%rsp), %edi
vmovsd 0x120(%rsp), %xmm1
vfmadd213sd 0x128(%rsp), %xmm0, %xmm1 # xmm1 = (xmm0 * xmm1) + mem
vcvttsd2si %xmm1, %esi
cmovael 0x50(%rsp), %esi
vmovsd 0x118(%rsp), %xmm1
vfmadd213sd 0x98(%rsp), %xmm1, %xmm0 # xmm0 = (xmm1 * xmm0) + mem
vcvttsd2si %xmm0, %edx
cmovael 0x28(%rsp), %edx
movl 0x2c(%rsp), %ebx
movl %ebx, (%rsp)
andl %ebp, %edi
andl %ebp, %esi
andl %ebp, %edx
movl %r14d, %ecx
movl %r12d, %r8d
movq %r13, %r9
callq 0x2501
incl %r12d
cmpl %ebx, %r12d
jne 0x370a
incl %r14d
cmpl 0x3c(%rsp), %r14d
jne 0x36d5
leaq 0x18(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xd7a1(%rip), %rsi      # 0x110d4
leaq 0xd7a5(%rip), %rdx      # 0x110df
leaq 0x8(%rsp), %rdi
callq 0x3fda
leaq 0x8(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
movl 0x3c(%rsp), %edx
movl 0x2c(%rsp), %ecx
movl $0x6, %r8d
movl $0x8, %r9d
callq 0xd952
movl %eax, %ebp
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x397b
callq 0x2120
testl %ebp, %ebp
je 0x3a0b
movq 0x1364e(%rip), %rbx     # 0x16fd8
leaq 0xd8e0(%rip), %rsi      # 0x11271
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2190
movl %ebp, %edi
callq 0xd23a
movq %rax, %r14
testq %rax, %rax
je 0x39c9
movq %r14, %rdi
callq 0x2090
movq 0x1361c(%rip), %rdi     # 0x16fd8
movq %r14, %rsi
movq %rax, %rdx
callq 0x2190
jmp 0x39e0
movq (%rbx), %rax
movq -0x18(%rax), %rax
leaq (%rbx,%rax), %rdi
movl 0x20(%rbx,%rax), %esi
orl $0x1, %esi
callq 0x2270
movq (%rbx), %rax
addq -0x18(%rax), %rbx
movq %rbx, %rdi
movl $0xa, %esi
callq 0x2130
movsbl %al, %esi
movq 0x135da(%rip), %rdi     # 0x16fd8
callq 0x2040
movq %rax, %rdi
callq 0x20d0
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x3a1d
callq 0x2120
xorl %r14d, %r14d
movl %r14d, %eax
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xd8ba(%rip), %rdi      # 0x112f6
xorl %esi, %esi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x2210
leaq 0xd8a7(%rip), %rdi      # 0x112f6
xorl %esi, %esi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x2210
leaq 0xd894(%rip), %rdi      # 0x112f6
xorl %esi, %esi
movq %rcx, %rdx
xorl %eax, %eax
callq 0x2210
jmp 0x3b5a
jmp 0x3b5a
jmp 0x3b5a
movq %rax, %rbx
movq 0x138(%rsp), %rdi
jmp 0x3b08
jmp 0x3b71
movq %rax, %rbx
movq 0x158(%rsp), %rdi
jmp 0x3ad5
jmp 0x3b71
movq %rax, %rbx
movq 0x178(%rsp), %rdi
jmp 0x3b1c
jmp 0x3b8b
jmp 0x3b8b
movq %rax, %rbx
movq 0x198(%rsp), %rdi
jmp 0x3b08
jmp 0x3b71
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
cmpq %r12, %rdi
jne 0x3b35
jmp 0x3b74
jmp 0x3b71
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
jmp 0x3b1c
jmp 0x3b8b
jmp 0x3b8b
jmp 0x3b68
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %rbp, %rdi
jne 0x3b35
jmp 0x3b74
jmp 0x3b71
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r15, %rdi
jne 0x3b35
jmp 0x3b74
jmp 0x3b71
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r14, %rdi
je 0x3b74
callq 0x2120
jmp 0x3b74
jmp 0x3b8b
jmp 0x3b8b
jmp 0x3b68
movq %rax, %rbx
movq 0x8(%rsp), %rdi
cmpq %r14, %rdi
je 0x3ba6
callq 0x2120
jmp 0x3ba6
jmp 0x3ba3
jmp 0x3b68
movq %rax, %rbx
leaq 0x18(%rsp), %rax
jmp 0x3b96
jmp 0x3b68
jmp 0x3b71
movq %rax, %rbx
jmp 0x3bb8
jmp 0x3b71
jmp 0x3b8b
movq %rax, %rbx
leaq 0x18(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3b8e
callq 0x2120
jmp 0x3b8e
jmp 0x3b8b
movq %rax, %rbx
leaq 0x80(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
jne 0x3bb3
jmp 0x3bb8
jmp 0x3ba3
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x3bb8
callq 0x2120
movq %rbx, %rdi
callq 0x2290