// File: /workspace/github_cpp_makefile_star2_O3/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 0x48a3e
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, 0xa0(%rsp)
movapd %xmm0, 0x90(%rsp)
movl $0x4, %edi
callq 0x4460
leaq 0x90(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x10(%rsi)
movl $0x0, (%rax)
movq %rcx, 0x8(%rsi)
movq %rbx, %rdi
callq 0xf03a
movq 0x2f0(%r14), %rax
movsd 0x18(%rax), %xmm0
movsd 0x20(%rax), %xmm1
movsd 0x28(%rax), %xmm2
leaq 0xb0(%rsp), %rdi
callq 0x84364
leaq 0x78(%rsp), %rdi
leaq 0xb0(%rsp), %rdx
movl 0xc(%rsp), %esi
callq 0xa2ee4
leaq 0x30(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x108482
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa2a2f
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl $0x1, 0x8(%rsp)
cmpl $0x2, 0x110(%r14)
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jl 0xa2d11
movl $0x1, %eax
leaq 0x78(%rsp), %r15
leaq 0x10(%rsp), %r13
movq %rbx, 0x50(%rsp)
movq 0x30(%rsp), %rcx
cmpq %rcx, 0x38(%rsp)
je 0xa2c0d
xorl %r13d, %r13d
leaq (,%r13,2), %r15
addq %r13, %r15
movq (%rcx,%r15,8), %rax
cmpq %rax, 0x8(%rcx,%r15,8)
je 0xa2bce
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 0x53538
movapd %xmm0, %xmm1
movsd 0xafc6c(%rip), %xmm0    # 0x152750
movsd %xmm1, 0x58(%rsp)
ucomisd %xmm1, %xmm0
ja 0xa2b17
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 0xa2a97
jmp 0xa2bce
movq (%rbx), %rbx
movq (%rbx,%r15,8), %rdx
movq 0x8(%rbx,%r15,8), %rbp
cmpq %rdx, %rbp
je 0xa2e28
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 0xa2e0b
testq %rdx, %rdx
je 0xa2b7f
addq %rax, %rcx
addq $0x40, %rcx
addq %rsi, %rax
addq $0x40, %rax
movq (%rax), %rsi
movq (%rcx), %rdi
callq 0x4480
testl %eax, %eax
jne 0xa2e0b
leaq (%rbx,%r15,8), %rdi
movq 0x60(%rsp), %rax
movl %r13d, (%rax,%r12,4)
cmpq 0x10(%rdi), %rbp
je 0xa2bb2
movl 0x8(%rsp), %eax
movl %eax, (%rbp)
addq $0x4, %rbp
movq %rbp, 0x8(%rdi)
movq 0x50(%rsp), %rbx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
jmp 0xa2bce
movq %rbp, %rsi
leaq 0x8(%rsp), %rdx
movq 0x50(%rsp), %rbx
callq 0xf864
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
movsd 0xafb7a(%rip), %xmm0    # 0x152750
ucomisd 0x58(%rsp), %xmm0
ja 0xa2bff
incl %r13d
movq 0x30(%rsp), %rcx
movq 0x38(%rsp), %rax
subq %rcx, %rax
sarq $0x3, %rax
imulq %r12, %rax
cmpq %r13, %rax
ja 0xa2a76
movl 0x8(%rsp), %eax
leaq 0x78(%rsp), %r15
leaq 0x10(%rsp), %r13
movsd 0x58(%rsp), %xmm0
ucomisd 0xafb35(%rip), %xmm0    # 0x152750
jb 0xa2cfe
movq 0x38(%rsp), %rcx
subq 0x30(%rsp), %rcx
shrq $0x3, %rcx
imull $0xaaaaaaab, %ecx, %ecx # imm = 0xAAAAAAAB
cltq
movq 0x60(%rsp), %rdx
movl %ecx, (%rdx,%rax,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 0x84364
movq %r13, %rdi
movl 0xc(%rsp), %esi
movq %r15, %rdx
callq 0xa2ee4
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x108482
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa2c9f
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, %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 0xf03a
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa2cfa
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl 0x8(%rsp), %eax
incl %eax
movl %eax, 0x8(%rsp)
cmpl 0x110(%r14), %eax
jl 0xa2a63
movq 0x8(%rbx), %rax
cmpq (%rbx), %rax
je 0xa2db8
movl $0x1, %r13d
xorl %ebp, %ebp
movq 0xf2293(%rip), %r14     # 0x194fc0
movl $0x6, %edx
movq %r14, %rdi
leaq 0xb3fc7(%rip), %rsi     # 0x156d03
callq 0x44e0
movq %r14, %rdi
movq %rbp, %rsi
callq 0x42b0
movq %rax, %r15
movl $0x8, %edx
movq %rax, %rdi
leaq 0xb3fac(%rip), %rsi     # 0x156d0a
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 0xb0889(%rip), %rsi     # 0x15361e
callq 0x44e0
movl %r13d, %ebp
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rax
imulq %r12, %rax
incl %r13d
cmpq %rbp, %rax
ja 0xa2d2d
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xa2dd5
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x30(%rsp), %rdi
callq 0x67966
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa2df6
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 0xf21de(%rip), %rdi     # 0x194ff0
leaq 0xb3ea7(%rip), %rsi     # 0x156cc0
callq 0x4440
movl $0x1, %edi
callq 0x72bc
leaq 0xaa8c6(%rip), %rdi     # 0x14d6f5
xorl %esi, %esi
xorl %edx, %edx
xorl %eax, %eax
callq 0x4630
movq %rax, %r14
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0xa2e96
movq 0x88(%rsp), %rsi
jmp 0xa2e77
jmp 0xa2e93
jmp 0xa2e93
jmp 0xa2e93
movq %rax, %r14
jmp 0xa2eb3
movq %rax, %r14
jmp 0xa2ec5
jmp 0xa2e93
jmp 0xa2e65
movq %rax, %r14
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0xa2e96
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
jmp 0xa2e96
jmp 0xa2e93
jmp 0xa2e93
jmp 0xa2e93
movq %rax, %r14
movq 0x50(%rsp), %rbx
jmp 0xa2e96
jmp 0xa2e93
movq %rax, %r14
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0xa2eb3
movq 0xa0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x30(%rsp), %rdi
callq 0x67966
movq %rbx, %rdi
callq 0xf066
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0xa2edc
movq 0x70(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %r14, %rdi
callq 0x4780