// File: /workspace/github_cpp_makefile_star2_O1/hamikm[P]Raytracer/src/scene.hh
// Function: scene<double, double, double, 3>::traceRay(ray<double, double, 3> const&, int) const
rgbcolor<color_T> traceRay(
			const ray<vec_T, time_T, dim> &r, int depth = 0) const {
		time_T tIntersect; // out parameter
		sp_shape intersectedObjPtr =
				findClosestShape(r, tIntersect);
		if(intersectedObjPtr == 0) {
			return DEFAULT_BKCOLOR;
		}

		mvector<vec_T, dim> intersectionPt = r.getPointAtT(tIntersect);
		mvector<vec_T, dim> N = intersectedObjPtr->surfaceNorm(intersectionPt);

		// Loop over all the point lights, summing the color contributions from
		// each one
		rgbcolor<color_T> finalColor;
		typename std::vector<sp_light>::const_iterator iter;
		for (iter = pointlights.begin(); iter < pointlights.end(); iter++) {
			sp_light currLightPtr = *iter;
			mvector<vec_T, dim> L = currLightPtr->getPos() - intersectionPt;
			L = L.norm();
			vec_T LdotN = L * N;

			// A hack to make sure an object doesn't intersect itself...
			// make the "to light" ray start a little outside an object itself
			// by adding a tiny scalar multiple of a normal line to the
			// starting point
			mvector<vec_T, dim> intersectionPtWithDelta =
					intersectionPt + N * DELTA;

			// shoot a ray to this light. if it hits anything on the way,
			// skip the light (if shadows are on)
			ray<vec_T, time_T, dim> rayToLight(
					intersectionPtWithDelta, L);
			time_T t;
			if (useShadows && findClosestShape(rayToLight, t) != 0) {
				continue;
			}

			// add in the color contribution of the light
			if(LdotN > 0) {
				finalColor += (currLightPtr->getColor() *
						intersectedObjPtr->getColor() * LdotN);
			}
		}

		// Loop over all the spotlights, summing the color contributions from
		// each one. Skip the spotlight if the angle between the ray and the
		// spotlight's direction vector is > the cone angle.
		typename std::vector<sp_spotlight>::const_iterator iter2;
		for (iter2 = spotlights.begin(); iter2 < spotlights.end(); iter2++) {
			sp_spotlight currLightPtr = *iter2;
			mvector<vec_T, dim> L = currLightPtr->getPos() - intersectionPt;
			L = L.norm();

			// skip this light if it's outside the spotlight cone
			float ray_spotlight_angle =
					acos(currLightPtr->getDir().norm() * -L);
			if (ray_spotlight_angle > currLightPtr->getAngle()) {
				continue;
			}

			vec_T LdotN = L * N;

			// A hack to make sure an object doesn't intersect itself...
			// make the "to light" ray start a little outside an object itself
			// by adding a tiny scalar multiple of a normal line to the
			// starting point
			mvector<vec_T, dim> intersectionPtWithDelta =
					intersectionPt + N * DELTA;

			// shoot a ray to this light. if it hits anything on the way,
			// skip the light (if shadows are on)
			ray<vec_T, time_T, dim> rayToLight(
					intersectionPtWithDelta, L);
			time_T t;
			if (useShadows && findClosestShape(rayToLight, t) != 0) {
				continue;
			}

			// add in the color contribution of the light
			if(LdotN > 0) {
				finalColor += (currLightPtr->getColor() *
						intersectedObjPtr->getColor() * LdotN);
			}
		}

		// handle reflections
		if (intersectedObjPtr->getReflectivity() > 0 && depth < MAX_REFLECT) {
			// R_r is the direction of the reflected vector
			ray<vec_T, time_T, dim> R_r = r.reflect(intersectionPt, N);
			// col_r is the reflection color
			rgbcolor<color_T> col_r = traceRay(R_r, depth + 1);
			finalColor +=
					((color_T) intersectedObjPtr->getReflectivity()) * col_r;
		}

		return finalColor;
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movl %ecx, %r14d
movq %rdx, %r12
movq %rdi, %r15
leaq -0x80(%rbp), %rbx
leaq -0x138(%rbp), %rcx
movq %rbx, %rdi
movq %rsi, -0x60(%rbp)
callq 0x895e
cmpq $0x0, (%rbx)
je 0x878d
movsd -0x138(%rbp), %xmm0
leaq -0x110(%rbp), %rdi
movq %r12, %rsi
callq 0x8a90
movq -0x80(%rbp), %rsi
testq %rsi, %rsi
je 0x8865
movq %r12, -0x118(%rbp)
movq (%rsi), %rax
leaq -0x170(%rbp), %rdi
leaq -0x110(%rbp), %rdx
callq *0x28(%rax)
movl %r14d, -0x84(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq %r15, %rax
movq -0x60(%rbp), %rcx
movq (%rcx), %rdx
xorpd %xmm0, %xmm0
cmpq 0x8(%rcx), %rdx
movq %r15, -0x40(%rbp)
jae 0x83a3
leaq -0xa8(%rbp), %r15
movsd 0x8(%rax), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0xe0(%rbp), %r14
leaq -0xc0(%rbp), %r13
leaq -0x170(%rbp), %rbx
xorpd %xmm0, %xmm0
movq (%rdx), %rsi
movq %rsi, -0x70(%rbp)
movq 0x8(%rdx), %rax
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x8167
lock
incl 0x8(%rax)
movq %rdx, -0x48(%rbp)
movsd %xmm0, -0x38(%rbp)
testq %rsi, %rsi
je 0x87f7
addq $0x20, %rsi
movq %r14, %rdi
leaq -0x110(%rbp), %rdx
callq 0x4c76
movq %r13, %r12
movq %r13, %rdi
movq %r14, %rsi
callq 0x4cf0
movq -0xb0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movupd -0xc0(%rbp), %xmm0
movapd %xmm0, -0xe0(%rbp)
xorpd %xmm0, %xmm0
xorl %r13d, %r13d
movsd %xmm0, -0x50(%rbp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x5c1a
mulsd -0xe0(%rbp,%r13,8), %xmm0
movsd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
incq %r13
cmpq $0x3, %r13
jne 0x81bf
movq %r12, %r13
movq %r12, %rdi
movq %rbx, %rsi
movsd 0xe4a(%rip), %xmm0      # 0x9050
callq 0x6663
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movq %r13, %rdx
callq 0x65ea
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq -0x120(%rbp), %rax
movq %rax, -0xb0(%rbp)
movupd -0x130(%rbp), %xmm0
movapd %xmm0, -0xc0(%rbp)
leaq -0xf8(%rbp), %rdi
movq %r15, %r13
movq %r14, %r15
movq %r14, %rsi
callq 0x4cf0
movq -0xe8(%rbp), %rax
movq %rax, 0x10(%r13)
movupd -0xf8(%rbp), %xmm0
movupd %xmm0, (%r13)
movq -0x60(%rbp), %rax
movb 0x48(%rax), %r13b
movb $0x1, %r14b
cmpb $0x1, %r13b
jne 0x82b5
leaq -0x158(%rbp), %rdi
movq -0x60(%rbp), %rsi
movq %r12, %rdx
leaq -0xf8(%rbp), %rcx
callq 0x895e
cmpq $0x0, -0x158(%rbp)
sete %r14b
testb %r13b, %r13b
je 0x82c6
leaq -0x150(%rbp), %rdi
callq 0x581c
movsd -0x50(%rbp), %xmm0
ucomisd 0xd8d(%rip), %xmm0      # 0x9060
seta %al
testb %r14b, %al
movq %r12, %r13
je 0x835d
movq -0x70(%rbp), %rcx
testq %rcx, %rcx
je 0x87f7
movq %r15, %r14
movq -0x80(%rbp), %rax
testq %rax, %rax
leaq -0xa8(%rbp), %r15
je 0x882f
movsd 0x8(%rcx), %xmm0
movsd 0x10(%rcx), %xmm1
movsd 0x18(%rcx), %xmm2
mulsd 0x8(%rax), %xmm0
mulsd 0x10(%rax), %xmm1
mulsd 0x18(%rax), %xmm2
movsd -0x50(%rbp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm2
movsd -0x38(%rbp), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x38(%rbp)
movsd -0x58(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x30(%rbp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x8367
movq %r15, %r14
leaq -0xa8(%rbp), %r15
leaq -0x68(%rbp), %rdi
callq 0x581c
movq -0x48(%rbp), %rdx
addq $0x10, %rdx
movq -0x60(%rbp), %rax
cmpq 0x8(%rax), %rdx
movsd -0x38(%rbp), %xmm0
jb 0x814f
movq -0x40(%rbp), %rax
movsd -0x58(%rbp), %xmm1
movsd %xmm1, 0x8(%rax)
movsd -0x30(%rbp), %xmm1
movsd %xmm1, 0x10(%rax)
movsd %xmm0, (%rax)
movq -0x60(%rbp), %rcx
movq 0x18(%rcx), %r14
cmpq 0x20(%rcx), %r14
movq %rax, %r15
jae 0x86be
leaq -0xa8(%rbp), %rax
movsd 0x8(%r15), %xmm1
movsd %xmm1, -0x30(%rbp)
movsd 0x10(%r15), %xmm1
movq %rax, %r15
movsd %xmm1, -0x48(%rbp)
leaq -0xe0(%rbp), %rbx
leaq -0xf8(%rbp), %r13
leaq -0x170(%rbp), %r12
movq (%r14), %rsi
movq %rsi, -0x70(%rbp)
movq 0x8(%r14), %rax
movq %rax, -0x68(%rbp)
testq %rax, %rax
je 0x8409
lock
incl 0x8(%rax)
movsd %xmm0, -0x38(%rbp)
testq %rsi, %rsi
je 0x87bc
addq $0x20, %rsi
movq %rbx, %rdi
leaq -0x110(%rbp), %rdx
callq 0x4c76
leaq -0xc0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4cf0
movq -0xb0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movupd -0xc0(%rbp), %xmm0
movapd %xmm0, -0xe0(%rbp)
movq -0x70(%rbp), %rsi
testq %rsi, %rsi
je 0x87bc
addq $0x38, %rsi
leaq -0xc0(%rbp), %rdi
callq 0x4cf0
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8af8
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, -0x50(%rbp)
movq %r13, %rdi
movl %ebx, %esi
callq 0x5c1a
mulsd -0xc0(%rbp,%rbx,8), %xmm0
movsd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
incq %rbx
cmpq $0x3, %rbx
jne 0x8485
callq 0x31a0
movq -0x70(%rbp), %rax
testq %rax, %rax
je 0x87bc
cvtsd2ss %xmm0, %xmm0
ucomiss 0x50(%rax), %xmm0
jbe 0x84e1
leaq -0xe0(%rbp), %rbx
jmp 0x8684
xorps %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, -0x50(%rbp)
movq %r12, %rdi
movl %ebx, %esi
callq 0x5c1a
mulsd -0xe0(%rbp,%rbx,8), %xmm0
movsd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
incq %rbx
cmpq $0x3, %rbx
jne 0x84e6
leaq -0xc0(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movsd 0xb21(%rip), %xmm0      # 0x9050
callq 0x6663
leaq -0x130(%rbp), %rdi
leaq -0x110(%rbp), %rsi
movq %rbx, %rdx
callq 0x65ea
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq -0x120(%rbp), %rax
movq %rax, -0xb0(%rbp)
movupd -0x130(%rbp), %xmm0
movapd %xmm0, -0xc0(%rbp)
movq %r13, %rdi
leaq -0xe0(%rbp), %rsi
callq 0x4cf0
movq -0xe8(%rbp), %rax
movq %rax, 0x10(%r15)
movupd -0xf8(%rbp), %xmm0
movupd %xmm0, (%r15)
movq -0x60(%rbp), %rax
movb 0x48(%rax), %bl
movb $0x1, %r15b
cmpb $0x1, %bl
jne 0x85d5
leaq -0x148(%rbp), %rdi
movq -0x60(%rbp), %rsi
leaq -0xc0(%rbp), %rdx
movq %r13, %rcx
callq 0x895e
cmpq $0x0, -0x148(%rbp)
sete %r15b
testb %bl, %bl
je 0x85e5
leaq -0x140(%rbp), %rdi
callq 0x581c
movsd -0x50(%rbp), %xmm0
ucomisd 0xa6e(%rip), %xmm0      # 0x9060
seta %al
testb %r15b, %al
leaq -0xe0(%rbp), %rbx
je 0x867d
movq -0x70(%rbp), %rcx
testq %rcx, %rcx
leaq -0xa8(%rbp), %r15
je 0x87bc
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x8844
movsd 0x8(%rcx), %xmm0
movsd 0x10(%rcx), %xmm1
movsd 0x18(%rcx), %xmm2
mulsd 0x8(%rax), %xmm0
mulsd 0x10(%rax), %xmm1
mulsd 0x18(%rax), %xmm2
movsd -0x50(%rbp), %xmm3
mulsd %xmm3, %xmm0
mulsd %xmm3, %xmm1
mulsd %xmm3, %xmm2
movsd -0x38(%rbp), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x38(%rbp)
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x48(%rbp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x8684
leaq -0xa8(%rbp), %r15
leaq -0x68(%rbp), %rdi
callq 0x581c
addq $0x10, %r14
movq -0x60(%rbp), %rax
cmpq 0x20(%rax), %r14
movsd -0x38(%rbp), %xmm0
jb 0x83f1
movq -0x40(%rbp), %r15
movsd -0x30(%rbp), %xmm1
movsd %xmm1, 0x8(%r15)
movsd -0x48(%rbp), %xmm1
movsd %xmm1, 0x10(%r15)
movsd %xmm0, (%r15)
movq -0x80(%rbp), %rax
testq %rax, %rax
movl -0x84(%rbp), %ebx
movq -0x118(%rbp), %rsi
je 0x8865
cmpl $0x9, %ebx
jg 0x879e
movss 0x20(%rax), %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x879e
leaq -0xc0(%rbp), %rdi
leaq -0x110(%rbp), %rdx
leaq -0x170(%rbp), %rcx
movsd 0x944(%rip), %xmm0      # 0x9058
callq 0x8b58
incl %ebx
leaq -0xf8(%rbp), %rdi
leaq -0xc0(%rbp), %rdx
movq -0x60(%rbp), %rsi
movl %ebx, %ecx
callq 0x806a
movq -0x80(%rbp), %rax
testq %rax, %rax
je 0x8865
xorps %xmm0, %xmm0
cvtss2sd 0x20(%rax), %xmm0
movsd -0xf8(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm2
mulsd %xmm0, %xmm2
mulsd -0xe8(%rbp), %xmm0
addsd (%r15), %xmm1
movsd %xmm1, (%r15)
addsd 0x8(%r15), %xmm2
movsd %xmm2, 0x8(%r15)
addsd 0x10(%r15), %xmm0
movsd %xmm0, 0x10(%r15)
jmp 0x879e
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
leaq -0x78(%rbp), %rdi
callq 0x581c
movq %r15, %rax
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq -0x40(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x139f(%rip), %rdi      # 0x9b83
leaq 0x13a0(%rip), %rsi      # 0x9b8b
leaq 0x19ba(%rip), %rcx      # 0xa1ac
jmp 0x887a
movq -0x40(%rbp), %rax
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x1364(%rip), %rdi      # 0x9b83
leaq 0x1365(%rip), %rsi      # 0x9b8b
leaq 0x18de(%rip), %rcx      # 0xa10b
jmp 0x887a
movq -0x40(%rbp), %rax
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x30(%rbp), %xmm0
jmp 0x8857
movq -0x40(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x48(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x1317(%rip), %rdi      # 0x9b83
leaq 0x1318(%rip), %rsi      # 0x9b8b
leaq 0x17f0(%rip), %rcx      # 0xa06a
movl $0x2d8, %edx            # imm = 0x2D8
callq 0x30f0
jmp 0x888a
jmp 0x888a
jmp 0x888a
movq %rax, %rbx
jmp 0x88e8
jmp 0x889d
jmp 0x889d
jmp 0x88bb
jmp 0x889d
jmp 0x889d
jmp 0x889d
jmp 0x889d
movq %rax, %rbx
movq -0x40(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x48(%rbp), %xmm0
jmp 0x88d1
jmp 0x88bb
jmp 0x88bb
jmp 0x88bb
movq %rax, %rbx
movq -0x40(%rbp), %rax
movsd -0x58(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x68(%rbp), %rdi
callq 0x581c
leaq -0x78(%rbp), %rdi
callq 0x581c
movq %rbx, %rdi
callq 0x32a0