// File: /workspace/github_cpp_makefile_star2_O3/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 $0x128, %rsp            # imm = 0x128
movl %ecx, %r14d
movq %rdx, %r12
movq %rdi, %r15
leaq -0x90(%rbp), %rbx
leaq -0x138(%rbp), %rcx
movq %rbx, %rdi
movq %rsi, -0x58(%rbp)
callq 0x8820
cmpq $0x0, (%rbx)
je 0x8661
movsd -0x138(%rbp), %xmm0
leaq -0x108(%rbp), %rdi
movq %r12, %rsi
callq 0x89e4
movq -0x90(%rbp), %rsi
testq %rsi, %rsi
je 0x872f
movq %r12, -0x110(%rbp)
movq (%rsi), %rax
leaq -0x150(%rbp), %rdi
leaq -0x108(%rbp), %rdx
callq *0x28(%rax)
movl %r14d, -0x94(%rbp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq -0x58(%rbp), %rax
movq (%rax), %r12
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
movsd %xmm0, -0x30(%rbp)
cmpq 0x8(%rax), %r12
movq %r15, -0x48(%rbp)
jae 0x82c2
leaq -0xb8(%rbp), %r15
leaq -0xf0(%rbp), %r13
leaq -0x150(%rbp), %rbx
movsd %xmm0, -0x38(%rbp)
movsd %xmm0, -0x30(%rbp)
movsd %xmm0, -0x40(%rbp)
movq (%r12), %rsi
movq %rsi, -0x68(%rbp)
movq 0x8(%r12), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
je 0x80b2
lock
incl 0x8(%rax)
testq %rsi, %rsi
je 0x86cb
addq $0x20, %rsi
movq %r13, %rdi
leaq -0x108(%rbp), %rdx
callq 0x4c1e
leaq -0xd0(%rbp), %rdi
movq %r13, %r14
movq %r13, %rsi
callq 0x4c98
movq -0xc0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movupd -0xd0(%rbp), %xmm0
movapd %xmm0, -0xf0(%rbp)
xorpd %xmm0, %xmm0
xorl %r13d, %r13d
movsd %xmm0, -0x50(%rbp)
movq %rbx, %rdi
movl %r13d, %esi
callq 0x5b6e
mulsd -0xf0(%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 0x8105
leaq -0xd0(%rbp), %r13
movq %r13, %rdi
movq %rbx, %rsi
movsd 0xf00(%rip), %xmm0      # 0x9050
callq 0x65a3
leaq -0x130(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movq %r13, %rdx
callq 0x652a
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
movq -0x120(%rbp), %rax
movq %rax, -0xc0(%rbp)
movupd -0x130(%rbp), %xmm0
movapd %xmm0, -0xd0(%rbp)
leaq -0x80(%rbp), %rdi
movq %r14, %rsi
callq 0x4c98
movq -0x70(%rbp), %rax
movq %rax, 0x10(%r15)
movupd -0x80(%rbp), %xmm0
movupd %xmm0, (%r15)
movb $0x1, %r13b
movq -0x58(%rbp), %rax
cmpb $0x1, 0x48(%rax)
jne 0x81f2
leaq -0x80(%rbp), %rdi
movq -0x58(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
leaq -0x118(%rbp), %rcx
callq 0x8820
cmpq $0x0, -0x80(%rbp)
sete %r13b
leaq -0x78(%rbp), %rdi
callq 0x576e
movsd -0x50(%rbp), %xmm0
ucomisd 0xe61(%rip), %xmm0      # 0x9060
jbe 0x8285
testb %r13b, %r13b
je 0x8285
movq -0x68(%rbp), %rcx
testq %rcx, %rcx
je 0x86cb
movq -0x90(%rbp), %rax
testq %rax, %rax
je 0x8703
movq %r14, %r13
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 -0x40(%rbp), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, -0x38(%rbp)
jmp 0x8288
movq %r14, %r13
leaq -0x60(%rbp), %rdi
callq 0x576e
addq $0x10, %r12
movq -0x58(%rbp), %rax
cmpq 0x8(%rax), %r12
jb 0x8098
movq -0x48(%rbp), %r15
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%r15)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, (%r15)
movq -0x58(%rbp), %rax
movq 0x18(%rax), %r14
cmpq 0x20(%rax), %r14
jae 0x8594
leaq -0xf0(%rbp), %rbx
leaq -0x80(%rbp), %r13
leaq -0x150(%rbp), %r12
movq (%r14), %rsi
movq %rsi, -0x68(%rbp)
movq 0x8(%r14), %rax
movq %rax, -0x60(%rbp)
testq %rax, %rax
je 0x8308
lock
incl 0x8(%rax)
testq %rsi, %rsi
je 0x8693
addq $0x20, %rsi
movq %rbx, %rdi
leaq -0x108(%rbp), %rdx
callq 0x4c1e
leaq -0xd0(%rbp), %rdi
movq %rbx, %rsi
callq 0x4c98
movq -0xc0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movupd -0xd0(%rbp), %xmm0
movapd %xmm0, -0xf0(%rbp)
movq -0x68(%rbp), %rsi
testq %rsi, %rsi
je 0x8693
addq $0x38, %rsi
leaq -0xd0(%rbp), %rdi
callq 0x4c98
movq %r13, %rdi
movq %rbx, %r15
movq %rbx, %rsi
callq 0x8a4c
xorpd %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, -0x50(%rbp)
movq %r13, %rdi
movl %ebx, %esi
callq 0x5b6e
mulsd -0xd0(%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 0x8382
callq 0x31a0
movq -0x68(%rbp), %rax
testq %rax, %rax
je 0x8693
cvtsd2ss %xmm0, %xmm0
ucomiss 0x50(%rax), %xmm0
jbe 0x83da
movq %r15, %rbx
jmp 0x855f
xorps %xmm0, %xmm0
xorl %ebx, %ebx
movsd %xmm0, -0x50(%rbp)
movq %r12, %rdi
movl %ebx, %esi
callq 0x5b6e
mulsd -0xf0(%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 0x83df
leaq -0xd0(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
movsd 0xc28(%rip), %xmm0      # 0x9050
callq 0x65a3
leaq -0x130(%rbp), %rdi
leaq -0x108(%rbp), %rsi
movq %rbx, %rdx
callq 0x652a
leaq -0xb8(%rbp), %rbx
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
movq -0x120(%rbp), %rax
movq %rax, -0xc0(%rbp)
movupd -0x130(%rbp), %xmm0
movapd %xmm0, -0xd0(%rbp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x4c98
movq -0x70(%rbp), %rax
movq %rax, 0x10(%rbx)
movupd -0x80(%rbp), %xmm0
movupd %xmm0, (%rbx)
movb $0x1, %bl
movq -0x58(%rbp), %rax
cmpb $0x1, 0x48(%rax)
jne 0x84cb
movq %r13, %rdi
movq -0x58(%rbp), %rsi
leaq -0xd0(%rbp), %rdx
leaq -0x118(%rbp), %rcx
callq 0x8820
cmpq $0x0, -0x80(%rbp)
sete %bl
leaq -0x78(%rbp), %rdi
callq 0x576e
movsd -0x50(%rbp), %xmm0
ucomisd 0xb88(%rip), %xmm0      # 0x9060
jbe 0x83d2
testb %bl, %bl
je 0x83d2
movq -0x68(%rbp), %rcx
testq %rcx, %rcx
je 0x8693
movq -0x90(%rbp), %rax
testq %rax, %rax
je 0x870e
movq %r15, %rbx
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 -0x40(%rbp), %xmm3
addsd %xmm0, %xmm3
movsd %xmm3, -0x40(%rbp)
movsd -0x30(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x38(%rbp), %xmm0
addsd %xmm2, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x576e
addq $0x10, %r14
movq -0x58(%rbp), %rax
cmpq 0x20(%rax), %r14
jb 0x82f0
movsd -0x30(%rbp), %xmm0
movq -0x48(%rbp), %r15
movsd %xmm0, 0x8(%r15)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%r15)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%r15)
movq -0x90(%rbp), %rax
testq %rax, %rax
movl -0x94(%rbp), %ebx
movq -0x110(%rbp), %rsi
je 0x872f
cmpl $0x9, %ebx
jg 0x8672
movss 0x20(%rax), %xmm0
xorpd %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jbe 0x8672
leaq -0xd0(%rbp), %rdi
leaq -0x108(%rbp), %rdx
leaq -0x150(%rbp), %rcx
movsd 0xa65(%rip), %xmm0      # 0x9058
callq 0x8aac
incl %ebx
leaq -0x80(%rbp), %rdi
leaq -0xd0(%rbp), %rdx
movq -0x58(%rbp), %rsi
movl %ebx, %ecx
callq 0x7fb6
movq -0x90(%rbp), %rax
testq %rax, %rax
je 0x872f
xorps %xmm0, %xmm0
cvtss2sd 0x20(%rax), %xmm0
movsd -0x80(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x78(%rbp), %xmm2
mulsd %xmm0, %xmm2
addsd -0x30(%rbp), %xmm2
mulsd -0x70(%rbp), %xmm0
addsd -0x38(%rbp), %xmm0
addsd -0x40(%rbp), %xmm1
movsd %xmm1, (%r15)
movsd %xmm2, 0x8(%r15)
movsd %xmm0, 0x10(%r15)
jmp 0x8672
xorpd %xmm0, %xmm0
movupd %xmm0, (%r15)
movq $0x0, 0x10(%r15)
leaq -0x88(%rbp), %rdi
callq 0x576e
movq %r15, %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd -0x30(%rbp), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x14c8(%rip), %rdi      # 0x9b83
leaq 0x14c9(%rip), %rsi      # 0x9b8b
leaq 0x1ae3(%rip), %rcx      # 0xa1ac
jmp 0x8744
movq -0x48(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x1490(%rip), %rdi      # 0x9b83
leaq 0x1491(%rip), %rsi      # 0x9b8b
leaq 0x1a0a(%rip), %rcx      # 0xa10b
jmp 0x8744
movq -0x48(%rbp), %rax
movsd -0x30(%rbp), %xmm0
jmp 0x8717
movsd -0x30(%rbp), %xmm0
movq -0x48(%rbp), %rax
movsd %xmm0, 0x8(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq 0x144d(%rip), %rdi      # 0x9b83
leaq 0x144e(%rip), %rsi      # 0x9b8b
leaq 0x1926(%rip), %rcx      # 0xa06a
movl $0x2d8, %edx            # imm = 0x2D8
callq 0x30f0
jmp 0x8754
jmp 0x8754
jmp 0x8754
movq %rax, %rbx
jmp 0x87a8
jmp 0x8767
jmp 0x8767
jmp 0x877b
jmp 0x8767
jmp 0x8767
jmp 0x8767
jmp 0x8767
movq %rax, %rbx
movsd -0x30(%rbp), %xmm0
movq -0x48(%rbp), %rax
jmp 0x8787
jmp 0x877b
jmp 0x877b
jmp 0x877b
movq %rax, %rbx
movq -0x48(%rbp), %rax
movsd -0x30(%rbp), %xmm0
movsd %xmm0, 0x8(%rax)
movsd -0x38(%rbp), %xmm0
movsd %xmm0, 0x10(%rax)
movsd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x576e
leaq -0x88(%rbp), %rdi
callq 0x576e
movq %rbx, %rdi
callq 0x32a0