// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/ray.cc
// Function: rayTraceToSphere(ATOM_NETWORK*, std::vector<Sphere, std::allocator<Sphere>>&, ray, std::vector<Plane, std::allocator<Plane>>&, hitdata&)
void rayTraceToSphere(ATOM_NETWORK *cell,vector<Sphere>& spheres,ray r, vector<Plane>& faces,hitdata& hitobject)
{
  
#if DEBUG
  cout << "Current Ray Length: " << hitobject.dist << endl;
#endif
  
  if (hitobject.dist > MAXRAYDIST){
    return;
  }
  
  

  //Find the closest atom that it will hit
  hitdata hitsphere = findClosestSphere(spheres,r);
  
  //If I hit an Sphere great!
  if (hitsphere.hit == true)
    {
      if (hitsphere.id == hitobject.id)
	{
	  //cerr << "Just hit same atom this is not allowable" << endl;
	}
      hitobject.hit = true;
      hitobject.hitpoint = hitsphere.hitpoint;
      hitobject.dist += hitsphere.dist;
      hitobject.id = hitsphere.id;
      hitobject.object = hitsphere.object;
      return;
    }
  //If I didn't hit a Sphere then I must hit a unitcell face
  hitsphere = findClosestPlane(faces,r);
  
  assert(hitsphere.hit==true); //Thus it hit a plane

  hitobject.hit = true;
  hitobject.hitpoint = hitsphere.hitpoint;
  hitobject.dist += hitsphere.dist;
  hitobject.id = -1;
  hitobject.object = NULL;
  
  //I am moving the point just slightly outside of the unit cell to be shifted back in
  r.base = cell->shiftXYZInUC(hitobject.hitpoint+r.vector.scale(threshold));
  
  //this is a recursive call to get the total length of the ray
  rayTraceToSphere(cell,spheres,r,faces,hitobject);
  return;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movsd 0x20(%rcx), %xmm0
ucomisd 0x1023a9(%rip), %xmm0   # 0x14f040
ja 0x4ce27
movq %rcx, %rbx
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %r12
leaq 0x110(%rsp), %r13
leaq 0x30(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rdx
callq 0x4b6cd
cmpb $0x1, (%rbp)
jne 0x4cd01
movb $0x1, (%rbx)
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x8(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rbx)
movsd 0x50(%rsp), %xmm0
addsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x20(%rbx)
movl 0x58(%rsp), %eax
movl %eax, 0x28(%rbx)
movq 0x60(%rsp), %rax
movq %rax, 0x30(%rbx)
jmp 0x4ce27
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x4b7e3
movq 0x30(%rbp), %rax
movq %rax, 0x60(%rsp)
movups (%rbp), %xmm0
movups 0x10(%rbp), %xmm1
movups 0x20(%rbp), %xmm2
movaps %xmm2, 0x50(%rsp)
movaps %xmm1, 0x40(%rsp)
movaps %xmm0, 0x30(%rsp)
cmpb $0x0, 0x30(%rsp)
je 0x4ce39
movb $0x1, (%rbx)
leaq 0x8(%rbx), %rax
movq %rax, 0x68(%rsp)
movups 0x38(%rsp), %xmm0
movups %xmm0, 0x8(%rbx)
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rbx)
movsd 0x50(%rsp), %xmm0
addsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x20(%rbx)
movl $0xffffffff, 0x28(%rbx) # imm = 0xFFFFFFFF
movq $0x0, 0x30(%rbx)
leaq 0x18(%r13), %rsi
leaq 0x70(%rsp), %rbp
movsd 0x107434(%rip), %xmm0   # 0x1541c8
movq %rbp, %rdi
callq 0x85590
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
leaq 0x88(%rsp), %rbp
movq %rbp, %rdi
movq 0x68(%rsp), %rsi
callq 0x857a0
movq 0x10(%rbp), %rax
movq %rax, 0x10(%rsp)
movups (%rbp), %xmm0
movups %xmm0, (%rsp)
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x53e0c
movq 0x10(%rbp), %rax
movq %rax, 0x10(%r13)
movups (%rbp), %xmm0
movups %xmm0, (%r13)
movupd (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r12, %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rbx, %rcx
callq 0x4cc79
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x10753f(%rip), %rdi    # 0x15437f
leaq 0x107427(%rip), %rsi    # 0x15426e
leaq 0x107545(%rip), %rcx    # 0x154393
movl $0x195, %edx            # imm = 0x195
callq 0x4290