// File: Crawler995[P]Cpp-Ray-Tracing/libs/checker_material.cpp
// Function: CheckMaterial::sample(Ray3, Vector3, Vector3)
Color CheckMaterial::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();
    double es = normal.dot(h);

    ed = (ed >= 0.0) ? ed : 0;
    es = (es >= 0.0) ? es : 0;
    
    Color diffuse_color = abs(floor(position.get_x() * scale) + floor(position.get_z() * scale)) % 2 ?
                          Color(0, 0, 0) : Color(255, 255, 255);
    // Color diffuse_color(255, 255, 255);
    Color diffuse = diffuse_color.multiply(diffuse_factor * ed);
    Color specular = specular_color.multiply(specular_factor * pow(es, highlight_factor));
    Color envir = envir_color.multiply(envir_factor);

    Color res = envir.add(specular.add(diffuse));

    return res;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
leaq 0x58(%rbp), %rax
movq %rax, -0x1b0(%rbp)
leaq 0x40(%rbp), %rax
movq %rax, -0x1c8(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x1c0(%rbp)
leaq -0x30(%rbp), %rdi
movsd 0x2a81(%rip), %xmm2     # 0x9098
movaps %xmm2, %xmm0
movaps %xmm2, %xmm1
callq 0x2c50
leaq -0x50(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x2d90
movq -0x1b0(%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 -0x1b8(%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
movq -0x1b0(%rbp), %rdi
movq -0x68(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x60(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xd0(%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, -0xb8(%rbp)
movsd -0x38(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x672f
movsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x1d0(%rbp)
jmp 0x673c
xorps %xmm0, %xmm0
movsd %xmm0, -0x1d0(%rbp)
jmp 0x673c
movsd -0x1d0(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movsd -0xb8(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x676c
movsd -0xb8(%rbp), %xmm0
movsd %xmm0, -0x1d8(%rbp)
jmp 0x6779
xorps %xmm0, %xmm0
movsd %xmm0, -0x1d8(%rbp)
jmp 0x6779
movq -0x1c8(%rbp), %rdi
movsd -0x1d8(%rbp), %xmm0
movsd %xmm0, -0xb8(%rbp)
callq 0x2f20
movq -0x1c0(%rbp), %rax
mulsd 0x48(%rax), %xmm0
callq 0x21c0
movq -0x1c8(%rbp), %rdi
movsd %xmm0, -0x1e0(%rbp)
callq 0x2f60
movq -0x1c0(%rbp), %rax
mulsd 0x48(%rax), %xmm0
callq 0x21c0
movaps %xmm0, %xmm1
movsd -0x1e0(%rbp), %xmm0
addsd %xmm1, %xmm0
cvttsd2si %xmm0, %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl $0x2, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
je 0x6806
leaq -0xdc(%rbp), %rdi
xorl %ecx, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
jmp 0x681b
leaq -0xdc(%rbp), %rdi
movl $0xff, %ecx
movl %ecx, %esi
movl %ecx, %edx
callq 0x4c50
movq -0x1c0(%rbp), %rax
movsd 0x10(%rax), %xmm0
movsd -0x38(%rbp), %xmm1
mulsd %xmm1, %xmm0
leaq -0xdc(%rbp), %rdi
callq 0x4d50
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
movl %edx, -0xf0(%rbp)
movq %rcx, -0xf8(%rbp)
movl -0xf0(%rbp), %ecx
movl %ecx, -0xe0(%rbp)
movq -0xf8(%rbp), %rcx
movq %rcx, -0xe8(%rbp)
movq %rax, %rcx
addq $0x38, %rcx
movq %rcx, -0x1f0(%rbp)
movsd -0xb8(%rbp), %xmm0
movsd 0x18(%rax), %xmm1
movsd %xmm1, -0x1e8(%rbp)
movsd 0x50(%rax), %xmm1
callq 0x21d0
movq -0x1f0(%rbp), %rdi
movaps %xmm0, %xmm1
movsd -0x1e8(%rbp), %xmm0
mulsd %xmm1, %xmm0
callq 0x4d50
movq %rax, %rcx
movq -0x1c0(%rbp), %rax
movl %edx, -0x110(%rbp)
movq %rcx, -0x118(%rbp)
movl -0x110(%rbp), %ecx
movl %ecx, -0x100(%rbp)
movq -0x118(%rbp), %rcx
movq %rcx, -0x108(%rbp)
movq %rax, %rdi
addq $0x20, %rdi
movsd 0x8(%rax), %xmm0
callq 0x4d50
movl %edx, -0x130(%rbp)
movq %rax, -0x138(%rbp)
movl -0x130(%rbp), %eax
movl %eax, -0x120(%rbp)
movq -0x138(%rbp), %rax
movq %rax, -0x128(%rbp)
movl -0xe0(%rbp), %eax
movl %eax, -0x150(%rbp)
movq -0xe8(%rbp), %rax
movq %rax, -0x158(%rbp)
movl -0x150(%rbp), %eax
movl %eax, -0x160(%rbp)
movq -0x158(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x168(%rbp), %rsi
movl -0x160(%rbp), %edx
leaq -0x108(%rbp), %rdi
callq 0x4cf0
movl %edx, -0x170(%rbp)
movq %rax, -0x178(%rbp)
movl -0x170(%rbp), %eax
movl %eax, -0x140(%rbp)
movq -0x178(%rbp), %rax
movq %rax, -0x148(%rbp)
movl -0x140(%rbp), %eax
movl %eax, -0x180(%rbp)
movq -0x148(%rbp), %rax
movq %rax, -0x188(%rbp)
movq -0x188(%rbp), %rsi
movl -0x180(%rbp), %edx
leaq -0x128(%rbp), %rdi
callq 0x4cf0
movl %edx, -0x190(%rbp)
movq %rax, -0x198(%rbp)
movl -0x190(%rbp), %eax
movl %eax, -0x8(%rbp)
movq -0x198(%rbp), %rax
movq %rax, -0x10(%rbp)
movl -0x8(%rbp), %eax
movl %eax, -0x1a0(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x1a8(%rbp), %rax
movl -0x1a0(%rbp), %edx
addq $0x210, %rsp            # imm = 0x210
popq %rbp
retq