// File: /workspace/github_cpp_makefile_star2_O1/BartMassey[P]ancient-raytracer/sphere.cc
// Function: sphere::intersect(ray, intersection&)
int sphere::intersect( ray r, intersection &s ) {
  r.transform( toi );  // now we have the ray in object coords...
  
  float a = r.d().mag2();
  float b = r.o() * r.d();
  float c = r.o().mag2() - 1.0;
  float d = b*b - a*c;
  float t;

  if( d < TINY ) {
    // ray misses sphere
    return 0;
  }
  if( a < 0 )
    t = (-b + sqrt( d )) / a;
  else
    t = (-b - sqrt( d )) / a;
  if( t < TINY ) {
    // ray is travelling away from sphere, so no hit
    return 0;
  }
  point i( r.o() + r.d() * t );  // the intersection point in object coords
  i.transform(toi);
	
  // there are many possible mappings -- here's a lame one
  s.t = t;
  s.at = new point( X(i), Y(i) );
  s.normal = new point( (i - tr).unit() );
  
  return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %rdx, 0x68(%rsp)
movq %rsi, %r12
movq %rdi, %r14
leaq 0xb0(%rdi), %r15
movq %rsi, %rdi
movq %r15, %rsi
callq 0x51a0
leaq 0x5969(%rip), %rbx      # 0xc848
movq %rbx, 0x10(%rsp)
movslq 0x30(%r12), %rbp
movl %ebp, 0x18(%rsp)
testq %rbp, %rbp
jle 0x6f26
leaq 0x34(%r12), %rsi
leaq 0x1c(%rsp), %rdi
leaq (,%rbp,4), %rdx
callq 0x20a0
xorps %xmm2, %xmm2
xorl %eax, %eax
movss 0x1c(%rsp,%rax,4), %xmm0
mulss %xmm0, %xmm0
addss %xmm0, %xmm2
incq %rax
cmpq %rax, %rbp
jne 0x6f0e
jmp 0x6f29
xorps %xmm2, %xmm2
movq %rbx, 0x10(%rsp)
movslq 0x10(%r12), %r13
movl %r13d, 0x18(%rsp)
testq %r13, %r13
movss %xmm2, 0xc(%rsp)
jle 0x6f60
leaq 0x14(%r12), %rsi
leaq 0x1c(%rsp), %rdi
leaq (,%r13,4), %rdx
callq 0x20a0
movss 0xc(%rsp), %xmm2
movq %rbx, 0xd0(%rsp)
movl %ebp, 0xd8(%rsp)
testl %ebp, %ebp
jle 0x6f92
leaq 0x34(%r12), %rsi
leaq 0xdc(%rsp), %rdi
movq %rbp, %rdx
shlq $0x2, %rdx
callq 0x20a0
movss 0xc(%rsp), %xmm2
cmpl %ebp, %r13d
jne 0x74da
xorps %xmm3, %xmm3
testl %r13d, %r13d
jle 0x6fc0
xorl %eax, %eax
movss 0x1c(%rsp,%rax,4), %xmm0
mulss 0xdc(%rsp,%rax,4), %xmm0
addss %xmm0, %xmm3
incq %rax
cmpq %rax, %r13
jne 0x6fa5
movq %rbx, 0x10(%rsp)
movl %r13d, 0x18(%rsp)
testl %r13d, %r13d
jle 0x701b
movaps %xmm3, 0x50(%rsp)
leaq 0x14(%r12), %rsi
leaq 0x1c(%rsp), %rdi
leaq (,%r13,4), %rdx
callq 0x20a0
xorps %xmm1, %xmm1
xorl %eax, %eax
movss 0x1c(%rsp,%rax,4), %xmm0
mulss %xmm0, %xmm0
addss %xmm0, %xmm1
incq %rax
cmpq %rax, %r13
jne 0x6ff0
addss 0x2742(%rip), %xmm1     # 0x9750
movss 0xc(%rsp), %xmm2
movaps 0x50(%rsp), %xmm3
jmp 0x7023
movss 0x272d(%rip), %xmm1     # 0x9750
mulss %xmm2, %xmm1
movaps %xmm3, %xmm0
mulss %xmm3, %xmm0
subss %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
xorl %ebp, %ebp
movsd 0x1fdd(%rip), %xmm4     # 0x9020
ucomisd %xmm1, %xmm4
ja 0x74c6
xorps %xmm1, %xmm1
ucomiss %xmm2, %xmm1
jbe 0x7060
ucomiss %xmm1, %xmm0
jb 0x7072
sqrtss %xmm0, %xmm0
jmp 0x708f
xorps 0x1fc9(%rip), %xmm3     # 0x9030
ucomiss %xmm1, %xmm0
jb 0x7095
sqrtss %xmm0, %xmm0
jmp 0x70b2
movaps %xmm3, 0x50(%rsp)
callq 0x21c0
movsd 0x1f9c(%rip), %xmm4     # 0x9020
movaps 0x50(%rsp), %xmm3
movss 0xc(%rsp), %xmm2
subss %xmm3, %xmm0
jmp 0x70b9
movaps %xmm3, 0x50(%rsp)
callq 0x21c0
movsd 0x1f79(%rip), %xmm4     # 0x9020
movaps 0x50(%rsp), %xmm3
movss 0xc(%rsp), %xmm2
subss %xmm0, %xmm3
movaps %xmm3, %xmm0
divss %xmm2, %xmm0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd %xmm1, %xmm4
ja 0x74c6
movslq 0x10(%r12), %r13
testq %r13, %r13
movss %xmm0, 0xc(%rsp)
jle 0x70f5
leaq 0x14(%r12), %rsi
leaq (,%r13,4), %rdx
leaq 0x70(%rsp), %rdi
callq 0x20a0
movslq 0x30(%r12), %rbp
testq %rbp, %rbp
jle 0x714a
addq $0x34, %r12
leaq (,%rbp,4), %rdx
leaq 0xbc(%rsp), %rdi
movq %rbx, -0xc(%rdi)
movl %ebp, -0x4(%rdi)
movq %r12, %rsi
callq 0x20a0
movss 0xc(%rsp), %xmm1
xorl %eax, %eax
movss 0xbc(%rsp,%rax,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0xbc(%rsp,%rax,4)
incq %rax
cmpq %rax, %rbp
jne 0x712a
jmp 0x7159
movq %rbx, 0xb0(%rsp)
movl %ebp, 0xb8(%rsp)
movq %rbx, 0x30(%rsp)
movl %r13d, 0x38(%rsp)
testl %r13d, %r13d
jle 0x717f
leaq 0x3c(%rsp), %rdi
leaq (,%r13,4), %rdx
leaq 0x70(%rsp), %rsi
callq 0x20a0
movq %rbx, 0x10(%rsp)
movl %ebp, 0x18(%rsp)
testl %ebp, %ebp
jle 0x71a5
leaq 0xbc(%rsp), %rsi
leaq 0x1c(%rsp), %rdi
movq %rbp, %rdx
shlq $0x2, %rdx
callq 0x20a0
cmpl %ebp, %r13d
jne 0x74f9
testl %r13d, %r13d
jle 0x71cf
xorl %eax, %eax
movss 0x1c(%rsp,%rax,4), %xmm0
addss 0x3c(%rsp,%rax,4), %xmm0
movss %xmm0, 0x3c(%rsp,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x71b5
cmpl $0x4, %r13d
jg 0x7518
testl %r13d, %r13d
jle 0x71f9
leaq 0x3c(%rsp), %rsi
movq %r13, %rdx
shlq $0x2, %rdx
leaq 0x10(%rsp), %rdi
callq 0x20a0
movl %r13d, %eax
jmp 0x71fb
xorl %eax, %eax
cmpl $0x2, %eax
ja 0x7225
movl %eax, %ecx
leaq (%rsp,%rcx,4), %rdi
addq $0x10, %rdi
movl $0x2, %ecx
subl %eax, %ecx
leaq 0x4(,%rcx,4), %rdx
xorl %esi, %esi
callq 0x2070
movl $0x3, %eax
cmpl $0x3, %eax
jne 0x7232
movl $0x3f800000, 0x1c(%rsp) # imm = 0x3F800000
testl %r13d, %r13d
jle 0x7262
xorl %r12d, %r12d
leaq 0x10(%rsp), %r13
movq (%r15), %rax
movq %r15, %rdi
movl %r12d, %esi
movq %r13, %rdx
callq *0x20(%rax)
movss %xmm0, 0x3c(%rsp,%r12,4)
incq %r12
movslq 0x38(%rsp), %rax
cmpq %rax, %r12
jl 0x723f
movq 0x68(%rsp), %r12
movss 0xc(%rsp), %xmm0
movss %xmm0, (%r12)
movl $0x20, %edi
callq 0x20f0
movq %rax, %r15
leaq 0x30(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
testl %eax, %eax
jle 0x7537
leaq 0x30(%rsp), %rdi
movq (%rdi), %rax
xorl %esi, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
leaq 0x30(%rsp), %rdi
movq (%rdi), %rax
callq *0xe8(%rax)
cmpl $0x1, %eax
jle 0x7556
leaq 0x30(%rsp), %rdi
movq (%rdi), %rax
movl $0x1, %esi
callq *0x30(%rax)
movss (%rax), %xmm0
movq %rbx, (%r15)
movl $0x2, 0x8(%r15)
movss 0xc(%rsp), %xmm1
movss %xmm1, 0xc(%r15)
movss %xmm0, 0x10(%r15)
movq %r15, 0x10(%r12)
movl $0x20, %edi
callq 0x20f0
movq %rax, %r15
movslq 0x150(%r14), %rbp
testq %rbp, %rbp
jle 0x7332
addq $0x154, %r14            # imm = 0x154
leaq (,%rbp,4), %rdx
leaq 0xf4(%rsp), %rdi
movq %r14, %rsi
callq 0x20a0
movq %rbx, 0x90(%rsp)
movslq 0x38(%rsp), %r13
movl %r13d, 0x98(%rsp)
testq %r13, %r13
jle 0x7366
leaq 0x3c(%rsp), %rsi
leaq 0x9c(%rsp), %rdi
leaq (,%r13,4), %rdx
callq 0x20a0
testl %ebp, %ebp
jle 0x73d2
leaq (,%rbp,4), %r14
leaq 0x1c(%rsp), %r12
movq %rbx, -0xc(%r12)
movl %ebp, -0x4(%r12)
leaq 0xf4(%rsp), %rsi
movq %r12, %rdi
movq %r14, %rdx
callq 0x20a0
xorl %eax, %eax
movaps 0x1c93(%rip), %xmm0     # 0x9030
movss 0x1c(%rsp,%rax,4), %xmm1
xorps %xmm0, %xmm1
movss %xmm1, 0x1c(%rsp,%rax,4)
incq %rax
cmpq %rax, %rbp
jne 0x739d
leaq 0x7c(%rsp), %rdi
movq %rbx, -0xc(%rdi)
movl %ebp, -0x4(%rdi)
movq %r12, %rsi
movq %r14, %rdx
callq 0x20a0
movq 0x68(%rsp), %r12
jmp 0x73e4
movq %rbx, 0x10(%rsp)
movl %ebp, 0x18(%rsp)
movq %rbx, 0x70(%rsp)
movl %ebp, 0x78(%rsp)
cmpl 0x78(%rsp), %r13d
jne 0x74f9
testl %r13d, %r13d
jle 0x7459
leaq 0x9c(%rsp), %rsi
xorl %eax, %eax
movss 0x7c(%rsp,%rax,4), %xmm0
addss 0x9c(%rsp,%rax,4), %xmm0
movss %xmm0, 0x9c(%rsp,%rax,4)
incq %rax
cmpq %rax, %r13
jne 0x73fe
movq %rbx, (%r15)
movl %r13d, 0x8(%r15)
movq %r15, %r14
addq $0xc, %r14
leaq (,%r13,4), %rdx
movq %r14, %rdi
callq 0x20a0
xorps %xmm0, %xmm0
xorl %eax, %eax
movss (%r14,%rax,4), %xmm1
mulss %xmm1, %xmm1
addss %xmm1, %xmm0
incq %rax
cmpq %rax, %r13
jne 0x7441
jmp 0x7463
movq %rbx, (%r15)
movl %r13d, 0x8(%r15)
xorps %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomiss %xmm1, %xmm0
jb 0x7471
sqrtss %xmm0, %xmm0
jmp 0x7476
callq 0x21c0
xorps %xmm1, %xmm1
cvtss2sd %xmm0, %xmm1
ucomisd 0x1b9b(%rip), %xmm1     # 0x9020
jbe 0x7575
movslq 0x8(%r15), %rax
testq %rax, %rax
jle 0x74bc
movss 0x1b6c(%rip), %xmm1     # 0x9008
divss %xmm0, %xmm1
xorl %ecx, %ecx
movss 0xc(%r15,%rcx,4), %xmm0
mulss %xmm1, %xmm0
movss %xmm0, 0xc(%r15,%rcx,4)
incq %rcx
cmpq %rcx, %rax
jne 0x74a2
movq %r15, 0x8(%r12)
movl $0x1, %ebp
movl %ebp, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1bb7(%rip), %rdi      # 0x9098
leaq 0x1b86(%rip), %rsi      # 0x906e
leaq 0x1bb4(%rip), %rcx      # 0x90a3
movl $0x4f, %edx
callq 0x2080
leaq 0x1b98(%rip), %rdi      # 0x9098
leaq 0x1b67(%rip), %rsi      # 0x906e
leaq 0x1bbb(%rip), %rcx      # 0x90c9
movl $0x66, %edx
callq 0x2080
leaq 0x1bd0(%rip), %rdi      # 0x90ef
leaq 0x1b48(%rip), %rsi      # 0x906e
leaq 0x1bc9(%rip), %rcx      # 0x90f6
movl $0x92, %edx
callq 0x2080
leaq 0x1d7d(%rip), %rdi      # 0x92bb
leaq 0x1b29(%rip), %rsi      # 0x906e
leaq 0x1d79(%rip), %rcx      # 0x92c5
movl $0x104, %edx            # imm = 0x104
callq 0x2080
leaq 0x1d79(%rip), %rdi      # 0x92d6
leaq 0x1b0a(%rip), %rsi      # 0x906e
leaq 0x1d75(%rip), %rcx      # 0x92e0
movl $0x109, %edx            # imm = 0x109
callq 0x2080
leaq 0x1c27(%rip), %rdi      # 0x91a3
leaq 0x1aeb(%rip), %rsi      # 0x906e
leaq 0x1c22(%rip), %rcx      # 0x91ac
movl $0xc9, %edx
callq 0x2080
movq %rax, %rbx
movl $0x20, %esi
movq %r15, %rdi
callq 0x2100
movq %rbx, %rdi
callq 0x21a0