// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0xe0, %rsp
movq %rdi, %rbx
leaq -0xe8(%rbp), %r15
movsd 0x1d40(%rip), %xmm0     # 0x6098
movq %r15, %rdi
movapd %xmm0, %xmm1
movapd %xmm0, %xmm2
callq 0x283c
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
movq %r15, %rsi
callq 0x28d0
movq 0x10(%r14), %rax
movq %rax, 0x10(%rsp)
movups (%r14), %xmm0
movups %xmm0, (%rsp)
leaq 0x58(%rbp), %r14
movq %r14, %rdi
callq 0x2a36
movaps %xmm0, -0x40(%rbp)
leaq -0x88(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x28d0
leaq -0xa0(%rbp), %r15
leaq 0x10(%rbp), %rsi
movq %r15, %rdi
callq 0x2b88
movq 0x10(%r15), %rax
movq %rax, 0x10(%rsp)
movups (%r15), %xmm0
movups %xmm0, (%rsp)
leaq -0x60(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
callq 0x29a2
leaq -0xb8(%rbp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x28d0
movq 0x10(%r12), %rax
movq %rax, 0x10(%rsp)
movupd (%r12), %xmm0
movupd %xmm0, (%rsp)
movq %r14, %rdi
callq 0x2a36
movapd %xmm0, -0x30(%rbp)
leaq 0x40(%rbp), %r14
movq %r14, %rdi
callq 0x2980
mulsd 0x48(%rbx), %xmm0
callq 0x2180
movsd %xmm0, -0x48(%rbp)
movq %r14, %rdi
callq 0x2996
mulsd 0x48(%rbx), %xmm0
callq 0x2180
addsd -0x48(%rbp), %xmm0
cvttsd2si %xmm0, %eax
leaq -0x60(%rbp), %rdi
testb $0x1, %al
jne 0x4463
movl $0xff, %esi
movl $0xff, %edx
movl $0xff, %ecx
jmp 0x4469
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x35d8
xorpd %xmm0, %xmm0
xorpd %xmm2, %xmm2
movapd -0x30(%rbp), %xmm1
cmplesd %xmm1, %xmm2
andpd %xmm1, %xmm2
movapd %xmm2, -0x30(%rbp)
movapd -0x40(%rbp), %xmm1
cmplesd %xmm1, %xmm0
andpd %xmm1, %xmm0
mulsd 0x10(%rbx), %xmm0
leaq -0x60(%rbp), %rdi
callq 0x361c
movq %rax, %r14
movl %edx, %r15d
leaq 0x38(%rbx), %r12
movsd 0x18(%rbx), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd 0x50(%rbx), %xmm1
movapd -0x30(%rbp), %xmm0
callq 0x2190
mulsd -0x40(%rbp), %xmm0
movq %r12, %rdi
callq 0x361c
leaq -0x88(%rbp), %r12
movq %rax, (%r12)
movl %edx, 0x8(%r12)
movsd 0x8(%rbx), %xmm0
addq $0x20, %rbx
movq %rbx, %rdi
callq 0x361c
leaq -0x70(%rbp), %rbx
movq %rax, (%rbx)
movl %edx, 0x8(%rbx)
movq %r12, %rdi
movq %r14, %rsi
movl %r15d, %edx
callq 0x3600
movq %rbx, %rdi
movq %rax, %rsi
callq 0x3600
addq $0xe0, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
nop