// File: /workspace/github_cpp_makefile_star2_O1/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 $0x5e8, %rsp            # imm = 0x5E8
movq %rsi, 0x140(%rsp)
movl %edi, 0x8c(%rsp)
movabsq $0x3f747ae147ae147b, %rax # imm = 0x3F747AE147AE147B
movq %rax, 0x160(%rsp)
xorpd %xmm0, %xmm0
leaq 0xb0(%rsp), %rax
movapd %xmm0, (%rax)
movq $0x0, 0x10(%rax)
movl $0xfffffff5, %eax       # imm = 0xFFFFFFF5
movabsq $0x3fc999999999999a, %r12 # imm = 0x3FC999999999999A
leaq 0x338(%rsp), %rbx
leaq 0x98(%rsp), %rbp
leaq 0x1b0(%rsp), %r14
leaq 0x538(%rsp), %r15
movl %eax, 0x90(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x158(%rsp)
movl $0xfffffff5, %r13d      # imm = 0xFFFFFFF5
callq 0x3d9a
movsd %xmm0, 0x50(%rsp)
callq 0x3d9a
movsd %xmm0, 0x48(%rsp)
callq 0x3d9a
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movsd 0x5adc(%rip), %xmm2     # 0xa0f8
movsd 0x48(%rsp), %xmm3
mulsd %xmm2, %xmm3
addsd 0x158(%rsp), %xmm3
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm3, 0x338(%rsp)
movq %r12, 0x340(%rsp)
movsd %xmm0, 0x348(%rsp)
addsd 0x5aa7(%rip), %xmm3     # 0xa100
mulsd %xmm3, %xmm3
addsd 0x5adb(%rip), %xmm3     # 0xa140
mulsd %xmm0, %xmm0
addsd %xmm3, %xmm0
ucomisd 0x5a93(%rip), %xmm0     # 0xa108
jbe 0x49cf
xorpd %xmm0, %xmm0
movapd %xmm0, 0x1b0(%rsp)
movsd 0x5a78(%rip), %xmm0     # 0xa108
movsd 0x50(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x4760
callq 0x3d9a
movsd %xmm0, 0x48(%rsp)
callq 0x3d9a
movsd %xmm0, 0x50(%rsp)
callq 0x3d9a
movsd %xmm0, 0x68(%rsp)
callq 0x3d9a
movsd %xmm0, 0x80(%rsp)
callq 0x3d9a
movsd %xmm0, 0x150(%rsp)
callq 0x3d9a
movsd %xmm0, 0x148(%rsp)
movl $0x30, %edi
callq 0x31d0
movsd 0x48(%rsp), %xmm0
mulsd 0x50(%rsp), %xmm0
movsd 0x68(%rsp), %xmm1
mulsd 0x80(%rsp), %xmm1
movsd 0x150(%rsp), %xmm2
mulsd 0x148(%rsp), %xmm2
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x92c9(%rip), %rcx      # 0xda00
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x9368(%rip), %rdx      # 0xdab0
movq %rdx, 0x10(%rax)
movsd %xmm0, 0x18(%rax)
movsd %xmm1, 0x20(%rax)
movsd %xmm2, 0x28(%rax)
jmp 0x492d
movsd 0x5990(%rip), %xmm0     # 0xa0f8
ucomisd %xmm1, %xmm0
jbe 0x483d
callq 0x3d9a
addsd 0x58e9(%rip), %xmm0     # 0xa068
mulsd 0x5961(%rip), %xmm0     # 0xa0e8
movsd %xmm0, 0x48(%rsp)
callq 0x3d9a
movsd %xmm0, 0x50(%rsp)
callq 0x3d9a
movsd %xmm0, 0x68(%rsp)
callq 0x3d9a
movsd %xmm0, 0x80(%rsp)
movl $0x38, %edi
callq 0x31d0
movsd 0x58a5(%rip), %xmm0     # 0xa068
movsd 0x50(%rsp), %xmm2
addsd %xmm0, %xmm2
movsd 0x5913(%rip), %xmm1     # 0xa0e8
mulsd %xmm1, %xmm2
movsd 0x68(%rsp), %xmm3
addsd %xmm0, %xmm3
mulsd %xmm1, %xmm3
movsd 0x80(%rsp), %xmm4
mulsd %xmm1, %xmm4
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x92ef(%rip), %rcx      # 0xdaf8
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x932e(%rip), %rdx      # 0xdb48
movq %rdx, 0x10(%rax)
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movsd %xmm2, 0x20(%rax)
movsd %xmm3, 0x28(%rax)
movsd %xmm4, 0x30(%rax)
jmp 0x492d
movsd 0x58cb(%rip), %xmm0     # 0xa110
ucomisd %xmm1, %xmm0
jbe 0x48eb
callq 0x3d9a
movsd %xmm0, 0x48(%rsp)
movsd 0x48(%rsp), %xmm0
mulsd 0x58b0(%rip), %xmm0     # 0xa118
movsd %xmm0, 0x48(%rsp)
callq 0x3d9a
movsd %xmm0, 0x50(%rsp)
callq 0x3d9a
movsd %xmm0, 0x68(%rsp)
movl $0x30, %edi
callq 0x31d0
movsd 0x5882(%rip), %xmm0     # 0xa118
movsd 0x68(%rsp), %xmm2
mulsd %xmm0, %xmm2
movsd 0x50(%rsp), %xmm1
mulsd %xmm0, %xmm1
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x92c1(%rip), %rcx      # 0xdb80
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x18(%rax)
movsd %xmm1, 0x20(%rax)
movsd %xmm2, 0x28(%rax)
leaq 0x92eb(%rip), %rdx      # 0xdbd0
movq %rdx, 0x10(%rax)
jmp 0x492d
movl $0x20, %edi
callq 0x31d0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x92fe(%rip), %rcx      # 0xdc08
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x933d(%rip), %rdx      # 0xdc58
movq %rdx, 0x10(%rax)
movabsq $0x3ff8000000000000, %rdx # imm = 0x3FF8000000000000
movq %rdx, 0x18(%rax)
movq %rcx, 0x1b0(%rsp)
movq 0x1b8(%rsp), %rdi
movq %rax, 0x1b8(%rsp)
testq %rdi, %rdi
je 0x494f
callq 0x37ec
movq %r12, 0x98(%rsp)
movq $0x0, 0xf0(%rsp)
leaq 0xf8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
leaq 0xc8(%rsp), %rdx
movq %rbx, %rcx
movq %rbp, %r8
movq %r14, %r9
callq 0x6b2a
movupd 0xf0(%rsp), %xmm0
movupd %xmm0, 0x538(%rsp)
leaq 0xb0(%rsp), %rdi
movq %r15, %rsi
callq 0x3b7c
movq 0x540(%rsp), %rdi
testq %rdi, %rdi
je 0x49bd
callq 0x37ec
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x49cf
callq 0x37ec
incl %r13d
cmpl $0xb, %r13d
jne 0x45f1
movl 0x90(%rsp), %eax
incl %eax
cmpl $0xb, %eax
jne 0x45d4
movl $0x30, %edi
callq 0x31d0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x8ff3(%rip), %rcx      # 0xda00
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x9092(%rip), %rdx      # 0xdab0
movq %rdx, 0x10(%rax)
movabsq $0x3fe0000000000000, %r14 # imm = 0x3FE0000000000000
movq %r14, 0x18(%rax)
movq %r14, 0x20(%rax)
movq %r14, 0x28(%rax)
leaq 0x58(%rsp), %r9
movq %rcx, (%r9)
movq %rax, 0x8(%r9)
xorl %eax, %eax
leaq 0x338(%rsp), %rcx
movq %rax, (%rcx)
movabsq $-0x3f70c00000000000, %rdx # imm = 0xC08F400000000000
movq %rdx, 0x8(%rcx)
movq %rax, 0x10(%rcx)
leaq 0x538(%rsp), %r8
movl $0x3e8, (%r8)           # imm = 0x3E8
leaq 0x1b8(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x1b0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
callq 0x6ce8
movupd 0x1b0(%rsp), %xmm0
leaq 0x70(%rsp), %rsi
movupd %xmm0, (%rsi)
leaq 0xb0(%rsp), %rdi
callq 0x3b7c
movl $0x20, %edi
callq 0x31d0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x9137(%rip), %rcx      # 0xdc08
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x9176(%rip), %rdx      # 0xdc58
movq %rdx, 0x10(%rax)
movabsq $0x3ff8000000000000, %rdx # imm = 0x3FF8000000000000
movq %rdx, 0x18(%rax)
movq %rcx, 0x58(%rsp)
movq 0x60(%rsp), %rdi
movq %rax, 0x60(%rsp)
testq %rdi, %rdi
je 0x4b0d
callq 0x37ec
xorl %eax, %eax
leaq 0x338(%rsp), %rcx
movq %rax, (%rcx)
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
movq %rbx, 0x8(%rcx)
movq %rax, 0x10(%rcx)
leaq 0x538(%rsp), %r8
movq %rbx, (%r8)
leaq 0x1b8(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x1b0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0x58(%rsp), %r9
callq 0x6e30
movapd 0x1b0(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x1b0(%rsp)
movq 0x78(%rsp), %rdi
movupd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4b88
callq 0x37ec
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x4b9a
callq 0x37ec
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3b7c
movl $0x30, %edi
callq 0x31d0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x8fb5(%rip), %rcx      # 0xdb80
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
movabsq $0x4024000000000000, %rdx # imm = 0x4024000000000000
movq %rdx, 0x18(%rax)
movq %rdx, 0x20(%rax)
movq %rdx, 0x28(%rax)
leaq 0x8fde(%rip), %rdx      # 0xdbd0
movq %rdx, 0x10(%rax)
movq %rcx, 0x58(%rsp)
movq 0x60(%rsp), %rdi
movq %rax, 0x60(%rsp)
testq %rdi, %rdi
je 0x4c0f
callq 0x37ec
movabsq $-0x3ff0000000000000, %rax # imm = 0xC010000000000000
leaq 0x338(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, 0x8(%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x538(%rsp), %r8
movq %rbx, (%r8)
leaq 0x1b8(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x1b0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0x58(%rsp), %r9
callq 0x6e30
movapd 0x1b0(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x1b0(%rsp)
movq 0x78(%rsp), %rdi
movupd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4c8a
callq 0x37ec
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x4c9c
callq 0x37ec
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3b7c
movl $0x38, %edi
callq 0x31d0
movabsq $0x100000001, %rcx      # imm = 0x100000001
movq %rcx, 0x8(%rax)
leaq 0x8e2b(%rip), %rcx      # 0xdaf8
movq %rcx, (%rax)
movq %rax, %rcx
addq $0x10, %rcx
leaq 0x8e6a(%rip), %rdx      # 0xdb48
movq %rdx, 0x10(%rax)
movabsq $0x3fe6666666666666, %rdx # imm = 0x3FE6666666666666
movq %rdx, 0x18(%rax)
movabsq $0x3fe3333333333333, %rdx # imm = 0x3FE3333333333333
movq %rdx, 0x20(%rax)
movq %r14, 0x28(%rax)
movq $0x0, 0x30(%rax)
movq %rcx, 0x58(%rsp)
movq 0x60(%rsp), %rdi
movq %rax, 0x60(%rsp)
testq %rdi, %rdi
je 0x4d23
callq 0x37ec
movabsq $0x4010000000000000, %rax # imm = 0x4010000000000000
leaq 0x338(%rsp), %rcx
movq %rax, (%rcx)
movq %rbx, 0x8(%rcx)
xorl %eax, %eax
movq %rax, 0x10(%rcx)
leaq 0x538(%rsp), %r8
movq %rbx, (%r8)
leaq 0x1b8(%rsp), %rdi
movq %rax, -0x8(%rdi)
leaq 0x1b0(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
leaq 0x58(%rsp), %r9
callq 0x6e30
movapd 0x1b0(%rsp), %xmm0
xorpd %xmm1, %xmm1
movapd %xmm1, 0x1b0(%rsp)
movq 0x78(%rsp), %rdi
movupd %xmm0, 0x70(%rsp)
testq %rdi, %rdi
je 0x4d9e
callq 0x37ec
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x4db0
callq 0x37ec
leaq 0xb0(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x3b7c
movq 0xb0(%rsp), %rax
movq 0xb8(%rsp), %rdx
leaq 0x338(%rsp), %rcx
movq %rax, (%rcx)
leaq 0x1b0(%rsp), %r8
movq %rdx, (%r8)
leaq 0xe8(%rsp), %rdi
movq $0x0, -0x8(%rdi)
leaq 0xe0(%rsp), %rsi
leaq 0x538(%rsp), %rdx
callq 0x6f74
movabsq $0x4028000000000000, %rax # imm = 0x4028000000000000
movq %rax, 0x198(%rsp)
movq %rbx, 0x1a0(%rsp)
movabsq $0x4008000000000000, %rax # imm = 0x4008000000000000
movq %rax, 0x1a8(%rsp)
xorl %eax, %eax
movq %rax, 0x180(%rsp)
movq %rbx, 0x188(%rsp)
movq %rax, 0x190(%rsp)
movq %rax, 0x168(%rsp)
movq %rbx, 0x170(%rsp)
movq %rax, 0x178(%rsp)
movq 0x178(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x168(%rsp), %xmm0
movups %xmm0, 0x30(%rsp)
movq 0x190(%rsp), %rax
movq %rax, 0x28(%rsp)
movups 0x180(%rsp), %xmm0
movups %xmm0, 0x18(%rsp)
movq 0x1a8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x198(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x538(%rsp), %rdi
movsd 0x5258(%rip), %xmm0     # 0xa120
movsd 0x5258(%rip), %xmm1     # 0xa128
movsd 0x5258(%rip), %xmm2     # 0xa130
movsd 0x5258(%rip), %xmm3     # 0xa138
callq 0x5d40
xorpd %xmm0, %xmm0
movapd %xmm0, 0x100(%rsp)
movapd %xmm0, 0xf0(%rsp)
movq $0x0, 0x110(%rsp)
leaq 0x98(%rsp), %rdi
leaq 0x338(%rsp), %rdx
movl $0x21c, %esi            # imm = 0x21C
callq 0x6024
leaq 0xc8(%rsp), %rdi
leaq 0x338(%rsp), %rdx
movl $0x21c, %esi            # imm = 0x21C
callq 0x6024
movl $0xffffffff, 0x94(%rsp) # imm = 0xFFFFFFFF
xorpd %xmm0, %xmm0
movapd %xmm0, 0x120(%rsp)
movq $0x0, 0x130(%rsp)
callq 0x3220
cmpl $0x1, %eax
je 0x5051
xorl %r15d, %r15d
leaq 0x94(%rsp), %r13
leaq 0x160(%rsp), %r12
leaq 0x1b0(%rsp), %rbp
leaq 0x338(%rsp), %rbx
leaq 0x120(%rsp), %r14
movq $0x0, 0x1b0(%rsp)
movl $0x40, %edi
callq 0x31d0
leaq 0x8d7b(%rip), %rcx      # 0xdd30
movq %rcx, (%rax)
movq %r13, 0x8(%rax)
leaq 0x538(%rsp), %rcx
movq %rcx, 0x10(%rax)
leaq 0xe0(%rsp), %rcx
movq %rcx, 0x18(%rax)
movq %r12, 0x20(%rax)
leaq 0xf0(%rsp), %rcx
movq %rcx, 0x28(%rax)
leaq 0x98(%rsp), %rcx
movq %rcx, 0x30(%rax)
leaq 0xc8(%rsp), %rcx
movq %rcx, 0x38(%rax)
movq %rax, 0x338(%rsp)
movq %rbp, %rdi
movq %rbx, %rsi
xorl %edx, %edx
callq 0x31a0
movq 0x338(%rsp), %rdi
testq %rdi, %rdi
je 0x5024
movq (%rdi), %rax
callq *0x8(%rax)
movq %r14, %rdi
movq %rbp, %rsi
callq 0x7218
cmpq $0x0, 0x1b0(%rsp)
jne 0x549b
incl %r15d
callq 0x3220
decl %eax
cmpl %eax, %r15d
jb 0x4f98
movq 0x120(%rsp), %rbx
movq 0x128(%rsp), %r14
cmpq %r14, %rbx
je 0x5074
movq %rbx, %rdi
callq 0x32b0
addq $0x8, %rbx
jmp 0x5061
leaq 0x1b0(%rsp), %rdi
callq 0x30f0
leaq 0x1c0(%rsp), %rbx
leaq 0x5110(%rip), %rsi      # 0xa1a0
movl $0x2, %edx
movq %rbx, %rdi
callq 0x3200
movq 0x1c0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30e0
movq %rbx, %rdi
movl $0x3c0, %esi            # imm = 0x3C0
callq 0x32c0
movq %rax, %r14
leaq 0x510f(%rip), %rsi      # 0xa1ef
movl $0x1, %edx
movq %rax, %rdi
callq 0x3200
movq %r14, %rdi
movl $0x21c, %esi            # imm = 0x21C
callq 0x32c0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30e0
leaq 0x5078(%rip), %rsi      # 0xa1a3
movl $0x3, %edx
movq %rbx, %rdi
callq 0x3200
movq 0x1c0(%rsp), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x31c0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x30e0
leaq 0x1c8(%rsp), %rbx
leaq 0x338(%rsp), %rdi
movq %rbx, %rsi
callq 0x3280
leaq 0x98(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x73b6
leaq 0x348(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x51b2
movq 0x348(%rsp), %rsi
incq %rsi
callq 0x31e0
leaq 0x338(%rsp), %rdi
movq %rbx, %rsi
callq 0x3280
leaq 0xc8(%rsp), %rdi
leaq 0x338(%rsp), %rsi
callq 0x73b6
movq 0x338(%rsp), %rdi
cmpq %r14, %rdi
je 0x51f4
movq 0x348(%rsp), %rsi
incq %rsi
callq 0x31e0
cmpl $0x1, 0x8c(%rsp)
jne 0x5234
movq 0xa0(%rsp), %rax
movq 0x8dc3(%rip), %rbx      # 0xdfd0
cmpq 0x98(%rsp), %rax
je 0x52bd
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x3200
movq %r14, %rax
jmp 0x520d
movq 0x140(%rsp), %rax
movq 0x8(%rax), %rsi
leaq 0x338(%rsp), %rdi
movl $0x10, %edx
callq 0x31f0
movq 0xa0(%rsp), %rax
leaq 0x338(%rsp), %rbx
cmpq 0x98(%rsp), %rax
je 0x5285
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x3200
movq %r14, %rax
jmp 0x5262
movq 0x8d34(%rip), %rax      # 0xdfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x340(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x338(%rsp,%rcx)
callq 0x3180
leaq 0x430(%rsp), %rdi
callq 0x3050
leaq 0x4ee3(%rip), %rsi      # 0xa1a7
leaq 0x338(%rsp), %rdi
movl $0x10, %edx
callq 0x31f0
movq 0xd0(%rsp), %rax
leaq 0x338(%rsp), %rbx
cmpq 0xc8(%rsp), %rax
je 0x5309
leaq -0x20(%rax), %r14
movq -0x20(%rax), %rsi
movq -0x18(%rax), %rdx
movq %rbx, %rdi
callq 0x3200
movq %r14, %rax
jmp 0x52e6
movq 0x8cb0(%rip), %rax      # 0xdfc0
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x340(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x338(%rsp,%rcx)
callq 0x3180
leaq 0x430(%rsp), %rdi
callq 0x3050
movq 0x8c60(%rip), %rsi      # 0xdfa8
leaq 0x1b0(%rsp), %rdi
callq 0x3120
leaq 0x230(%rsp), %rdi
callq 0x3050
leaq 0x120(%rsp), %rdi
callq 0x60ae
leaq 0xc8(%rsp), %rdi
callq 0x60ea
leaq 0x98(%rsp), %rdi
callq 0x60ea
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x539b
callq 0x37ec
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x53aa
callq 0x37ec
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x53b9
callq 0x37ec
leaq 0xb0(%rsp), %rdi
callq 0x6146
xorl %eax, %eax
addq $0x5e8, %rsp            # imm = 0x5E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x5465
jmp 0x5465
movq %rax, %rbx
movq 0x338(%rsp), %rdi
cmpq %r14, %rdi
jne 0x5413
jmp 0x54b5
jmp 0x5465
movq %rax, %rbx
leaq 0x348(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x54b5
movq 0x348(%rsp), %rsi
incq %rsi
callq 0x31e0
jmp 0x54b5
jmp 0x5465
jmp 0x54a0
movq %rax, %rbx
jmp 0x54f0
jmp 0x5436
movq %rax, %rbx
jmp 0x54fd
jmp 0x5459
jmp 0x5459
jmp 0x5459
jmp 0x5459
jmp 0x5459
jmp 0x5459
jmp 0x5459
movq %rax, %rbx
jmp 0x551e
jmp 0x555f
movq %rax, %rbx
jmp 0x550f
jmp 0x5465
jmp 0x54a5
movq %rax, %rbx
jmp 0x54b5
jmp 0x54a0
movq %rax, %rbx
movq 0x338(%rsp), %rdi
testq %rdi, %rdi
je 0x5482
movq (%rdi), %rax
callq *0x8(%rax)
movq $0x0, 0x338(%rsp)
jmp 0x54d6
cmpq $0x0, 0x1b0(%rsp)
je 0x54a0
callq 0x3040
movq %rax, %rbx
jmp 0x54d6
movq %rax, %rbx
leaq 0x338(%rsp), %rdi
callq 0x3260
movq 0x8aec(%rip), %rsi      # 0xdfa8
leaq 0x1b0(%rsp), %rdi
callq 0x3120
leaq 0x230(%rsp), %rdi
callq 0x3050
leaq 0x120(%rsp), %rdi
callq 0x60ae
leaq 0xc8(%rsp), %rdi
callq 0x60ea
leaq 0x98(%rsp), %rdi
callq 0x60ea
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x550f
callq 0x37ec
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x551e
callq 0x37ec
movq 0x60(%rsp), %rdi
jmp 0x5553
jmp 0x5548
jmp 0x5548
jmp 0x5548
jmp 0x5548
jmp 0x5548
movq %rax, %rbx
movq 0x540(%rsp), %rdi
testq %rdi, %rdi
je 0x554b
callq 0x37ec
jmp 0x554b
jmp 0x555f
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
testq %rdi, %rdi
je 0x5562
callq 0x37ec
jmp 0x5562
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x6146
movq %rbx, %rdi
callq 0x32e0
nop