// File: /workspace/github_cpp_makefile_star2_O3/GUI-Graphics[P]cpuraytracing/sphere.cpp
// Function: gui::Sphere::intersect(gui::Ray const&, float, float, gui::Intersection&) const
bool Sphere::intersect(
		const Ray& ray,
		float tMin,
		float tMax,
		Intersection& intersection) const {
			
			++Renderer::nIntersects;

			Vector3 co = ray.origin - center;
			float a = ray.direction.lengthSquared();
			float b = ray.direction.dot(co);
			float c = co.lengthSquared() - radius * radius;
			float delta = b * b - a * c;

			if(delta < 0) return false;

			delta = sqrt(delta);
			float t = (-b - delta) / a;

			if(t > tMin && t < tMax) {
				intersection.t = t;
				intersection.position = ray.origin + ray.direction * t;
				intersection.normal = (intersection.position - center) / radius;
				intersection.material = material;
				return true;
			}

			t = (-b + delta) / a;
			if(t > tMin && t < tMax) {
				intersection.t = t;
				intersection.position = ray.origin + ray.direction * t;
				intersection.normal = (intersection.position - center) / radius;
				intersection.material = material;
				return true;
			}

			return false;
	}

// Assembly:
pushq %r15
pushq %r14
pushq %rbx
subq $0x20, %rsp
leaq 0x6f84(%rip), %rax      # 0xa868
incq (%rax)
movss (%rsi), %xmm2
movss 0x4(%rsi), %xmm3
subss 0x10(%rdi), %xmm2
subss 0x14(%rdi), %xmm3
movss 0x8(%rsi), %xmm7
subss 0x18(%rdi), %xmm7
movaps %xmm0, %xmm8
movss 0xc(%rsi), %xmm0
movss 0x10(%rsi), %xmm4
movaps %xmm4, %xmm5
mulss %xmm4, %xmm5
movaps %xmm0, %xmm6
mulss %xmm0, %xmm6
addss %xmm5, %xmm6
movss 0x14(%rsi), %xmm9
movaps %xmm9, %xmm5
mulss %xmm9, %xmm5
addss %xmm6, %xmm5
mulss %xmm3, %xmm4
mulss %xmm2, %xmm0
addss %xmm4, %xmm0
mulss %xmm7, %xmm9
addss %xmm0, %xmm9
mulss %xmm3, %xmm3
mulss %xmm2, %xmm2
addss %xmm3, %xmm2
mulss %xmm7, %xmm7
addss %xmm2, %xmm7
movss 0x1c(%rdi), %xmm0
mulss %xmm0, %xmm0
subss %xmm0, %xmm7
mulss %xmm5, %xmm7
movaps %xmm9, %xmm0
mulss %xmm9, %xmm0
subss %xmm7, %xmm0
xorps %xmm2, %xmm2
ucomiss %xmm0, %xmm2
jbe 0x398e
xorl %eax, %eax
jmp 0x3a7c
movq %rdx, %rbx
movq %rsi, %r15
movq %rdi, %r14
ucomiss %xmm2, %xmm0
jb 0x39a2
sqrtss %xmm0, %xmm0
jmp 0x39d9
movss %xmm1, 0xc(%rsp)
movss %xmm8, 0x8(%rsp)
movss %xmm5, 0x4(%rsp)
movaps %xmm9, 0x10(%rsp)
callq 0x2250
movaps 0x10(%rsp), %xmm9
movss 0x4(%rsp), %xmm5
movss 0x8(%rsp), %xmm8
movss 0xc(%rsp), %xmm1
movaps 0x17f0(%rip), %xmm4     # 0x51d0
xorps %xmm9, %xmm4
subss %xmm0, %xmm4
divss %xmm5, %xmm4
ucomiss %xmm8, %xmm4
jbe 0x39f7
ucomiss %xmm4, %xmm1
ja 0x3a10
subss %xmm9, %xmm0
movaps %xmm0, %xmm4
divss %xmm5, %xmm4
xorl %eax, %eax
ucomiss %xmm8, %xmm4
jbe 0x3a7c
ucomiss %xmm4, %xmm1
jbe 0x3a7c
movss %xmm4, (%rbx)
movss 0x14(%r15), %xmm0
mulss %xmm4, %xmm0
movsd (%r15), %xmm2
movsd 0xc(%r15), %xmm3
shufps $0x0, %xmm4, %xmm4      # xmm4 = xmm4[0,0,0,0]
mulps %xmm3, %xmm4
addps %xmm2, %xmm4
addss 0x8(%r15), %xmm0
movlps %xmm4, 0x4(%rbx)
movss %xmm0, 0xc(%rbx)
subss 0x18(%r14), %xmm0
movss 0x15c0(%rip), %xmm2     # 0x5010
divss 0x1c(%r14), %xmm2
movsd 0x10(%r14), %xmm3
subps %xmm3, %xmm4
mulss %xmm2, %xmm0
unpcklps %xmm2, %xmm2            # xmm2 = xmm2[0,0,1,1]
mulps %xmm4, %xmm2
movlps %xmm2, 0x10(%rbx)
movss %xmm0, 0x18(%rbx)
movq 0x8(%r14), %rax
movq %rax, 0x20(%rbx)
movb $0x1, %al
addq $0x20, %rsp
popq %rbx
popq %r14
popq %r15
retq