// File: logicx24[P]RayTracer/raytracer.cpp
// Function: Sphere::intersection(Ray&, float)
float intersection(Ray &ray, float eps) {
		vec3 p_c = ray.pos - center;
        vec3 d = ray.vec;
        float discriminant = pow(d * p_c, 2) - ((d * d) * ((p_c * p_c) - pow(radius, 2)));
        if (discriminant < 0) {
        	return MAXFLOAT;
        }
		float t1 = (-d*(p_c) + sqrt(discriminant)) / (d * d);
		float t2 = (-d*(p_c) - sqrt(discriminant)) / (d * d);
        if (t1 < eps && t2 < eps) {
        	return MAXFLOAT;
        }
        vec3 p1 = ray.pointAt(t1);
        vec3 p2 = ray.pointAt(t2);
        float d1 = distance(ray.pos, p1);
        float d2 = distance(ray.pos, p2);
	    if (d1 < d2) {
        	return t1;
        } else {
        	return t2;
        }
	}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movss %xmm0, -0x1c(%rbp)
movq -0x10(%rbp), %rdx
movq %rdx, -0xe8(%rbp)
movq -0x18(%rbp), %rsi
addq $0x1f0, %rdx            # imm = 0x1F0
leaq -0x38(%rbp), %rdi
callq 0xa040
movq -0x18(%rbp), %rsi
addq $0x18, %rsi
leaq -0x50(%rbp), %rdi
callq 0x7e40
leaq -0x50(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xaee0
movl $0x2, %edi
callq 0x6830
movsd %xmm0, -0xd8(%rbp)
leaq -0x50(%rbp), %rsi
movq %rsi, %rdi
callq 0xaee0
movsd %xmm0, -0xd0(%rbp)
leaq -0x38(%rbp), %rsi
movq %rsi, %rdi
callq 0xaee0
movq -0xe8(%rbp), %rax
movsd %xmm0, -0xe0(%rbp)
movss 0x208(%rax), %xmm0
movl $0x2, %edi
callq 0xc750
movsd -0xe0(%rbp), %xmm2
movsd -0xd8(%rbp), %xmm1
movaps %xmm0, %xmm3
movsd -0xd0(%rbp), %xmm0
subsd %xmm3, %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x54(%rbp)
xorps %xmm0, %xmm0
ucomiss -0x54(%rbp), %xmm0
jbe 0xc56a
movss 0x18ad0(%rip), %xmm0    # 0x25030
movss %xmm0, -0x4(%rbp)
jmp 0xc6fb
leaq -0x70(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xc780
leaq -0x70(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xaee0
movsd %xmm0, -0x108(%rbp)
movss -0x54(%rbp), %xmm0
callq 0xc810
movaps %xmm0, %xmm1
movsd -0x108(%rbp), %xmm0
cvtss2sd %xmm1, %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x100(%rbp)
leaq -0x50(%rbp), %rsi
movq %rsi, %rdi
callq 0xaee0
movaps %xmm0, %xmm1
movsd -0x100(%rbp), %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x58(%rbp)
leaq -0x90(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0xc780
leaq -0x90(%rbp), %rdi
leaq -0x38(%rbp), %rsi
callq 0xaee0
movsd %xmm0, -0xf8(%rbp)
movss -0x54(%rbp), %xmm0
callq 0xc810
movaps %xmm0, %xmm1
movsd -0xf8(%rbp), %xmm0
cvtss2sd %xmm1, %xmm1
subsd %xmm1, %xmm0
movsd %xmm0, -0xf0(%rbp)
leaq -0x50(%rbp), %rsi
movq %rsi, %rdi
callq 0xaee0
movaps %xmm0, %xmm1
movsd -0xf0(%rbp), %xmm0
divsd %xmm1, %xmm0
cvtsd2ss %xmm0, %xmm0
movss %xmm0, -0x74(%rbp)
movss -0x58(%rbp), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xc676
movss -0x74(%rbp), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xc676
movss 0x189c4(%rip), %xmm0    # 0x25030
movss %xmm0, -0x4(%rbp)
jmp 0xc6fb
movq -0x18(%rbp), %rsi
movss -0x58(%rbp), %xmm0
leaq -0xa8(%rbp), %rdi
callq 0xaf60
movq -0x18(%rbp), %rsi
movss -0x74(%rbp), %xmm0
leaq -0xc0(%rbp), %rdi
callq 0xaf60
movq -0x18(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x37a0
movss %xmm0, -0xc4(%rbp)
movq -0x18(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x37a0
movss %xmm0, -0xc8(%rbp)
movss -0xc4(%rbp), %xmm1
movss -0xc8(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xc6f1
movss -0x58(%rbp), %xmm0
movss %xmm0, -0x4(%rbp)
jmp 0xc6fb
movss -0x74(%rbp), %xmm0
movss %xmm0, -0x4(%rbp)
movss -0x4(%rbp), %xmm0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopl (%rax)