// File: /workspace/github_cpp_makefile_star2_O3/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, -0x58(%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 0x5b6e
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 0x5c6b
xorpd %xmm0, %xmm0
xorl %r14d, %r14d
movapd %xmm0, -0x50(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5b6e
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 0x5ca5
leaq 0x30(%r15), %r13
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x30(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0x30(%rbp), %xmm1
mulsd 0x18(%r12,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5ce2
movapd -0x50(%rbp), %xmm0
subsd %xmm1, %xmm0
movapd %xmm0, -0x50(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x68(%rbp)
movq %r12, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0x68(%rbp), %xmm1
mulsd (%r12,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5d20
movsd %xmm1, -0x68(%rbp)
xorpd %xmm1, %xmm1
xorl %r14d, %r14d
movsd %xmm1, -0x60(%rbp)
movq %r13, %rdi
movl %r14d, %esi
callq 0x5b6e
movsd -0x60(%rbp), %xmm1
mulsd (%r13,%r14,8), %xmm0
addsd %xmm0, %xmm1
incq %r14
cmpq $0x3, %r14
jne 0x5d54
movsd %xmm1, -0x60(%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 0x5b6e
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 0x5d97
movsd -0x68(%rbp), %xmm3
addsd -0x60(%rbp), %xmm3
addsd %xmm0, %xmm0
subsd %xmm0, %xmm3
movsd 0x28(%r15), %xmm0
mulsd %xmm0, %xmm0
subsd %xmm0, %xmm3
movsd 0x323f(%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
jbe 0x5e2e
movq %r14, (%rbx)
xorl %ecx, %ecx
movq -0x58(%rbp), %rbx
jmp 0x5e5b
ucomisd %xmm1, %xmm0
jne 0x5e6f
jp 0x5e6f
xorpd 0x3252(%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 0x5e60
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 0x5e7b
sqrtsd %xmm0, %xmm0
jmp 0x5e8a
callq 0x3170
movapd -0x50(%rbp), %xmm3
movsd -0x38(%rbp), %xmm2
movq -0x58(%rbp), %rax
movapd %xmm0, %xmm1
subsd %xmm3, %xmm1
xorpd 0x31f2(%rip), %xmm3     # 0x9090
addsd %xmm2, %xmm2
divsd %xmm2, %xmm1
movsd %xmm1, (%rbx)
subsd %xmm0, %xmm3
divsd %xmm2, %xmm3
movsd %xmm3, (%rax)
movsd (%rbx), %xmm0
ucomisd %xmm3, %xmm0
jbe 0x5ed0
movsd %xmm3, (%rbx)
movsd %xmm0, (%rax)
movapd %xmm0, %xmm3
movsd (%rbx), %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm0, %xmm1
jbe 0x5ee4
ucomisd %xmm3, %xmm1
ja 0x5e23
movl $0x2, %eax
movl $0x1, %ecx
ucomisd %xmm0, %xmm1
ja 0x5e5b
jmp 0x5e60
nop