// File: /workspace/github_cpp_makefile_star2_O3/Kingsford-Group[P]ghost2/src/localImprove.hpp
// Function: searchIter(Graph&, Graph&, boost::unordered::unordered_map<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, double, boost::hash<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::equal_to<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, std::allocator<std::pair<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>> const, double>>>*, boost::bimaps::bimap<boost::bimaps::unordered_set_of<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, boost::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, boost::bimaps::unordered_set_of<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, boost::hash<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::equal_to<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, mpl_::na, mpl_::na, mpl_::na>*, double, int)
int searchIter(Graph& G, Graph& H, blastmap *dists, bmap *f, double ratio, int numthreads)
{
  if(numthreads == -1) numthreads = boost::thread::hardware_concurrency();
  if(numthreads < 2) numthreads = 2;
  boost::threadpool::pool threads(numthreads);

  int totalDelt = 0;
  vector<string> hverts = H.nodes();
  int numMoves = hverts.size();
  vector<string> lefts;
  for(auto it = f->left.begin(); it != f->left.end(); it++) 
    lefts.push_back(it->first);

  move** moves = new move*[numMoves];
  int i = 0;
  for(auto it = hverts.begin(); it != hverts.end(); it++){
    auto up = f->right.find(*it);
    moves[i++] = new move(*it, up == f->right.end() ? "" : up->second);
  }

  ProgressBar pbar(lefts.size(), bclock::local_time());
  srand(time(0));
  
  for(auto it = lefts.begin(); it != lefts.end(); it++){
    string u = *it;
    string w = f->left.at(u);
    
    move *bestMove = NULL;
    bool constrained = rand() > (ratio*RAND_MAX);

    for(int threadsMade = 0, i = 0; threadsMade < numthreads; threadsMade++){
      int n = (numMoves - i)/(numthreads - threadsMade);
      auto worker = boost::bind(&calcScoresWorker, &G, &H, dists, f, u, w, moves + i, n);
      i += n;
      threads.schedule(worker);
    }
    threads.wait();

    for(int i = 0; i < numMoves; i++){
      move *m = moves[i];
      //Check if move is acceptible
      //if(m->s0 > 0 && m->s1 >= 0 && (!constrained || m->s2 >= 0)){
      if(m->s0 >= 0){
        if(!bestMove) bestMove = m;
        else if(m->s0 > bestMove->s0) bestMove = m;
        else if(m->s0 == bestMove->s0 && m->s1 > bestMove->s1) bestMove = m;
        else if(m->s0 == bestMove->s0 && m->s1 == bestMove->s1 && m->s2 > bestMove->s2) bestMove = m;
      }
    }

    if(bestMove){
      bestMove->apply(f);
      totalDelt += bestMove->s0;
      
      auto upt = f->right.find(bestMove->w);
      string up = upt == f->right.end() ? "" : upt->second;
      for(int i = 0; i < numMoves; i++)
        if(moves[i]->v == bestMove->w){moves[i]->up = up; break;}
    }
    pbar.update();
  }
  return totalDelt; 
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2c8, %rsp            # imm = 0x2C8
movq %rcx, 0x18(%rsp)
movq %rdx, 0x140(%rsp)
movq %rsi, %rbx
movq %rdi, 0x130(%rsp)
cmpl $-0x1, %r8d
jne 0x19237
callq 0xc6b0
movl %eax, %r8d
cmpl $0x3, %r8d
movl $0x2, %esi
cmovgel %r8d, %esi
leaq 0x1c0(%rsp), %rdi
movq %rsi, 0x120(%rsp)
callq 0x1cb1e
leaq 0xa8(%rsp), %rdi
movq %rbx, %rsi
callq 0xd978
movq 0xb0(%rsp), %rax
subq 0xa8(%rsp), %rax
movq %rax, 0x8(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x30(%rsp)
movq $0x0, 0x40(%rsp)
movq 0x18(%rsp), %rax
leaq 0x98(%rax), %r12
movq 0x98(%rax), %rax
movq -0x8(%rax), %rax
movq 0x48(%rax), %rcx
movq (%rcx), %r14
leaq -0x40(%r14), %rcx
testq %r14, %r14
cmovneq %rcx, %r14
cmpq %rax, %r14
je 0x192f6
leaq 0x30(%rsp), %r15
movq %r15, %rdi
movq %r14, %rsi
callq 0x1c08e
movq 0x48(%r14), %rax
addq $0x40, %r14
movq (%rax), %rcx
cmpq %r14, %rcx
cmoveq %rax, %rcx
leaq -0x40(%rcx), %r14
testq %rcx, %rcx
cmoveq %rcx, %r14
movq (%r12), %rax
cmpq -0x8(%rax), %r14
jne 0x192c4
movq %r12, 0x128(%rsp)
movq %rbx, 0x138(%rsp)
movq 0x8(%rsp), %rax
shlq $0x1b, %rax
movq %rax, %rcx
sarq $0x1d, %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0xc040
movq %rax, %r13
movq 0xa8(%rsp), %r15
cmpq 0xb0(%rsp), %r15
je 0x19479
movq 0x18(%rsp), %rax
addq $0xa0, %rax
movq %rax, 0x10(%rsp)
leaq 0x88(%rsp), %r14
movq %r13, 0x28(%rsp)
movq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x1de6a
movq %rax, %rbp
movl $0x98, %edi
callq 0xc520
movq %rax, 0x20(%rsp)
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x27846
movq 0x10(%rsp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rcx
leaq 0x98(%rsp), %rax
movq %rax, 0x88(%rsp)
movq %rcx, (%rsp)
cmpq %rcx, %rbp
je 0x193e2
movq (%rbp), %rsi
movq 0x8(%rbp), %rdx
addq %rsi, %rdx
movq %r14, %r12
movq %r14, %rdi
callq 0x27846
jmp 0x193f7
movq %r14, %r12
movq %r14, %rdi
leaq 0x2f4f5(%rip), %rdx     # 0x488e4
movq %rdx, %rsi
callq 0x278dc
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
leaq 0xe0(%rsp), %rsi
movq %r12, %rdx
callq 0x1ef54
movq 0x28(%rsp), %rax
movq %rbx, (%rax)
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x1943c
movq 0x98(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x19461
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xc550
addq $0x20, %r15
addq $0x8, 0x28(%rsp)
cmpq 0xb0(%rsp), %r15
jne 0x1935f
movq 0x30(%rsp), %r14
movq 0x38(%rsp), %rbx
leaq 0xf492(%rip), %rdi      # 0x2891c
callq 0x28826
subq %r14, %rbx
shrq $0x5, %rbx
leaq 0x278(%rsp), %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x1ce88
movq $0x0, (%rsp)
xorl %edi, %edi
callq 0xc4a0
movl %eax, %edi
callq 0xc4d0
movq 0x30(%rsp), %rdx
cmpq 0x38(%rsp), %rdx
je 0x199ce
movq 0x8(%rsp), %rcx
shrq $0x5, %rcx
movq 0x18(%rsp), %rax
leaq 0xa0(%rax), %rbx
movq %rcx, 0x8(%rsp)
movl %ecx, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq $0x0, (%rsp)
leaq 0x48(%rsp), %r15
leaq 0x258(%rsp), %r12
movq %rbx, 0x20(%rsp)
movq %rbp, 0x10(%rsp)
leaq 0x58(%rsp), %rax
movq %rax, 0x48(%rsp)
movq (%rdx), %rsi
movq %rdx, 0x28(%rsp)
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x27846
movq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0x1f098
leaq 0x78(%rsp), %rcx
movq %rcx, 0x68(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x27846
callq 0xc190
xorl %ebx, %ebx
movq 0x120(%rsp), %rax
movl %eax, %ebp
movq 0x8(%rsp), %rax
subl %ebx, %eax
cltd
idivl %ebp
movl %eax, %r15d
leaq 0xd0(%rsp), %rax
movq %rax, 0xc0(%rsp)
movq 0x48(%rsp), %rsi
movq 0x50(%rsp), %rdx
addq %rsi, %rdx
leaq 0xc0(%rsp), %rdi
callq 0x27846
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %r14
movq %r14, %rdi
callq 0x27846
movslq %ebx, %rax
leaq (,%rax,8), %rax
addq %r13, %rax
leaq 0x148(%rsp), %rdi
leaq -0x487(%rip), %rsi      # 0x19169
movq 0x130(%rsp), %rdx
movq 0x138(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x18(%rsp), %r9
pushq %r15
pushq %rax
pushq %r14
leaq 0xd8(%rsp), %rax
pushq %rax
callq 0x1f0e5
addq $0x20, %rsp
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x19649
movq 0x110(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x1966e
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x148(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x150(%rsp), %rax
movupd (%rax), %xmm0
movups 0x10(%rax), %xmm1
leaq 0x1e8(%rsp), %rax
movups %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
leaq 0x218(%rsp), %rax
movq %rax, 0x208(%rsp)
movq 0x170(%rsp), %rsi
movq 0x178(%rsp), %rdx
addq %rsi, %rdx
leaq 0x208(%rsp), %rdi
callq 0x27846
leaq 0x238(%rsp), %rax
movq %rax, 0x228(%rsp)
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
addq %rsi, %rdx
leaq 0x228(%rsp), %rdi
callq 0x27846
movq 0x1b0(%rsp), %rax
movq %rax, 0x248(%rsp)
movl 0x1b8(%rsp), %eax
movl %eax, 0x250(%rsp)
movq %r12, %rdi
leaq 0x1e0(%rsp), %rsi
xorl %edx, %edx
callq 0x1f27c
leaq 0x1c0(%rsp), %rdi
movq %r12, %rsi
callq 0x1cf74
movq %r12, %rdi
callq 0x1d158
movq 0x228(%rsp), %rdi
leaq 0x238(%rsp), %rax
cmpq %rax, %rdi
je 0x1976b
movq 0x238(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x19790
movq 0x218(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x197b5
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x197da
movq 0x180(%rsp), %rsi
incq %rsi
callq 0xc550
addl %r15d, %ebx
decl %ebp
jne 0x1956f
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
callq 0x1d190
movq 0x20(%rsp), %rbx
movq 0x10(%rsp), %rbp
cmpl $0x0, 0x8(%rsp)
jle 0x19970
xorl %eax, %eax
xorl %r15d, %r15d
movq (%r13,%rax,8), %rcx
movsd 0x80(%rcx), %xmm0
ucomisd 0x2e845(%rip), %xmm0    # 0x48068
jb 0x19866
testq %r15, %r15
je 0x19863
ucomisd 0x80(%r15), %xmm0
ja 0x19863
jne 0x19866
jp 0x19866
movsd 0x88(%rcx), %xmm0
ucomisd 0x88(%r15), %xmm0
ja 0x19863
jne 0x19866
jp 0x19866
movsd 0x90(%rcx), %xmm0
ucomisd 0x90(%r15), %xmm0
jbe 0x19866
movq %rcx, %r15
incq %rax
cmpq %rax, %rbp
jne 0x1980e
testq %r15, %r15
je 0x19970
movq %r15, %rdi
movq 0x18(%rsp), %rsi
callq 0x1f3a4
xorps %xmm0, %xmm0
cvtsi2sdl (%rsp), %xmm0
addsd 0x80(%r15), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%r15), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1de6a
movq (%rbx), %rcx
cmpq -0x8(%rcx), %rax
leaq 0x158(%rsp), %rcx
movq %rcx, 0x148(%rsp)
je 0x198db
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0x27846
jmp 0x198f2
leaq 0x148(%rsp), %rdi
leaq 0x2effa(%rip), %rdx     # 0x488e4
movq %rdx, %rsi
callq 0x278dc
cmpl $0x0, 0x8(%rsp)
jle 0x19942
movq 0x28(%r15), %r15
xorl %ebp, %ebp
movq (%r13,%rbp,8), %rbx
cmpq %r15, 0x48(%rbx)
jne 0x19922
testq %r15, %r15
je 0x1992e
movq (%r14), %rsi
movq 0x40(%rbx), %rdi
movq %r15, %rdx
callq 0xc570
testl %eax, %eax
je 0x1992e
incq %rbp
cmpq %rbp, 0x10(%rsp)
jne 0x198ff
jmp 0x19942
addq $0x60, %rbx
movq %rbx, %rdi
leaq 0x148(%rsp), %rsi
callq 0xc2d0
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x19967
movq 0x158(%rsp), %rsi
incq %rsi
callq 0xc550
cvttsd2si (%rsp), %eax
movq %rax, (%rsp)
leaq 0x278(%rsp), %rdi
callq 0xf7ee
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x19999
movq 0x78(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x199b5
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x28(%rsp), %rdx
addq $0x20, %rdx
cmpq 0x38(%rsp), %rdx
leaq 0x48(%rsp), %r15
jne 0x1950f
leaq 0x2a0(%rsp), %rdi
callq 0x27078
leaq 0x30(%rsp), %rdi
callq 0x1c0cc
leaq 0xa8(%rsp), %rdi
callq 0x1c0cc
leaq 0x1d8(%rsp), %rdi
callq 0x21c42
leaq 0x1c8(%rsp), %rdi
callq 0x21c42
movq (%rsp), %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x19aef
movq %rax, %r15
jmp 0x19c0f
jmp 0x19aef
movq %rax, %r15
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x19bb3
movq 0x158(%rsp), %rsi
jmp 0x19bab
jmp 0x19b86
jmp 0x19b86
jmp 0x19a6e
jmp 0x19b86
movq %rax, %r15
jmp 0x19aac
movq %rax, %r15
jmp 0x19beb
movq %rax, %r15
jmp 0x19ad1
movq %rax, %r15
movq 0x88(%rsp), %rdi
cmpq (%rsp), %rbp
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x19aac
movq 0x98(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x19ad1
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xc550
movl $0x98, %esi
movq 0x20(%rsp), %rdi
callq 0xc550
jmp 0x19bf8
jmp 0x19aef
movq %rax, %r15
jmp 0x19bcf
movq %rax, %r15
jmp 0x19bf8
jmp 0x19b86
movq %rax, %r15
jmp 0x19b40
movq %rax, %r15
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x19b8e
movq 0x110(%rsp), %rsi
incq %rsi
callq 0xc550
jmp 0x19b8e
movq %rax, %r15
jmp 0x19b77
movq %rax, %r15
leaq 0x258(%rsp), %rdi
callq 0x1d158
leaq 0x1e0(%rsp), %rdi
callq 0x1f36c
jmp 0x19b77
movq %rax, %r15
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x19b77
movq 0x218(%rsp), %rsi
incq %rsi
callq 0xc550
leaq 0x148(%rsp), %rdi
callq 0x1f36c
jmp 0x19bb3
movq %rax, %r15
jmp 0x19bb3
movq %rax, %r15
movq 0xc0(%rsp), %rdi
leaq 0xd0(%rsp), %rax
cmpq %rax, %rdi
je 0x19bb3
movq 0xd0(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x19bcf
movq 0x78(%rsp), %rsi
incq %rsi
callq 0xc550
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
je 0x19beb
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xc550
leaq 0x2a0(%rsp), %rdi
callq 0x27078
leaq 0x30(%rsp), %rdi
callq 0x1c0cc
leaq 0xa8(%rsp), %rdi
callq 0x1c0cc
leaq 0x1d8(%rsp), %rdi
callq 0x21c42
leaq 0x1c8(%rsp), %rdi
callq 0x21c42
movq %r15, %rdi
callq 0xc9c0