// File: /workspace/github_cpp_makefile_star2_O3/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 0x10068c(%rip), %xmm0   # 0x14d040
ja 0x4cb44
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 0x4b3cd
cmpb $0x1, (%rbp)
jne 0x4ca1e
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 0x4cb44
leaq 0xa0(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
callq 0x4b4ee
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 0x4cb56
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 0x1057c7(%rip), %xmm0   # 0x152278
movq %rbp, %rdi
callq 0x84096
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 0x84196
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 0x53b0e
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 0x4c996
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x1058d2(%rip), %rdi    # 0x15242f
leaq 0x1057ba(%rip), %rsi    # 0x15231e
leaq 0x1058d8(%rip), %rcx    # 0x152443
movl $0x195, %edx            # imm = 0x195
callq 0x4290