// File: /workspace/github_cpp_makefile_star2_O1/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 0x85436
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 0x4c2d4
movl %eax, %eax
movq %rax, 0xc0(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x98(%rsp), %rax
movq (%rax), %r12
cmpq %r12, 0x8(%rax)
je 0x4be9d
movl $0x1, %ebx
xorl %edx, %edx
movq %rdx, 0xc8(%rsp)
leaq (%rdx,%rdx,2), %rbp
shlq $0x4, %rbp
movq (%r14), %rax
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(%r12,%rbp), %rax
movq %rax, 0x10(%rsp)
movupd (%r12,%rbp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
callq 0x8576e
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 0x857d2
andpd 0x10323f(%rip), %xmm0   # 0x14f090
movq (%r14), %rax
movsd 0x18(%rax,%r13), %xmm1
ucomisd %xmm0, %xmm1
movq 0xc8(%rsp), %rax
seta 0x1a(%rsp,%rax)
movl %ebx, %edx
movq 0x98(%rsp), %rax
movq (%rax), %r12
movq 0x8(%rax), %rax
subq %r12, %rax
sarq $0x4, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
incl %ebx
cmpq %rdx, %rax
ja 0x4bdb2
movq 0x40(%rsp), %rax
cmpq %rax, 0x48(%rsp)
je 0x4beae
movq %rax, 0x48(%rsp)
movq $0x0, 0x78(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x4bed5
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4bee4
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
movabsq $0x3ff0000000000000, %rbx # imm = 0x3FF0000000000000
je 0x4beff
movq %rax, 0x28(%rsp)
movq $0x0, 0x78(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4bf26
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4bf35
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
movq 0x60(%rsp), %rax
cmpq %rax, 0x68(%rsp)
je 0x4bf46
movq %rax, 0x68(%rsp)
movq $0x0, 0x78(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x4bf6d
movq $0x0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4bf7c
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1a(%rsp)
jne 0x4bfb1
movq %rbx, 0x78(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x4bfa2
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4bfb1
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1b(%rsp)
jne 0x4bfe6
movq %rbx, 0x78(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4bfd7
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4bfe6
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1c(%rsp)
jne 0x4c01b
movq %rbx, 0x78(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x4c00c
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4c01b
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1d(%rsp)
movabsq $-0x4010000000000000, %rbx # imm = 0xBFF0000000000000
jne 0x4c05a
movq %rbx, 0x78(%rsp)
movq 0x68(%rsp), %rsi
cmpq 0x70(%rsp), %rsi
je 0x4c04b
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x68(%rsp)
jmp 0x4c05a
leaq 0x60(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1e(%rsp)
jne 0x4c08f
movq %rbx, 0x78(%rsp)
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x4c080
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x28(%rsp)
jmp 0x4c08f
leaq 0x20(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
cmpb $0x1, 0x1f(%rsp)
jne 0x4c0c4
movq %rbx, 0x78(%rsp)
movq 0x48(%rsp), %rsi
cmpq 0x50(%rsp), %rsi
je 0x4c0b5
movq %rbx, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x48(%rsp)
jmp 0x4c0c4
leaq 0x40(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x139c2
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 0x48(%rsp), %rax
cmpq 0x40(%rsp), %rax
je 0x4c2b3
xorl %ebp, %ebp
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0x4c29a
xorl %r12d, %r12d
movq 0x60(%rsp), %rax
cmpq %rax, 0x68(%rsp)
je 0x4c280
movl $0x1, %ebx
xorl %ecx, %ecx
movq 0x40(%rsp), %rdx
movsd (%rdx,%rbp,8), %xmm0
ucomisd 0x107180(%rip), %xmm0   # 0x1532c0
jne 0x4c170
jp 0x4c170
movq 0x20(%rsp), %rsi
movsd (%rsi,%r12,8), %xmm0
ucomisd 0x107169(%rip), %xmm0   # 0x1532c0
jne 0x4c170
jp 0x4c170
movsd (%rax,%rcx,8), %xmm0
ucomisd 0x107158(%rip), %xmm0   # 0x1532c0
jne 0x4c170
jnp 0x4c262
movq (%r14), %rsi
movq 0x10(%rsi,%r13), %rdi
movq %rdi, 0xb0(%rsp)
movups (%rsi,%r13), %xmm0
movaps %xmm0, 0xa0(%rsp)
movsd (%rdx,%rbp,8), %xmm0
movq 0x20(%rsp), %rdx
movsd (%rdx,%r12,8), %xmm1
movsd (%rax,%rcx,8), %xmm2
leaq 0xf0(%rsp), %rdi
callq 0x85436
movq 0x100(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0xf0(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
callq 0x52144
movq 0x118(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x108(%rsp), %xmm0
movupd %xmm0, (%rsp)
leaq 0x78(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x857a0
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 0x4c252
movapd 0xa0(%rsp), %xmm0
movapd 0xb0(%rsp), %xmm1
movupd %xmm1, 0x10(%rsi)
movupd %xmm0, (%rsi)
addq $0x20, 0x8(%r14)
jmp 0x4c262
movq %r14, %rdi
leaq 0xa0(%rsp), %rdx
callq 0x506d2
movl %ebx, %ecx
movq 0x60(%rsp), %rax
movq 0x68(%rsp), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
incl %ebx
cmpq %rcx, %rdx
ja 0x4c12e
incl %r12d
movq 0x28(%rsp), %rax
subq 0x20(%rsp), %rax
sarq $0x3, %rax
cmpq %r12, %rax
ja 0x4c117
incl %ebp
movq 0x48(%rsp), %rax
subq 0x40(%rsp), %rax
sarq $0x3, %rax
cmpq %rbp, %rax
ja 0x4c104
movq 0x90(%rsp), %rcx
incq %rcx
movq %rcx, 0x90(%rsp)
cmpq 0xc0(%rsp), %rcx
jne 0x4bd96
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x4c2eb
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c302
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x4c319
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 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
jmp 0x4c341
movq %rax, %rbx
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x4c35b
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x4c372
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x4c389
movq 0x50(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780