// File: /workspace/github_cpp_makefile_star2_O3/2TallTim[P]modern-raytracing/raytrace.cpp
// Function: main
int main(int argc, char **argv) {
    const int nx = 960;
    const int ny = 540;
    const int ns = 1024;
    const int nobj = 500;
    const double tgt_var = 0.005;

    std::vector<hitable::Ptr> oblist;

    for (int a = -11; a < 11; a++) {
        for (int b = -11; b < 11; b++) {
            double choose_mat = rng::gen01();
            vec3 center(a + 0.9 * rng::gen01(), 0.2, b + 0.9 * rng::gen01());
            if ((center - vec3(4, 0.2, 0)).squared_length() > 0.8) {
                material::Ptr mat;
                if (choose_mat < 0.8) { //diffuse
                    mat = std::make_shared<lambert>(vec3(rng::gen01() * rng::gen01(), rng::gen01() * rng::gen01(), rng::gen01() * rng::gen01()));
                } else if (choose_mat < 0.9) { //metal
                    mat = std::make_shared<metal>(vec3(0.5 * (1 + rng::gen01()), 0.5 * (1 + rng::gen01()), 0.5 * (1 + rng::gen01())), 0.5 * rng::gen01());
                } else if (choose_mat < 0.95){
                    mat = std::make_shared<diffuse_light>(vec3(80*rng::gen01(),80*rng::gen01(),80*rng::gen01()));
                } else { //glass
                    mat = std::make_shared<dielectric>(1.5);
                }
                hitable::Ptr sp = std::make_shared<sphere>(center, 0.2, mat);
                oblist.push_back(sp);
            }
        }
    }

    material::Ptr mat = std::make_shared<lambert>(vec3(0.5, 0.5, 0.5));
    hitable::Ptr sp = std::make_shared<sphere>(vec3(0, -1000, 0), 1000, mat);
    oblist.push_back(sp);

    mat = std::make_shared<dielectric>(1.5);
    sp = std::make_shared<sphere>(vec3(0, 1, 0), 1.0, mat);
    oblist.push_back(sp);

    mat = std::make_shared<diffuse_light>(vec3(10, 10, 10));
    sp = std::make_shared<sphere>(vec3(-4, 1, 0), 1.0, mat);
    oblist.push_back(sp);

    mat = std::make_shared<metal>(vec3(0.7, 0.6, 0.5), 0.0);
    sp = std::make_shared<sphere>(vec3(4, 1, 0), 1.0, mat);
    oblist.push_back(sp);

    auto world = std::make_shared<bvh_node>(oblist.begin(), oblist.end());

    vec3 origin(12, 1, 3);
    vec3 aim(0, 1, 0);
    double dist_to_focus = (origin - aim).length();
    double aperture = 0.03;

    camera cam(origin, aim, vec3(0, 1, 0), 30, (double)nx / ny, aperture, dist_to_focus);

    std::mutex result_mutex;
    std::vector<std::string> results(ny);
    std::vector<std::string> smpmap(ny);
    std::atomic_int nextrow(-1);

    auto renderRow = [&]() -> void {
        int j = ++nextrow;
        while (j < ny){
            std::stringstream tmpresults;
            std::stringstream smpcntresults;
            tmpresults << "# ROW " << j << std::endl;
            int t_samples = 0;
            for (int i = 0; i < nx; i++){
                vec3 col, vr;

                //Intialize variance tracking
                int s = 0;
                for (s = 0; s < ns; s++) {
                    double u = (double)(i + rng::gen01()) / nx;
                    double v = (double)(j + rng::gen01()) / ny;
                    ray r = cam.get_ray(u, v);
                    vec3 sample = color(r, world);

                    t_samples++;

                    col += sample;

                    vr += vec3(sample.r() * sample.r(),
                               sample.g() * sample.g(),
                               sample.b() * sample.b());

                    if (s > sqrt((float)ns)) {
                        vec3 musquared_s((col.r() * col.r()) / s,
                                         (col.g() * col.g()) / s,
                                         (col.b() * col.b()) / s);
                        vec3 variance = ((double)s / ((s - 1) * (double)s)) * (vr - musquared_s);
                        variance = vec3(variance.r() * variance.r(),
                                        variance.g() * variance.g(),
                                        variance.b() * variance.b());
                        if ((variance.r()/(col.r()/s) < tgt_var) &&
                            (variance.g()/(col.g()/s) < tgt_var) &&
                            (variance.b()/(col.b()/s) < tgt_var)) break;
                    }
                }
                col = col / (s + 1);
                col = vec3(fmin(sqrt(col.r()),1.0), 
                           fmin(sqrt(col.g()),1.0),
                           fmin( sqrt(col.b()),1.0));
                int ir = int(255.99 * col.r());
                int ig = int(255.99 * col.g());
                int ib = int(255.99 * col.b());

                tmpresults << ir << " " << ig << " " << ib << std::endl;
                int nsgv = int((double)255.99 * ((2 * log(s) / log(ns)) - 1));
                smpcntresults << nsgv << " " << nsgv << " " << nsgv << std::endl;
            }
            std::lock_guard<std::mutex> lock(result_mutex);
            results[j] = tmpresults.str();
            smpmap[j] = smpcntresults.str();
            j = ++nextrow;
            std::cout << j << " / " << ny << " Avg samples in row: " << (double)t_samples / nx << std::endl;
        }
    };
    std::vector<std::thread> threads;
    for (int t = 0; t < std::thread::hardware_concurrency() - 1; t++) {
        threads.push_back(std::thread(renderRow));
    }
    for (auto &t : threads) {
        t.join();
    }

    std::stringstream header;
    header << "P3" << std::endl;
    header << nx << " " << ny << std::endl;
    header << "255" << std::endl;

    results.push_back(header.str());
    smpmap.push_back(header.str());
    if (argc == 1){
        for (auto iter = results.rbegin(); iter != results.rend(); iter++) {
            std::cout << *iter;
        }
    } else {
        std::ofstream out(argv[1], std::ios::out);
        for (auto iter = results.rbegin(); iter != results.rend(); iter++) {
            out << *iter;
        }
    }
    std::ofstream smpout("./samples.ppm", std::ios::out);
    for (auto iter = smpmap.rbegin(); iter != smpmap.rend(); iter++) {
        smpout << *iter;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x648, %rsp            # imm = 0x648
movq %rsi, 0x170(%rsp)
movl %edi, 0x9c(%rsp)
movabsq $0x3f747ae147ae147b, %rax # imm = 0x3F747AE147AE147B
movq %rax, 0x198(%rsp)
xorpd %xmm0, %xmm0
leaq 0xc0(%rsp), %rax
movapd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl $0xfffffff5, %eax       # imm = 0xFFFFFFF5
movabsq $0x3fc999999999999a, %r12 # imm = 0x3FC999999999999A
leaq 0x390(%rsp), %rbx
leaq 0xa8(%rsp), %rbp
leaq 0x200(%rsp), %r14
leaq 0x590(%rsp), %r15
movl %eax, 0xa0(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x190(%rsp)
movl $0xfffffff5, %r13d      # imm = 0xFFFFFFF5
callq 0x3ce0
movsd %xmm0, 0x80(%rsp)
callq 0x3ce0
movsd %xmm0, 0x60(%rsp)
callq 0x3ce0
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd 0x5c0f(%rip), %xmm2     # 0xa128
movsd 0x60(%rsp), %xmm3
mulsd %xmm2, %xmm3
addsd 0x190(%rsp), %xmm3
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm3, 0x390(%rsp)
movq %r12, 0x398(%rsp)
movsd %xmm0, 0x3a0(%rsp)
addsd 0x5bda(%rip), %xmm3     # 0xa130
mulsd %xmm3, %xmm3
addsd 0x5c16(%rip), %xmm3     # 0xa178
mulsd %xmm0, %xmm0
addsd %xmm3, %xmm0
ucomisd 0x5bc6(%rip), %xmm0     # 0xa138
jbe 0x48d3
xorpd %xmm0, %xmm0
movapd %xmm0, 0x200(%rsp)
movsd 0x5bab(%rip), %xmm0     # 0xa138
movsd 0x80(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x466c
callq 0x3ce0
movsd %xmm0, 0x60(%rsp)
callq 0x3ce0
movsd %xmm0, 0x80(%rsp)
callq 0x3ce0
movsd %xmm0, 0xe0(%rsp)
callq 0x3ce0
movsd %xmm0, 0x188(%rsp)
callq 0x3ce0
movsd %xmm0, 0x180(%rsp)
callq 0x3ce0
movsd %xmm0, 0x178(%rsp)
movl $0x30, %edi
callq 0x31c0
movsd 0x60(%rsp), %xmm0
mulsd 0x80(%rsp), %xmm0
movsd 0xe0(%rsp), %xmm1
mulsd 0x188(%rsp), %xmm1
movsd 0x180(%rsp), %xmm2
mulsd 0x178(%rsp), %xmm2
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x93f5(%rip), %rcx      # 0xda38
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x945c(%rip), %rdx      # 0xdab0
movq %rdx, 0x10(%rax)
movsd %xmm0, 0x18(%rax)
movsd %xmm1, 0x20(%rax)
movsd %xmm2, 0x28(%rax)
jmp 0x4831
movsd 0x5ab4(%rip), %xmm0     # 0xa128
ucomisd %xmm1, %xmm0
jbe 0x4742
callq 0x3ce0
addsd 0x59d5(%rip), %xmm0     # 0xa060
mulsd 0x5a8d(%rip), %xmm0     # 0xa120
movsd %xmm0, 0x80(%rsp)
callq 0x3ce0
movapd %xmm0, 0x60(%rsp)
callq 0x3ce0
movapd 0x60(%rsp), %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
addpd 0x5b32(%rip), %xmm1     # 0xa1f0
mulpd 0x5b3a(%rip), %xmm1     # 0xa200
movapd %xmm1, 0x60(%rsp)
callq 0x3ce0
movsd %xmm0, 0xe0(%rsp)
movl $0x38, %edi
callq 0x31c0
movsd 0xe0(%rsp), %xmm1
mulsd 0x5a2b(%rip), %xmm1     # 0xa120
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x93ee(%rip), %rcx      # 0xdaf8
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x942d(%rip), %rdx      # 0xdb48
movq %rdx, 0x10(%rax)
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movapd 0x60(%rsp), %xmm0
movupd %xmm0, 0x20(%rax)
movsd %xmm1, 0x30(%rax)
jmp 0x4831
movsd 0x59f6(%rip), %xmm0     # 0xa140
ucomisd %xmm1, %xmm0
jbe 0x47ef
callq 0x3ce0
movsd %xmm0, 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
mulsd 0x59db(%rip), %xmm0     # 0xa148
movsd %xmm0, 0x60(%rsp)
callq 0x3ce0
movapd %xmm0, 0x80(%rsp)
callq 0x3ce0
movapd %xmm0, 0xe0(%rsp)
movl $0x30, %edi
callq 0x31c0
movapd 0x80(%rsp), %xmm1
unpcklpd 0xe0(%rsp), %xmm1       # xmm1 = xmm1[0],mem[0]
mulpd 0x5a2d(%rip), %xmm1     # 0xa1e0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x93b8(%rip), %rcx      # 0xdb80
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movsd 0x60(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movupd %xmm1, 0x20(%rax)
leaq 0x93e7(%rip), %rdx      # 0xdbd0
movq %rdx, 0x10(%rax)
jmp 0x4831
movl $0x20, %edi
callq 0x31c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x93fa(%rip), %rcx      # 0xdc08
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x9439(%rip), %rdx      # 0xdc58
movq %rdx, 0x10(%rax)
movabsq $0x3ff8000000000000, %rdx # imm = 0x3FF8000000000000
movq %rdx, 0x18(%rax)
movq %rcx, 0x200(%rsp)
movq 0x208(%rsp), %rdi
movq %rax, 0x208(%rsp)
testq %rdi, %rdi
je 0x4853
callq 0x37b6
movq %r12, 0xa8(%rsp)
movq $0x0, 0x120(%rsp)
leaq 0x128(%rsp), %rdi
leaq 0x120(%rsp), %rsi
leaq 0xf8(%rsp), %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x673a
movapd 0x120(%rsp), %xmm0
movapd %xmm0, 0x590(%rsp)
leaq 0xc0(%rsp), %rdi
movq %r15, %rsi
callq 0x3ac4
movq 0x598(%rsp), %rdi
testq %rdi, %rdi
je 0x48c1
callq 0x37b6
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x48d3
callq 0x37b6
incl %r13d
cmpl $0xb, %r13d
jne 0x44eb
movl 0xa0(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x44ce
movl $0x30, %edi
callq 0x31c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x9127(%rip), %rcx      # 0xda38
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x918e(%rip), %rdx      # 0xdab0
movq %rdx, 0x10(%rax)
movapd 0x58d2(%rip), %xmm0     # 0xa200
movupd %xmm0, 0x18(%rax)
movabsq $0x3fe0000000000000, %rdx # imm = 0x3FE0000000000000
movq %rdx, 0x28(%rax)
leaq 0x50(%rsp), %r9
movq %rcx, (%r9)
movq %rax, 0x8(%r9)
xorpd %xmm0, %xmm0
movhpd 0x57f7(%rip), %xmm0     # xmm0 = xmm0[0],mem[0]
leaq 0x390(%rsp), %rcx
movapd %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x590(%rsp), %r8
movl $0x3e8, (%r8)           # imm = 0x3E8
leaq 0x208(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x200(%rsp), %rsi
leaq 0x120(%rsp), %rdx
callq 0x68f0
movapd 0x200(%rsp), %xmm0
leaq 0x70(%rsp), %rsi
movapd %xmm0, (%rsi)
leaq 0xc0(%rsp), %rdi
callq 0x3ac4
movl $0x20, %edi
callq 0x31c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x922f(%rip), %rcx      # 0xdc08
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x926e(%rip), %rdx      # 0xdc58
movq %rdx, 0x10(%rax)
movabsq $0x3ff8000000000000, %rdx # imm = 0x3FF8000000000000
movq %rdx, 0x18(%rax)
movq %rcx, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq %rax, 0x58(%rsp)
testq %rdi, %rdi
je 0x4a15
callq 0x37b6
xorpd %xmm0, %xmm0
movhpd 0x563f(%rip), %xmm0     # xmm0 = xmm0[0],mem[0]
leaq 0x390(%rsp), %rcx
movapd %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
leaq 0x590(%rsp), %r8
movq %rbx, (%r8)
leaq 0x208(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x200(%rsp), %rsi
leaq 0x120(%rsp), %rdx
leaq 0x50(%rsp), %r9
callq 0x6a36
movapd 0x200(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x200(%rsp)
movq 0x78(%rsp), %rdi
movapd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4aab
callq 0x37b6
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x4aab
callq 0x37b6
leaq 0xc0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3ac4
movl $0x30, %edi
callq 0x31c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x90a4(%rip), %rcx      # 0xdb80
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movaps 0x5723(%rip), %xmm0     # 0xa210
movups %xmm0, 0x18(%rax)
movabsq $0x4024000000000000, %rdx # imm = 0x4024000000000000
movq %rdx, 0x28(%rax)
leaq 0x90ca(%rip), %rdx      # 0xdbd0
movq %rdx, 0x10(%rax)
movq %rcx, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq %rax, 0x58(%rsp)
testq %rdi, %rdi
je 0x4b23
callq 0x37b6
movapd 0x56f5(%rip), %xmm0     # 0xa220
leaq 0x390(%rsp), %rcx
movapd %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x590(%rsp), %r8
movq %rbx, (%r8)
leaq 0x208(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x200(%rsp), %rsi
leaq 0x120(%rsp), %rdx
leaq 0x50(%rsp), %r9
callq 0x6a36
movapd 0x200(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x200(%rsp)
movq 0x78(%rsp), %rdi
movapd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4bab
callq 0x37b6
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x4bab
callq 0x37b6
leaq 0xc0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3ac4
movl $0x38, %edi
callq 0x31c0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x8f1c(%rip), %rcx      # 0xdaf8
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x8f5b(%rip), %rdx      # 0xdb48
movq %rdx, 0x10(%rax)
movaps 0x5638(%rip), %xmm0     # 0xa230
movups %xmm0, 0x18(%rax)
movsd 0x551c(%rip), %xmm0     # 0xa120
movups %xmm0, 0x28(%rax)
movq %rcx, 0x50(%rsp)
movq 0x58(%rsp), %rdi
movq %rax, 0x58(%rsp)
testq %rdi, %rdi
je 0x4c21
callq 0x37b6
movapd 0x5617(%rip), %xmm0     # 0xa240
leaq 0x390(%rsp), %rcx
movapd %xmm0, (%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x590(%rsp), %r8
movq %rbx, (%r8)
leaq 0x208(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x200(%rsp), %rsi
leaq 0x120(%rsp), %rdx
leaq 0x50(%rsp), %r9
callq 0x6a36
movapd 0x200(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x200(%rsp)
movq 0x78(%rsp), %rdi
movapd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4ca9
callq 0x37b6
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x4ca9
callq 0x37b6
leaq 0xc0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3ac4
movq 0xc0(%rsp), %rax
movq 0xc8(%rsp), %rdx
leaq 0x390(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x200(%rsp), %r8
movq %rdx, (%r8)
leaq 0x118(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0x110(%rsp), %rsi
leaq 0x590(%rsp), %rdx
callq 0x6b78
movaps 0x5543(%rip), %xmm0     # 0xa250
movaps %xmm0, 0x1e0(%rsp)
movabsq $0x4008000000000000, %rax # imm = 0x4008000000000000
movq %rax, 0x1f0(%rsp)
xorps %xmm0, %xmm0
movhps 0x532f(%rip), %xmm0     # xmm0 = xmm0[0,1],mem[0,1]
movaps %xmm0, 0x1c0(%rsp)
xorl %eax, %eax
movq %rax, 0x1d0(%rsp)
movaps %xmm0, 0x1a0(%rsp)
movq %rax, 0x1b0(%rsp)
movq 0x1b0(%rsp), %rax
movq %rax, 0x40(%rsp)
movaps 0x1a0(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
movq 0x1d0(%rsp), %rax
movq %rax, 0x28(%rsp)
movaps 0x1c0(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x1f0(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x1e0(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x590(%rsp), %rdi
movsd 0x53a8(%rip), %xmm0     # 0xa158
movsd 0x53a8(%rip), %xmm1     # 0xa160
movsd 0x53a8(%rip), %xmm2     # 0xa168
movsd 0x53a8(%rip), %xmm3     # 0xa170
callq 0x5be4
xorpd %xmm0, %xmm0
movapd %xmm0, 0x130(%rsp)
movapd %xmm0, 0x120(%rsp)
movq $0x0, 0x140(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x390(%rsp), %rdx
movl $0x21c, %esi            # imm = 0x21C
callq 0x5df6
leaq 0xf8(%rsp), %rdi
leaq 0x390(%rsp), %rdx
movl $0x21c, %esi            # imm = 0x21C
callq 0x5df6
movl $0xffffffff, 0xa4(%rsp) # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movapd %xmm0, 0x150(%rsp)
movq $0x0, 0x160(%rsp)
callq 0x3210
cmpl $0x1, %eax
je 0x4f39
xorl %r15d, %r15d
leaq 0xa4(%rsp), %r13
leaq 0x198(%rsp), %r12
leaq 0x200(%rsp), %rbp
leaq 0x390(%rsp), %rbx
leaq 0x150(%rsp), %r14
movq $0x0, 0x200(%rsp)
movl $0x40, %edi
callq 0x31c0
leaq 0x8e93(%rip), %rcx      # 0xdd30
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
leaq 0x590(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0x110(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %r12, 0x20(%rax)
leaq 0x120(%rsp), %rcx
movq %rcx, 0x28(%rax)
leaq 0xa8(%rsp), %rcx
movq %rcx, 0x30(%rax)
leaq 0xf8(%rsp), %rcx
movq %rcx, 0x38(%rax)
movq %rax, 0x390(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x3190
movq 0x390(%rsp), %rdi
testq %rdi, %rdi
je 0x4f0c
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x6ddc
cmpq $0x0, 0x200(%rsp)
jne 0x5377
incl %r15d
callq 0x3210
decl %eax
cmpl %eax, %r15d
jb 0x4e80
movq 0x150(%rsp), %rbx
movq 0x158(%rsp), %r14
cmpq %r14, %rbx
je 0x4f5c
movq %rbx, %rdi
callq 0x32a0
addq $0x8, %rbx
jmp 0x4f49
leaq 0x200(%rsp), %rdi
callq 0x30e0
leaq 0x210(%rsp), %rbx
leaq 0x52f8(%rip), %rsi      # 0xa270
movl $0x2, %edx
movq %rbx, %rdi
callq 0x31f0
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30d0
movq %rbx, %rdi
movl $0x3c0, %esi            # imm = 0x3C0
callq 0x32b0
movq %rax, %r14
leaq 0x52f7(%rip), %rsi      # 0xa2bf
movl $0x1, %edx
movq %rax, %rdi
callq 0x31f0
movq %r14, %rdi
movl $0x21c, %esi            # imm = 0x21C
callq 0x32b0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30d0
leaq 0x5260(%rip), %rsi      # 0xa273
movl $0x3, %edx
movq %rbx, %rdi
callq 0x31f0
movq 0x210(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30d0
leaq 0x218(%rsp), %rbx
leaq 0x390(%rsp), %rdi
movq %rbx, %rsi
callq 0x3270
leaq 0xa8(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0x6f78
leaq 0x3a0(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x509a
movq 0x3a0(%rsp), %rsi
incq %rsi
callq 0x31d0
leaq 0x390(%rsp), %rdi
movq %rbx, %rsi
callq 0x3270
leaq 0xf8(%rsp), %rdi
leaq 0x390(%rsp), %rsi
callq 0x6f78
movq 0x390(%rsp), %rdi
cmpq %r14, %rdi
je 0x50dc
movq 0x3a0(%rsp), %rsi
incq %rsi
callq 0x31d0
cmpl $0x1, 0x9c(%rsp)
jne 0x511c
movq 0xb0(%rsp), %rax
movq 0x8edb(%rip), %rbx      # 0xdfd0
cmpq 0xa8(%rsp), %rax
je 0x51a5
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x31f0
movq %r14, %rax
jmp 0x50f5
movq 0x170(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x390(%rsp), %rdi
movl $0x10, %edx
callq 0x31e0
movq 0xb0(%rsp), %rax
leaq 0x390(%rsp), %rbx
cmpq 0xa8(%rsp), %rax
je 0x516d
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x31f0
movq %r14, %rax
jmp 0x514a
movq 0x8e4c(%rip), %rax      # 0xdfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x398(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x390(%rsp,%rcx)
callq 0x3170
leaq 0x488(%rsp), %rdi
callq 0x3050
leaq 0x50cb(%rip), %rsi      # 0xa277
leaq 0x390(%rsp), %rdi
movl $0x10, %edx
callq 0x31e0
movq 0x100(%rsp), %rax
leaq 0x390(%rsp), %rbx
cmpq 0xf8(%rsp), %rax
je 0x51f1
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x31f0
movq %r14, %rax
jmp 0x51ce
movq 0x8dc8(%rip), %rax      # 0xdfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x398(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x390(%rsp,%rcx)
callq 0x3170
leaq 0x488(%rsp), %rdi
callq 0x3050
movq 0x8d78(%rip), %rsi      # 0xdfa8
leaq 0x200(%rsp), %rdi
callq 0x3110
leaq 0x280(%rsp), %rdi
callq 0x3050
leaq 0x150(%rsp), %rdi
callq 0x5e82
leaq 0xf8(%rsp), %rdi
callq 0x5ebe
leaq 0xa8(%rsp), %rdi
callq 0x5ebe
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x5283
callq 0x37b6
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x5292
callq 0x37b6
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x52a1
callq 0x37b6
leaq 0xc0(%rsp), %rdi
callq 0x5f1c
xorl %eax, %eax
addq $0x648, %rsp            # imm = 0x648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x534d
jmp 0x534d
movq %rax, %rbx
movq 0x390(%rsp), %rdi
cmpq %r14, %rdi
jne 0x52fb
jmp 0x5391
jmp 0x534d
movq %rax, %rbx
leaq 0x3a0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x5391
movq 0x3a0(%rsp), %rsi
incq %rsi
callq 0x31d0
jmp 0x5391
jmp 0x534d
jmp 0x537c
movq %rax, %rbx
jmp 0x53cc
jmp 0x531e
movq %rax, %rbx
jmp 0x53d9
jmp 0x5341
jmp 0x5341
jmp 0x5341
jmp 0x5341
jmp 0x5341
jmp 0x5341
jmp 0x5341
movq %rax, %rbx
jmp 0x53fa
jmp 0x543b
movq %rax, %rbx
jmp 0x53eb
jmp 0x534d
jmp 0x5381
movq %rax, %rbx
jmp 0x5391
jmp 0x537c
movq %rax, %rbx
movq 0x390(%rsp), %rdi
testq %rdi, %rdi
je 0x53b2
movq (%rdi), %rax
callq *0x8(%rax)
jmp 0x53b2
cmpq $0x0, 0x200(%rsp)
je 0x537c
callq 0x3040
movq %rax, %rbx
jmp 0x53b2
movq %rax, %rbx
leaq 0x390(%rsp), %rdi
callq 0x3250
movq 0x8c10(%rip), %rsi      # 0xdfa8
leaq 0x200(%rsp), %rdi
callq 0x3110
leaq 0x280(%rsp), %rdi
callq 0x3050
leaq 0x150(%rsp), %rdi
callq 0x5e82
leaq 0xf8(%rsp), %rdi
callq 0x5ebe
leaq 0xa8(%rsp), %rdi
callq 0x5ebe
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x53eb
callq 0x37b6
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x53fa
callq 0x37b6
movq 0x58(%rsp), %rdi
jmp 0x542f
jmp 0x5424
jmp 0x5424
jmp 0x5424
jmp 0x5424
jmp 0x5424
movq %rax, %rbx
movq 0x598(%rsp), %rdi
testq %rdi, %rdi
je 0x5427
callq 0x37b6
jmp 0x5427
jmp 0x543b
movq %rax, %rbx
movq 0x208(%rsp), %rdi
testq %rdi, %rdi
je 0x543e
callq 0x37b6
jmp 0x543e
movq %rax, %rbx
leaq 0xc0(%rsp), %rdi
callq 0x5f1c
movq %rbx, %rdi
callq 0x32d0
nop