// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkanalysis.cc
// Function: CAGE::reconstructCage(std::set<int, std::less<int>, std::allocator<int>>, ATOM_NETWORK*, VORONOI_NETWORK*)
void CAGE::reconstructCage(set<int> ids, ATOM_NETWORK *atmnet, VORONOI_NETWORK *vornet){
  int idCount = 0;
  set<int>::iterator iter = ids.begin();
  Point pivot = atmnet->xyz_to_abc(vornet->nodes[*iter].x, vornet->nodes[*iter].y, vornet->nodes[*iter].z);
  vector<Point> nodeXYZCoords;   nodeXYZCoords.push_back(Point(vornet->nodes[*iter].x, vornet->nodes[*iter].y, vornet->nodes[*iter].z));
  nodeIDs.push_back(*iter); 
  nodeOffsets.push_back(DELTA_POS(0,0,0));
  nodeIndices.insert(pair<int,int>(*iter, idCount));
  iter++;
  idCount++;
  
  // Calculate and store the closest positions of other points to pivot point
  while(iter != ids.end()) {
    double minDa = DBL_MAX, minDb = DBL_MAX, minDc = DBL_MAX;
    Point other = atmnet->xyz_to_abc(vornet->nodes[*iter].x,  vornet->nodes[*iter].y, vornet->nodes[*iter].z);
    atmnet->getDistCalc().minimum_periodic_distance(pivot[0], pivot[1], pivot[2], other[0], other[1], other[2], minDa, minDb, minDc);
    Point shifted = Point(minDa, minDb, minDc).add(pivot);
    nodeXYZCoords.push_back(atmnet->abc_to_xyz(shifted));
    
    Point offset = shifted.subtract(other);
    nodeIDs.push_back(*iter);  
    nodeOffsets.push_back(DELTA_POS((int)(floor(offset[0] + 0.5)), (int)(floor(offset[1] + 0.5)), (int)(floor(offset[2] + 0.5))));
    nodeIndices.insert(pair<int,int>(*iter, idCount));
    iter++;
    idCount++;
  }
  
  // Compute the center point of the cage
  cx = cy = cz = 0;
  for(unsigned int i = 0; i < nodeXYZCoords.size(); i++){
    cx += nodeXYZCoords[i][0]; cy += nodeXYZCoords[i][1]; cz += nodeXYZCoords[i][2];
  }
  cx /= nodeXYZCoords.size(); cy /= nodeXYZCoords.size(); cz /= nodeXYZCoords.size();
  
  // Compute the radius of the cage
  iter = ids.begin();
  radius = DBL_MAX;
  for(unsigned int i = 0; i < nodeXYZCoords.size(); i++){
    radius = min(radius, calcEuclideanDistance(cx, cy, cz, nodeXYZCoords[i][0], nodeXYZCoords[i][1], nodeXYZCoords[i][2]) + vornet->nodes[*iter].rad_stat_sphere);
    iter++;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x188, %rsp            # imm = 0x188
movq %rcx, %r15
movq %rdx, %rbp
movq %rdi, %r14
movq %rsi, 0x70(%rsp)
movq 0x18(%rsi), %rbx
movslq 0x20(%rbx), %rax
movq 0x48(%rcx), %rcx
shlq $0x6, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
movsd 0x10(%rcx,%rax), %xmm2
leaq 0xe0(%rsp), %rdi
movq %rdx, %rsi
callq 0x3f1ce
andq $0x0, 0x50(%rsp)
xorps %xmm0, %xmm0
movaps %xmm0, 0x40(%rsp)
movslq 0x20(%rbx), %rax
movq %r15, 0x78(%rsp)
movq 0x48(%r15), %rcx
shlq $0x6, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
movsd 0x10(%rcx,%rax), %xmm2
leaq 0xf8(%rsp), %rdi
callq 0x63c46
leaq 0x40(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xee82
leaq 0x20(%rbx), %r15
leaq 0x30(%r14), %rdi
movq %rdi, 0xb0(%rsp)
movq %r15, %rsi
callq 0x9434
leaq 0xf8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
leaq 0x48(%r14), %rdi
leaq 0xf8(%rsp), %rsi
movq %rdi, 0xa8(%rsp)
callq 0x2c7e6
movl (%r15), %eax
leaq 0xf8(%rsp), %rsi
movl %eax, (%rsi)
andl $0x0, 0x4(%rsi)
movq %r14, %rdi
callq 0xf6e0
movq %rbx, %rdi
callq 0x4510
movq %rax, %r15
movq 0x70(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xb8(%rsp)
pushq $0x1
popq %rbx
leaq 0xe0(%rsp), %r13
leaq 0x170(%rsp), %r12
movl %ebx, 0x38(%rsp)
movq %rbp, 0x98(%rsp)
movq %r14, 0xa0(%rsp)
cmpq 0xb8(%rsp), %r15
je 0x286b6
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x90(%rsp)
movq %rax, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movslq 0x20(%r15), %rax
movq 0x78(%rsp), %rcx
movq 0x48(%rcx), %rcx
shlq $0x6, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
movsd 0x10(%rcx,%rax), %xmm2
leaq 0xc8(%rsp), %rdi
movq %rbp, %rsi
callq 0x3f1ce
leaq 0xf8(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ec9e
movq %r13, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x30(%rsp)
movq %r13, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0xc8(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
leaq 0xc8(%rsp), %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm5
leaq 0xf8(%rsp), %rdi
movsd 0x30(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
movsd 0x20(%rsp), %xmm2
movsd 0x58(%rsp), %xmm3
movsd 0xc0(%rsp), %xmm4
leaq 0x90(%rsp), %rsi
leaq 0x88(%rsp), %rdx
leaq 0x80(%rsp), %rcx
callq 0x59984
leaq 0xf8(%rsp), %r13
movq %r13, %rdi
callq 0xb0f0
movsd 0x90(%rsp), %xmm0
movsd 0x88(%rsp), %xmm1
movsd 0x80(%rsp), %xmm2
movq %r12, %rdi
callq 0x63c46
movq 0xf0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xe0(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r13, %rdi
movq %r12, %rsi
callq 0x63c56
movq 0x108(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xf8(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
movq %rbp, %rsi
callq 0x3e536
leaq 0x40(%rsp), %rdi
movq %r12, %rsi
callq 0x2468e
movq 0xd8(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0xc8(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r12, %rbp
movq %r12, %rdi
leaq 0xf8(%rsp), %rsi
callq 0x63d26
leaq 0x20(%r15), %r13
movq 0xb0(%rsp), %rdi
movq %r13, %rsi
callq 0x9434
movq %r15, 0x28(%rsp)
movq %rbp, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
addsd 0xd3a66(%rip), %xmm0    # 0xfc038
callq 0x4720
movsd %xmm0, 0x30(%rsp)
movq %rbp, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rbp, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movq %rax, %r12
movl %ebx, %r14d
cvttsd2si 0x30(%rsp), %ebx
movsd 0xd3a28(%rip), %xmm1    # 0xfc038
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
callq 0x4720
cvttsd2si %xmm0, %r15d
movsd (%r12), %xmm0
addsd 0xd3a06(%rip), %xmm0    # 0xfc038
callq 0x4720
cvttsd2si %xmm0, %ecx
leaq 0x64(%rsp), %rdi
movl %ebx, %esi
movl %r14d, %ebx
movl %r15d, %edx
callq 0x3d328
movq 0xa8(%rsp), %rdi
leaq 0x64(%rsp), %rsi
callq 0x2c7e6
movl (%r13), %eax
movl %eax, 0x64(%rsp)
movl 0x38(%rsp), %r12d
movl %r12d, 0x68(%rsp)
movq 0xa0(%rsp), %r14
movq %r14, %rdi
leaq 0x64(%rsp), %rsi
callq 0xf6e0
movq 0x28(%rsp), %rdi
callq 0x4510
movq %rax, %r15
incl %r12d
movl %r12d, 0x38(%rsp)
movq 0x98(%rsp), %rax
leaq 0xe0(%rsp), %r13
movq %rbp, %r12
movq %rax, %rbp
jmp 0x283af
leaq 0x60(%r14), %r12
xorpd %xmm0, %xmm0
movupd %xmm0, 0x60(%r14)
andq $0x0, 0x70(%r14)
xorl %r13d, %r13d
xorpd %xmm0, %xmm0
pushq $0x1
popq %rbx
pushq $0x2
popq %rbp
movl %r13d, %r13d
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rcx
movq %rcx, %rax
subq %rdi, %rax
cqto
pushq $0x18
popq %rsi
idivq %rsi
cmpq %r13, %rax
jbe 0x2875a
imulq $0x18, %r13, %r15
addq %r15, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
addsd (%r12), %xmm0
movsd %xmm0, (%r12)
movq 0x40(%rsp), %rdi
addq %r15, %rdi
movl %ebx, %esi
callq 0x63c78
movsd (%rax), %xmm0
addsd 0x68(%r14), %xmm0
movsd %xmm0, 0x68(%r14)
addq 0x40(%rsp), %r15
movq %r15, %rdi
movl %ebp, %esi
callq 0x63c78
movsd (%rax), %xmm0
addsd 0x70(%r14), %xmm0
movsd %xmm0, 0x70(%r14)
incl %r13d
jmp 0x286d6
cvtsi2sd %rax, %xmm1
movupd 0x60(%r14), %xmm2
divsd %xmm1, %xmm0
unpcklpd %xmm1, %xmm1            # xmm1 = xmm1[0,0]
divpd %xmm1, %xmm2
movupd %xmm2, 0x60(%r14)
movsd %xmm0, 0x70(%r14)
movq 0x70(%rsp), %rax
movq 0x18(%rax), %r15
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x78(%r14)
xorl %ebx, %ebx
pushq $0x1
popq %r13
pushq $0x2
popq %rbp
movl %ebx, %ebx
subq %rdi, %rcx
movq %rcx, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %rbx, %rax
jbe 0x28881
movsd 0x60(%r14), %xmm0
movsd %xmm0, 0x38(%rsp)
movsd 0x68(%r14), %xmm0
movsd %xmm0, 0x30(%rsp)
movsd 0x70(%r14), %xmm0
movsd %xmm0, 0x28(%rsp)
imulq $0x18, %rbx, %r12
addq %r12, %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rdi
addq %r12, %rdi
movl %r13d, %esi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0x58(%rsp)
addq 0x40(%rsp), %r12
movq %r12, %rdi
movl %ebp, %esi
callq 0x63c78
movsd (%rax), %xmm5
movsd 0x38(%rsp), %xmm0
movsd 0x30(%rsp), %xmm1
movsd 0x28(%rsp), %xmm2
movsd 0x20(%rsp), %xmm3
movsd 0x58(%rsp), %xmm4
callq 0x64934
movslq 0x20(%r15), %rax
movq 0x78(%rsp), %rcx
movq 0x48(%rcx), %rcx
shlq $0x6, %rax
addsd 0x18(%rcx,%rax), %xmm0
minsd 0x78(%r14), %xmm0
movsd %xmm0, 0x78(%r14)
movq %r15, %rdi
callq 0x4510
movq %rax, %r15
incl %ebx
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rcx
jmp 0x2879d
leaq 0x40(%rsp), %rdi
callq 0xb83e
addq $0x188, %rsp            # imm = 0x188
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
jmp 0x288b5
movq %rax, %rbx
jmp 0x288ca
movq %rax, %rbx
leaq 0xf8(%rsp), %rdi
callq 0xb0f0
leaq 0x40(%rsp), %rdi
callq 0xb83e
movq %rbx, %rdi
callq 0x4780