// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/ray.cc
// Function: duplicateSpheresOnFace(ATOM_NETWORK*, std::vector<Sphere, std::allocator<Sphere>>&, std::vector<Plane, std::allocator<Plane>>&)
void duplicateSpheresOnFace(ATOM_NETWORK *cell,vector<Sphere>& spheres,vector<Plane>& faces)
{
  Sphere temp_sphere;
  bool touch_face[6];
  
  vector<double> permutation_a;
  vector<double> permutation_b;
  vector<double> permutation_c;

  unsigned int size = spheres.size(); //because I will be adding spheres to list (there is a smarter way to do this...)
  for (unsigned int i=0; i<size; i++)
    {
      //Assemble touch_face[] for which faces it touches
      for (unsigned int j=0; j<faces.size(); j++) 
	{
	  if (faces[j].distToPlane(spheres[i].center) < (spheres[i].radius))
	    {
	      touch_face[j] = true;
	    }
	  else
	    {
	      touch_face[j] = false;
	    }
	}    
      
      //Add allowable permutations on the unitcell
      permutation_a.clear(); permutation_a.push_back(0.0);
      permutation_b.clear(); permutation_b.push_back(0.0);
      permutation_c.clear(); permutation_c.push_back(0.0);
      
      if (touch_face[0] == true)
	{
	  permutation_c.push_back(1.0);
	}
      if (touch_face[1] == true)
	{
	  permutation_b.push_back(1.0);
	}
      if (touch_face[2] == true)
	{
	  permutation_a.push_back(1.0);
	}
      if (touch_face[3] == true)
	{
	  permutation_c.push_back(-1.0);
	}
      if (touch_face[4] == true)
	{
	  permutation_b.push_back(-1.0);
	}
      if (touch_face[5] == true)
	{
	  permutation_a.push_back(-1.0);
	}
      
      //Iterate through all the permutations on the sphere
      temp_sphere = spheres[i];
      for (unsigned int a=0; a<permutation_a.size(); a++)
	{
	  for (unsigned int b=0; b<permutation_b.size(); b++)
	    {
	      for (unsigned int c=0; c<permutation_c.size(); c++)
		{
		  if (permutation_a[a] != 0 || permutation_b[b] != 0 || permutation_c[c] != 0)
		    {
		      temp_sphere.center = spheres[i].center;
		      temp_sphere.center = temp_sphere.center + cell->abc_to_xyz(Point(permutation_a[a],permutation_b[b],permutation_c[c]));
		      spheres.push_back(temp_sphere);
		    }
		}
	    }
	}
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x118, %rsp            # imm = 0x118
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, 0xb8(%rsp)
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
callq 0x3cd06
xorpd %xmm0, %xmm0
leaq 0x80(%rsp), %r13
andq $0x0, 0x10(%r13)
leaq 0x40(%rsp), %rax
andq $0x0, 0x10(%rax)
movapd %xmm0, (%r13)
movapd %xmm0, (%rax)
leaq 0x60(%rsp), %rax
movapd %xmm0, (%rax)
andq $0x0, 0x10(%rax)
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x5, %rax
movl %eax, %eax
movq %rax, 0xa8(%rsp)
xorl %ebp, %ebp
movq %r15, 0xa0(%rsp)
cmpq 0xa8(%rsp), %rbp
je 0x39974
xorl %eax, %eax
movq %rbp, 0xb0(%rsp)
shlq $0x5, %rbp
movl %eax, %ebx
movq (%r15), %rdi
movq 0x8(%r15), %rax
subq %rdi, %rax
cqto
pushq $0x30
popq %rcx
idivq %rcx
cmpq %rbx, %rax
jbe 0x3966d
imulq $0x30, %rbx, %rax
addq %rax, %rdi
movq (%r14), %rax
movq 0x10(%rax,%rbp), %rcx
movq %rcx, 0x10(%rsp)
movupd (%rax,%rbp), %xmm0
movupd %xmm0, (%rsp)
callq 0x3904a
movq (%r14), %rax
movsd 0x18(%rax,%rbp), %xmm1
ucomisd %xmm0, %xmm1
seta 0x22(%rsp,%rbx)
leal 0x1(%rbx), %eax
jmp 0x3961a
movq 0x80(%rsp), %rax
cmpq %rax, 0x88(%rsp)
je 0x39687
movq %rax, 0x88(%rsp)
andq $0x0, 0x28(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
movq 0x40(%rsp), %rax
cmpq %rax, 0x48(%rsp)
je 0x396ab
movq %rax, 0x48(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
movq 0x60(%rsp), %rax
cmpq %rax, 0x68(%rsp)
je 0x396d1
movq %rax, 0x68(%rsp)
andq $0x0, 0x28(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x22(%rsp)
jne 0x3970b
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x28(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x23(%rsp)
jne 0x39730
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x28(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x24(%rsp)
jne 0x39753
movabsq $0x3ff0000000000000, %rax # imm = 0x3FF0000000000000
movq %rax, 0x28(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x25(%rsp)
jne 0x39778
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x28(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x26(%rsp)
jne 0x3979d
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x28(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
cmpb $0x1, 0x27(%rsp)
jne 0x397c0
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x28(%rsp)
movq %r13, %rdi
leaq 0x28(%rsp), %rsi
callq 0xf9fe
movq (%r14), %rax
movupd (%rax,%rbp), %xmm0
movupd 0x10(%rax,%rbp), %xmm1
movapd %xmm1, 0xd0(%rsp)
movapd %xmm0, 0xc0(%rsp)
xorl %r13d, %r13d
movl %r13d, %r13d
movq 0x88(%rsp), %rax
subq 0x80(%rsp), %rax
sarq $0x3, %rax
cmpq %r13, %rax
jbe 0x39954
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
sarq $0x3, %rax
cmpq %rbx, %rax
jbe 0x3994c
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
cmpq %r15, %rcx
jbe 0x39945
movq 0x80(%rsp), %rcx
movsd (%rcx,%r13,8), %xmm0
ucomisd 0xc6a8c(%rip), %xmm0    # 0x1002e0
movq 0x40(%rsp), %rdx
jne 0x39884
jp 0x39884
movsd (%rdx,%rbx,8), %xmm0
ucomisd 0xc6a76(%rip), %xmm0    # 0x1002e0
jne 0x39884
jp 0x39884
movsd (%rax,%r15,8), %xmm0
ucomisd 0xc6a64(%rip), %xmm0    # 0x1002e0
jne 0x39884
jnp 0x3993d
movq (%r14), %rsi
movq 0x10(%rsi,%rbp), %rdi
movq %rdi, 0xd0(%rsp)
movups (%rsi,%rbp), %xmm0
movaps %xmm0, 0xc0(%rsp)
movsd (%rcx,%r13,8), %xmm0
movsd (%rdx,%rbx,8), %xmm1
movsd (%rax,%r15,8), %xmm2
leaq 0xe8(%rsp), %rdi
callq 0x63c46
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0xe8(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x100(%rsp), %rdi
movq 0xb8(%rsp), %rsi
callq 0x3e536
movq 0x110(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x100(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x28(%rsp), %rdi
movq %r12, %rsi
callq 0x63e70
movq 0x38(%rsp), %rax
movq %rax, 0xd0(%rsp)
movupd 0x28(%rsp), %xmm0
movapd %xmm0, 0xc0(%rsp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x3cd14
incl %r15d
jmp 0x39821
incl %ebx
jmp 0x39805
incl %r13d
jmp 0x397e3
movq 0xb0(%rsp), %rbp
incq %rbp
movq 0xa0(%rsp), %r15
leaq 0x80(%rsp), %r13
jmp 0x395fe
leaq 0x60(%rsp), %rdi
callq 0xb25c
leaq 0x40(%rsp), %rdi
callq 0xb25c
leaq 0x80(%rsp), %rdi
callq 0xb25c
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
jmp 0x399bd
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0xb25c
leaq 0x40(%rsp), %rdi
callq 0xb25c
leaq 0x80(%rsp), %rdi
callq 0xb25c
movq %rbx, %rdi
callq 0x4780