// File: Crawler995[P]Cpp-Ray-Tracing/libs/cook_torrance_material.cpp
// Function: CookTorranceMaterial::sample(Ray3, Vector3, Vector3)
Color CookTorranceMaterial::sample(Ray3 ray, Vector3 position, Vector3 normal) {
    Vector3 light(1, 1, 1);
    double ed = normal.dot(light.normalize());
    Vector3 h = light.normalize().subtract(ray.get_dir()).normalize();

    ed = (ed >= 0.0) ? ed : 0;
    
    Color diffuse = diffuse_color.multiply(diffuse_factor * ed);
    Color specular = specular_color.multiply(specular_factor * BRDF(ray, normal));
    Color envir = envir_color.multiply(envir_factor);

    Color res = envir.add(specular.add(diffuse));

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x250, %rsp            # imm = 0x250
leaq 0x58(%rbp), %rax
movq %rax, -0x1e0(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x1d8(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1e8(%rbp)
leaq -0x30(%rbp), %rdi
movsd 0x375c(%rip), %xmm2     # 0x9098
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2c50
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d90
movq -0x1e0(%rbp), %rdi
leaq -0x50(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x30d0
movsd %xmm0, -0x38(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d90
movq -0x1d8(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
callq 0x3470
leaq -0x80(%rbp), %rdi
leaq -0x98(%rbp), %rsi
leaq -0xb0(%rbp), %rax
movq (%rax), %rcx
movq %rcx, (%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x8(%rsp)
movq 0x10(%rax), %rax
movq %rax, 0x10(%rsp)
callq 0x2f80
leaq -0x68(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x2d90
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x59ff
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x1f0(%rbp)
jmp 0x5a0c
xorps %xmm0, %xmm0
movsd %xmm0, -0x1f0(%rbp)
jmp 0x5a0c
movq -0x1e8(%rbp), %rax
movsd -0x1f0(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %rax, %rdi
addq $0x2c, %rdi
movsd 0x10(%rax), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x4d50
movq -0x1d8(%rbp), %rcx
movq -0x1e8(%rbp), %rdi
movq %rax, %rsi
movq -0x1e0(%rbp), %rax
movq %rsi, -0x208(%rbp)
movl %edx, %esi
movq -0x208(%rbp), %rdx
movl %esi, -0xc8(%rbp)
movq %rdx, -0xd0(%rbp)
movl -0xc8(%rbp), %edx
movl %edx, -0xb8(%rbp)
movq -0xd0(%rbp), %rdx
movq %rdx, -0xc0(%rbp)
movq %rdi, %rdx
addq $0x38, %rdx
movq %rdx, -0x200(%rbp)
movsd 0x18(%rdi), %xmm0
movsd %xmm0, -0x1f8(%rbp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movups 0x20(%rcx), %xmm2
movaps %xmm2, -0xf0(%rbp)
movaps %xmm1, -0x100(%rbp)
movaps %xmm0, -0x110(%rbp)
movq 0x10(%rax), %rcx
movq %rcx, -0x120(%rbp)
movups (%rax), %xmm0
movaps %xmm0, -0x130(%rbp)
movq -0x120(%rbp), %rcx
movq %rsp, %rax
movq %rcx, 0x40(%rax)
movaps -0x130(%rbp), %xmm0
movups %xmm0, 0x30(%rax)
movaps -0x110(%rbp), %xmm0
movaps -0x100(%rbp), %xmm1
movaps -0xf0(%rbp), %xmm2
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x5c90
movq -0x200(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x1f8(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x4d50
movq %rax, %rcx
movq -0x1e8(%rbp), %rax
movl %edx, -0x138(%rbp)
movq %rcx, -0x140(%rbp)
movl -0x138(%rbp), %ecx
movl %ecx, -0xd8(%rbp)
movq -0x140(%rbp), %rcx
movq %rcx, -0xe0(%rbp)
movq %rax, %rdi
addq $0x20, %rdi
movsd 0x8(%rax), %xmm0
callq 0x4d50
movl %edx, -0x158(%rbp)
movq %rax, -0x160(%rbp)
movl -0x158(%rbp), %eax
movl %eax, -0x148(%rbp)
movq -0x160(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0xb8(%rbp), %eax
movl %eax, -0x178(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x180(%rbp)
movl -0x178(%rbp), %eax
movl %eax, -0x188(%rbp)
movq -0x180(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x190(%rbp), %rsi
movl -0x188(%rbp), %edx
leaq -0xe0(%rbp), %rdi
callq 0x4cf0
movl %edx, -0x198(%rbp)
movq %rax, -0x1a0(%rbp)
movl -0x198(%rbp), %eax
movl %eax, -0x168(%rbp)
movq -0x1a0(%rbp), %rax
movq %rax, -0x170(%rbp)
movl -0x168(%rbp), %eax
movl %eax, -0x1a8(%rbp)
movq -0x170(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x1b0(%rbp), %rsi
movl -0x1a8(%rbp), %edx
leaq -0x150(%rbp), %rdi
callq 0x4cf0
movl %edx, -0x1b8(%rbp)
movq %rax, -0x1c0(%rbp)
movl -0x1b8(%rbp), %eax
movl %eax, -0x8(%rbp)
movq -0x1c0(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x1c8(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rax
movl -0x1c8(%rbp), %edx
addq $0x250, %rsp            # imm = 0x250
popq %rbp
retq
nopl (%rax)