// File: /workspace/github_cpp_makefile_star2_O2/logicx24[P]RayTracer/raytracer.cpp
// Function: Scene::phongShade(Ray&, Polygon*, vec3&, vec3&)
vec3 phongShade(Ray &ray, Polygon *polygon, vec3 &normal, vec3 &point) {
        vec3 total_intensity = vec3(0, 0, 0);
        total_intensity += multiplyComponents(ambientLight.color, polygon->mat.ka);
        for (int i = 0; i < lights.size(); i++) {
        	Light *light = lights[i];
        	vec3 intensity = light->intensityAt(point);
        	Ray shadowRay = light->lightRay(point);
            if (traceShadowRay(shadowRay, polygon)) {
                continue;
            }
        	vec3 l = light->lightVec(point);
            vec3 v = -ray.vec;
            vec3 r = -l + ((2*(l * normal)) * normal);
            l.normalize();
        	v.normalize();
        	r.normalize();
            vec3 coeffs = polygon->mat.kd * MAX(l * normal, 0.0f)
                        + polygon->mat.ks * pow(MAX(r * v, 0.0f), polygon->mat.sp);
            total_intensity += multiplyComponents(intensity, coeffs);
        }
        return total_intensity;
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %r9, -0x38(%rbp)
movq %r8, -0x78(%rbp)
movq %rcx, %r15
movq %rdx, -0x70(%rbp)
movq %rsi, %r14
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movsd 0xd0(%rsi), %xmm0
movsd 0xd8(%rsi), %xmm1
movsd 0xe0(%rsi), %xmm2
mulsd 0x8(%rcx), %xmm0
mulsd 0x10(%rcx), %xmm1
mulsd 0x18(%rcx), %xmm2
leaq -0x118(%rbp), %rsi
movsd %xmm0, (%rsi)
movsd %xmm1, 0x8(%rsi)
movsd %xmm2, 0x10(%rsi)
movq %rdi, -0x30(%rbp)
callq 0x88ca
xorl %edx, %edx
movq 0xb8(%r14), %rax
movq 0xc0(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rdx, %rcx
jbe 0x88b3
movq %rdx, -0x98(%rbp)
movq (%rax,%rdx,8), %r12
leaq -0xe0(%rbp), %rdi
movq %r12, %rsi
movq %r14, %rbx
movq -0x38(%rbp), %r14
movq %r14, %rdx
callq 0x88fe
leaq -0x118(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq %r14, %rdx
movq %rbx, %r14
callq 0x896c
movq %rbx, %rdi
movq %r13, %rsi
movq %r15, %rdx
callq 0x89cc
testb %al, %al
jne 0x88a4
leaq -0x68(%rbp), %r13
movq %r13, %rdi
movq %r12, %rsi
movq -0x38(%rbp), %rdx
callq 0x8a38
movq -0x70(%rbp), %rax
movsd 0x28(%rax), %xmm0
movaps 0xa97f(%rip), %xmm2     # 0x13070
xorps %xmm2, %xmm0
movups 0x18(%rax), %xmm1
xorps %xmm2, %xmm1
movups %xmm1, -0xb0(%rbp)
movlps %xmm0, -0xa0(%rbp)
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
movq -0x78(%rbp), %r14
movsd (%r14), %xmm3
movsd 0x8(%r14), %xmm4
movapd %xmm1, %xmm5
mulsd %xmm4, %xmm5
movapd %xmm0, %xmm6
mulsd %xmm3, %xmm6
addsd %xmm5, %xmm6
movsd 0x10(%r14), %xmm5
movapd %xmm2, %xmm7
mulsd %xmm5, %xmm7
addsd %xmm6, %xmm7
addsd %xmm7, %xmm7
mulsd %xmm7, %xmm3
mulsd %xmm7, %xmm4
mulsd %xmm5, %xmm7
subsd %xmm0, %xmm3
subsd %xmm1, %xmm4
subsd %xmm2, %xmm7
movsd %xmm3, -0x50(%rbp)
movsd %xmm4, -0x48(%rbp)
movsd %xmm7, -0x40(%rbp)
movq %r13, %rdi
callq 0x7286
leaq -0xb0(%rbp), %rdi
callq 0x7286
leaq -0x50(%rbp), %rdi
callq 0x7286
movsd -0x68(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
mulsd 0x8(%r14), %xmm1
mulsd (%r14), %xmm0
addsd %xmm1, %xmm0
movsd -0x58(%rbp), %xmm1
mulsd 0x10(%r14), %xmm1
movq %rbx, %r14
addsd %xmm0, %xmm1
xorpd %xmm2, %xmm2
maxsd %xmm2, %xmm1
movsd 0x20(%r15), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x80(%rbp)
movsd 0x28(%r15), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x88(%rbp)
mulsd 0x30(%r15), %xmm1
movsd %xmm1, -0x90(%rbp)
movsd -0x50(%rbp), %xmm1
movsd -0x48(%rbp), %xmm0
mulsd -0xa8(%rbp), %xmm0
mulsd -0xb0(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd -0xa0(%rbp), %xmm0
addsd %xmm1, %xmm0
maxsd %xmm2, %xmm0
cvtss2sd 0x68(%r15), %xmm1
callq 0x33e0
movsd 0x38(%r15), %xmm1
mulsd %xmm0, %xmm1
addsd -0x80(%rbp), %xmm1
movsd 0x40(%r15), %xmm2
mulsd %xmm0, %xmm2
mulsd 0x48(%r15), %xmm0
addsd -0x88(%rbp), %xmm2
addsd -0x90(%rbp), %xmm0
mulsd -0xe0(%rbp), %xmm1
mulsd -0xd8(%rbp), %xmm2
mulsd -0xd0(%rbp), %xmm0
movsd %xmm1, -0xc8(%rbp)
movsd %xmm2, -0xc0(%rbp)
movsd %xmm0, -0xb8(%rbp)
movq -0x30(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x88ca
movq -0x98(%rbp), %rdx
incq %rdx
jmp 0x865e
movq -0x30(%rbp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop