// File: /workspace/github_cpp_makefile_star2_O3/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 $0x178, %rsp            # imm = 0x178
movq %rcx, %r15
movq %rdi, %r14
movq %rsi, 0x68(%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 0xd0(%rsp), %rdi
movq %rdx, 0x48(%rsp)
movq %rdx, %rsi
callq 0x52eec
xorps %xmm0, %xmm0
movaps %xmm0, 0x20(%rsp)
movq $0x0, 0x30(%rsp)
movslq 0x20(%rbx), %rax
movq %r15, 0x70(%rsp)
movq 0x48(%r15), %rcx
shlq $0x6, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
movsd 0x10(%rcx,%rax), %xmm2
leaq 0xe8(%rsp), %rdi
callq 0x83f68
leaq 0x20(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
xorl %esi, %esi
callq 0x12d36
leaq 0x20(%rbx), %r15
leaq 0x30(%r14), %rdi
movq 0x38(%r14), %rsi
cmpq 0x40(%r14), %rsi
movq %rdi, 0x98(%rsp)
je 0x359d3
movl (%r15), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%r14)
jmp 0x359db
movq %r15, %rdx
callq 0xf864
leaq 0xe8(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
leaq 0x48(%r14), %r13
movq 0x50(%r14), %rsi
cmpq 0x58(%r14), %rsi
je 0x35a18
movl 0xf0(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0xe8(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x50(%r14)
jmp 0x35a28
leaq 0xe8(%rsp), %rdx
movq %r13, %rdi
callq 0x3b6f2
movl (%r15), %eax
leaq 0xe8(%rsp), %rsi
movl %eax, (%rsi)
movl $0x0, 0x4(%rsi)
movq %r14, %rdi
callq 0x135ee
movq %r13, 0x90(%rsp)
movq %rbx, %rdi
callq 0x44f0
movq %rax, %rbx
movq 0x68(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
cmpq %rax, %rbx
je 0x35e3a
movl $0x1, 0x50(%rsp)
leaq 0x160(%rsp), %r13
leaq 0xe8(%rsp), %r15
leaq 0xd0(%rsp), %r12
leaq 0xb8(%rsp), %rbp
movabsq $0x7fefffffffffffff, %rax # imm = 0x7FEFFFFFFFFFFFFF
movq %rax, 0x88(%rsp)
movq %rax, 0x80(%rsp)
movq %rax, 0x78(%rsp)
movslq 0x20(%rbx), %rax
movq 0x70(%rsp), %rcx
movq 0x48(%rcx), %rcx
shlq $0x6, %rax
movsd (%rcx,%rax), %xmm0
movsd 0x8(%rcx,%rax), %xmm1
movsd 0x10(%rcx,%rax), %xmm2
movq %r13, %rdi
movq 0x48(%rsp), %rsi
callq 0x52eec
movq %r15, %rdi
movq 0x48(%rsp), %rsi
callq 0x527f2
movq %r12, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x40(%rsp)
movq %r12, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movq %r12, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0xb0(%rsp)
movq %r13, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0xa8(%rsp)
movq %r13, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm5
movq %r15, %rdi
movsd 0x40(%rsp), %xmm0
movsd 0x18(%rsp), %xmm1
movsd 0x38(%rsp), %xmm2
movsd 0xb0(%rsp), %xmm3
movsd 0xa8(%rsp), %xmm4
leaq 0x88(%rsp), %rsi
leaq 0x80(%rsp), %rdx
leaq 0x78(%rsp), %rcx
callq 0x77c12
movq 0x118(%rsp), %rdi
testq %rdi, %rdi
je 0x35bd6
movq 0x128(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x100(%rsp), %rdi
testq %rdi, %rdi
je 0x35bf3
movq 0x110(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x35c10
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd 0x88(%rsp), %xmm0
movsd 0x80(%rsp), %xmm1
movsd 0x78(%rsp), %xmm2
movq %rbp, %rdi
callq 0x83f68
movq 0xe0(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xd0(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x83f78
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0xe8(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %rbp, %rdi
movq 0x48(%rsp), %rsi
callq 0x51d04
movq 0x28(%rsp), %rsi
cmpq 0x30(%rsp), %rsi
je 0x35ca5
movq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsi)
movups 0xb8(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x18, 0x28(%rsp)
jmp 0x35cb2
leaq 0x20(%rsp), %rdi
movq %rbp, %rdx
callq 0x2fec4
movq 0x170(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x160(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %rbp, %rdi
movq %r15, %rsi
callq 0x8404a
leaq 0x20(%rbx), %rdx
movq 0x38(%r14), %rsi
cmpq 0x40(%r14), %rsi
movq %rdx, 0x40(%rsp)
je 0x35cf9
movl (%rdx), %eax
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%r14)
jmp 0x35d06
movq 0x98(%rsp), %rdi
callq 0xf864
movq %rbp, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
addsd 0x11731c(%rip), %xmm0   # 0x14d038
callq 0x4700
movsd %xmm0, 0x18(%rsp)
leaq 0xb8(%rsp), %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0xb8(%rsp), %rdi
movl $0x2, %esi
callq 0x83f9a
movq %rax, %rbp
cvttsd2si 0x18(%rsp), %eax
movl %eax, 0x18(%rsp)
movsd 0x1172ce(%rip), %xmm1   # 0x14d038
movsd 0x38(%rsp), %xmm0
addsd %xmm1, %xmm0
callq 0x4700
movq %r15, %r12
movq %r13, %r15
movq %r14, %r13
movq %rbx, %r14
cvttsd2si %xmm0, %ebx
movsd (%rbp), %xmm0
addsd 0x1172a2(%rip), %xmm0   # 0x14d038
callq 0x4700
cvttsd2si %xmm0, %ecx
leaq 0x5c(%rsp), %rdi
movl 0x18(%rsp), %esi
movl %ebx, %edx
movq %r14, %rbx
movq %r13, %r14
movq %r15, %r13
movq %r12, %r15
leaq 0xd0(%rsp), %r12
callq 0x506b0
movq 0x50(%r14), %rsi
cmpq 0x58(%r14), %rsi
je 0x35de3
movl 0x64(%rsp), %eax
movl %eax, 0x8(%rsi)
movq 0x5c(%rsp), %rax
movq %rax, (%rsi)
addq $0xc, 0x50(%r14)
jmp 0x35df5
movq 0x90(%rsp), %rdi
leaq 0x5c(%rsp), %rdx
callq 0x3b6f2
movq 0x40(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x5c(%rsp)
movl 0x50(%rsp), %eax
movl %eax, 0x60(%rsp)
movq %r14, %rdi
leaq 0x5c(%rsp), %rsi
callq 0x135ee
movq %rbx, %rdi
callq 0x44f0
movq %rax, %rbx
incl 0x50(%rsp)
cmpq 0xa0(%rsp), %rax
leaq 0xb8(%rsp), %rbp
jne 0x35a99
xorpd %xmm1, %xmm1
movupd %xmm1, 0x60(%r14)
movq $0x0, 0x70(%r14)
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, %rcx
movabsq $-0x5555555555555555, %r12 # imm = 0xAAAAAAAAAAAAAAAB
subq %rdi, %rcx
je 0x35f08
leaq 0x60(%r14), %r15
movl $0x1, %ebp
xorl %edx, %edx
leaq (%rdx,%rdx,2), %rbx
leaq (%rdi,%rbx,8), %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
addsd (%r15), %xmm0
movsd %xmm0, (%r15)
shlq $0x3, %rbx
movq 0x20(%rsp), %rdi
addq %rbx, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
addsd 0x68(%r14), %xmm0
movsd %xmm0, 0x68(%r14)
addq 0x20(%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
addsd 0x70(%r14), %xmm0
movsd %xmm0, 0x70(%r14)
movl %ebp, %edx
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rax
movq %rax, %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
incl %ebp
cmpq %rdx, %rcx
ja 0x35e77
movupd (%r15), %xmm1
jmp 0x35f14
sarq $0x3, %rcx
imulq %r12, %rcx
xorpd %xmm0, %xmm0
cvtsi2sd %rcx, %xmm2
divsd %xmm2, %xmm0
unpcklpd %xmm2, %xmm2            # xmm2 = xmm2[0,0]
divpd %xmm2, %xmm1
movupd %xmm1, 0x60(%r14)
movsd %xmm0, 0x70(%r14)
movq 0x68(%rsp), %rcx
movq 0x18(%rcx), %rbx
movabsq $0x7fefffffffffffff, %rcx # imm = 0x7FEFFFFFFFFFFFFF
movq %rcx, 0x78(%r14)
cmpq %rdi, %rax
je 0x3603e
movl $0x1, %ebp
xorl %eax, %eax
movsd 0x60(%r14), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x68(%r14), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x70(%r14), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq (%rax,%rax,2), %r15
leaq (%rdi,%r15,8), %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
shlq $0x3, %r15
movq 0x20(%rsp), %rdi
addq %r15, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0x38(%rsp)
addq 0x20(%rsp), %r15
movq %r15, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm5
movsd 0x48(%rsp), %xmm0
movsd 0x50(%rsp), %xmm1
movsd 0x40(%rsp), %xmm2
movsd 0x18(%rsp), %xmm3
movsd 0x38(%rsp), %xmm4
callq 0x84cbb
movslq 0x20(%rbx), %rax
movq 0x70(%rsp), %rcx
movq 0x48(%rcx), %rcx
shlq $0x6, %rax
addsd 0x18(%rcx,%rax), %xmm0
minsd 0x78(%r14), %xmm0
movsd %xmm0, 0x78(%r14)
movq %rbx, %rdi
callq 0x44f0
movq %rax, %rbx
movl %ebp, %eax
movq 0x20(%rsp), %rdi
movq 0x28(%rsp), %rcx
subq %rdi, %rcx
sarq $0x3, %rcx
imulq %r12, %rcx
incl %ebp
cmpq %rax, %rcx
ja 0x35f58
testq %rdi, %rdi
je 0x36050
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
jmp 0x3607a
movq %rax, %rbx
jmp 0x3608f
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x385cc
movq 0x20(%rsp), %rdi
testq %rdi, %rdi
je 0x360a6
movq 0x30(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780