// File: Luthaf[P]zeopp/networkanalysis.cc
// Function: TRAVERSAL_NETWORK::findMaxFreeSphere()
PATH TRAVERSAL_NETWORK::findMaxFreeSphere(){
  double maxR = -1;
  PATH bestPath;
  vector<bool> haveVisited = vector<bool> (dnet->nodes.size(), false);
  HEAP<PATH> heap (hasLowerMaxR);
  
  // Initialize the stack with all nodes connected to the source nodes
  for(unsigned int i = 0; i < sourceNodeIDs.size(); i++){
    DIJKSTRA_NODE sourceNode = dnet->nodes.at(sourceNodeIDs.at(i));
    vector<CONN> viableConns = connectToSink.at(sourceNode.id);
    for(unsigned int j = 0; j <  viableConns.size(); j++){
      CONN nextConn = viableConns.at(j);
      DIJKSTRA_NODE nextNode = dnet->nodes.at(nextConn.to);
      PATH newPath = PATH(nextNode, nextConn.max_radius, max(sourceNode.max_radius, nextNode.max_radius), nextConn.length);
      newPath.visitedIDs.push_back(sourceNode.id);
      heap.insert(newPath);
    }
  }

  while(heap.size() != 0){
    PATH best = heap.pop();
    best.visitedIDs.push_back(best.currentNode.id);
    
    //Done searching if max radius path leads to sink node
    if(best.toSink){
      maxR = best.max_radius;
      bestPath = best;
      break;
    }
    
    // Mark nodes that have been visited or abandon current path if node
    // already visited
    if(haveVisited.at(best.currentNode.id))
      continue;
    else
      haveVisited.at(best.currentNode.id) = true;
    
    // Add all nodes that are connected within the unit cell to the stack
    vector<CONN> regConns = regConnections.at(best.currentNode.id);
    for(unsigned int i = 0; i < regConns.size(); i++){
      CONN nextConn = regConns.at(i);
      if(!haveVisited.at(nextConn.to)){
	DIJKSTRA_NODE nextNode = dnet->nodes.at(nextConn.to);
	PATH nextPath = PATH(nextNode,min(best.max_radius,nextConn.max_radius), max(best.max_inc_radius, nextNode.max_radius), best.length + nextConn.length);
	nextPath.visitedIDs = best.visitedIDs;
	heap.insert(nextPath);
      }
    }

    // Add all nodes that are connected in the sink to the stack
    vector<CONN> sinkConns = connectToSink.at(best.currentNode.id);
    for(unsigned int i = 0; i < sinkConns.size(); i++){
      CONN nextConn = sinkConns.at(i);
      DIJKSTRA_NODE nextNode = dnet->nodes.at(nextConn.to);
      PATH nextPath = PATH(nextNode, min(best.max_radius, nextConn.max_radius), max(best.max_inc_radius, nextNode.max_radius), best.length + nextConn.length);
      nextPath.toSink = true;
      nextPath.visitedIDs = best.visitedIDs;
      heap.insert(nextPath);
    }
  }
  return bestPath;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xa50, %rsp            # imm = 0xA50
movq %rdi, -0x948(%rbp)
movq %rdi, %rax
movq %rax, -0x940(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x938(%rbp)
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
callq 0x5ce70
movq -0x938(%rbp), %rax
movq 0x70(%rax), %rdi
callq 0x10100
movq %rax, -0x930(%rbp)
movb $0x0, -0x49(%rbp)
leaq -0x4a(%rbp), %rdi
movq %rdi, -0x928(%rbp)
callq 0x64b50
movq -0x930(%rbp), %rsi
movq -0x928(%rbp), %rcx
leaq -0x48(%rbp), %rdi
leaq -0x49(%rbp), %rdx
callq 0x64b70
jmp 0x5f2ae
leaq -0x4a(%rbp), %rdi
callq 0x64bf0
leaq -0x1e7e(%rip), %rsi     # 0x5d440
leaq -0x80(%rbp), %rdi
callq 0x64c10
jmp 0x5f2c9
movl $0x0, -0x84(%rbp)
movq -0x938(%rbp), %rdi
movl -0x84(%rbp), %eax
movq %rax, -0x950(%rbp)
callq 0x10090
movq %rax, %rcx
movq -0x950(%rbp), %rax
cmpq %rcx, %rax
jae 0x5f63f
movq -0x938(%rbp), %rdi
movq 0x70(%rdi), %rax
movq %rax, -0x960(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
callq 0x101d0
movq %rax, -0x958(%rbp)
jmp 0x5f327
movq -0x960(%rbp), %rdi
movq -0x958(%rbp), %rax
movslq (%rax), %rsi
callq 0x10130
movq %rax, -0x968(%rbp)
jmp 0x5f346
movq -0x968(%rbp), %rsi
leaq -0xd0(%rbp), %rdi
callq 0x64400
jmp 0x5f35b
movq -0x938(%rbp), %rdi
addq $0x48, %rdi
movslq -0xd0(%rbp), %rsi
callq 0x64a20
movq %rax, -0x970(%rbp)
jmp 0x5f37b
movq -0x970(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
callq 0x64a60
jmp 0x5f390
movl $0x0, -0xec(%rbp)
movl -0xec(%rbp), %eax
movq %rax, -0x978(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x2a9e0
movq %rax, %rcx
movq -0x978(%rbp), %rax
cmpq %rcx, %rax
jae 0x5f5f6
movl -0xec(%rbp), %eax
movl %eax, %esi
leaq -0xe8(%rbp), %rdi
callq 0x64470
movq %rax, -0x980(%rbp)
jmp 0x5f3e3
movq -0x938(%rbp), %rax
movq -0x980(%rbp), %rcx
movq 0x20(%rcx), %rdx
movq %rdx, -0x100(%rbp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, -0x110(%rbp)
movaps %xmm0, -0x120(%rbp)
movq 0x70(%rax), %rdi
movslq -0x11c(%rbp), %rsi
callq 0x10130
movq %rax, -0x988(%rbp)
jmp 0x5f42a
movq -0x988(%rbp), %rsi
leaq -0x168(%rbp), %rdi
callq 0x64400
jmp 0x5f43f
leaq -0x278(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x64400
jmp 0x5f454
movsd -0x110(%rbp), %xmm0
movsd %xmm0, -0x998(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x64c70
movq %rax, -0x990(%rbp)
jmp 0x5f480
movsd -0x998(%rbp), %xmm0
movq -0x990(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x118(%rbp), %xmm2
leaq -0x230(%rbp), %rdi
leaq -0x278(%rbp), %rsi
callq 0x5cfa0
jmp 0x5f4b0
leaq -0x278(%rbp), %rdi
callq 0x100e0
leaq -0x1b0(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0xd1b0
jmp 0x5f4d1
leaq -0x340(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x64d10
jmp 0x5f4e6
leaq -0x80(%rbp), %rdi
leaq -0x340(%rbp), %rsi
callq 0x64cb0
jmp 0x5f4f8
leaq -0x340(%rbp), %rdi
callq 0x10df0
leaq -0x230(%rbp), %rdi
callq 0x10df0
leaq -0x168(%rbp), %rdi
callq 0x100e0
movl -0xec(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xec(%rbp)
jmp 0x5f39a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x4a(%rbp), %rdi
callq 0x64bf0
jmp 0x5fda6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fd7f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fd76
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5f62e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5f622
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5f5e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x278(%rbp), %rdi
callq 0x100e0
jmp 0x5f5e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5f5dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x10df0
leaq -0x230(%rbp), %rdi
callq 0x10df0
leaq -0x168(%rbp), %rdi
callq 0x100e0
jmp 0x5f622
leaq -0xe8(%rbp), %rdi
callq 0x11230
leaq -0xd0(%rbp), %rdi
callq 0x100e0
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x5f2d3
leaq -0xe8(%rbp), %rdi
callq 0x11230
leaq -0xd0(%rbp), %rdi
callq 0x100e0
jmp 0x5fd76
jmp 0x5f641
leaq -0x80(%rbp), %rdi
callq 0x64e00
movl %eax, -0x99c(%rbp)
jmp 0x5f652
movl -0x99c(%rbp), %eax
cmpl $0x0, %eax
je 0x5fd4e
leaq -0x408(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x64e20
jmp 0x5f673
leaq -0x388(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0xd1b0
jmp 0x5f688
testb $0x1, -0x390(%rbp)
je 0x5f6d3
movq -0x948(%rbp), %rdi
movsd -0x3a8(%rbp), %xmm0
movsd %xmm0, -0x18(%rbp)
leaq -0x408(%rbp), %rsi
callq 0x64eb0
jmp 0x5f6b3
movl $0x9, -0x40c(%rbp)
jmp 0x5fcf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fd40
movslq -0x3f0(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x9b0(%rbp)
movq %rax, -0x9a8(%rbp)
jmp 0x5f6f3
movq -0x9b0(%rbp), %rax
movq -0x9a8(%rbp), %rcx
movq %rcx, -0x420(%rbp)
movq %rax, -0x418(%rbp)
leaq -0x420(%rbp), %rdi
callq 0x101a0
testb $0x1, %al
jne 0x5f721
jmp 0x5f730
movl $0x8, -0x40c(%rbp)
jmp 0x5fcf2
movslq -0x3f0(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x9c0(%rbp)
movq %rax, -0x9b8(%rbp)
jmp 0x5f750
movq -0x9c0(%rbp), %rax
movq -0x9b8(%rbp), %rcx
movq %rcx, -0x430(%rbp)
movq %rax, -0x428(%rbp)
leaq -0x430(%rbp), %rdi
movl $0x1, %esi
callq 0x10040
movq -0x938(%rbp), %rdi
addq $0x18, %rdi
movslq -0x3f0(%rbp), %rsi
callq 0x64a20
movq %rax, -0x9c8(%rbp)
jmp 0x5f79d
movq -0x9c8(%rbp), %rsi
leaq -0x448(%rbp), %rdi
callq 0x64a60
jmp 0x5f7b2
movl $0x0, -0x44c(%rbp)
movl -0x44c(%rbp), %eax
movq %rax, -0x9d0(%rbp)
leaq -0x448(%rbp), %rdi
callq 0x2a9e0
movq %rax, %rcx
movq -0x9d0(%rbp), %rax
cmpq %rcx, %rax
jae 0x5fa50
movl -0x44c(%rbp), %eax
movl %eax, %esi
leaq -0x448(%rbp), %rdi
callq 0x64470
movq %rax, -0x9d8(%rbp)
jmp 0x5f805
movq -0x9d8(%rbp), %rax
movq 0x20(%rax), %rcx
movq %rcx, -0x460(%rbp)
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movaps %xmm1, -0x470(%rbp)
movaps %xmm0, -0x480(%rbp)
movslq -0x47c(%rbp), %rsi
leaq -0x48(%rbp), %rdi
callq 0xfff0
movq %rdx, -0x9e8(%rbp)
movq %rax, -0x9e0(%rbp)
jmp 0x5f84c
movq -0x9e8(%rbp), %rax
movq -0x9e0(%rbp), %rcx
movq %rcx, -0x490(%rbp)
movq %rax, -0x488(%rbp)
leaq -0x490(%rbp), %rdi
callq 0x101a0
xorb $-0x1, %al
testb $0x1, %al
jne 0x5f87f
jmp 0x5fa3a
movq -0x938(%rbp), %rax
movq 0x70(%rax), %rdi
movslq -0x47c(%rbp), %rsi
callq 0x10130
movq %rax, -0x9f0(%rbp)
jmp 0x5f89f
movq -0x9f0(%rbp), %rsi
leaq -0x4d8(%rbp), %rdi
callq 0x64400
jmp 0x5f8b4
leaq -0x5e8(%rbp), %rdi
leaq -0x4d8(%rbp), %rsi
callq 0x64400
jmp 0x5f8c9
leaq -0x3a8(%rbp), %rdi
leaq -0x470(%rbp), %rsi
callq 0x64f50
movq %rax, -0x9f8(%rbp)
jmp 0x5f8e5
movq -0x9f8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xa08(%rbp)
leaq -0x3a0(%rbp), %rdi
leaq -0x4a0(%rbp), %rsi
callq 0x64c70
movq %rax, -0xa00(%rbp)
jmp 0x5f914
movsd -0xa08(%rbp), %xmm0
movq -0xa00(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x398(%rbp), %xmm2
movsd -0x478(%rbp), %xmm3
addsd %xmm3, %xmm2
leaq -0x5a0(%rbp), %rdi
leaq -0x5e8(%rbp), %rsi
callq 0x5cfa0
jmp 0x5f950
leaq -0x5e8(%rbp), %rdi
callq 0x100e0
leaq -0x388(%rbp), %rsi
leaq -0x520(%rbp), %rdi
callq 0x17a10
jmp 0x5f971
leaq -0x6b0(%rbp), %rdi
leaq -0x5a0(%rbp), %rsi
callq 0x64d10
jmp 0x5f986
leaq -0x80(%rbp), %rdi
leaq -0x6b0(%rbp), %rsi
callq 0x64cb0
jmp 0x5f998
leaq -0x6b0(%rbp), %rdi
callq 0x10df0
leaq -0x5a0(%rbp), %rdi
callq 0x10df0
leaq -0x4d8(%rbp), %rdi
callq 0x100e0
jmp 0x5fa3a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fd34
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fa29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x5e8(%rbp), %rdi
callq 0x100e0
jmp 0x5fa29
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fa1d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x6b0(%rbp), %rdi
callq 0x10df0
leaq -0x5a0(%rbp), %rdi
callq 0x10df0
leaq -0x4d8(%rbp), %rdi
callq 0x100e0
jmp 0x5fd34
jmp 0x5fa3c
movl -0x44c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44c(%rbp)
jmp 0x5f7bc
movq -0x938(%rbp), %rdi
addq $0x48, %rdi
movslq -0x3f0(%rbp), %rsi
callq 0x64a20
movq %rax, -0xa10(%rbp)
jmp 0x5fa70
movq -0xa10(%rbp), %rsi
leaq -0x6c8(%rbp), %rdi
callq 0x64a60
jmp 0x5fa85
movl $0x0, -0x6cc(%rbp)
movl -0x6cc(%rbp), %eax
movq %rax, -0xa18(%rbp)
leaq -0x6c8(%rbp), %rdi
callq 0x2a9e0
movq %rax, %rcx
movq -0xa18(%rbp), %rax
cmpq %rcx, %rax
jae 0x5fcd0
movl -0x6cc(%rbp), %eax
movl %eax, %esi
leaq -0x6c8(%rbp), %rdi
callq 0x64470
movq %rax, -0xa20(%rbp)
jmp 0x5fad8
movq -0x938(%rbp), %rax
movq -0xa20(%rbp), %rcx
movq 0x20(%rcx), %rdx
movq %rdx, -0x6e0(%rbp)
movups (%rcx), %xmm0
movups 0x10(%rcx), %xmm1
movaps %xmm1, -0x6f0(%rbp)
movaps %xmm0, -0x700(%rbp)
movq 0x70(%rax), %rdi
movslq -0x6fc(%rbp), %rsi
callq 0x10130
movq %rax, -0xa28(%rbp)
jmp 0x5fb1f
movq -0xa28(%rbp), %rsi
leaq -0x748(%rbp), %rdi
callq 0x64400
jmp 0x5fb34
leaq -0x858(%rbp), %rdi
leaq -0x748(%rbp), %rsi
callq 0x64400
jmp 0x5fb49
leaq -0x3a8(%rbp), %rdi
leaq -0x6f0(%rbp), %rsi
callq 0x64f50
movq %rax, -0xa30(%rbp)
jmp 0x5fb65
movq -0xa30(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0xa40(%rbp)
leaq -0x3a0(%rbp), %rdi
leaq -0x710(%rbp), %rsi
callq 0x64c70
movq %rax, -0xa38(%rbp)
jmp 0x5fb94
movsd -0xa40(%rbp), %xmm0
movq -0xa38(%rbp), %rax
movsd (%rax), %xmm1
movsd -0x398(%rbp), %xmm2
movsd -0x6f8(%rbp), %xmm3
addsd %xmm3, %xmm2
leaq -0x810(%rbp), %rdi
leaq -0x858(%rbp), %rsi
callq 0x5cfa0
jmp 0x5fbd0
leaq -0x858(%rbp), %rdi
callq 0x100e0
movb $0x1, -0x798(%rbp)
leaq -0x388(%rbp), %rsi
leaq -0x790(%rbp), %rdi
callq 0x17a10
jmp 0x5fbf8
leaq -0x920(%rbp), %rdi
leaq -0x810(%rbp), %rsi
callq 0x64d10
jmp 0x5fc0d
leaq -0x80(%rbp), %rdi
leaq -0x920(%rbp), %rsi
callq 0x64cb0
jmp 0x5fc1f
leaq -0x920(%rbp), %rdi
callq 0x10df0
leaq -0x810(%rbp), %rdi
callq 0x10df0
leaq -0x748(%rbp), %rdi
callq 0x100e0
movl -0x6cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6cc(%rbp)
jmp 0x5fa8f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fd28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fcc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x858(%rbp), %rdi
callq 0x100e0
jmp 0x5fcc2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x5fcb6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x920(%rbp), %rdi
callq 0x10df0
leaq -0x810(%rbp), %rdi
callq 0x10df0
leaq -0x748(%rbp), %rdi
callq 0x100e0
jmp 0x5fd28
leaq -0x6c8(%rbp), %rdi
callq 0x11230
leaq -0x448(%rbp), %rdi
callq 0x11230
movl $0x0, -0x40c(%rbp)
leaq -0x408(%rbp), %rdi
callq 0x10df0
movl -0x40c(%rbp), %eax
movl %eax, -0xa44(%rbp)
testl %eax, %eax
je 0x5fd23
jmp 0x5fd10
movl -0xa44(%rbp), %eax
subl $0x8, %eax
je 0x5f641
jmp 0x5fd21
jmp 0x5fd4e
jmp 0x5f641
leaq -0x6c8(%rbp), %rdi
callq 0x11230
leaq -0x448(%rbp), %rdi
callq 0x11230
leaq -0x408(%rbp), %rdi
callq 0x10df0
jmp 0x5fd76
movb $0x1, -0x19(%rbp)
movl $0x1, -0x40c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x64fd0
leaq -0x48(%rbp), %rdi
callq 0xf9b0
testb $0x1, -0x19(%rbp)
jne 0x5fd96
jmp 0x5fd8a
leaq -0x80(%rbp), %rdi
callq 0x64fd0
leaq -0x48(%rbp), %rdi
callq 0xf9b0
jmp 0x5fda6
movq -0x948(%rbp), %rdi
callq 0x10df0
movq -0x940(%rbp), %rax
addq $0xa50, %rsp            # imm = 0xA50
popq %rbp
retq
movq -0x948(%rbp), %rdi
callq 0x10df0
movq -0x58(%rbp), %rdi
callq 0x58f0
nopl (%rax,%rax)