// File: /workspace/github_cpp_makefile_star2_O3/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 $0x138, %rsp            # imm = 0x138
movq %rdx, 0x98(%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0xa0(%rsp), %rdi
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
xorps %xmm2, %xmm2
callq 0x83f68
xorl %eax, %eax
movq %rax, 0x50(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x40(%rsp)
movq %rax, 0x30(%rsp)
movapd %xmm0, 0x20(%rsp)
movq %rax, 0x70(%rsp)
movapd %xmm0, 0x60(%rsp)
movq 0x8(%r14), %rax
subq (%r14), %rax
shrq $0x5, %rax
testl %eax, %eax
je 0x4c053
movl %eax, %eax
movq %rax, 0xc0(%rsp)
xorl %esi, %esi
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
movabsq $-0x4010000000000000, %r12 # imm = 0xBFF0000000000000
xorl %edx, %edx
movq $0x0, 0x90(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %rdi
cmpq %rdi, 0x8(%rax)
je 0x4bbe9
movq (%r14), %rax
movl $0x1, %ebx
xorl %esi, %esi
movq %rsi, 0xc8(%rsp)
leaq (%rsi,%rsi,2), %rbp
shlq $0x4, %rbp
movq 0x90(%rsp), %r13
shlq $0x5, %r13
movq 0x10(%rax,%r13), %rcx
movq %rcx, 0x130(%rsp)
movups (%rax,%r13), %xmm0
movaps %xmm0, 0x120(%rsp)
movaps %xmm0, 0xd0(%rsp)
movq %rcx, 0xe0(%rsp)
movq 0x10(%rdi,%rbp), %rax
movq %rax, 0x10(%rsp)
movupd (%rdi,%rbp), %xmm0
movupd %xmm0, (%rsp)
movq %rdi, %r12
leaq 0x78(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x84174
addq %rbp, %r12
addq $0x18, %r12
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r12, %rdi
callq 0x841b8
andpd 0x101521(%rip), %xmm0   # 0x14d0a0
movq (%r14), %rax
movsd 0x18(%rax,%r13), %xmm1
ucomisd %xmm0, %xmm1
movq 0xc8(%rsp), %rcx
seta 0x1a(%rsp,%rcx)
movl %ebx, %esi
movq 0x98(%rsp), %rcx
movq (%rcx), %rdi
movq 0x8(%rcx), %rcx
subq %rdi, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
incl %ebx
cmpq %rsi, %rcx
ja 0x4bae1
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rsi
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
movabsq $-0x4010000000000000, %r12 # imm = 0xBFF0000000000000
cmpq %rdx, %rsi
je 0x4bbf6
movq %rdx, 0x48(%rsp)
movq %rdx, %rsi
movq $0x0, 0x78(%rsp)
cmpq 0x50(%rsp), %rsi
je 0x4bc18
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4bc27
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rsi
cmpq %rax, %rsi
je 0x4bc3e
movq %rax, 0x28(%rsp)
movq %rax, %rsi
movq $0x0, 0x78(%rsp)
cmpq 0x30(%rsp), %rsi
je 0x4bc60
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4bc6f
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rsi
cmpq %rax, %rsi
je 0x4bc86
movq %rax, 0x68(%rsp)
movq %rax, %rsi
movq $0x0, 0x78(%rsp)
cmpq 0x70(%rsp), %rsi
je 0x4bca8
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4bcb7
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
cmpb $0x1, 0x1a(%rsp)
jne 0x4bcec
movq %rbx, 0x78(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x4bcdd
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4bcec
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
cmpb $0x1, 0x1b(%rsp)
jne 0x4bd21
movq %rbx, 0x78(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4bd12
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4bd21
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
cmpb $0x1, 0x1c(%rsp)
jne 0x4bd56
movq %rbx, 0x78(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x4bd47
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4bd56
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
cmpb $0x1, 0x1d(%rsp)
jne 0x4bd8b
movq %r12, 0x78(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x4bd7c
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4bd8b
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
cmpb $0x1, 0x1e(%rsp)
jne 0x4bdc0
movq %r12, 0x78(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4bdb1
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4bdc0
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
movq 0x48(%rsp), %rsi
cmpb $0x1, 0x1f(%rsp)
jne 0x4bdfa
movq %r12, 0x78(%rsp)
cmpq 0x50(%rsp), %rsi
je 0x4bde6
movq %r12, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4bdfa
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x1391c
movq 0x48(%rsp), %rsi
movq (%r14), %rax
movq 0x90(%rsp), %r13
shlq $0x5, %r13
movupd (%rax,%r13), %xmm0
movupd 0x10(%rax,%r13), %xmm1
movapd %xmm1, 0xb0(%rsp)
movapd %xmm0, 0xa0(%rsp)
movq 0x40(%rsp), %rdx
cmpq %rdx, %rsi
je 0x4c007
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
xorl %ebp, %ebp
movq %rcx, %rdi
cmpq %rax, %rdi
je 0x4bfef
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rsi
xorl %r12d, %r12d
cmpq %rdx, %rsi
je 0x4bfc7
movl $0x1, %ebx
xorl %eax, %eax
movq 0x40(%rsp), %rcx
movsd (%rcx,%rbp,8), %xmm0
ucomisd 0x1054d3(%rip), %xmm0   # 0x151350
movq 0x20(%rsp), %rsi
jne 0x4bead
jp 0x4bead
movsd (%rsi,%r12,8), %xmm0
ucomisd 0x1054bc(%rip), %xmm0   # 0x151350
jne 0x4bead
jp 0x4bead
movsd (%rdx,%rax,8), %xmm0
ucomisd 0x1054ab(%rip), %xmm0   # 0x151350
jne 0x4bead
jnp 0x4bf9a
movq (%r14), %rdi
movq 0x10(%rdi,%r13), %r8
movq %r8, 0xb0(%rsp)
movups (%rdi,%r13), %xmm0
movaps %xmm0, 0xa0(%rsp)
movsd (%rcx,%rbp,8), %xmm0
movsd (%rsi,%r12,8), %xmm1
movsd (%rdx,%rax,8), %xmm2
leaq 0xf0(%rsp), %rdi
callq 0x83f68
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0xf0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x51d04
movq 0x118(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x108(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x84196
movq 0x88(%rsp), %rax
movq %rax, 0xb0(%rsp)
movupd 0x78(%rsp), %xmm0
movapd %xmm0, 0xa0(%rsp)
movq 0x8(%r14), %rsi
cmpq 0x10(%r14), %rsi
je 0x4bf8a
movapd 0xa0(%rsp), %xmm0
movapd 0xb0(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x20, 0x8(%r14)
jmp 0x4bf9a
movq %r14, %rdi
leaq 0xa0(%rsp), %rdx
callq 0x503aa
movl %ebx, %eax
movq 0x60(%rsp), %rdx
movq 0x68(%rsp), %rsi
movq %rsi, %rcx
subq %rdx, %rcx
sarq $0x3, %rcx
incl %ebx
cmpq %rax, %rcx
ja 0x4be6b
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rcx
jmp 0x4bfca
movq %rdx, %rsi
incl %r12d
movq %rcx, %rdi
subq %rax, %rdi
sarq $0x3, %rdi
cmpq %r12, %rdi
ja 0x4be5b
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rsi
movq %rcx, %rdi
jmp 0x4bff2
movq %rax, %rdi
incl %ebp
movq %rsi, %r8
subq %rdx, %r8
sarq $0x3, %r8
cmpq %rbp, %r8
ja 0x4be45
movq 0x90(%rsp), %rcx
incq %rcx
movq %rcx, 0x90(%rsp)
cmpq 0xc0(%rsp), %rcx
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
movabsq $-0x4010000000000000, %r12 # imm = 0xBFF0000000000000
jne 0x4bac2
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x4c053
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c06a
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x4c081
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x138, %rsp            # imm = 0x138
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
jmp 0x4c0a9
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x4c0c3
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c0da
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x4c0f1
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780