// File: /workspace/github_cpp_makefile_star2_O2/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 $0x28, %rsp
movq %rcx, -0x30(%rbp)
movq %rdx, %rbx
movq %rsi, %r12
movq %rdi, %r15
leaq 0x18(%rsi), %r13
movq %r13, %rdi
movq %r13, %rsi
callq 0x58c4
movsd %xmm0, -0x40(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x58c4
movapd %xmm0, -0x50(%rbp)
leaq 0x30(%r15), %r14
movq %r13, %rdi
movq %r14, %rsi
callq 0x58c4
movapd -0x50(%rbp), %xmm1
subsd %xmm0, %xmm1
addsd %xmm1, %xmm1
movapd %xmm1, -0x50(%rbp)
movq %r12, %rdi
movq %r12, %rsi
callq 0x58c4
movsd %xmm0, -0x38(%rbp)
movq %r14, %rdi
movq %r14, %rsi
callq 0x58c4
addsd -0x38(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x58c4
movsd -0x40(%rbp), %xmm3
movapd -0x50(%rbp), %xmm2
addsd %xmm0, %xmm0
movsd -0x38(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd 0x28(%r15), %xmm0
mulsd %xmm0, %xmm0
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
movsd 0x386a(%rip), %xmm1     # 0x9030
mulsd %xmm3, %xmm1
mulsd %xmm0, %xmm1
movapd %xmm2, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
movabsq $-0x4010000000000000, %r14 # imm = 0xBFF0000000000000
jbe 0x57fc
movq %r14, (%rbx)
xorl %eax, %eax
movq -0x30(%rbp), %rbx
jmp 0x58ad
ucomisd %xmm1, %xmm0
jne 0x582f
jp 0x582f
xorpd 0x3874(%rip), %xmm2     # 0x9080
addsd %xmm3, %xmm3
divsd %xmm3, %xmm2
movsd %xmm2, (%rbx)
xorl %eax, %eax
xorpd %xmm0, %xmm0
ucomisd %xmm2, %xmm0
ja 0x58ad
pushq $0x1
jmp 0x58b4
ucomisd %xmm1, %xmm0
jb 0x583b
sqrtsd %xmm0, %xmm0
jmp 0x584a
callq 0x3180
movsd -0x40(%rbp), %xmm3
movapd -0x50(%rbp), %xmm2
movq -0x30(%rbp), %rax
movapd %xmm0, %xmm1
subsd %xmm2, %xmm1
xorpd 0x3822(%rip), %xmm2     # 0x9080
addsd %xmm3, %xmm3
divsd %xmm3, %xmm1
movsd %xmm1, (%rbx)
subsd %xmm0, %xmm2
divsd %xmm3, %xmm2
movsd %xmm2, (%rax)
movsd (%rbx), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x5890
movsd %xmm2, (%rbx)
movsd %xmm0, (%rax)
movapd %xmm0, %xmm2
movsd (%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x58a4
ucomisd %xmm2, %xmm1
ja 0x57ee
ucomisd %xmm0, %xmm1
jbe 0x58b2
pushq $0x1
popq %rax
movq %r14, (%rbx)
jmp 0x58b5
pushq $0x2
popq %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq