// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkanalysis.cc
// Function: calculateNodalFreeSphere(DIJKSTRA_NETWORK*, DELTA_POS)
double calculateNodalFreeSphere(DIJKSTRA_NETWORK *dnet, DELTA_POS filter){
  vector<bool> nodeProcessed = vector<bool>(dnet->nodes.size(), false);
  vector<double> bestRadii   = vector<double>(dnet->nodes.size(), -1);
  unsigned int nodeIndex = 0;

  double maxRadius = 0.0;

  // Iterate over all nodes
  while(nodeIndex < nodeProcessed.size()){
   
    // Place starting node on stack with (0,0,0) displacement
    DELTA_POS displacement = DELTA_POS(0,0,0);
    map<int, pair<DELTA_POS, double> > visitedNodes;
    
    HEAP<pair<int, pair<DELTA_POS, double> > > heap (betterPath);
    heap.insert(pair<int, pair<DELTA_POS, double> > (nodeIndex, pair<DELTA_POS, double> (displacement, dnet->nodes[nodeIndex].max_radius)));
  
    while(heap.size() != 0){
      // Remove best remaining path
      pair<int, pair<DELTA_POS, double> > pathInfo = heap.pop();
      map<int, pair<DELTA_POS, double> >::iterator nodeInfo = visitedNodes.find(pathInfo.first);
      
      if(pathInfo.second.second < maxRadius)
	break;

      // Ending on a preprocessed node
      if(pathInfo.first == -1){
	bestRadii[nodeIndex] = pathInfo.first;
	break;
      }

      if(nodeInfo != visitedNodes.end()){
	if(nodeInfo->second.first.equals(pathInfo.second.first)){
	  // Circling back to previous node so terminate path
	  continue;
	}
	else {
	  // Found the optimal path through the start node
	  bestRadii[nodeIndex] = min(pathInfo.second.second, nodeInfo->second.second);
	  maxRadius = max(maxRadius, bestRadii[nodeIndex]);
	  break;
	}
      }
      else{
	visitedNodes.insert(pathInfo);
	DIJKSTRA_NODE currentNode = dnet->nodes[pathInfo.first];
	vector<CONN>::iterator connIter = currentNode.connections.begin();
	// Follow all edges leading to adjoining nodes
      
	while(connIter != currentNode.connections.end()){
	  int to = connIter->to;
	  if(nodeProcessed[to]){
	    // Know the best radii for this path because the next node has already been processed
	    // Change its node id to -1 to denote this
	    heap.insert(pair<int, pair<DELTA_POS, double> > (
	      -1, pair<DELTA_POS, double> (DELTA_POS(0,0,0), min(
	      connIter->max_radius, min(pathInfo.second.second, bestRadii[to])))));
	  }
	  else{
	    DELTA_POS newDisplacement = pathInfo.second.first + (
	      connIter->deltaPos*filter);
	    heap.insert(pair<int, pair<DELTA_POS, double> > (
	      to, pair<DELTA_POS, double> (newDisplacement, min(
	      dnet->nodes[to].max_radius, min(pathInfo.second.second,
	      connIter->max_radius)))));
	  }
	  connIter++;
	}
      }
    }
    nodeProcessed[nodeIndex] = true;
    nodeIndex++;
  }
  return maxRadius;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1c8, %rsp            # imm = 0x1C8
movq %rdi, %r15
movq %rsi, 0xc0(%rsp)
movl %edx, 0xc8(%rsp)
movq 0x8(%rdi), %rax
subq (%rdi), %rax
pushq $0x48
popq %rbx
cqto
idivq %rbx
leaq 0x120(%rsp), %r14
movb $0x0, (%r14)
leaq 0xf8(%rsp), %rdi
leaq 0x78(%rsp), %rcx
movq %rax, %rsi
movq %r14, %rdx
callq 0x2a0d6
movq 0x8(%r15), %rax
movq %r15, 0x40(%rsp)
subq (%r15), %rax
cqto
idivq %rbx
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq %rcx, (%r14)
leaq 0xa8(%rsp), %rdi
leaq 0x120(%rsp), %rdx
leaq 0x78(%rsp), %rcx
movq %rax, %rsi
callq 0x2a2b4
xorl %eax, %eax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
leaq 0x170(%rsp), %rbx
leaq 0x1a8(%rsp), %rbp
leaq 0xf8(%rsp), %r12
leaq 0x58(%rsp), %r15
leaq 0x48(%rsp), %r14
movl %eax, 0x2c(%rsp)
movl %eax, %edx
movq 0x108(%rsp), %rax
movl 0x110(%rsp), %ecx
subq 0xf8(%rsp), %rax
leaq (%rcx,%rax,8), %rax
movq %rdx, 0x30(%rsp)
cmpq %rdx, %rax
jbe 0x27d7b
leaq 0xcc(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
andl $0x0, 0x80(%rsp)
andq $0x0, 0x88(%rsp)
leaq 0x80(%rsp), %rax
movq %rax, 0x90(%rsp)
movq %rax, 0x98(%rsp)
andq $0x0, 0xa0(%rsp)
movq %rbp, %rdi
leaq -0x14d(%rip), %rsi      # 0x27923
callq 0x2a30a
movq 0x40(%rsp), %rax
movq (%rax), %rax
imulq $0x48, 0x30(%rsp), %rcx
movl 0xd4(%rsp), %edx
movl %edx, 0x128(%rsp)
movq 0xcc(%rsp), %rdx
movq %rdx, 0x120(%rsp)
movsd 0x38(%rax,%rcx), %xmm0
movl 0x2c(%rsp), %eax
movl %eax, 0x188(%rsp)
movq 0x120(%rsp), %rax
leaq 0x190(%rsp), %rcx
movq %rax, (%rcx)
movl 0x128(%rsp), %eax
movl %eax, 0x8(%rcx)
movl 0x12c(%rsp), %eax
movl %eax, 0xc(%rcx)
movsd %xmm0, 0x1a0(%rsp)
movupd 0x188(%rsp), %xmm0
movups 0x198(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x2a340
movq 0x1b0(%rsp), %rax
subq 0x1a8(%rsp), %rax
shrq $0x5, %rax
testl %eax, %eax
je 0x27d44
movq %r15, %rdi
movq %rbp, %rsi
callq 0x2a360
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x2c1f6
movsd 0x38(%rsp), %xmm0
ucomisd 0x70(%rsp), %xmm0
ja 0x27d44
cmpl $-0x1, 0x58(%rsp)
je 0x27cfd
movq %rax, %r15
leaq 0x80(%rsp), %rax
cmpq %rax, %r15
je 0x27b85
leaq 0x28(%r15), %rdi
movq 0x60(%rsp), %rsi
movl 0x68(%rsp), %edx
callq 0x3d332
testb %al, %al
jne 0x27cf3
jmp 0x27d1a
leaq 0x78(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x2c248
movslq 0x58(%rsp), %rax
imulq $0x48, %rax, %rsi
movq 0x40(%rsp), %rax
addq (%rax), %rsi
leaq 0x120(%rsp), %rdi
callq 0x29ebe
movq 0x140(%rsp), %r15
addq $0x18, %r15
leaq -0x18(%r15), %rax
cmpq 0x148(%rsp), %rax
je 0x27ce6
movl 0x4(%rax), %eax
movslq %eax, %r13
movq %r12, %rdi
movq %r13, %rsi
callq 0x1043e
testq %rdx, (%rax)
je 0x27c56
movq %r14, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x3d328
movq 0xa8(%rsp), %rax
movsd (%rax,%r13,8), %xmm0
minsd 0x70(%rsp), %xmm0
minsd -0x8(%r15), %xmm0
movl 0x50(%rsp), %eax
movl %eax, 0x8(%rbx)
movq 0x48(%rsp), %rax
movq %rax, (%rbx)
orl $-0x1, 0x168(%rsp)
movsd %xmm0, 0x180(%rsp)
movupd 0x168(%rsp), %xmm0
movups 0x178(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x2a340
jmp 0x27cdd
movq %r15, %rdi
leaq 0xc0(%rsp), %rsi
callq 0x3d364
movq %rax, 0x48(%rsp)
movl %edx, 0x50(%rsp)
leaq 0x60(%rsp), %rdi
movq %r14, %rsi
callq 0x3d380
movq 0x40(%rsp), %rcx
movq (%rcx), %rcx
imulq $0x48, %r13, %rsi
movsd -0x8(%r15), %xmm0
minsd 0x70(%rsp), %xmm0
minsd 0x38(%rcx,%rsi), %xmm0
movl %r13d, 0xd8(%rsp)
movq %rax, 0xe0(%rsp)
movl %edx, 0xe8(%rsp)
movsd %xmm0, 0xf0(%rsp)
movupd 0xd8(%rsp), %xmm0
movups 0xe8(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x2a340
addq $0x28, %r15
jmp 0x27bbe
leaq 0x140(%rsp), %rdi
callq 0xaf14
leaq 0x58(%rsp), %r15
jmp 0x27b05
movq 0xa8(%rsp), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq 0x30(%rsp), %rdx
movq %rcx, (%rax,%rdx,8)
jmp 0x27d44
movsd 0x38(%r15), %xmm0
minsd 0x70(%rsp), %xmm0
movq 0xa8(%rsp), %rax
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
maxsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r12, %rdi
movq 0x30(%rsp), %rsi
callq 0x1043e
orq %rdx, (%rax)
movl 0x2c(%rsp), %r15d
incl %r15d
movq %rbp, %rdi
callq 0x2ab72
leaq 0x78(%rsp), %rdi
callq 0x2aba6
movl %r15d, %eax
leaq 0x58(%rsp), %r15
jmp 0x279f2
leaq 0xa8(%rsp), %rdi
callq 0xb25c
leaq 0xf8(%rsp), %rdi
callq 0xa976
movsd 0x38(%rsp), %xmm0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x27dfe
jmp 0x27dbf
movq %rax, %rbx
jmp 0x27df1
jmp 0x27dbf
jmp 0x27dbf
jmp 0x27dbf
movq %rax, %rbx
jmp 0x27dda
jmp 0x27dca
jmp 0x27dca
jmp 0x27dca
movq %rax, %rbx
leaq 0x140(%rsp), %rdi
callq 0xaf14
leaq 0x1a8(%rsp), %rdi
callq 0x2ab72
leaq 0x78(%rsp), %rdi
callq 0x2aba6
leaq 0xa8(%rsp), %rdi
callq 0xb25c
leaq 0xf8(%rsp), %rdi
callq 0xa976
movq %rbx, %rdi
callq 0x4780