// File: daltonbr[P]RayTracing/./src/main.cpp
// Function: color(ray const&, hitable*, int)
vec3 color(const ray& r, hitable *world, int depth)
{
    hit_record rec;
    if (world->hit(r, 0.001, MAXFLOAT, rec))  // acne problem solved
    {
        ray scattered;
        vec3 attenuation;
        if (depth < 50 && rec.mat_ptr->scatter(r, rec, attenuation, scattered))
        {
            return attenuation * color(scattered, world, depth + 1);
        }
        else
        {
            return vec3(0, 0, 0);
        }
    }
    else
    {
        vec3 unit_direction = unit_vector(r.direction());
        float t = 0.5 * (unit_direction.y() + 1.0);
        // Lerping from white to blue in y
        return (1.0 - t) * vec3(1, 1, 1) + t * vec3(0.5, 0.7, 1.0);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
movl %edx, -0x24(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x20e90
movq -0x20(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
movss 0x1a6fe(%rip), %xmm0    # 0x22030
movss 0x1a6fa(%rip), %xmm1    # 0x22034
leaq -0x50(%rbp), %rdx
callq *(%rax)
testb $0x1, %al
jne 0x7949
jmp 0x7a07
leaq -0x68(%rbp), %rdi
callq 0x20ec0
leaq -0x74(%rbp), %rdi
callq 0x20a20
cmpl $0x32, -0x24(%rbp)
jge 0x79f0
movq -0x30(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq (%rdi), %rax
leaq -0x50(%rbp), %rdx
leaq -0x74(%rbp), %rcx
leaq -0x68(%rbp), %r8
callq *(%rax)
testb $0x1, %al
jne 0x7984
jmp 0x79f0
movq -0x20(%rbp), %rsi
movl -0x24(%rbp), %edx
incl %edx
leaq -0x68(%rbp), %rdi
callq 0x7900
movss %xmm1, -0x88(%rbp)
movlpd %xmm0, -0x90(%rbp)
movl -0x88(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0x80(%rbp)
leaq -0x74(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x20ef0
movss %xmm1, -0x98(%rbp)
movlpd %xmm0, -0xa0(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0x98(%rbp), %eax
movl %eax, -0x4(%rbp)
jmp 0x7bfa
leaq -0xc(%rbp), %rdi
xorps %xmm2, %xmm2
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x20b10
jmp 0x7bfa
movq -0x18(%rbp), %rdi
callq 0x20d50
movss %xmm1, -0xc8(%rbp)
movlpd %xmm0, -0xd0(%rbp)
movl -0xc8(%rbp), %eax
movl %eax, -0xb8(%rbp)
movq -0xd0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0xd8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movsd -0xe0(%rbp), %xmm0
movss -0xd8(%rbp), %xmm1
callq 0x20bf0
movss %xmm1, -0xe8(%rbp)
movlpd %xmm0, -0xf0(%rbp)
movl -0xe8(%rbp), %eax
movl %eax, -0xa8(%rbp)
movq -0xf0(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x20f60
cvtss2sd %xmm0, %xmm1
movsd 0x1a5f5(%rip), %xmm0    # 0x220a0
addsd %xmm0, %xmm1
movsd 0x1a5f1(%rip), %xmm2    # 0x220a8
mulsd %xmm2, %xmm1
cvtsd2ss %xmm1, %xmm1
movss %xmm1, -0xf4(%rbp)
movss -0xf4(%rbp), %xmm1
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x18c(%rbp)
leaq -0x10c(%rbp), %rdi
movq %rdi, -0x188(%rbp)
movss 0x1a50f(%rip), %xmm2    # 0x22008
movss %xmm2, -0x180(%rbp)
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x20b10
movss -0x18c(%rbp), %xmm0
movq -0x188(%rbp), %rdi
callq 0x20aa0
movss -0x180(%rbp), %xmm2
movss %xmm1, -0x118(%rbp)
movlpd %xmm0, -0x120(%rbp)
movl -0x118(%rbp), %eax
movl %eax, -0xf8(%rbp)
movq -0x120(%rbp), %rax
movq %rax, -0x100(%rbp)
movss -0xf4(%rbp), %xmm0
movss %xmm0, -0x17c(%rbp)
leaq -0x13c(%rbp), %rdi
movq %rdi, -0x178(%rbp)
movss 0x1a498(%rip), %xmm0    # 0x22010
movss 0x1a4b8(%rip), %xmm1    # 0x22038
callq 0x20b10
movss -0x17c(%rbp), %xmm0
movq -0x178(%rbp), %rdi
callq 0x20aa0
movss %xmm1, -0x148(%rbp)
movlpd %xmm0, -0x150(%rbp)
movl -0x148(%rbp), %eax
movl %eax, -0x128(%rbp)
movq -0x150(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x20f80
movss %xmm1, -0x158(%rbp)
movlpd %xmm0, -0x160(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0xc(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x4(%rbp)
movl -0x4(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0xc(%rbp), %rax
movq %rax, -0x170(%rbp)
movsd -0x170(%rbp), %xmm0
movss -0x168(%rbp), %xmm1
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopw (%rax,%rax)