// File: /workspace/github_cpp_makefile_star2_O1/logicx24[P]RayTracer/raytracer.cpp
// Function: Scene::traceRay(Ray&, int)
vec3 traceRay(Ray &testRay, int depth) {
		Polygon *hitObject = NULL;
    	float min_dist = MAXFLOAT;
		vec3 minIntersection;
    	Ray ray;
		for (int i = 0; i < objects.size(); i++) {
			ray = objects[i]->transformRay(testRay);
			float t = objects[i]->intersection(ray, eps);
			vec3 intersection = ray.pointAt(t);
			intersection = objects[i]->transformIntersection(intersection);
			float d = distance(ray.pos, intersection);
            if (t != MAXFLOAT && d < min_dist) {
                min_dist = d;
                hitObject = objects[i];
                minIntersection = intersection;
		    }
		}
		if (hitObject != NULL) {
			//minIntersection = hitObject->inverseTransform * minIntersection;
            vec3 normal = hitObject->normal(hitObject->inverseTransform * minIntersection);
            normal = hitObject->transformNormal(normal);
            normal.normalize();
            vec3 reflectionVec = ray.vec - (2*(ray.vec * normal))*normal;
            reflectionVec.normalize();
            Ray reflected = Ray(minIntersection, reflectionVec);
            if (depth == 0) {
            	return phongShade(ray, hitObject, normal, minIntersection);
            } else {
        	    return phongShade(ray, hitObject, normal, minIntersection)
        	           + multiplyComponents(traceRay(reflected, depth - 1), hitObject->mat.kr);
		    }
		} else {
		    return vec3(0, 0, 0);

        }
    }

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movl %ecx, -0x30(%rbp)
movq %rsi, %r14
movq %rdi, -0x58(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0x80(%rbp)
movaps %xmm0, -0x90(%rbp)
movaps %xmm0, -0xa0(%rbp)
movq 0xa0(%rsi), %rax
cmpq %rax, 0xa8(%rsi)
je 0x8e70
movq %rdx, %r13
movss 0xe3dc(%rip), %xmm0     # 0x1708c
xorl %ebx, %ebx
leaq -0xd8(%rbp), %r15
xorl %r12d, %r12d
movss %xmm0, -0x38(%rbp)
movq (%rax,%rbx,8), %rsi
movq %r15, %rdi
movq %r13, %rdx
callq 0x92e6
movups -0xd8(%rbp), %xmm0
movups -0xc8(%rbp), %xmm1
movups -0xb8(%rbp), %xmm2
movaps %xmm0, -0xa0(%rbp)
movaps %xmm1, -0x90(%rbp)
movaps %xmm2, -0x80(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x70(%rbp)
movq 0xa0(%r14), %rax
movq (%rax,%rbx,8), %rdi
movss 0x114(%r14), %xmm0
movq (%rdi), %rax
leaq -0xa0(%rbp), %rsi
callq *0x8(%rax)
movss %xmm0, -0x60(%rbp)
cvtss2sd %xmm0, %xmm0
movsd -0x88(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x80(%rbp), %xmm2
mulsd %xmm0, %xmm2
mulsd -0x78(%rbp), %xmm0
addsd -0xa0(%rbp), %xmm1
addsd -0x98(%rbp), %xmm2
addsd -0x90(%rbp), %xmm0
movsd %xmm1, -0xd8(%rbp)
movsd %xmm2, -0xd0(%rbp)
movsd %xmm0, -0xc8(%rbp)
movq 0xa0(%r14), %rax
movq (%rax,%rbx,8), %rsi
leaq -0x50(%rbp), %rdi
movq %r15, %rdx
callq 0x94d6
movsd -0x50(%rbp), %xmm0
movsd -0x48(%rbp), %xmm1
movsd %xmm0, -0xd8(%rbp)
movsd %xmm1, -0xd0(%rbp)
movsd -0x40(%rbp), %xmm2
movsd %xmm2, -0xc8(%rbp)
movsd -0xa0(%rbp), %xmm3
movsd -0x98(%rbp), %xmm4
subsd %xmm0, %xmm3
mulsd %xmm3, %xmm3
subsd %xmm1, %xmm4
mulsd %xmm4, %xmm4
addsd %xmm3, %xmm4
movsd -0x90(%rbp), %xmm0
subsd %xmm2, %xmm0
mulsd %xmm0, %xmm0
addsd %xmm4, %xmm0
ucomisd 0xe224(%rip), %xmm0     # 0x17018
jb 0x8dfc
sqrtsd %xmm0, %xmm0
jmp 0x8e01
callq 0x31a0
movss -0x60(%rbp), %xmm1
ucomiss 0xe27f(%rip), %xmm1     # 0x1708c
jne 0x8e11
jnp 0x8e4d
cvtsd2ss %xmm0, %xmm0
movss -0x38(%rbp), %xmm1
ucomiss %xmm0, %xmm1
jbe 0x8e4d
movq 0xa0(%r14), %rax
movq (%rax,%rbx,8), %r12
movsd -0xd8(%rbp), %xmm1
movsd %xmm1, -0xf0(%rbp)
movups -0xd0(%rbp), %xmm1
movups %xmm1, -0xe8(%rbp)
movss %xmm0, -0x38(%rbp)
incq %rbx
movq 0xa0(%r14), %rax
movq 0xa8(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %rbx, %rcx
ja 0x8cc1
jmp 0x8e73
xorl %r12d, %r12d
testq %r12, %r12
je 0x9002
movsd -0xf0(%rbp), %xmm1
movsd -0xe8(%rbp), %xmm2
movsd -0xe0(%rbp), %xmm0
movsd 0xf8(%r12), %xmm3
mulsd %xmm2, %xmm3
movsd 0xf0(%r12), %xmm4
mulsd %xmm1, %xmm4
addsd %xmm3, %xmm4
movsd 0x100(%r12), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm4, %xmm3
addsd 0x108(%r12), %xmm3
movsd 0x118(%r12), %xmm4
mulsd %xmm2, %xmm4
movsd 0x110(%r12), %xmm5
mulsd %xmm1, %xmm5
addsd %xmm4, %xmm5
movsd 0x120(%r12), %xmm4
mulsd %xmm0, %xmm4
addsd %xmm5, %xmm4
addsd 0x128(%r12), %xmm4
movsd 0x138(%r12), %xmm5
mulsd %xmm2, %xmm5
movsd 0x130(%r12), %xmm6
mulsd %xmm1, %xmm6
addsd %xmm5, %xmm6
movsd 0x140(%r12), %xmm5
mulsd %xmm0, %xmm5
addsd %xmm6, %xmm5
addsd 0x148(%r12), %xmm5
mulsd 0x158(%r12), %xmm2
mulsd 0x150(%r12), %xmm1
mulsd 0x160(%r12), %xmm0
addsd %xmm2, %xmm1
addsd %xmm1, %xmm0
addsd 0x168(%r12), %xmm0
divsd %xmm0, %xmm3
leaq -0x138(%rbp), %rdx
movsd %xmm3, (%rdx)
divsd %xmm0, %xmm4
movsd %xmm4, 0x8(%rdx)
divsd %xmm0, %xmm5
movsd %xmm5, 0x10(%rdx)
movq (%r12), %rax
leaq -0x50(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq *0x10(%rax)
leaq -0xd8(%rbp), %r15
movq %r15, %rdi
movq %r12, %rsi
movq %rbx, %rdx
callq 0x95c6
movsd (%r15), %xmm1
movsd 0x8(%r15), %xmm2
movsd %xmm1, (%rbx)
movsd %xmm2, 0x8(%rbx)
movsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%rbx)
mulsd %xmm2, %xmm2
mulsd %xmm1, %xmm1
addsd %xmm2, %xmm1
mulsd %xmm0, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm6, %xmm6
ucomisd %xmm6, %xmm0
jb 0x9019
sqrtsd %xmm0, %xmm0
jmp 0x9022
xorps %xmm0, %xmm0
movq -0x58(%rbp), %rbx
movups %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
jmp 0x9224
callq 0x31a0
xorpd %xmm6, %xmm6
movl -0x30(%rbp), %r13d
movsd 0xdfe2(%rip), %xmm5     # 0x17010
movapd %xmm5, %xmm1
divsd %xmm0, %xmm1
movsd -0x50(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd %xmm0, -0x50(%rbp)
movsd -0x48(%rbp), %xmm2
mulsd %xmm1, %xmm2
movsd %xmm2, -0x48(%rbp)
mulsd -0x40(%rbp), %xmm1
movsd %xmm1, -0x40(%rbp)
movsd -0x88(%rbp), %xmm7
movsd -0x80(%rbp), %xmm8
movapd %xmm2, %xmm3
mulsd %xmm8, %xmm3
movapd %xmm7, %xmm4
mulsd %xmm0, %xmm4
addsd %xmm3, %xmm4
movsd -0x78(%rbp), %xmm9
movapd %xmm9, %xmm3
mulsd %xmm1, %xmm3
addsd %xmm4, %xmm3
addsd %xmm3, %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm2
mulsd %xmm1, %xmm3
subsd %xmm0, %xmm7
subsd %xmm2, %xmm8
subsd %xmm3, %xmm9
movapd %xmm8, %xmm0
mulsd %xmm8, %xmm0
movapd %xmm7, %xmm1
mulsd %xmm7, %xmm1
addsd %xmm0, %xmm1
movapd %xmm9, %xmm0
mulsd %xmm9, %xmm0
addsd %xmm1, %xmm0
ucomisd %xmm6, %xmm0
jb 0x90e0
sqrtsd %xmm0, %xmm0
jmp 0x910f
movsd %xmm7, -0x60(%rbp)
movsd %xmm8, -0x38(%rbp)
movsd %xmm9, -0x30(%rbp)
callq 0x31a0
movsd -0x30(%rbp), %xmm9
movsd -0x38(%rbp), %xmm8
movsd -0x60(%rbp), %xmm7
movsd 0xdf01(%rip), %xmm5     # 0x17010
divsd %xmm0, %xmm5
mulsd %xmm5, %xmm7
mulsd %xmm5, %xmm8
mulsd %xmm9, %xmm5
movsd -0xf0(%rbp), %xmm0
movsd %xmm0, -0xd8(%rbp)
movups -0xe8(%rbp), %xmm0
movups %xmm0, -0xd0(%rbp)
movsd %xmm7, -0xc0(%rbp)
movsd %xmm8, -0xb8(%rbp)
movsd %xmm5, -0xb0(%rbp)
movabsq $0x7f7fffff3a83126f, %rax # imm = 0x7F7FFFFF3A83126F
movq %rax, -0xa8(%rbp)
testl %r13d, %r13d
je 0x9200
leaq -0x120(%rbp), %rbx
leaq -0xa0(%rbp), %rdx
leaq -0x50(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x9694
decl %r13d
leaq -0x108(%rbp), %r15
leaq -0xd8(%rbp), %rdx
movq %r15, %rdi
movq %r14, %rsi
movl %r13d, %ecx
callq 0x8c5e
movsd 0x50(%r12), %xmm0
movsd 0x58(%r12), %xmm1
movsd 0x60(%r12), %xmm2
mulsd (%r15), %xmm0
mulsd 0x8(%r15), %xmm1
mulsd 0x10(%r15), %xmm2
addsd (%rbx), %xmm0
addsd 0x8(%rbx), %xmm1
addsd 0x10(%rbx), %xmm2
movq -0x58(%rbp), %rbx
movsd %xmm0, (%rbx)
movsd %xmm1, 0x8(%rbx)
movsd %xmm2, 0x10(%rbx)
jmp 0x9224
leaq -0xa0(%rbp), %rdx
leaq -0x50(%rbp), %r8
leaq -0xf0(%rbp), %r9
movq -0x58(%rbp), %rbx
movq %rbx, %rdi
movq %r14, %rsi
movq %r12, %rcx
callq 0x9694
movq %rbx, %rax
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop