// File: /workspace/github_cpp_makefile_star2_O1/alan0201tw[P]RayTracer/src/main.cpp
// Function: thread_entry(int, int)
void thread_entry(int i, int j)
{
    vec3 accumulated_col(0, 0, 0);

    for(int s = 0; s < msaa_sample_count; s++)
    {
        float u = float(i + drand48()) / float(image_width);
        float v = float(j + drand48()) / float(image_height);

        ray r = cam.get_ray(u, v);
        accumulated_col += get_color(r, world, 0);
    }
    accumulated_col /= (float)msaa_sample_count;

    // accumulated_col[0] = std::clamp(accumulated_col[0], 0.0f, 1.0f);
    // accumulated_col[1] = std::clamp(accumulated_col[1], 0.0f, 1.0f);
    // accumulated_col[2] = std::clamp(accumulated_col[2], 0.0f, 1.0f);

    accumulated_col = vec3(std::sqrt(accumulated_col[0]), std::sqrt(accumulated_col[1]), std::sqrt(accumulated_col[2]));
    int r255 = int(255.99f * accumulated_col[0]);
    int g255 = int(255.99f * accumulated_col[1]);
    int b255 = int(255.99f * accumulated_col[2]);

    r255 = std::clamp(r255, 0, 255);
    g255 = std::clamp(g255, 0, 255);
    b255 = std::clamp(b255, 0, 255);

    //std::cout << r01 << " " << g01 << " " << b01 << "\n";
    //  
    //  r[j][i]
    //  
    //  r01 g01 b01, r02 g02 b02, r03 g03 b03 .... , r0<width> b0<width> g0<width>,
    //  r11 g11 b11 ( = rgb[ width + 1 ] )
    //
    image[j * 3 * image_width + i * 3 + 0] = r255;
    image[j * 3 * image_width + i * 3 + 1] = g255;
    image[j * 3 * image_width + i * 3 + 2] = b255;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movl %esi, %ebp
movl %edi, %ebx
cvtsi2sd %edi, %xmm0
movsd %xmm0, 0x50(%rsp)
xorps %xmm0, %xmm0
cvtsi2sd %esi, %xmm0
movsd %xmm0, 0x48(%rsp)
xorpd %xmm0, %xmm0
movss %xmm0, 0x8(%rsp)
movl $0x12c, %r12d           # imm = 0x12C
leaq 0x60(%rsp), %r14
leaq 0x20(%rsp), %r15
movq 0x263ea(%rip), %r13     # 0x4efa0
movss %xmm0, 0x10(%rsp)
movss %xmm0, 0xc(%rsp)
callq 0x63a0
addsd 0x50(%rsp), %xmm0
xorps %xmm1, %xmm1
cvtsd2ss %xmm0, %xmm1
movss 0x146c4(%rip), %xmm0    # 0x3d2a0
divss %xmm0, %xmm1
movss %xmm1, 0x30(%rsp)
callq 0x63a0
addsd 0x48(%rsp), %xmm0
cvtsd2ss %xmm0, %xmm0
divss 0x146a3(%rip), %xmm0    # 0x3d2a0
movss %xmm0, 0x18(%rsp)
movss 0x2697d(%rip), %xmm0    # 0x4f588
movss %xmm0, 0x14(%rsp)
callq 0x15075
movss 0x14(%rsp), %xmm4
movaps %xmm4, %xmm3
mulss %xmm0, %xmm3
shufps $0x55, %xmm0, %xmm0     # xmm0 = xmm0[1,1,1,1]
movss 0x26941(%rip), %xmm1    # 0x4f570
mulss %xmm3, %xmm1
movss 0x26939(%rip), %xmm2    # 0x4f574
mulss %xmm3, %xmm2
mulss 0x26931(%rip), %xmm3    # 0x4f578
mulss %xmm4, %xmm0
movss 0x26929(%rip), %xmm4    # 0x4f57c
mulss %xmm0, %xmm4
addss %xmm1, %xmm4
movss %xmm4, 0x14(%rsp)
movss 0x26917(%rip), %xmm1    # 0x4f580
mulss %xmm0, %xmm1
mulss 0x2690f(%rip), %xmm0    # 0x4f584
addss %xmm2, %xmm1
movss %xmm1, 0x1c(%rsp)
addss %xmm3, %xmm0
movaps %xmm0, 0x80(%rsp)
xorps %xmm0, %xmm0
cvtss2sd 0x268f6(%rip), %xmm0    # 0x4f58c
movsd %xmm0, 0x58(%rsp)
callq 0x63a0
movss 0x268e7(%rip), %xmm1    # 0x4f590
subss 0x268db(%rip), %xmm1    # 0x4f58c
cvtss2sd %xmm1, %xmm1
mulsd %xmm0, %xmm1
addsd 0x58(%rsp), %xmm1
xorps %xmm0, %xmm0
cvtsd2ss %xmm1, %xmm0
movss 0x2688a(%rip), %xmm3    # 0x4f558
movss 0x14(%rsp), %xmm11
movaps %xmm11, %xmm1
addss %xmm3, %xmm1
movss 0x26877(%rip), %xmm4    # 0x4f55c
movss 0x1c(%rsp), %xmm13
movaps %xmm13, %xmm2
addss %xmm4, %xmm2
unpcklps %xmm2, %xmm1            # xmm1 = xmm1[0],xmm2[0],xmm1[1],xmm2[1]
movss 0x26861(%rip), %xmm5    # 0x4f560
movaps 0x80(%rsp), %xmm12
movaps %xmm12, %xmm2
addss %xmm5, %xmm2
movss 0x26828(%rip), %xmm6    # 0x4f540
movss 0x30(%rsp), %xmm8
mulss %xmm8, %xmm6
movss 0x26818(%rip), %xmm7    # 0x4f544
mulss %xmm8, %xmm7
mulss 0x2680e(%rip), %xmm8    # 0x4f548
addss 0x267f2(%rip), %xmm6    # 0x4f534
addss 0x267ee(%rip), %xmm7    # 0x4f538
addss 0x267e9(%rip), %xmm8    # 0x4f53c
movaps %xmm8, %xmm10
movss 0x267ec(%rip), %xmm8    # 0x4f54c
movss 0x18(%rsp), %xmm9
mulss %xmm9, %xmm8
addss %xmm6, %xmm8
movss 0x267d7(%rip), %xmm6    # 0x4f550
mulss %xmm9, %xmm6
addss %xmm7, %xmm6
mulss 0x267c9(%rip), %xmm9    # 0x4f554
addss %xmm10, %xmm9
subss %xmm3, %xmm8
subss %xmm4, %xmm6
subss %xmm5, %xmm9
subss %xmm11, %xmm8
subss %xmm13, %xmm6
unpcklps %xmm6, %xmm8            # xmm8 = xmm8[0],xmm6[0],xmm8[1],xmm6[1]
subss %xmm12, %xmm9
movlps %xmm1, 0x60(%rsp)
movss %xmm2, 0x68(%rsp)
movlps %xmm8, 0x6c(%rsp)
movss %xmm9, 0x74(%rsp)
movss %xmm0, 0x78(%rsp)
movq 0x2672a(%rip), %rax     # 0x4f500
movq %rax, 0x20(%rsp)
movq 0x26726(%rip), %rax     # 0x4f508
movq %rax, 0x28(%rsp)
testq %rax, %rax
je 0x28dfc
cmpb $0x0, (%r13)
je 0x28df8
incl 0x8(%rax)
jmp 0x28dfc
lock
incl 0x8(%rax)
movq %r14, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq 0x289d6
movaps %xmm0, %xmm2
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x28e31
movss %xmm1, 0x18(%rsp)
movaps %xmm2, 0x30(%rsp)
callq 0x7768
movaps 0x30(%rsp), %xmm2
movss 0x18(%rsp), %xmm1
movss 0xc(%rsp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0xc(%rsp)
shufps $0x55, %xmm2, %xmm2     # xmm2 = xmm2[1,1,1,1]
movss 0x10(%rsp), %xmm0
addss %xmm2, %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x8(%rsp), %xmm0
addss %xmm1, %xmm0
movss %xmm0, 0x8(%rsp)
decl %r12d
jne 0x28bc2
movss 0x1442e(%rip), %xmm2    # 0x3d2a4
movss 0xc(%rsp), %xmm1
mulss %xmm2, %xmm1
movss 0x10(%rsp), %xmm0
mulss %xmm2, %xmm0
movss %xmm0, 0x10(%rsp)
xorps %xmm3, %xmm3
ucomiss %xmm3, %xmm1
jb 0x28e9e
sqrtss %xmm1, %xmm1
jmp 0x28eb4
movaps %xmm1, %xmm0
callq 0x6710
xorps %xmm3, %xmm3
movss 0x143f3(%rip), %xmm2    # 0x3d2a4
movaps %xmm0, %xmm1
movss 0x8(%rsp), %xmm0
mulss %xmm2, %xmm0
movss %xmm0, 0x8(%rsp)
movss 0x10(%rsp), %xmm0
ucomiss %xmm3, %xmm0
movss %xmm1, 0xc(%rsp)
jb 0x28ede
xorps %xmm3, %xmm3
sqrtss %xmm0, %xmm3
jmp 0x28ee6
callq 0x6710
movaps %xmm0, %xmm3
xorps %xmm1, %xmm1
movss 0x8(%rsp), %xmm0
ucomiss %xmm1, %xmm0
jb 0x28efa
sqrtss %xmm0, %xmm0
jmp 0x28f0b
movss %xmm3, 0x8(%rsp)
callq 0x6710
movss 0x8(%rsp), %xmm3
movss 0xc(%rsp), %xmm2
movss 0x1438f(%rip), %xmm1    # 0x3d2a8
mulss %xmm1, %xmm2
cvttss2si %xmm2, %eax
mulss %xmm1, %xmm3
cvttss2si %xmm3, %ecx
mulss %xmm1, %xmm0
cvttss2si %xmm0, %esi
movl $0xff, %edx
cmpl %edx, %eax
cmovgel %edx, %eax
xorl %edi, %edi
testl %eax, %eax
cmovlel %edi, %eax
cmpl %edx, %ecx
cmovgel %edx, %ecx
testl %ecx, %ecx
cmovlel %edi, %ecx
cmpl %edx, %esi
cmovll %esi, %edx
testl %edx, %edx
cmovlel %edi, %edx
imull $0x960, %ebp, %esi      # imm = 0x960
movslq %ebx, %rdi
leaq (%rdi,%rdi,2), %rdi
movslq %esi, %rsi
addq %rdi, %rsi
leaq 0x26630(%rip), %rdi     # 0x4f5a0
movb %al, (%rdi,%rsi)
movb %cl, 0x1(%rdi,%rsi)
movb %dl, 0x2(%rdi,%rsi)
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x28(%rsp), %rdi
testq %rdi, %rdi
je 0x28f9f
callq 0x7768
movq %rbx, %rdi
callq 0x66e0