// File: /workspace/github_cpp_makefile_star2_O1/Luthaf[P]zeopp/symmetry.cc
// Function: IdentifyEquivalentAtoms(ATOM_NETWORK&, int)
vector < vector<int> >  IdentifyEquivalentAtoms(ATOM_NETWORK &atomNet, int spacegroup)
{
  vector <int> AtomGroup; AtomGroup.resize(atomNet.numAtoms,-1); // for each atom stores information if it waswas assigned to a group
  vector < vector<int> > Groups;
  vector < vector<XYZ> > EqPosGroup;

  // First atom sets a new group of atoms equivalent by position

  AtomGroup[0]=0;
  vector <int> v(1,0);
  Groups.push_back(v);
  XYZ at(atomNet.atoms[0].a_coord, atomNet.atoms[0].b_coord, atomNet.atoms[0].c_coord);
  EqPosGroup.push_back(GetEquivalentPositions(spacegroup,&at));

  // Second and other atoms
  for(int i=1; i<atomNet.numAtoms; i++)
    {
    double dist;

    for(unsigned int gr=0; gr<EqPosGroup.size(); gr++) 
      {
      for(unsigned int pos=0; pos<EqPosGroup[gr].size(); pos++)
         {
         dist=atomNet.calcDistanceXYZABC(atomNet.atoms[i].x,atomNet.atoms[i].y,atomNet.atoms[i].z,
                                    EqPosGroup[gr].at(pos).x,EqPosGroup[gr].at(pos).y,EqPosGroup[gr].at(pos).z);
         if(dist<TOLERANCE) 
            {
            if(atomNet.atoms[i].type!=atomNet.atoms[Groups[gr].at(0)].type)
              {
              cerr << "Atoms of different types occupy positions equivalent by symmetry.\n";
              exit(1); 
              };
            AtomGroup[i]=gr;
            Groups[gr].push_back(i);
            break;
            };
         };
         if(dist<TOLERANCE) break; // leave the outer loop if equivalent position was found
      }; // outer loop 

    if(dist>=TOLERANCE) // if dist larger than TOLERANCE, equivalent position has not been found and a new group of equivalent position is to be created
      {
      AtomGroup[i]=EqPosGroup.size();
      XYZ at(atomNet.atoms[i].a_coord, atomNet.atoms[i].b_coord, atomNet.atoms[i].c_coord);
      EqPosGroup.push_back(GetEquivalentPositions(spacegroup,&at));
      vector <int> v(1,i);
      Groups.push_back(v);
      };

    }; // loop other all atoms


 // Print Symmetry group summary 
 for(unsigned int i=0; i<Groups.size(); i++)
   {
   cout << "Group " << i << "  size= " << Groups[i].size() << "\n";
   };

  return Groups; 

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xc8, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %r14
movq %rdi, %rbx
xorpd %xmm0, %xmm0
leaq 0x60(%rsp), %rdi
movapd %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movslq 0x110(%rsi), %rsi
leaq 0x30(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
callq 0x49326
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
xorl %eax, %eax
movq %rax, 0x10(%rbx)
movq %rax, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movq 0x60(%rsp), %rcx
movl $0x0, (%rcx)
movq %rax, 0x90(%rsp)
movapd %xmm0, 0x80(%rsp)
movl $0x4, %edi
callq 0x4460
leaq 0x80(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rsi)
movl $0x0, (%rax)
movq %rcx, 0x8(%rsi)
movq %rbx, %rdi
callq 0xefae
movq 0x2f0(%r14), %rax
movsd 0x18(%rax), %xmm0
movsd 0x20(%rax), %xmm1
movsd 0x28(%rax), %xmm2
leaq 0xb0(%rsp), %rdi
callq 0x85982
leaq 0x98(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movl 0xc(%rsp), %esi
callq 0xa4cb9
leaq 0x30(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x10986a
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0xa4807
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x1, 0x8(%rsp)
cmpl $0x2, 0x110(%r14)
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jl 0xa4ae3
movq %rbx, 0x50(%rsp)
movq 0x38(%rsp), %rax
cmpq 0x30(%rsp), %rax
je 0xa49ca
xorl %r13d, %r13d
movq 0x30(%rsp), %rcx
leaq (,%r13,2), %r15
addq %r13, %r15
movq (%rcx,%r15,8), %rax
cmpq %rax, 0x8(%rcx,%r15,8)
je 0xa499c
movl $0x1, %ebp
xorl %ecx, %ecx
movslq 0x8(%rsp), %rdx
movq 0x2f0(%r14), %rsi
imulq $0x98, %rdx, %rdx
movsd (%rsi,%rdx), %xmm0
movsd 0x8(%rsi,%rdx), %xmm1
movsd 0x10(%rsi,%rdx), %xmm2
leaq (%rcx,%rcx,2), %rcx
movsd (%rax,%rcx,8), %xmm3
movsd 0x8(%rax,%rcx,8), %xmm4
movsd 0x10(%rax,%rcx,8), %xmm5
movq %r14, %rdi
callq 0x53836
movapd %xmm0, %xmm1
movsd 0xafdee(%rip), %xmm0    # 0x1546a0
movsd %xmm1, 0x58(%rsp)
ucomisd %xmm1, %xmm0
ja 0xa48e5
movl %ebp, %ecx
movq 0x30(%rsp), %rdx
movq (%rdx,%r15,8), %rax
movq 0x8(%rdx,%r15,8), %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %r12, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0xa4865
jmp 0xa499c
movq (%rbx), %rbx
movq (%rbx,%r15,8), %rdx
movq 0x8(%rbx,%r15,8), %rbp
cmpq %rdx, %rbp
je 0xa4bfa
movslq 0x8(%rsp), %r12
movq 0x2f0(%r14), %rax
imulq $0x98, %r12, %rcx
movslq (%rdx), %rdx
imulq $0x98, %rdx, %rsi
movq 0x48(%rax,%rcx), %rdx
cmpq 0x48(%rax,%rsi), %rdx
jne 0xa4bdd
testq %rdx, %rdx
je 0xa494d
addq %rax, %rcx
addq $0x40, %rcx
addq %rsi, %rax
addq $0x40, %rax
movq (%rax), %rsi
movq (%rcx), %rdi
callq 0x4480
testl %eax, %eax
jne 0xa4bdd
leaq (%rbx,%r15,8), %rdi
movq 0x60(%rsp), %rax
movl %r13d, (%rax,%r12,4)
cmpq 0x10(%rdi), %rbp
je 0xa4980
movl 0x8(%rsp), %eax
movl %eax, (%rbp)
addq $0x4, %rbp
movq %rbp, 0x8(%rdi)
movq 0x50(%rsp), %rbx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jmp 0xa499c
movq %rbp, %rsi
leaq 0x8(%rsp), %rdx
movq 0x50(%rsp), %rbx
callq 0xf7b4
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movsd 0xafcfc(%rip), %xmm0    # 0x1546a0
ucomisd 0x58(%rsp), %xmm0
ja 0xa49ca
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
incl %r13d
sarq $0x3, %rax
imulq %r12, %rax
cmpq %r13, %rax
ja 0xa483f
movsd 0x58(%rsp), %xmm0
ucomisd 0xafcc8(%rip), %xmm0    # 0x1546a0
leaq 0x98(%rsp), %r15
leaq 0x10(%rsp), %r13
jb 0xa4acc
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
shrq $0x3, %rax
imull $0xaaaaaaab, %eax, %eax # imm = 0xAAAAAAAB
movslq 0x8(%rsp), %rcx
movq 0x60(%rsp), %rdx
movl %eax, (%rdx,%rcx,4)
movslq 0x8(%rsp), %rax
movq 0x2f0(%r14), %rcx
imulq $0x98, %rax, %rax
movsd 0x18(%rcx,%rax), %xmm0
movsd 0x20(%rcx,%rax), %xmm1
movsd 0x28(%rcx,%rax), %xmm2
movq %r15, %rdi
callq 0x85982
movq %r13, %rdi
movl 0xc(%rsp), %esi
movq %r15, %rdx
callq 0xa4cb9
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x10986a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa4a6c
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movl $0x4, %edi
callq 0x4460
movq %rax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movl 0x8(%rsp), %edx
movl %edx, (%rax)
movq %rcx, 0x18(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0xefae
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa4acc
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl 0x110(%r14), %eax
jl 0xa482c
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0xa4b8a
movl $0x1, %r13d
xorl %ebp, %ebp
movq 0xf24c1(%rip), %r14     # 0x196fc0
movl $0x6, %edx
movq %r14, %rdi
leaq 0xb4035(%rip), %rsi     # 0x158b43
callq 0x44e0
movq %r14, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rax, %r15
movl $0x8, %edx
movq %rax, %rdi
leaq 0xb401a(%rip), %rsi     # 0x158b4a
callq 0x44e0
movq (%rbx), %rax
leaq (,%rbp,2), %rcx
addq %rbp, %rcx
movq 0x8(%rax,%rcx,8), %rsi
subq (%rax,%rcx,8), %rsi
sarq $0x2, %rsi
movq %r15, %rdi
callq 0x42b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0xb09c7(%rip), %rsi     # 0x15552e
callq 0x44e0
movl %r13d, %ebp
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
imulq %r12, %rax
incl %r13d
cmpq %rbp, %rax
ja 0xa4aff
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xa4ba7
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x30(%rsp), %rdi
callq 0x68298
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa4bc8
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xf240c(%rip), %rdi     # 0x196ff0
leaq 0xb3f15(%rip), %rsi     # 0x158b00
callq 0x4440
movl $0x1, %edi
callq 0x710c
leaq 0xaaaa4(%rip), %rdi     # 0x14f6a5
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4630
movq %rax, %r14
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0xa4c6b
movq 0xa8(%rsp), %rsi
jmp 0xa4c4c
jmp 0xa4c68
jmp 0xa4c68
jmp 0xa4c68
movq %rax, %r14
jmp 0xa4c88
movq %rax, %r14
jmp 0xa4c9a
jmp 0xa4c68
jmp 0xa4c3a
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa4c6b
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0xa4c6b
jmp 0xa4c68
jmp 0xa4c68
jmp 0xa4c68
movq %rax, %r14
movq 0x50(%rsp), %rbx
jmp 0xa4c6b
jmp 0xa4c68
movq %rax, %r14
movq 0x80(%rsp), %rdi
testq %rdi, %rdi
je 0xa4c88
movq 0x90(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x30(%rsp), %rdi
callq 0x68298
movq %rbx, %rdi
callq 0xefda
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa4cb1
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %r14, %rdi
callq 0x4780