// File: Crawler995[P]Cpp-Ray-Tracing/libs/cook_torrance_material.cpp
// Function: CookTorranceMaterial::normal_distribution(Ray3, Vector3)
double CookTorranceMaterial::normal_distribution(Ray3 ray, Vector3 normal) {
    Vector3 light(1, 1, 1);
    Vector3 h = light.normalize().subtract(ray.get_dir()).normalize();

    double n_dot_h = normal.dot(h);
    double v_dot_h = ray.get_dir().negate().dot(h);

    double g1 = 2 * n_dot_h * normal.dot(light.normalize()) / v_dot_h;
    double g2 = 2 * n_dot_h * normal.dot(ray.get_dir().negate()) / v_dot_h;

    return std::min(std::min(1.0, g1), g2);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x190, %rsp            # imm = 0x190
leaq 0x40(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x170(%rbp)
movq %rdi, -0x8(%rbp)
leaq -0x20(%rbp), %rdi
movsd 0x2e47(%rip), %xmm2     # 0x9098
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2c50
leaq -0x68(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2d90
movq -0x170(%rbp), %rsi
leaq -0x80(%rbp), %rdi
callq 0x3470
leaq -0x50(%rbp), %rdi
leaq -0x68(%rbp), %rsi
leaq -0x80(%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 -0x38(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x2d90
movq -0x160(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0x98(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x90(%rbp)
leaq -0xa0(%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
movq -0x170(%rbp), %rsi
movsd %xmm0, -0x88(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x3470
leaq -0xc0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
callq 0x2df0
movq -0x38(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0x30(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0xc0(%rbp), %rdi
leaq -0xf0(%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, -0xa8(%rbp)
movsd 0x2d58(%rip), %xmm0     # 0x90e0
mulsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x168(%rbp)
leaq -0x110(%rbp), %rdi
leaq -0x20(%rbp), %rsi
callq 0x2d90
movq -0x160(%rbp), %rdi
leaq -0x110(%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
movq -0x170(%rbp), %rsi
movaps %xmm0, %xmm1
movsd -0x168(%rbp), %xmm0
mulsd %xmm1, %xmm0
divsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0xf8(%rbp)
movsd 0x2cde(%rip), %xmm0     # 0x90e0
mulsd -0x88(%rbp), %xmm0
movsd %xmm0, -0x158(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x3470
leaq -0x130(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x2df0
movq -0x160(%rbp), %rdi
leaq -0x130(%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
movaps %xmm0, %xmm1
movsd -0x158(%rbp), %xmm0
mulsd %xmm1, %xmm0
divsd -0xa8(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
movsd 0x2c14(%rip), %xmm0     # 0x9098
movsd %xmm0, -0x150(%rbp)
leaq -0x150(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x64c0
movq %rax, %rdi
leaq -0x118(%rbp), %rsi
callq 0x64c0
movsd (%rax), %xmm0
addq $0x190, %rsp            # imm = 0x190
popq %rbp
retq
nopl (%rax,%rax)