// File: /workspace/github_cpp_makefile_star2_O2/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, 0x8(%rsp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r12
leaq 0x118(%rsp), %r15
movq %r15, %rdi
callq 0x4540
leaq 0xd6e40(%rip), %rsi     # 0x100500
pushq $0x10
popq %rdx
movq %r15, %rdi
callq 0x4410
xorpd %xmm0, %xmm0
leaq 0x70(%rsp), %r9
movapd %xmm0, (%r9)
andq $0x0, 0x10(%r9)
pushq $0x1
popq %rcx
leaq 0x118(%rsp), %r8
movq %r12, 0xb8(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
movsd 0x8(%rsp), %xmm0
callq 0x28b75
leaq 0x50(%rsp), %r15
andq $0x0, 0x10(%r15)
xorpd %xmm0, %xmm0
movapd %xmm0, (%r15)
xorl %r13d, %r13d
leaq 0xe8(%rsp), %r12
movl %r13d, %r13d
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rax
subq %rsi, %rax
sarq $0x7, %rax
cmpq %r13, %rax
jbe 0x2975e
movq %r13, %rax
shlq $0x7, %rax
addq %rax, %rsi
movq %r12, %rdi
callq 0x28a1a
movq %r15, %rdi
movq %r12, %rsi
callq 0xee82
incl %r13d
jmp 0x29723
movq 0x50(%r14), %rsi
subq 0x48(%r14), %rsi
sarq $0x6, %rsi
leaq 0xe8(%rsp), %rdx
orl $-0x1, (%rdx)
leaq 0xd0(%rsp), %rdi
leaq 0x38(%rsp), %rcx
callq 0x2a44a
xorl %ebp, %ebp
leaq 0xe8(%rsp), %r14
movl %ebp, %eax
movq 0x70(%rsp), %rcx
movq 0x78(%rsp), %r15
subq %rcx, %r15
sarq $0x7, %r15
cmpq %rax, %r15
jbe 0x297fc
shlq $0x7, %rax
leaq (%rcx,%rax), %rsi
addq $0x30, %rsi
movq %r14, %rdi
callq 0xa6ce
movq 0xe8(%rsp), %rax
movq 0xf0(%rsp), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
xorl %esi, %esi
movq 0xd0(%rsp), %rdx
movl %esi, %esi
cmpq %rsi, %rcx
jbe 0x297f0
movslq (%rax,%rsi,4), %rdi
movl %ebp, (%rdx,%rdi,4)
incl %esi
jmp 0x297de
movq %r14, %rdi
callq 0xb290
incl %ebp
jmp 0x29791
leaq 0x13c60(%rip), %rax     # 0x3d463
leaq 0xf0(%rsp), %rcx
movq %rax, -0x8(%rcx)
andl $0x0, (%rcx)
andq $0x0, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
andq $0x0, 0x20(%rcx)
leaq 0x20(%rsp), %rdi
leaq 0xe8(%rsp), %rdx
leaq 0xa8(%rsp), %rcx
movq %r15, %rsi
callq 0x2a4a0
leaq 0x38(%rsp), %rdi
leaq 0x20(%rsp), %rdx
leaq 0x98(%rsp), %rcx
movq %r15, %rsi
callq 0x2a4f6
leaq 0x20(%rsp), %rdi
callq 0x2a54c
movq (%rbx), %rcx
xorl %r15d, %r15d
movl %r15d, %r15d
movq 0x8(%rbx), %rax
subq %rcx, %rax
cqto
pushq $0x48
popq %rsi
idivq %rsi
cmpq %r15, %rax
jbe 0x299a6
movq 0xd0(%rsp), %rax
cmpl $-0x1, (%rax,%r15,4)
je 0x2999e
imulq $0x48, %r15, %r12
movq 0x20(%rcx,%r12), %rbp
addq $0x18, %rbp
leaq -0x18(%rbp), %rax
cmpq 0x28(%rcx,%r12), %rax
je 0x2999e
movslq (%rax), %rdx
movq 0xd0(%rsp), %rcx
movslq (%rcx,%rdx,4), %r13
cmpq $-0x1, %r13
je 0x29992
movslq 0x4(%rax), %rsi
movl (%rcx,%rsi,4), %eax
cmpl $-0x1, %eax
je 0x29992
cmpl %eax, %r13d
jne 0x29977
movq %r13, %r14
shlq $0x7, %r14
movq 0x70(%rsp), %rdi
addq %r14, %rdi
callq 0x28978
movq %rax, 0xa8(%rsp)
movl %edx, 0xb0(%rsp)
addq 0x70(%rsp), %r14
movq %r14, %rdi
movl %r15d, %esi
callq 0x28978
movq %rax, 0x98(%rsp)
movl %edx, 0xa0(%rsp)
leaq 0xa8(%rsp), %rdi
leaq 0x98(%rsp), %rsi
callq 0x3d398
movq %rax, 0x20(%rsp)
movl %edx, 0x28(%rsp)
movq (%rbp), %rsi
movl 0x8(%rbp), %edx
leaq 0x20(%rsp), %rdi
callq 0x3d332
testb %al, %al
jne 0x29992
movq 0x38(%rsp), %rax
imulq $0x18, %r13, %rcx
imulq $0x30, %r13, %rdi
addq (%rax,%rcx), %rdi
movq %rbp, %rsi
callq 0x2d714
jmp 0x29992
cltq
movq 0x38(%rsp), %rcx
imulq $0x18, %r13, %rdx
imulq $0x30, %rax, %rdi
addq (%rcx,%rdx), %rdi
movq %rbp, %rsi
callq 0x2d714
movq (%rbx), %rcx
addq $0x28, %rbp
jmp 0x298a6
incl %r15d
jmp 0x2986b
leaq 0x128(%rsp), %rdi
leaq 0xd6b58(%rip), %rsi     # 0x10050d
callq 0x4480
leaq 0xd8bbd(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0xd6b4e(%rip), %rsi     # 0x10051e
movq %rax, %rdi
callq 0x4480
leaq 0xd8b9f(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
xorl %esi, %esi
movq 0x38(%rsp), %r14
movl %esi, %esi
movq 0x40(%rsp), %rax
subq %r14, %rax
cqto
pushq $0x18
popq %rcx
idivq %rcx
cmpq %rsi, %rax
jbe 0x29d6d
movq 0x1265b0(%rip), %rdi    # 0x14ffc0
movq %rsi, 0x10(%rsp)
callq 0x42e0
movq %rax, %rdi
leaq 0xd8b5a(%rip), %rsi     # 0x10257e
callq 0x4480
xorl %ebx, %ebx
movq 0x38(%rsp), %r14
imulq $0x18, 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movl %ebx, %ebx
movq 0x8(%rsp), %rax
movq (%r14,%rax), %rcx
movq 0x8(%r14,%rax), %rax
subq %rcx, %rax
cqto
pushq $0x30
popq %rsi
idivq %rsi
cmpq %rbx, %rax
jbe 0x29d61
imulq $0x30, %rbx, %rax
movq %rax, 0x90(%rsp)
cmpq $0x0, 0x28(%rcx,%rax)
je 0x29d5a
movq 0x126542(%rip), %rdi    # 0x14ffc0
leaq 0xd6aa6(%rip), %rsi     # 0x10052b
callq 0x4480
movq %rax, %rdi
movq %rbx, %rsi
callq 0x42e0
movq %rax, %rdi
leaq 0xd8adf(%rip), %rsi     # 0x10257e
callq 0x4480
movq %rbx, 0x18(%rsp)
movq 0x38(%rsp), %r14
movq 0x8(%rsp), %rax
movq (%r14,%rax), %r13
movq 0x90(%rsp), %rax
movq 0x18(%r13,%rax), %rbp
movq 0x90(%rsp), %rax
addq %r13, %rax
addq $0x8, %rax
cmpq %rax, %rbp
je 0x29d55
movl 0x20(%rbp), %r12d
movl 0x24(%rbp), %r15d
movl 0x28(%rbp), %ebx
movq 0x18(%rsp), %rax
cmpl %eax, 0x10(%rsp)
jne 0x29b04
testl %r12d, %r12d
jne 0x29b04
testl %r15d, %r15d
jne 0x29b04
testl %ebx, %ebx
je 0x29d45
movq 0x1264b5(%rip), %rdi    # 0x14ffc0
leaq 0xd38df(%rip), %rsi     # 0xfd3f1
callq 0x4480
movq %rax, %rdi
movl %r12d, %esi
callq 0x4760
movq %rax, %rdi
leaq 0xda9e6(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rdi
movl %r15d, %esi
callq 0x4760
movq %rax, %rdi
leaq 0xda9cc(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rdi
movl %ebx, %esi
callq 0x4760
movq %rax, %rdi
leaq 0xd8a1f(%rip), %rsi     # 0x10257e
callq 0x4480
imulq $0x18, 0x18(%rsp), %r14
movq 0x50(%rsp), %rdi
addq %r14, %rdi
xorl %esi, %esi
callq 0x63c78
movq 0xb8(%rsp), %r13
movsd (%rax), %xmm0
movsd %xmm0, 0xc8(%rsp)
movq 0x50(%rsp), %rdi
addq %r14, %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
addq 0x50(%rsp), %r14
movq %r14, %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm2
leaq 0x20(%rsp), %rdi
movsd 0xc8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm1
callq 0x63c46
cvtsi2sd %r12d, %xmm0
cvtsi2sd %r15d, %xmm1
cvtsi2sd %ebx, %xmm2
movq %r13, %rdi
leaq 0x20(%rsp), %rsi
callq 0x3f81c
leaq 0x128(%rsp), %rdi
leaq 0xd692b(%rip), %rsi     # 0x100530
callq 0x4480
movq %rax, %rbx
movq 0x50(%rsp), %rdi
addq 0x8(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xda8de(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rbx
movq 0x50(%rsp), %rdi
addq 0x8(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xda8ae(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rbx
movq 0x50(%rsp), %rdi
addq 0x8(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xd6894(%rip), %rsi     # 0x100528
callq 0x4480
movq %rax, %rdi
leaq 0xd96d7(%rip), %rsi     # 0x10337a
callq 0x4480
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xda845(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
pushq $0x1
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xda81a(%rip), %rsi     # 0x104512
callq 0x4480
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
pushq $0x2
popq %rsi
callq 0x63c78
movsd (%rax), %xmm0
movq %rbx, %rdi
callq 0x46c0
movq %rax, %rdi
leaq 0xd6815(%rip), %rsi     # 0x100538
callq 0x4480
movq %rax, %rdi
leaq 0xd884c(%rip), %rsi     # 0x10257e
callq 0x4480
movq 0x38(%rsp), %r14
movq 0x8(%rsp), %rax
movq (%r14,%rax), %r13
movq %rbp, %rdi
callq 0x4510
movq %rax, %rbp
jmp 0x29ac4
movq 0x18(%rsp), %rbx
incl %ebx
jmp 0x29a3b
movq 0x10(%rsp), %rsi
incl %esi
jmp 0x299ee
leaq 0xd956a(%rip), %rsi     # 0x1032de
leaq 0x128(%rsp), %rdi
callq 0x4480
leaq 0xd87f6(%rip), %rsi     # 0x10257e
movq %rax, %rdi
callq 0x4480
leaq 0x118(%rsp), %rdi
callq 0x4080
leaq 0x38(%rsp), %rdi
callq 0x2a56e
leaq 0xe8(%rsp), %rdi
callq 0x2abfe
leaq 0xd0(%rsp), %rdi
callq 0xb290
leaq 0x50(%rsp), %rdi
callq 0xb83e
leaq 0x70(%rsp), %rdi
callq 0x2a590
leaq 0x118(%rsp), %rdi
callq 0x4120
addq $0x328, %rsp            # imm = 0x328
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x20(%rsp), %rdi
callq 0x2a54c
jmp 0x29e3b
movq %rax, %rbx
jmp 0x29e3b
jmp 0x29e1d
movq %rax, %rbx
jmp 0x29e5f
movq %rax, %rbx
jmp 0x29e69
jmp 0x29e2e
movq %rax, %rbx
jmp 0x29e48
jmp 0x29e2e
movq %rax, %rbx
jmp 0x29e55
jmp 0x29e2e
jmp 0x29e2e
jmp 0x29e2e
jmp 0x29e2e
jmp 0x29e2e
jmp 0x29e2e
movq %rax, %rbx
leaq 0x38(%rsp), %rdi
callq 0x2a56e
leaq 0xe8(%rsp), %rdi
callq 0x2abfe
leaq 0xd0(%rsp), %rdi
callq 0xb290
leaq 0x50(%rsp), %rdi
callq 0xb83e
leaq 0x70(%rsp), %rdi
callq 0x2a590
leaq 0x118(%rsp), %rdi
callq 0x4120
movq %rbx, %rdi
callq 0x4780