// File: /workspace/github_cpp_makefile_star2_O3/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 0xb0(%rsp), %rdi
leaq 0xd8(%rsp), %rcx
movq %r14, %rdx
callq 0x37f36
movq 0x8(%r15), %rsi
movq %r15, 0x38(%rsp)
subq (%r15), %rsi
sarq $0x3, %rsi
imulq %rbx, %rsi
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, (%r14)
leaq 0x98(%rsp), %rdi
leaq 0x120(%rsp), %rdx
leaq 0xd8(%rsp), %rcx
callq 0x38220
movq 0xb0(%rsp), %rdi
movq 0xc0(%rsp), %rax
movl 0xc8(%rsp), %ecx
subq %rdi, %rax
shlq $0x3, %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x28(%rsp)
addq %rcx, %rax
je 0x351d2
movabsq $-0x8000000000000000, %rbp # imm = 0x8000000000000000
movabsq $0x1fffffffe0, %r14     # imm = 0x1FFFFFFFE0
leaq 0xe0(%rsp), %r15
movsd %xmm0, 0x28(%rsp)
leaq 0x190(%rsp), %r12
leaq 0x50(%rsp), %r13
movq $0x0, 0x20(%rsp)
xorl %ebx, %ebx
leaq 0x114(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movl $0x0, 0xe0(%rsp)
xorl %eax, %eax
movq %rax, 0xe8(%rsp)
movq %r15, 0xf0(%rsp)
movq %r15, 0xf8(%rsp)
movq %rax, 0x100(%rsp)
leaq -0x160(%rip), %rcx      # 0x34bf7
movq %rcx, 0x68(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
movq %rax, 0x60(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq 0x20(%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 %ebx, 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 %r13, %rdi
callq 0x38342
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
subq %rdi, %rax
testq %r14, %rax
je 0x35163
movl %ebx, 0x34(%rsp)
leaq 0x78(%rsp), %rdi
movq %r13, %rsi
callq 0x38468
movq 0xe8(%rsp), %r8
movq %r15, %rbx
testq %r8, %r8
je 0x34e77
movq %r15, %r9
movl 0x78(%rsp), %eax
movq %r15, %rsi
movq %rsi, %rcx
movq %r8, %rdx
movl 0x20(%r8), %edi
xorl %r8d, %r8d
cmpl %eax, %edi
setl %r8b
movq %rdx, %rsi
cmovlq %rcx, %rsi
movq 0x10(%rdx,%r8,8), %r8
testq %r8, %r8
jne 0x34e3b
movq %r9, %rbx
cmpq %r9, %rsi
je 0x34e77
cmpl %eax, %edi
cmovlq %rcx, %rdx
cmpl 0x20(%rdx), %eax
cmovlq %r9, %rsi
movq %rsi, %rbx
movsd 0x28(%rsp), %xmm0
ucomisd 0x90(%rsp), %xmm0
ja 0x35152
cmpl $-0x1, 0x78(%rsp)
je 0x35109
leaq 0xe0(%rsp), %rax
cmpq %rax, %rbx
je 0x34ec9
leaq 0x28(%rbx), %rdi
movq 0x80(%rsp), %rsi
movl 0x88(%rsp), %edx
callq 0x506ba
testb %al, %al
jne 0x350e9
jmp 0x35126
leaq 0xd8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x3b1ba
movq %rbp, %r15
movq %r12, %rbp
movq %r13, %r12
movslq 0x78(%rsp), %rax
movq 0x38(%rsp), %rcx
movq (%rcx), %rbx
leaq (%rax,%rax,8), %r14
leaq 0x20(%rbx,%r14,8), %rsi
movupd -0x20(%rsi), %xmm0
movups -0x10(%rsi), %xmm1
movapd %xmm0, 0x120(%rsp)
movaps %xmm1, 0x130(%rsp)
leaq 0x140(%rsp), %r13
movq %r13, %rdi
callq 0x37e9e
leaq (%rbx,%r14,8), %rax
movb 0x40(%rax), %cl
movb %cl, 0x20(%r13)
movq 0x38(%rax), %rax
movq %rax, 0x18(%r13)
movq 0x140(%rsp), %r14
cmpq 0x148(%rsp), %r14
je 0x350be
addq $0x18, %r14
movq %r12, %r13
movq %rbp, %r12
movq %r15, %rbp
leaq 0x40(%rsp), %r15
movslq -0x14(%r14), %rbx
leal 0x3f(%rbx), %eax
testq %rbx, %rbx
cmovnsl %ebx, %eax
sarl $0x6, %eax
cltq
shlq $0x3, %rax
addq 0xb0(%rsp), %rax
leaq 0x3f(%rbp), %rcx
andq %rbx, %rcx
xorl %edx, %edx
cmpq %rbp, %rcx
setbe %dl
movq -0x8(%rax,%rdx,8), %rax
btq %rbx, %rax
jae 0x3500f
movq %r15, %rdi
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
callq 0x506b0
movq 0x98(%rsp), %rax
movsd (%rax,%rbx,8), %xmm0
minsd 0x90(%rsp), %xmm0
movl 0x48(%rsp), %eax
minsd -0x8(%r14), %xmm0
movl %eax, 0x8(%r12)
movq 0x40(%rsp), %rax
movq %rax, (%r12)
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 %r13, %rdi
callq 0x38342
jmp 0x3509b
movq %r14, %rdi
leaq 0x108(%rsp), %rsi
callq 0x506ec
movq %rax, 0x40(%rsp)
movl %edx, 0x48(%rsp)
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x50708
movq 0x38(%rsp), %rcx
movq (%rcx), %rcx
leaq (%rbx,%rbx,8), %rsi
movsd -0x8(%r14), %xmm0
minsd 0x90(%rsp), %xmm0
minsd 0x38(%rcx,%rsi,8), %xmm0
movl %ebx, 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 %r13, %rdi
callq 0x38342
leaq 0x28(%r14), %rax
addq $0x10, %r14
cmpq 0x148(%rsp), %r14
movq %rax, %r14
jne 0x34f5f
movq 0x140(%rsp), %r14
jmp 0x350c7
movq %r12, %r13
movq %rbp, %r12
movq %r15, %rbp
testq %r14, %r14
je 0x350df
movq 0x150(%rsp), %rsi
subq %r14, %rsi
movq %r14, %rdi
callq 0x4470
movabsq $0x1fffffffe0, %r14     # imm = 0x1FFFFFFFE0
movq 0x50(%rsp), %rdi
movq 0x58(%rsp), %rax
subq %rdi, %rax
testq %r14, %rax
leaq 0xe0(%rsp), %r15
jne 0x34e14
jmp 0x3515f
movq 0x98(%rsp), %rax
movabsq $-0x4010000000000000, %rcx # imm = 0xBFF0000000000000
movq 0x20(%rsp), %rdx
movq %rcx, (%rax,%rdx,8)
jmp 0x35152
movsd 0x38(%rbx), %xmm0
minsd 0x90(%rsp), %xmm0
movq 0x98(%rsp), %rax
movq 0x20(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
maxsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
movq 0x50(%rsp), %rdi
leaq 0xe0(%rsp), %r15
movl 0x34(%rsp), %ebx
movq 0xb0(%rsp), %rax
movq 0x20(%rsp), %rcx
movq %rcx, %rdx
shrq $0x6, %rdx
movl $0x1, %esi
shlq %cl, %rsi
orq %rsi, (%rax,%rdx,8)
testq %rdi, %rdi
je 0x35195
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
incl %ebx
leaq 0xd8(%rsp), %rdi
callq 0x3906e
movl %ebx, %edx
movq 0xb0(%rsp), %rdi
movq 0xc0(%rsp), %rax
movl 0xc8(%rsp), %ecx
subq %rdi, %rax
leaq (%rcx,%rax,8), %rax
movq %rdx, 0x20(%rsp)
cmpq %rdx, %rax
ja 0x34d10
movq 0x98(%rsp), %rax
testq %rax, %rax
je 0x351fa
movq 0xa8(%rsp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x4470
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x3520f
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movsd 0x28(%rsp), %xmm0
addq $0x1c8, %rsp            # imm = 0x1C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x352a1
movq %rax, %rbx
jmp 0x35284
jmp 0x35237
jmp 0x35237
jmp 0x35237
movq %rax, %rbx
jmp 0x35260
jmp 0x35240
jmp 0x35240
movq %rax, %rbx
movq 0x140(%rsp), %rdi
testq %rdi, %rdi
je 0x35260
movq 0x150(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0x50(%rsp), %rdi
testq %rdi, %rdi
je 0x35277
movq 0x60(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
leaq 0xd8(%rsp), %rdi
callq 0x3906e
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x352a1
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq 0xb0(%rsp), %rdi
testq %rdi, %rdi
je 0x352be
movq 0xd0(%rsp), %rsi
subq %rdi, %rsi
callq 0x4470
movq %rbx, %rdi
callq 0x4780