// File: /workspace/github_cpp_makefile_star2_O3/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 0x399a6
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 0x3992e
decq %r12
jne 0x2862f
leaq 0x10(%rsp), %r15
movl $0x31f, (%r15)          # imm = 0x31F
leaq -0x46d(%rip), %r12      # 0x281ea
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 0x39720
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x28691
callq 0x7774
movl 0xc(%rsp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0xc(%rsp)
cmpl $0x31f, %eax            # imm = 0x31F
jl 0x2866e
movl 0x10(%rsp), %eax
leal -0x1(%rax), %ecx
movl %ecx, 0x10(%rsp)
testl %eax, %eax
jg 0x28666
leaq 0x10(%rsp), %rdi
leaq 0x98(%rsp), %rax
movq %rax, (%rdi)
movb $0x0, 0x8(%rdi)
callq 0x39ea8
movb $0x1, %al
leaq 0x10(%rsp), %rdi
movb %al, 0x8(%rdi)
movb %al, 0xf0(%rsp)
callq 0x39e92
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
callq 0x6690
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %r15
cmpq %r15, %r14
je 0x2870e
movq %r14, %rdi
callq 0x66a0
addq $0x8, %r14
jmp 0x286fb
movq %r12, %rdi
callq 0x6700
movq %rbx, %rdi
callq 0x3a00a
leaq 0x30(%rsp), %rdi
callq 0x3996a
movl $0x1, 0x26daa(%rip)     # 0x4f4dc
leaq 0x1709c(%rip), %rdi     # 0x3f7d5
leaq 0x26e40(%rip), %r8      # 0x4f580
movl $0x320, %esi            # imm = 0x320
movl $0x320, %edx            # imm = 0x320
movl $0x3, %ecx
xorl %r9d, %r9d
callq 0x2771b
testl %eax, %eax
jne 0x28773
movq 0x2687e(%rip), %rdi     # 0x4efe0
leaq 0x17077(%rip), %rsi     # 0x3f7e0
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 0x2878e
movq %rax, %r14
jmp 0x287a9
movq %rax, %rdi
callq 0x1b3c3
movq %rax, %r14
movq %r13, %rdi
callq 0x6700
movq %rbx, %rdi
callq 0x3a00a
leaq 0x30(%rsp), %rdi
callq 0x3996a
jmp 0x287c2
movq %rax, %r14
leaq 0x30(%rsp), %rdi
callq 0x3989e
movq %r14, %rdi
callq 0x66e0