// File: /workspace/github_cpp_makefile_star2_O1/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 $0x328, %rsp            # imm = 0x328
movsd %xmm0, 0x20(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x118(%rsp), %r15
movq %r15, %rdi
callq 0x4520
leaq 0x11bd58(%rip), %rsi    # 0x1534e0
movq %r15, %rdi
movl $0x10, %edx
callq 0x43d0
xorpd %xmm0, %xmm0
leaq 0x40(%rsp), %r9
movapd %xmm0, (%r9)
movq $0x0, 0x10(%r9)
leaq 0x118(%rsp), %r8
movq %r12, 0xc8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movsd 0x20(%rsp), %xmm0
movl $0x1, %ecx
callq 0x36831
xorpd %xmm0, %xmm0
movapd %xmm0, (%rsp)
movq $0x0, 0x10(%rsp)
movq 0x40(%rsp), %rax
cmpq %rax, 0x48(%rsp)
je 0x37878
movl $0x1, %ebp
xorl %ecx, %ecx
leaq 0xe8(%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 0x85436
movq 0x8(%rsp), %rsi
cmpq 0x10(%rsp), %rsi
je 0x37853
movq 0xf8(%rsp), %rax
movq %rax, 0x10(%rsi)
movupd 0xe8(%rsp), %xmm0
movupd %xmm0, (%rsi)
addq $0x18, 0x8(%rsp)
jmp 0x3785e
movq %r12, %rdi
movq %r15, %rdx
callq 0x12d92
movl %ebp, %ecx
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
incl %ebp
cmpq %rcx, %rdx
ja 0x37808
movq 0x50(%r14), %rsi
subq 0x48(%r14), %rsi
sarq $0x6, %rsi
leaq 0xe8(%rsp), %rdx
movl $0xffffffff, (%rdx)     # imm = 0xFFFFFFFF
leaq 0xb0(%rsp), %rdi
leaq 0x28(%rsp), %rcx
callq 0x38af6
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %r15
subq %rax, %r15
je 0x37940
xorl %ecx, %ecx
leaq 0xe8(%rsp), %r14
xorl %r12d, %r12d
shlq $0x7, %rcx
leaq (%rax,%rcx), %rsi
addq $0x30, %rsi
movq %r14, %rdi
callq 0xe886
movq 0xe8(%rsp), %rdi
movq 0xf0(%rsp), %rax
subq %rdi, %rax
je 0x3790d
sarq $0x2, %rax
movq 0xb0(%rsp), %rcx
xorl %edx, %edx
movslq (%rdi,%rdx,4), %rsi
movl %r12d, (%rcx,%rsi,4)
incq %rdx
movl %edx, %esi
cmpq %rsi, %rax
ja 0x378fb
testq %rdi, %rdi
je 0x37922
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incl %r12d
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %r15
subq %rax, %r15
sarq $0x7, %r15
movq %r12, %rcx
cmpq %r12, %r15
ja 0x378c4
jmp 0x37944
sarq $0x7, %r15
leaq 0x191ea(%rip), %rax     # 0x50b35
leaq 0xf0(%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 0x68(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
leaq 0xa0(%rsp), %rcx
movq %r15, %rsi
callq 0x38b74
leaq 0x28(%rsp), %rdi
leaq 0x68(%rsp), %rdx
leaq 0x90(%rsp), %rcx
movq %r15, %rsi
callq 0x38c0e
leaq 0x68(%rsp), %rdi
callq 0x38ca6
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x37b2b
xorl %r14d, %r14d
movq 0xb0(%rsp), %rcx
cmpl $-0x1, (%rcx,%r14,4)
je 0x37b03
leaq (,%r14,8), %rcx
leaq (%rcx,%rcx,8), %rcx
movq 0x20(%rax,%rcx), %rbp
movq (%rbx), %rax
cmpq 0x28(%rax,%rcx), %rbp
je 0x37b03
leaq (%r14,%r14,8), %r15
movslq (%rbp), %rcx
movq 0xb0(%rsp), %rax
movslq (%rax,%rcx,4), %r12
cmpq $-0x1, %r12
je 0x37af1
movslq 0x4(%rbp), %rcx
movl (%rax,%rcx,4), %eax
cmpl $-0x1, %eax
je 0x37af1
movslq %eax, %r13
cmpl %eax, %r12d
jne 0x37acc
movq %r13, %rdi
shlq $0x7, %rdi
addq 0x40(%rsp), %rdi
movl 0x4(%rbp), %esi
callq 0x365ba
movq %rax, 0xa0(%rsp)
movl %edx, 0xa8(%rsp)
movq %r12, %rdi
shlq $0x7, %rdi
addq 0x40(%rsp), %rdi
movl %r14d, %esi
callq 0x365ba
movq %rax, 0x90(%rsp)
movl %edx, 0x98(%rsp)
leaq 0xa0(%rsp), %rdi
leaq 0x90(%rsp), %rsi
callq 0x50a48
movq %rax, 0x68(%rsp)
movl %edx, 0x70(%rsp)
movq 0x18(%rbp), %rsi
movl 0x20(%rbp), %edx
leaq 0x68(%rsp), %rdi
callq 0x509e2
testb %al, %al
jne 0x37af1
leaq 0x18(%rbp), %rsi
movq 0x28(%rsp), %rax
leaq (%r12,%r12,2), %rcx
leaq (,%r13,2), %rdi
addq %r13, %rdi
shlq $0x4, %rdi
addq (%rax,%rcx,8), %rdi
callq 0x3c878
jmp 0x37af1
movq 0x28(%rsp), %rax
leaq (%r12,%r12,2), %rcx
leaq (,%r13,2), %rdi
addq %r13, %rdi
shlq $0x4, %rdi
addq (%rax,%rcx,8), %rdi
leaq 0x18(%rbp), %rsi
callq 0x3c878
addq $0x28, %rbp
movq (%rbx), %rax
cmpq 0x28(%rax,%r15,8), %rbp
jne 0x379f6
incl %r14d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $-0x71c71c71c71c71c7, %rdx # imm = 0x8E38E38E38E38E39
imulq %rdx, %rcx
cmpq %r14, %rcx
ja 0x379c0
leaq 0x128(%rsp), %rbx
leaq 0x11b9b3(%rip), %rsi    # 0x1534ed
movl $0x10, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11d9e0(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11b99c(%rip), %rsi    # 0x1534fe
movl $0xc, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11d9b8(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
movq 0x30(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x37fb9
xorl %ebx, %ebx
movq 0x15f424(%rip), %rdi    # 0x196fc0
movq %rbx, %rsi
callq 0x42b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11d97b(%rip), %rsi    # 0x15552e
callq 0x44e0
movq 0x28(%rsp), %rcx
movq %rbx, 0x88(%rsp)
leaq (%rbx,%rbx,2), %r15
movq (%rcx,%r15,8), %rax
cmpq %rax, 0x8(%rcx,%r15,8)
je 0x37f8a
xorl %esi, %esi
movq %rsi, 0x60(%rsp)
leaq (%rsi,%rsi,2), %rdx
movq %rdx, 0xd0(%rsp)
shlq $0x4, %rdx
movq %rdx, 0x20(%rsp)
cmpq $0x0, 0x28(%rax,%rdx)
je 0x37f57
movl $0x4, %edx
movq 0x15f3b4(%rip), %rdi    # 0x196fc0
leaq 0x11b8f8(%rip), %rsi    # 0x15350b
callq 0x44e0
movq 0x60(%rsp), %rsi
movq 0x15f39c(%rip), %rdi    # 0x196fc0
callq 0x42b0
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11d8f6(%rip), %rsi    # 0x15552e
callq 0x44e0
movq 0x28(%rsp), %rax
movq (%rax,%r15,8), %rax
movq 0x20(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
movq 0x10(%rax), %r14
cmpq %rax, %r14
je 0x37f57
movq 0x88(%rsp), %rax
xorl 0x60(%rsp), %eax
movl %eax, 0x84(%rsp)
movl 0x20(%r14), %r13d
movl 0x24(%r14), %r12d
movl 0x28(%r14), %ebx
movl 0x84(%rsp), %eax
orl %r13d, %eax
orl %r12d, %eax
orl %ebx, %eax
je 0x37f2e
movl $0x2, %edx
movq 0x15f321(%rip), %rdi    # 0x196fc0
leaq 0x1186db(%rip), %rsi    # 0x150381
callq 0x44e0
movq 0x15f30e(%rip), %rdi    # 0x196fc0
movl %r13d, %esi
callq 0x4750
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f7ba(%rip), %rsi    # 0x157486
callq 0x44e0
movq %rbp, %rdi
movl %r12d, %esi
callq 0x4750
movq %rax, %rbp
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f798(%rip), %rsi    # 0x157486
callq 0x44e0
movq %rbp, %rdi
movl %ebx, %esi
callq 0x4750
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11d822(%rip), %rsi    # 0x15552e
callq 0x44e0
movq 0xd0(%rsp), %rax
leaq (,%rax,8), %rbp
movq (%rsp), %rdi
addq %rbp, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
movq (%rsp), %rdi
addq %rbp, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movsd %xmm0, 0xd8(%rsp)
addq (%rsp), %rbp
movq %rbp, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm2
leaq 0x68(%rsp), %rdi
movsd 0xe0(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
callq 0x85436
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
xorps %xmm2, %xmm2
cvtsi2sd %ebx, %xmm2
movq 0xc8(%rsp), %rdi
leaq 0x68(%rsp), %rsi
callq 0x53c58
movl $0x7, %edx
leaq 0x128(%rsp), %rdi
leaq 0x11b748(%rip), %rsi    # 0x153510
callq 0x44e0
leaq (,%r15,8), %rbx
movq (%rsp), %rdi
addq %rbx, %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
leaq 0x128(%rsp), %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f680(%rip), %rsi    # 0x157486
callq 0x44e0
movq (%rsp), %rdi
addq %rbx, %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f64c(%rip), %rsi    # 0x157486
callq 0x44e0
addq (%rsp), %rbx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x2, %edx
movq %rax, %rdi
leaq 0x11b69a(%rip), %rsi    # 0x153508
callq 0x44e0
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x11e4a8(%rip), %rsi    # 0x15632a
callq 0x44e0
leaq 0x68(%rsp), %rdi
xorl %esi, %esi
callq 0x85478
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f5d5(%rip), %rsi    # 0x157486
callq 0x44e0
leaq 0x68(%rsp), %rdi
movl $0x1, %esi
callq 0x85478
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x1, %edx
movq %rax, %rdi
leaq 0x11f5a3(%rip), %rsi    # 0x157486
callq 0x44e0
leaq 0x68(%rsp), %rdi
movl $0x2, %esi
callq 0x85478
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46b0
movq %rax, %rbx
movl $0x3, %edx
movq %rax, %rdi
leaq 0x11b603(%rip), %rsi    # 0x153518
callq 0x44e0
movl $0x1, %edx
movq %rbx, %rdi
leaq 0x11d605(%rip), %rsi    # 0x15552e
callq 0x44e0
movq %r14, %rdi
callq 0x44f0
movq %rax, %r14
movq 0x28(%rsp), %rax
movq (%rax,%r15,8), %rax
movq 0x20(%rsp), %rcx
addq %rcx, %rax
addq $0x8, %rax
cmpq %rax, %r14
jne 0x37c72
movq 0x60(%rsp), %rsi
incl %esi
movq 0x28(%rsp), %rcx
movq (%rcx,%r15,8), %rax
movq 0x8(%rcx,%r15,8), %rcx
subq %rax, %rcx
sarq $0x4, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
cmpq %rsi, %rcx
ja 0x37bda
movq 0x30(%rsp), %rax
subq 0x28(%rsp), %rax
movq 0x88(%rsp), %rbx
incl %ebx
sarq $0x3, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rcx, %rax
cmpq %rbx, %rax
ja 0x37b95
leaq 0x11e2ce(%rip), %rsi    # 0x15628e
movl $0x1, %edx
leaq 0x128(%rsp), %rbx
movq %rbx, %rdi
callq 0x44e0
leaq 0x11d552(%rip), %rsi    # 0x15552e
movl $0x1, %edx
movq %rbx, %rdi
callq 0x44e0
leaq 0x118(%rsp), %rdi
callq 0x4090
leaq 0x28(%rsp), %rdi
callq 0x38ce8
leaq 0xe8(%rsp), %rdi
callq 0x39430
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x3802a
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x38040
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x40(%rsp), %rdi
callq 0x38d2a
leaq 0x118(%rsp), %rdi
callq 0x4110
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x38ca6
jmp 0x380b0
movq %rax, %rbx
jmp 0x380b0
jmp 0x38090
movq %rax, %rbx
jmp 0x380f0
movq %rax, %rbx
jmp 0x380fa
jmp 0x380a3
movq %rax, %rbx
jmp 0x380bd
movq %rax, %rbx
jmp 0x380da
jmp 0x380a3
jmp 0x380a3
jmp 0x380a3
jmp 0x380a3
jmp 0x380a3
jmp 0x380a3
jmp 0x380a3
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x38ce8
leaq 0xe8(%rsp), %rdi
callq 0x39430
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x380da
movq 0xc0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq (%rsp), %rdi
testq %rdi, %rdi
je 0x380f0
movq 0x10(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0x40(%rsp), %rdi
callq 0x38d2a
leaq 0x118(%rsp), %rdi
callq 0x4110
movq %rbx, %rdi
callq 0x4780
nop