// File: /workspace/github_cpp_makefile_star2_O2/Luthaf[P]zeopp/networkanalysis.cc
// Function: TRAVERSAL_NETWORK::findMaxFreeSphere(std::map<int, int, std::less<int>, std::allocator<std::pair<int const, int>>>*, std::set<int, std::less<int>, std::allocator<int>>*)
pair<bool,PATH> TRAVERSAL_NETWORK::findMaxFreeSphere(map<int,int> *idAliases, set<int> *sourceNodes){
  PATH bestPath; bestPath.max_radius = -1;
  vector<bool> haveVisited = vector<bool> (dnet->nodes.size(), false);
  HEAP<PATH> heap (hasLowerMaxR);
  bool NtoN = false;
  
  // 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);
      newPath.visitedSourceIDs.insert(idAliases->find(sourceNode.id)->second);
      heap.insert(newPath);
    }
  }
  
  while(heap.size() != 0){
    PATH best = heap.pop();
    
    //Done searching if max radius path leads to sink node
    if(best.toSink){
      best.visitedIDs.push_back(best.currentNode.id);
      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;
    
    if(sourceNodes->find(best.currentNode.id) != sourceNodes->end()){
      int origID = idAliases->find(best.currentNode.id)->second;
      if(best.visitedSourceIDs.find(origID) != best.visitedSourceIDs.end()){
	best.visitedIDs.push_back(best.currentNode.id);
	bestPath = best;
	NtoN = true;
	break;
      }
      else{
	best.visitedSourceIDs.insert(origID);
      }	
    }
    best.visitedIDs.push_back(best.currentNode.id);
    
    // 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[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.visitedSourceIDs = best.visitedSourceIDs;
	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[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;
      nextPath.visitedSourceIDs = best.visitedSourceIDs;
      heap.insert(nextPath);
    }
    
  }
  return pair<bool,PATH> (NtoN,bestPath);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x6b8, %rsp            # imm = 0x6B8
movq %rcx, 0x48(%rsp)
movq %rdx, 0x68(%rsp)
movq %rsi, %r14
movq %rdi, 0x90(%rsp)
leaq 0x398(%rsp), %rbx
movq %rbx, %rdi
callq 0x25a6c
movabsq $-0x4010000000000000, %rax # imm = 0xBFF0000000000000
movq %rax, 0x60(%rbx)
movq 0x70(%r14), %rcx
movq 0x8(%rcx), %rax
subq (%rcx), %rax
pushq $0x48
popq %rcx
cqto
idivq %rcx
leaq 0x108(%rsp), %rdx
movb $0x0, (%rdx)
leaq 0x1d0(%rsp), %rdi
leaq 0x1f8(%rsp), %rcx
movq %rax, %rsi
callq 0x2a0d6
leaq -0xa2f(%rip), %rsi      # 0x25f10
leaq 0x70(%rsp), %rdi
callq 0x2a13a
movq %r14, 0x28(%rsp)
leaq 0x48(%r14), %rax
movq %rax, 0x50(%rsp)
leaq 0x1a0(%rsp), %r12
xorl %esi, %esi
leaq 0x30(%rsp), %r13
leaq 0xc0(%rsp), %r14
leaq 0x350(%rsp), %r15
leaq 0x5f0(%rsp), %rbx
movl %esi, %esi
movq 0x28(%rsp), %rdi
movq 0x8(%rdi), %rax
subq (%rdi), %rax
sarq $0x2, %rax
cmpq %rsi, %rax
jbe 0x26b1f
movq 0x70(%rdi), %rbp
movq %rsi, 0x8(%rsp)
callq 0xac00
movslq (%rax), %rsi
movq %rbp, %rdi
callq 0xabe2
leaq 0x1f8(%rsp), %rdi
movq %rax, %rsi
callq 0x29ebe
movslq 0x1f8(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x2a050
movq %r13, %rdi
movq %rax, %rsi
callq 0x2a06e
xorl %ebp, %ebp
movl %ebp, %ebp
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %rbp, %rax
jbe 0x26afe
movq %r13, %rdi
movq %rbp, %rsi
callq 0x29efa
movslq 0x4(%rax), %rsi
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rdi
callq 0xabe2
movq %r14, %rdi
movq %rax, %rsi
callq 0x29ebe
movq %r15, %rdi
movq %r14, %rsi
callq 0x29ebe
movsd 0xf8(%rsp), %xmm1
maxsd 0x230(%rsp), %xmm1
leaq 0x108(%rsp), %rdi
movq %r15, %rsi
movsd 0x10(%rsp), %xmm0
movsd 0x18(%rsp), %xmm2
callq 0x25b74
leaq 0x370(%rsp), %rdi
callq 0xaf14
leaq 0x188(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x9434
movq 0x68(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x10996
addq $0x24, %rax
movq %r12, %rdi
movq %rax, %rsi
callq 0xf334
movq %rbx, %rdi
leaq 0x108(%rsp), %rsi
callq 0x2a18a
leaq 0x70(%rsp), %rdi
movq %rbx, %rsi
callq 0x2a170
movq %rbx, %rdi
callq 0xadf4
leaq 0x108(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
callq 0xaf14
incl %ebp
jmp 0x269e1
movq %r13, %rdi
callq 0xaf14
leaq 0x218(%rsp), %rdi
callq 0xaf14
movq 0x8(%rsp), %rsi
incl %esi
jmp 0x2697e
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
movl $0x98, %edx
leaq 0x108(%rsp), %rax
leaq (%rax,%rdx), %rcx
movq %rcx, 0x8(%rsp)
movl $0x80, %ecx
leaq (%rax,%rcx), %r13
leaq 0x18(%rdi), %rax
movq %rax, 0x98(%rsp)
leaq 0x1f8(%rsp), %rax
addq %rax, %rdx
movq %rdx, 0x58(%rsp)
addq %rax, %rcx
movq %rcx, 0x60(%rsp)
movl $0x0, 0x24(%rsp)
leaq 0x528(%rsp), %r14
movq 0x78(%rsp), %rax
subq 0x70(%rsp), %rax
cqto
movl $0xc8, %ecx
idivq %rcx
testl %eax, %eax
je 0x26fc1
leaq 0x108(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0x2a216
cmpb $0x1, 0x180(%rsp)
jne 0x26be7
movq %r13, %rdi
leaq 0x120(%rsp), %rsi
callq 0x9434
movb $0x1, %bl
leaq 0x398(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x2a256
jmp 0x26fac
movslq 0x120(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0xaba4
testq %rdx, (%rax)
jne 0x26faa
movslq 0x120(%rsp), %rsi
leaq 0x1d0(%rsp), %rdi
callq 0xaba4
orq %rdx, (%rax)
movq 0x48(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0xf68e
cmpq 0xa0(%rsp), %rax
je 0x26cb8
movq 0x68(%rsp), %rdi
leaq 0x120(%rsp), %rsi
callq 0x10996
movl 0x24(%rax), %eax
movl %eax, 0x1f8(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0xf68e
leaq 0x1a8(%rsp), %rcx
cmpq %rcx, %rax
je 0x26ca6
movq %r13, %rdi
leaq 0x120(%rsp), %rsi
callq 0x9434
leaq 0x398(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x2a256
movb $0x1, %al
movl %eax, 0x24(%rsp)
movb $0x1, %bl
jmp 0x26fac
movq 0x8(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0xf334
movq %r13, %rdi
leaq 0x120(%rsp), %rsi
callq 0x9434
movslq 0x120(%rsp), %rsi
movq 0x98(%rsp), %rdi
callq 0x2a050
leaq 0x30(%rsp), %rdi
movq %rax, %rsi
callq 0x2a06e
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0x38(%rsp), %rax
subq 0x30(%rsp), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %rbx, %rax
jbe 0x26e38
leaq 0x30(%rsp), %rdi
movq %rbx, %rsi
callq 0x29efa
movslq 0x4(%rax), %r15
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
leaq 0x1d0(%rsp), %rdi
movq %r15, %rsi
callq 0xaba4
testq %rdx, (%rax)
jne 0x26e31
movq 0x28(%rsp), %rax
movq 0x70(%rax), %rax
imulq $0x48, %r15, %rsi
addq (%rax), %rsi
leaq 0xc0(%rsp), %r15
movq %r15, %rdi
callq 0x29ebe
leaq 0x308(%rsp), %r12
movq %r12, %rdi
movq %r15, %rsi
callq 0x29ebe
movsd 0x10(%rsp), %xmm0
minsd 0x168(%rsp), %xmm0
movsd 0xf8(%rsp), %xmm1
maxsd 0x170(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x178(%rsp), %xmm2
leaq 0x1f8(%rsp), %rdi
movq %r12, %rsi
callq 0x25b74
leaq 0x328(%rsp), %rdi
callq 0xaf14
movq 0x58(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0xe7dc
movq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0xc178
leaq 0x460(%rsp), %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x2a18a
leaq 0x70(%rsp), %rdi
leaq 0x460(%rsp), %r15
movq %r15, %rsi
callq 0x2a170
movq %r15, %rdi
callq 0xadf4
leaq 0x1f8(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
callq 0xaf14
incl %ebx
jmp 0x26cec
movslq 0x120(%rsp), %rsi
movq 0x50(%rsp), %rdi
callq 0x2a050
movq 0x28(%rsp), %r15
leaq 0xa8(%rsp), %rdi
movq %rax, %rsi
callq 0x2a06e
xorl %ebx, %ebx
movl %ebx, %ebx
movq 0xb0(%rsp), %rax
subq 0xa8(%rsp), %rax
cqto
pushq $0x28
popq %rcx
idivq %rcx
cmpq %rbx, %rax
jbe 0x26f93
leaq 0xa8(%rsp), %rdi
movq %rbx, %rsi
callq 0x29efa
movslq 0x4(%rax), %rcx
movsd 0x8(%rax), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x10(%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x70(%r15), %rax
imulq $0x48, %rcx, %rsi
addq (%rax), %rsi
leaq 0xc0(%rsp), %r12
movq %r12, %rdi
callq 0x29ebe
leaq 0x2c0(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x29ebe
movsd 0x10(%rsp), %xmm0
minsd 0x168(%rsp), %xmm0
movsd 0xf8(%rsp), %xmm1
maxsd 0x170(%rsp), %xmm1
movsd 0x18(%rsp), %xmm2
addsd 0x178(%rsp), %xmm2
leaq 0x1f8(%rsp), %rdi
movq %rbp, %rsi
callq 0x25b74
leaq 0x2e0(%rsp), %rdi
callq 0xaf14
movb $0x1, 0x270(%rsp)
movq 0x60(%rsp), %rdi
movq %r13, %rsi
callq 0xc178
movq 0x58(%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0xe7dc
movq %r14, %rdi
leaq 0x1f8(%rsp), %rsi
callq 0x2a18a
leaq 0x70(%rsp), %rdi
movq %r14, %rsi
callq 0x2a170
movq %r14, %rdi
callq 0xadf4
leaq 0x1f8(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
callq 0xaf14
incl %ebx
jmp 0x26e61
leaq 0xa8(%rsp), %rdi
callq 0xaf14
leaq 0x30(%rsp), %rdi
callq 0xaf14
xorl %ebx, %ebx
leaq 0x108(%rsp), %rdi
callq 0xadf4
testb %bl, %bl
je 0x26b83
movq 0x90(%rsp), %rbx
movl 0x24(%rsp), %eax
movb %al, (%rbx)
movq %rbx, %rdi
addq $0x8, %rdi
leaq 0x398(%rsp), %rsi
callq 0x2a18a
leaq 0x70(%rsp), %rdi
callq 0x2aae8
leaq 0x1d0(%rsp), %rdi
callq 0xa976
leaq 0x398(%rsp), %rdi
callq 0xadf4
movq %rbx, %rax
addq $0x6b8, %rsp            # imm = 0x6B8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x270ca
movq %rax, %rbx
jmp 0x27192
jmp 0x2703e
jmp 0x2703e
jmp 0x2703e
jmp 0x2703e
jmp 0x2703e
jmp 0x270a3
jmp 0x2703e
jmp 0x2703e
jmp 0x270ca
movq %rax, %rbx
jmp 0x27106
jmp 0x270a3
movq %rax, %rbx
jmp 0x270c0
movq %rax, %rbx
leaq 0x328(%rsp), %rdi
callq 0xaf14
jmp 0x270c0
movq %rax, %rbx
leaq 0x460(%rsp), %rdi
callq 0xadf4
jmp 0x270b3
movq %rax, %rbx
leaq 0x2e0(%rsp), %rdi
callq 0xaf14
jmp 0x270e2
movq %rax, %rbx
jmp 0x270e2
jmp 0x2708a
movq %rax, %rbx
jmp 0x270ef
movq %rax, %rbx
leaq 0x528(%rsp), %rdi
callq 0xadf4
jmp 0x270d5
jmp 0x270a3
movq %rax, %rbx
jmp 0x270fc
movq %rax, %rbx
jmp 0x2716e
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
jmp 0x270f7
movq %rax, %rbx
jmp 0x2717b
movq %rax, %rbx
leaq 0x1f8(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
callq 0xaf14
leaq 0xa8(%rsp), %rdi
callq 0xaf14
leaq 0x30(%rsp), %rdi
callq 0xaf14
leaq 0x108(%rsp), %rdi
callq 0xadf4
jmp 0x2717b
movq %rax, %rbx
jmp 0x27157
movq %rax, %rbx
leaq 0x370(%rsp), %rdi
callq 0xaf14
jmp 0x27157
jmp 0x27140
movq %rax, %rbx
leaq 0x5f0(%rsp), %rdi
callq 0xadf4
jmp 0x2714a
movq %rax, %rbx
jmp 0x27164
jmp 0x27147
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0xadf4
leaq 0xe0(%rsp), %rdi
callq 0xaf14
leaq 0x30(%rsp), %rdi
callq 0xaf14
leaq 0x218(%rsp), %rdi
callq 0xaf14
leaq 0x70(%rsp), %rdi
callq 0x2aae8
leaq 0x1d0(%rsp), %rdi
callq 0xa976
leaq 0x398(%rsp), %rdi
callq 0xadf4
movq %rbx, %rdi
callq 0x4780
nop