// File: /workspace/github_cpp_makefile_star2_O1/hamikm[P]Raytracer/src/sphere.hh
// Function: sphere<double, double, double, 3>::getIntersections(ray<double, double, 3> const&, double&, double&) const
int getIntersections(const ray<vec_T, time_T, dim> &r,
			time_T &t1, time_T &t2) const {
		vec_T a = r.getDir() * r.getDir();
		vec_T b = 2 * (r.getOrig() * r.getDir() - r.getDir() * center);
		vec_T c = r.getOrig() * r.getOrig() + center * center -
				2 * (r.getOrig() * center) - rad * rad;
		vec_T tmpsqrt;
		tmpsqrt = b * b - 4 * a * c;
		if (tmpsqrt < 0) {
			t1 = RAY_MISS;
			t2 = RAY_MISS;
			return 0;
		}
		else if (tmpsqrt == 0) {
			t1 = (time_T)(-b / (2 * a));
			if (t1 < 0) {
				t1 = RAY_MISS;
				return 0;
			}
			return 1;
		}
		else {
			tmpsqrt = sqrt(tmpsqrt);
			t1 = (time_T)((-b + tmpsqrt) / (2 * a));
			t2 = (time_T)((-b - tmpsqrt) / (2 * a));
			// Put t1 and t2 into ascending order.
			if (t1 > t2) {
				time_T tmp = t1;
				t1 = t2;
				t2 = tmp;
			}
			// Now that they're in ascending order, check if they're negative.
			if (t1 < 0 && t2 < 0) {
				t1 = RAY_MISS;
				t2 = RAY_MISS;
				return 0;
			}
			if (t1 < 0) {
				t1 = RAY_MISS;
				return 1;
			}
			return 2;
		}
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rcx, -0x68(%rbp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x18(%rsi), %r13
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movsd %xmm0, -0x38(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5c1a
mulsd 0x18(%r12,%r14,8), %xmm0
movsd -0x38(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x38(%rbp)
movsd -0x38(%rbp), %xmm0
incq %r14
cmpq $0x3, %r14
jne 0x5d17
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movapd %xmm0, -0x50(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5c1a
mulsd (%r12,%r14,8), %xmm0
movapd -0x50(%rbp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, -0x50(%rbp)
movapd -0x50(%rbp), %xmm0
incq %r14
cmpq $0x3, %r14
jne 0x5d51
leaq 0x30(%r15), %r13
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x30(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5c1a
movsd -0x30(%rbp), %xmm1
mulsd 0x18(%r12,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5d8e
movapd -0x50(%rbp), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x60(%rbp)
movq %r12, %rdi
movl %r14d, %esi
callq 0x5c1a
movsd -0x60(%rbp), %xmm1
mulsd (%r12,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5dcc
movsd %xmm1, -0x60(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x58(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5c1a
movsd -0x58(%rbp), %xmm1
mulsd (%r13,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5e00
movsd %xmm1, -0x58(%rbp)
movapd -0x50(%rbp), %xmm0
addsd %xmm0, %xmm0
movapd %xmm0, -0x50(%rbp)
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movsd %xmm0, -0x30(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5c1a
mulsd (%r12,%r14,8), %xmm0
movsd -0x30(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
incq %r14
cmpq $0x3, %r14
jne 0x5e43
movsd -0x60(%rbp), %xmm3
addsd -0x58(%rbp), %xmm3
addsd %xmm0, %xmm0
subsd %xmm0, %xmm3
movsd 0x28(%r15), %xmm0
mulsd %xmm0, %xmm0
subsd %xmm0, %xmm3
movsd 0x3193(%rip), %xmm1     # 0x9030
movsd -0x38(%rbp), %xmm2
mulsd %xmm2, %xmm1
mulsd %xmm3, %xmm1
movapd -0x50(%rbp), %xmm3
movapd %xmm3, %xmm0
mulsd %xmm3, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movabsq $-0x4010000000000000, %r14 # imm = 0xBFF0000000000000
movq -0x68(%rbp), %r15
jbe 0x5edd
movq %r14, (%rbx)
xorl %ecx, %ecx
movq %r15, %rbx
jmp 0x5f0a
ucomisd %xmm1, %xmm0
jne 0x5f1e
jp 0x5f1e
xorpd 0x31a3(%rip), %xmm3     # 0x9090
addsd %xmm2, %xmm2
divsd %xmm2, %xmm3
movsd %xmm3, (%rbx)
movl $0x1, %eax
xorl %ecx, %ecx
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm0
jbe 0x5f0f
movq %r14, (%rbx)
movl %ecx, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
ucomisd %xmm1, %xmm0
jb 0x5f2a
sqrtsd %xmm0, %xmm0
jmp 0x5f39
callq 0x3170
movapd -0x50(%rbp), %xmm3
movsd -0x38(%rbp), %xmm2
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
xorpd 0x3147(%rip), %xmm3     # 0x9090
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, (%rbx)
subsd %xmm0, %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, (%r15)
movsd (%rbx), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x5f75
movsd %xmm3, (%rbx)
movsd %xmm0, (%r15)
movsd (%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5f8e
ucomisd (%r15), %xmm1
ja 0x5ed3
movl $0x2, %eax
movl $0x1, %ecx
ucomisd %xmm0, %xmm1
ja 0x5f0a
jmp 0x5f0f
nop