// File: /workspace/github_cpp_makefile_star2_O1/alan0201tw[P]RayTracer/src/main.cpp
// Function: main
int main()
{
    //srand48(int(time(nullptr)));

    {
        // since the destructor of ThreadPool joins all threads
        // I use a simple scope to wait for all works to be done
        ThreadPool pool(8);

        // Into the screen is negative z axis
        for(int j = image_height - 1; j >= 0; j--)
        {
            for(int i = 0; i < image_width; i++)
            {
                pool.enqueue(thread_entry, i, j);
            }
        }
    }
    
    stbi_flip_vertically_on_write(true);
    if(stbi_write_png("output.png", image_width, image_height, 3, image, 0) == 0)
    {
        std::cerr << "Error when saving image\n";
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
leaq 0x48(%rsp), %rbx
xorps %xmm0, %xmm0
movaps %xmm0, 0x38(%rbx)
movaps %xmm0, 0x28(%rbx)
movaps %xmm0, 0x18(%rbx)
movaps %xmm0, 0x8(%rbx)
movaps %xmm0, -0x8(%rbx)
movaps %xmm0, -0x18(%rbx)
movq $0x0, 0x48(%rbx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x39d64
leaq 0x98(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, 0x10(%rax)
movups %xmm0, (%rax)
movq $0x0, 0x20(%rax)
leaq 0xc0(%rsp), %r13
movq %r13, %rdi
callq 0x6510
movb $0x0, 0x30(%r13)
movl $0x8, %r12d
leaq 0x30(%rsp), %r14
leaq 0x10(%rsp), %r15
movq %r14, 0x10(%rsp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x39cf2
decq %r12
jne 0x29029
leaq 0x10(%rsp), %r15
movl $0x31f, (%r15)          # imm = 0x31F
leaq -0x4e8(%rip), %r12      # 0x28b69
leaq 0x20(%rsp), %r13
leaq 0x30(%rsp), %rbp
leaq 0xc(%rsp), %r14
movl $0x0, 0xc(%rsp)
movq %r13, %rdi
movq %rbp, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
callq 0x39ae4
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x2908b
callq 0x7768
movl 0xc(%rsp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
cmpl $0x31f, %eax            # imm = 0x31F
jl 0x29068
movl 0x10(%rsp), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsp)
testl %eax, %eax
jg 0x29060
leaq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rax
movq %rax, (%rdi)
movb $0x0, 0x8(%rdi)
callq 0x3a28e
movb $0x1, %al
leaq 0x10(%rsp), %rdi
movb %al, 0x8(%rdi)
movb %al, 0xf0(%rsp)
callq 0x3a278
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
callq 0x6690
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r15
cmpq %r15, %r14
je 0x29108
movq %r14, %rdi
callq 0x66a0
addq $0x8, %r14
jmp 0x290f5
movq %r12, %rdi
callq 0x6700
movq %rbx, %rdi
callq 0x3a3e8
leaq 0x30(%rsp), %rdi
callq 0x39d28
movl $0x1, 0x263d0(%rip)     # 0x4f4fc
leaq 0x1643a(%rip), %rdi     # 0x3f56d
leaq 0x26466(%rip), %r8      # 0x4f5a0
movl $0x320, %esi            # imm = 0x320
movl $0x320, %edx            # imm = 0x320
movl $0x3, %ecx
xorl %r9d, %r9d
callq 0x28168
testl %eax, %eax
jne 0x2916d
movq 0x25e84(%rip), %rdi     # 0x4efe0
leaq 0x16415(%rip), %rsi     # 0x3f578
movl $0x18, %edx
callq 0x6470
xorl %eax, %eax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x29188
movq %rax, %r14
jmp 0x291a3
movq %rax, %rdi
callq 0x1bd1a
movq %rax, %r14
movq %r13, %rdi
callq 0x6700
movq %rbx, %rdi
callq 0x3a3e8
leaq 0x30(%rsp), %rdi
callq 0x39d28
jmp 0x291bc
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x39c62
movq %r14, %rdi
callq 0x66e0