// File: /workspace/github_cpp_makefile_star2_O3/Luthaf[P]zeopp/networkanalysis.cc
// Function: simplifyCageNetwork(ATOM_NETWORK*, VORONOI_NETWORK*, DIJKSTRA_NETWORK*, double)
void simplifyCageNetwork(ATOM_NETWORK *atmnet, VORONOI_NETWORK *vornet, DIJKSTRA_NETWORK *dnet, double probe_radius){
  fstream output;
  output.open("testing.cage", fstream::out);
  vector<CAGE> cages;
  identifyCages(atmnet, vornet, dnet, probe_radius, true, output, cages);
   
  vector<Point> cageCenters;
  for(unsigned int i = 0; i < cages.size(); i++){
    cageCenters.push_back(cages[i].getCenter());
  }

  vector<int> nodeCageIDs = vector<int>(vornet->nodes.size(), -1);

  for(unsigned int i = 0; i < cages.size(); i++){
    vector<int> ids = cages[i].getNodeIDs();
    for(unsigned int j = 0; j < ids.size(); j++){
      nodeCageIDs[ids[j]] = i;
    }
  }

  set<DELTA_POS, bool(*)(DELTA_POS,DELTA_POS)> emptySet (deltaPosLessThan);
  vector< vector< set<DELTA_POS, bool(*)(DELTA_POS,DELTA_POS)> > > cageConnections = vector< vector< set<DELTA_POS, bool(*)(DELTA_POS,DELTA_POS)> > >(cages.size(), 
											   vector< set<DELTA_POS, bool(*)(DELTA_POS,DELTA_POS)> >(cages.size(), emptySet));
  for(unsigned int i = 0; i < dnet->nodes.size(); i++){
    int nodeID = nodeCageIDs[i];
    if(nodeID != -1){
      vector<CONN>::iterator connIter = dnet->nodes[i].connections.begin();
      while(connIter != dnet->nodes[i].connections.end()){
	int fromID = nodeCageIDs[connIter->from];
	int toID   = nodeCageIDs[connIter->to];
	if((fromID != -1) && (toID != -1)){
	  if(fromID != toID){
	    cageConnections[fromID][toID].insert(connIter->deltaPos);
	  }
	  else{
	    DELTA_POS cageDeltaPos = cages[toID].getNodeOffset(connIter->to) - (cages[fromID].getNodeOffset(i));
	    if(!cageDeltaPos.equals(connIter->deltaPos)){
	      cageConnections[fromID][toID].insert(connIter->deltaPos);
	    }
	  }
	}
	connIter++;
      }
    }
  }

  output << "set vornets(0) {" << "\n"
	 << "{color red} " << "\n";
  for(unsigned int i = 0; i < cageConnections.size(); i++){
    cout << i << "\n";
    for(unsigned int j = 0; j < cageConnections[i].size(); j++){
      if(cageConnections[i][j].size() > 0){
	cout << "\t ->" << j << "\n";
	set<DELTA_POS, bool(*)(DELTA_POS,DELTA_POS)>::iterator iter = cageConnections[i][j].begin();
	while(iter != cageConnections[i][j].end()){
	  DELTA_POS dp = *iter;
	  if((i != j) || (dp.x != 0) || (dp.y != 0) || (dp.z != 0)){
	    cout << "\t\t" <<  dp.x << " " << dp.y << " " << dp.z << "\n";
	    Point other = Point(cageCenters[j][0], cageCenters[j][1], cageCenters[j][2]);
	    atmnet->translatePoint(&other, dp.x, dp.y, dp.z);
	    output << "{line {" << cageCenters[i][0] << " " << cageCenters[i][1] << " " << cageCenters[i][2] << "} " 
		   <<       "{" << other[0] << " " << other[1] << " " << other[2] << "} }" << "\n";
	  }
	  iter++;
	}
      }
    }
  }
  output << "}" << "\n";
  output.close();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x318, %rsp            # imm = 0x318
movsd %xmm0, 0x18(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x108(%rsp), %r15
movq %r15, %rdi
callq 0x4520
leaq 0x11a26f(%rip), %rsi    # 0x151570
movq %r15, %rdi
movl $0x10, %edx
callq 0x43d0
xorpd %xmm0, %xmm0
leaq 0x20(%rsp), %r9
movapd %xmm0, (%r9)
movq $0x0, 0x10(%r9)
leaq 0x108(%rsp), %r8
movq %r12, 0xb8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movsd 0x18(%rsp), %xmm0
movl $0x1, %ecx
callq 0x363c9
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rax
cmpq %rax, 0x28(%rsp)
je 0x373f1
movl $0x1, %ebp
xorl %ecx, %ecx
leaq 0xd8(%rsp), %r15
movq %rsp, %r12
shlq $0x7, %rcx
movsd 0x60(%rax,%rcx), %xmm0
movsd 0x68(%rax,%rcx), %xmm1
movsd 0x70(%rax,%rcx), %xmm2
movq %r15, %rdi
callq 0x83f68
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x373cc
movq 0xe8(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0xd8(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x373d7
movq %r12, %rdi
movq %r15, %rdx
callq 0x12d36
movl %ebp, %ecx
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x37381
movq 0x50(%r14), %rsi
subq 0x48(%r14), %rsi
sarq $0x6, %rsi
leaq 0xd8(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0xa0(%rsp), %rdi
leaq 0x50(%rsp), %rcx
callq 0x3864a
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %r15
subq %rax, %r15
je 0x374bb
xorl %ecx, %ecx
leaq 0xd8(%rsp), %r14
xorl %r12d, %r12d
shlq $0x7, %rcx
leaq (%rax,%rcx), %rsi
addq $0x30, %rsi
movq %r14, %rdi
callq 0xe8f8
movq 0xd8(%rsp), %rdi
movq 0xe0(%rsp), %rax
subq %rdi, %rax
je 0x37488
sarq $0x2, %rax
movq 0xa0(%rsp), %rcx
xorl %edx, %edx
movslq (%rdi,%rdx,4), %rsi
movl %r12d, (%rcx,%rsi,4)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0x37474
jmp 0x3748d
testq %rdi, %rdi
je 0x3749d
movq 0xe8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incl %r12d
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %r15
subq %rax, %r15
sarq $0x7, %r15
movq %r12, %rcx
cmpq %r12, %r15
ja 0x3743d
jmp 0x374bf
sarq $0x7, %r15
leaq 0x19339(%rip), %rax     # 0x507ff
leaq 0xe0(%rsp), %rcx
movq %rax, -0x8(%rcx)
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq 0x38(%rsp), %rdi
leaq 0xd8(%rsp), %rdx
leaq 0x90(%rsp), %rcx
movq %r15, %rsi
callq 0x387c6
leaq 0x50(%rsp), %rdi
leaq 0x38(%rsp), %rdx
leaq 0x80(%rsp), %rcx
movq %r15, %rsi
callq 0x38860
leaq 0x38(%rsp), %rdi
callq 0x388f8
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rax, %rcx
je 0x376a8
xorl %r14d, %r14d
movabsq $-0x71c71c71c71c71c7, %rsi # imm = 0x8E38E38E38E38E39
movq 0xa0(%rsp), %rdx
cmpl $-0x1, (%rdx,%r14,4)
je 0x3768e
leaq (%r14,%r14,8), %r12
movq 0x20(%rax,%r12,8), %rbp
cmpq 0x28(%rax,%r12,8), %rbp
je 0x3768e
addq $0x18, %rbp
movslq -0x18(%rbp), %rcx
movq 0xa0(%rsp), %rax
movslq (%rax,%rcx,4), %r13
cmpq $-0x1, %r13
je 0x37666
movslq -0x14(%rbp), %rsi
movl (%rax,%rsi,4), %eax
cmpl $-0x1, %eax
je 0x37666
cmpl %eax, %r13d
jne 0x37640
movq %r13, %r15
shlq $0x7, %r15
movq 0x20(%rsp), %rdi
addq %r15, %rdi
callq 0x36162
movq %rax, 0x90(%rsp)
movl %edx, 0x98(%rsp)
addq 0x20(%rsp), %r15
movq %r15, %rdi
movl %r14d, %esi
callq 0x36162
movq %rax, 0x80(%rsp)
movl %edx, 0x88(%rsp)
leaq 0x90(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x50720
movq %rax, 0x38(%rsp)
movl %edx, 0x40(%rsp)
movq (%rbp), %rsi
movl 0x8(%rbp), %edx
leaq 0x38(%rsp), %rdi
callq 0x506ba
testb %al, %al
jne 0x37666
movq 0x50(%rsp), %rax
leaq (,%r13,2), %rcx
addq %r13, %rcx
movq %rcx, %rdi
shlq $0x4, %rdi
addq (%rax,%rcx,8), %rdi
movq %rbp, %rsi
callq 0x3c45a
jmp 0x37666
cltq
movq 0x50(%rsp), %rcx
leaq (,%r13,2), %rdx
addq %r13, %rdx
leaq (%rax,%rax,2), %rdi
shlq $0x4, %rdi
addq (%rcx,%rdx,8), %rdi
movq %rbp, %rsi
callq 0x3c45a
leaq -0x18(%rbp), %rcx
movq (%rbx), %rax
addq $0x28, %rbp
addq $0x28, %rcx
cmpq 0x28(%rax,%r12,8), %rcx
jne 0x37573
movq 0x8(%rbx), %rcx
movabsq $-0x71c71c71c71c71c7, %rsi # imm = 0x8E38E38E38E38E39
incl %r14d
movq %rcx, %rdx
subq %rax, %rdx
sarq $0x3, %rdx
imulq %rsi, %rdx
cmpq %r14, %rdx
ja 0x37548
leaq 0x118(%rsp), %rbx
leaq 0x119ec6(%rip), %rsi    # 0x15157d
movl $0x10, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11bf53(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x119eaf(%rip), %rsi    # 0x15158e
movl $0xc, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11bf2b(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x58(%rsp), %rax
cmpq 0x50(%rsp), %rax
je 0x37b20
xorl %ebx, %ebx
movq 0x15d8a7(%rip), %rdi    # 0x194fc0
movq %rbx, %rsi
callq 0x42b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11beee(%rip), %rsi    # 0x15361e
callq 0x44e0
movq 0x50(%rsp), %rbp
movq %rbx, 0x70(%rsp)
leaq (%rbx,%rbx,2), %r15
movq (%rbp,%r15,8), %rax
cmpq %rax, 0x8(%rbp,%r15,8)
je 0x37af6
xorl %esi, %esi
movq %rsi, 0x78(%rsp)
leaq (%rsi,%rsi,2), %rdx
movq %rdx, 0xc0(%rsp)
shlq $0x4, %rdx
movq %rdx, 0x18(%rsp)
cmpq $0x0, 0x28(%rax,%rdx)
je 0x37acc
movl $0x4, %edx
movq 0x15d839(%rip), %rdi    # 0x194fc0
leaq 0x119e0d(%rip), %rsi    # 0x15159b
callq 0x44e0
movq 0x78(%rsp), %rbx
movq 0x15d821(%rip), %rdi    # 0x194fc0
movq %rbx, %rsi
callq 0x42b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11be68(%rip), %rsi    # 0x15361e
callq 0x44e0
movq 0x50(%rsp), %rbp
movq (%rbp,%r15,8), %rax
movq 0x18(%rsp), %rcx
addq %rax, %rcx
addq $0x8, %rcx
movq 0x10(%rcx), %r14
cmpq %rcx, %r14
je 0x37acc
movq 0x70(%rsp), %rax
xorl %ebx, %eax
movl %eax, 0x6c(%rsp)
movl 0x20(%r14), %r13d
movl 0x24(%r14), %r12d
movl 0x28(%r14), %ebx
movl 0x6c(%rsp), %eax
orl %r13d, %eax
orl %r12d, %eax
orl %ebx, %eax
je 0x37aa7
movl $0x2, %edx
movq 0x15d7ad(%rip), %rdi    # 0x194fc0
leaq 0x116bd7(%rip), %rsi    # 0x14e3f1
callq 0x44e0
movq 0x15d79a(%rip), %rdi    # 0x194fc0
movl %r13d, %esi
callq 0x4750
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11dd96(%rip), %rsi    # 0x1555d6
callq 0x44e0
movq %rbp, %rdi
movl %r12d, %esi
callq 0x4750
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11dd74(%rip), %rsi    # 0x1555d6
callq 0x44e0
movq %rbp, %rdi
movl %ebx, %esi
callq 0x4750
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11bd9e(%rip), %rsi    # 0x15361e
callq 0x44e0
movq 0xc0(%rsp), %rax
leaq (,%rax,8), %rbp
movq (%rsp), %rdi
addq %rbp, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0xd0(%rsp)
movq (%rsp), %rdi
addq %rbp, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
addq (%rsp), %rbp
movq %rbp, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm2
leaq 0x38(%rsp), %rdi
movsd 0xd0(%rsp), %xmm0
movsd 0xc8(%rsp), %xmm1
callq 0x83f68
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ebx, %xmm2
movq 0xb8(%rsp), %rdi
leaq 0x38(%rsp), %rsi
callq 0x5395a
movl $0x7, %edx
leaq 0x118(%rsp), %rdi
leaq 0x119c64(%rip), %rsi    # 0x1515a0
callq 0x44e0
leaq (,%r15,8), %rbx
movq (%rsp), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
leaq 0x118(%rsp), %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11dc5c(%rip), %rsi    # 0x1555d6
callq 0x44e0
movq (%rsp), %rdi
addq %rbx, %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11dc28(%rip), %rsi    # 0x1555d6
callq 0x44e0
addq (%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0x119bb6(%rip), %rsi    # 0x151598
callq 0x44e0
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x11ca24(%rip), %rsi    # 0x15441a
callq 0x44e0
leaq 0x38(%rsp), %rdi
xorl %esi, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11dbb1(%rip), %rsi    # 0x1555d6
callq 0x44e0
leaq 0x38(%rsp), %rdi
movl $0x1, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11db7f(%rip), %rsi    # 0x1555d6
callq 0x44e0
leaq 0x38(%rsp), %rdi
movl $0x2, %esi
callq 0x83f9a
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x119b1f(%rip), %rsi    # 0x1515a8
callq 0x44e0
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x11bb81(%rip), %rsi    # 0x15361e
callq 0x44e0
movq 0x50(%rsp), %rbp
movq %r14, %rdi
callq 0x44f0
movq %rax, %r14
movq (%rbp,%r15,8), %rax
movq 0x18(%rsp), %rcx
addq %rax, %rcx
addq $0x8, %rcx
cmpq %rcx, %r14
jne 0x377e9
movq 0x78(%rsp), %rsi
incl %esi
movq 0x8(%rbp,%r15,8), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rsi, %rcx
ja 0x37755
movq 0x70(%rsp), %rbx
incl %ebx
movq 0x58(%rsp), %rax
subq %rbp, %rax
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %rbx, %rax
ja 0x37712
leaq 0x11c857(%rip), %rsi    # 0x15437e
movl $0x1, %edx
leaq 0x118(%rsp), %rbx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11badb(%rip), %rsi    # 0x15361e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x108(%rsp), %rdi
callq 0x4090
leaq 0x50(%rsp), %rdi
callq 0x38940
leaq 0xd8(%rsp), %rdi
callq 0x390be
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x37b91
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x37ba7
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x20(%rsp), %rdi
callq 0x38988
leaq 0x108(%rsp), %rdi
callq 0x4110
addq $0x318, %rsp            # imm = 0x318
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x388f8
jmp 0x37c17
movq %rax, %rbx
jmp 0x37c17
jmp 0x37bf7
movq %rax, %rbx
jmp 0x37c57
movq %rax, %rbx
jmp 0x37c61
jmp 0x37c0a
movq %rax, %rbx
jmp 0x37c24
movq %rax, %rbx
jmp 0x37c41
jmp 0x37c0a
jmp 0x37c0a
jmp 0x37c0a
jmp 0x37c0a
jmp 0x37c0a
jmp 0x37c0a
jmp 0x37c0a
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0x38940
leaq 0xd8(%rsp), %rdi
callq 0x390be
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x37c41
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x37c57
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x20(%rsp), %rdi
callq 0x38988
leaq 0x108(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780