// File: /workspace/github_cpp_makefile_star2_O1/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, 0x108(%rsp)
movl %edx, 0x110(%rsp)
movq 0x8(%rdi), %rsi
subq (%rdi), %rsi
sarq $0x3, %rsi
movabsq $-0x71c71c71c71c71c7, %rbx # imm = 0x8E38E38E38E38E39
imulq %rbx, %rsi
leaq 0x120(%rsp), %r14
movb $0x0, (%r14)
leaq 0x40(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
movq %r14, %rdx
callq 0x383b0
movq 0x8(%r15), %rsi
movq %r15, 0x68(%rsp)
subq (%r15), %rsi
sarq $0x3, %rsi
imulq %rbx, %rsi
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%r14)
leaq 0xa0(%rsp), %rdi
leaq 0x120(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
callq 0x3871a
movq 0x50(%rsp), %rax
subq 0x40(%rsp), %rax
movl 0x58(%rsp), %ecx
shlq $0x3, %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
addq %rcx, %rax
je 0x355dd
movabsq $-0x8000000000000000, %r13 # imm = 0x8000000000000000
leaq 0xe0(%rsp), %r14
movsd %xmm0, 0x38(%rsp)
leaq 0x190(%rsp), %rbx
leaq 0xb8(%rsp), %rbp
movq $0x0, 0x30(%rsp)
movl $0x0, 0x2c(%rsp)
leaq 0x114(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x509d8
movl $0x0, 0xe0(%rsp)
xorl %eax, %eax
movq %rax, 0xe8(%rsp)
movq %r14, 0xf0(%rsp)
movq %r14, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
movq %rbp, %rdi
leaq -0x153(%rip), %rsi      # 0x35049
callq 0x3879c
movq 0x68(%rsp), %rax
movq (%rax), %rax
movq 0x30(%rsp), %rcx
leaq (%rcx,%rcx,8), %rcx
movl 0x11c(%rsp), %edx
movl %edx, 0x128(%rsp)
movq 0x114(%rsp), %rdx
movq %rdx, 0x120(%rsp)
movsd 0x38(%rax,%rcx,8), %xmm0
movl 0x2c(%rsp), %eax
movl %eax, 0x1a8(%rsp)
movq 0x120(%rsp), %rax
leaq 0x1b0(%rsp), %rcx
movq %rax, (%rcx)
movl 0x128(%rsp), %eax
movl %eax, 0x8(%rcx)
movl 0x12c(%rsp), %eax
movl %eax, 0xc(%rcx)
movsd %xmm0, 0x1c0(%rsp)
movupd 0x1a8(%rsp), %xmm0
movups 0x1b8(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x387de
movq 0xc0(%rsp), %rax
subq 0xb8(%rsp), %rax
shrq $0x5, %rax
testl %eax, %eax
je 0x35566
leaq 0x80(%rsp), %rdi
movq %rbp, %rsi
callq 0x38914
movq 0xe8(%rsp), %rcx
movq %r14, %rax
testq %rcx, %rcx
je 0x35291
movl 0x80(%rsp), %edx
movq %r14, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x3527a
movq %r14, %r12
cmpq %r14, %rax
je 0x352aa
movl 0x80(%rsp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r14, %rax
movq %rax, %r12
movb $0x1, %r15b
movsd 0x38(%rsp), %xmm0
ucomisd 0x98(%rsp), %xmm0
ja 0x3555d
cmpl $-0x1, 0x80(%rsp)
je 0x35325
cmpq %r14, %r12
je 0x35345
leaq 0x28(%r12), %rdi
movq 0x88(%rsp), %rsi
movl 0x90(%rsp), %edx
callq 0x509e2
testb %al, %al
jne 0x3555a
movsd 0x38(%r12), %xmm0
minsd 0x98(%rsp), %xmm0
movq 0xa0(%rsp), %rax
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
maxsd 0x38(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
jmp 0x3555d
movq 0xa0(%rsp), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq 0x30(%rsp), %rdx
movq %rcx, (%rax,%rdx,8)
jmp 0x3555d
leaq 0xd8(%rsp), %rdi
leaq 0x80(%rsp), %rsi
callq 0x3b58c
movq %r14, %rbp
movq %r13, %r14
movq %rbx, %r13
movslq 0x80(%rsp), %rax
movq 0x68(%rsp), %rcx
movq (%rcx), %r15
leaq (%rax,%rax,8), %r12
leaq 0x20(%r15,%r12,8), %rsi
movupd -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movapd %xmm0, 0x120(%rsp)
movaps %xmm1, 0x130(%rsp)
leaq 0x140(%rsp), %rbx
movq %rbx, %rdi
callq 0x38318
leaq (%r15,%r12,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%rbx)
movq 0x38(%rax), %rax
movq %rax, 0x18(%rbx)
movq 0x140(%rsp), %r12
cmpq 0x148(%rsp), %r12
movq %r13, %rbx
movq %r14, %r13
movq %rbp, %r14
leaq 0xb8(%rsp), %rbp
je 0x3553d
addq $0x18, %r12
movslq -0x14(%r12), %r15
leaq 0x3f(%r15), %rax
testq %r15, %r15
cmovnsq %r15, %rax
sarq $0x6, %rax
shlq $0x3, %rax
addq 0x40(%rsp), %rax
leaq 0x3f(%r13), %rcx
andq %r15, %rcx
xorl %edx, %edx
cmpq %r13, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %r15, %rax
jae 0x35493
leaq 0x70(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x509d8
movq 0xa0(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
minsd 0x98(%rsp), %xmm0
movl 0x78(%rsp), %eax
minsd -0x8(%r12), %xmm0
movl %eax, 0x8(%rbx)
movq 0x70(%rsp), %rax
movq %rax, (%rbx)
movl $0xffffffff, 0x188(%rsp) # imm = 0xFFFFFFFF
movsd %xmm0, 0x1a0(%rsp)
movupd 0x188(%rsp), %xmm0
movups 0x198(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x387de
jmp 0x35523
movq %r12, %rdi
leaq 0x108(%rsp), %rsi
callq 0x50a14
movq %rax, 0x70(%rsp)
movl %edx, 0x78(%rsp)
leaq 0x88(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x50a30
movq 0x68(%rsp), %rcx
movq (%rcx), %rcx
leaq (%r15,%r15,8), %rsi
movsd -0x8(%r12), %xmm0
minsd 0x98(%rsp), %xmm0
minsd 0x38(%rcx,%rsi,8), %xmm0
movl %r15d, 0x168(%rsp)
movq %rax, 0x170(%rsp)
movl %edx, 0x178(%rsp)
movsd %xmm0, 0x180(%rsp)
movupd 0x168(%rsp), %xmm0
movups 0x178(%rsp), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x387de
leaq 0x28(%r12), %rax
addq $0x10, %r12
cmpq 0x148(%rsp), %r12
movq %rax, %r12
jne 0x353e3
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x3555a
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %r15d, %r15d
testb %r15b, %r15b
je 0x35234
movq 0x40(%rsp), %rax
movq 0x30(%rsp), %rcx
movq %rcx, %rdx
movl $0x1, %esi
shlq %cl, %rsi
shrq $0x6, %rdx
orq %rsi, (%rax,%rdx,8)
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x355a0
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movl 0x2c(%rsp), %r15d
incl %r15d
leaq 0xd8(%rsp), %rdi
callq 0x393e0
movl %r15d, 0x2c(%rsp)
movl %r15d, %edx
movq 0x50(%rsp), %rax
movl 0x58(%rsp), %ecx
subq 0x40(%rsp), %rax
leaq (%rcx,%rax,8), %rax
movq %rdx, 0x30(%rsp)
cmpq %rdx, %rax
ja 0x35152
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x355fa
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3562a
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movl %eax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movq %rax, 0x60(%rsp)
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 0x356c2
movq %rax, %rbx
jmp 0x356a5
jmp 0x35654
jmp 0x35654
jmp 0x35654
jmp 0x3565b
movq %rax, %rbx
jmp 0x3567b
jmp 0x3565b
movq %rax, %rbx
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x3567b
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xb8(%rsp), %rdi
testq %rdi, %rdi
je 0x35698
movq 0xc8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xd8(%rsp), %rdi
callq 0x393e0
movq 0xa0(%rsp), %rdi
testq %rdi, %rdi
je 0x356c2
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x356f2
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movl %eax, 0x48(%rsp)
movq %rax, 0x50(%rsp)
movl %eax, 0x58(%rsp)
movq %rax, 0x60(%rsp)
movq %rbx, %rdi
callq 0x4780