// File: 2TallTim[P]modern-raytracing/raytrace.cpp
// Function: color(ray const&, std::shared_ptr<hitable>, int)
vec3 color(const ray &r, hitable::Ptr world, int depth = 0)
{
    hit_record rec;
    if(world->hit(r, 0.001, MAXFLOAT, rec)){
        ray scattered;
        vec3 attenuation;
        vec3 emitted = rec.mat_ptr->emitted();
        if (depth < 5 && rec.mat_ptr->scatter(r, rec, attenuation, scattered)) {
            return emitted + attenuation * color(scattered, world, depth+1);
        }else{
            return emitted;
        }
    } else {
        vec3 unit_direction = unit_vector(r.direction());
        double t = 0.5 * (unit_direction.y() + 1.0);
        return (1.0 - t) * vec3(1.0, 1.0, 1.0) + t * vec3(0.5, 0.7, 1.0);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x220, %rsp            # imm = 0x220
movq %rdx, -0x1c8(%rbp)
movq %rdi, -0x1d8(%rbp)
movq %rdi, -0x1d0(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movl %ecx, -0x14(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x1c0(%rbp)
callq 0x4600
movq -0x1c8(%rbp), %rdi
callq 0x4730
movq -0x1c0(%rbp), %rdx
movq %rax, %rdi
movq -0x8(%rbp), %rsi
movq (%rdi), %rax
movq (%rax), %rax
movsd 0x1084d(%rip), %xmm0    # 0x170f0
movsd 0x1084d(%rip), %xmm1    # 0x170f8
callq *%rax
movb %al, -0x1b1(%rbp)
jmp 0x68b5
movb -0x1b1(%rbp), %al
testb $0x1, %al
jne 0x68c4
jmp 0x6a3b
leaq -0xa0(%rbp), %rdi
callq 0x8ed0
jmp 0x68d2
leaq -0xb8(%rbp), %rdi
callq 0x4d20
jmp 0x68e0
leaq -0x28(%rbp), %rdi
callq 0x8f00
movq %rax, %rsi
movq (%rsi), %rax
movq 0x8(%rax), %rax
leaq -0xd0(%rbp), %rdi
callq *%rax
jmp 0x68fe
cmpl $0x5, -0x14(%rbp)
jge 0x6a05
leaq -0x28(%rbp), %rdi
callq 0x8f00
movq %rax, %rdi
movq -0x8(%rbp), %rsi
movq (%rdi), %rax
movq (%rax), %rax
leaq -0x60(%rbp), %rdx
leaq -0xb8(%rbp), %rcx
leaq -0xa0(%rbp), %r8
callq *%rax
movb %al, -0x1d9(%rbp)
jmp 0x693a
movb -0x1d9(%rbp), %al
testb $0x1, %al
jne 0x6949
jmp 0x6a05
movq -0x1c8(%rbp), %rsi
leaq -0x110(%rbp), %rdi
movq %rdi, -0x1e8(%rbp)
callq 0x4700
movq -0x1e8(%rbp), %rdx
movl -0x14(%rbp), %ecx
incl %ecx
leaq -0x100(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x6840
jmp 0x6984
leaq -0xe8(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x100(%rbp), %rdx
callq 0x8f20
jmp 0x69a0
movq -0x1d8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
leaq -0xe8(%rbp), %rdx
callq 0x3e50
jmp 0x69bc
leaq -0x110(%rbp), %rdi
callq 0x47a0
movl $0x1, -0x114(%rbp)
jmp 0x6b72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x6b8b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x47a0
jmp 0x6b8b
movq -0x1d8(%rbp), %rax
movq -0xd0(%rbp), %rcx
movq %rcx, (%rax)
movq -0xc8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0xc0(%rbp), %rcx
movq %rcx, 0x10(%rax)
movl $0x1, -0x114(%rbp)
jmp 0x6b72
movq -0x8(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x3cf0
jmp 0x6a4d
movq -0x138(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x10(%rax)
movups -0x148(%rbp), %xmm0
movups %xmm0, (%rax)
leaq -0x130(%rbp), %rdi
callq 0x8fd0
jmp 0x6a73
leaq -0x130(%rbp), %rdi
callq 0x3f70
movsd %xmm0, -0x1f0(%rbp)
jmp 0x6a89
movsd -0x1f0(%rbp), %xmm0
movsd 0x105c7(%rip), %xmm2    # 0x17060
addsd %xmm2, %xmm0
movsd 0x1065b(%rip), %xmm1    # 0x17100
mulsd %xmm1, %xmm0
movsd %xmm0, -0x150(%rbp)
movsd -0x150(%rbp), %xmm1
movaps %xmm2, %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, -0x1f8(%rbp)
leaq -0x180(%rbp), %rdi
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x3e10
jmp 0x6adc
movsd -0x1f8(%rbp), %xmm0
leaq -0x168(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x3fb0
jmp 0x6af9
movsd -0x150(%rbp), %xmm0
movsd %xmm0, -0x200(%rbp)
leaq -0x1b0(%rbp), %rdi
movsd 0x105e8(%rip), %xmm0    # 0x17100
movsd 0x105e8(%rip), %xmm1    # 0x17108
movsd 0x10538(%rip), %xmm2    # 0x17060
callq 0x3e10
jmp 0x6b2f
movsd -0x200(%rbp), %xmm0
leaq -0x198(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x3fb0
jmp 0x6b4c
movq -0x1d8(%rbp), %rdi
leaq -0x168(%rbp), %rsi
leaq -0x198(%rbp), %rdx
callq 0x3e50
jmp 0x6b68
movl $0x1, -0x114(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x47e0
movq -0x1d0(%rbp), %rax
addq $0x220, %rsp            # imm = 0x220
popq %rbp
retq
leaq -0x60(%rbp), %rdi
callq 0x47e0
movq -0x68(%rbp), %rdi
callq 0x3390
nopl (%rax)