// File: /workspace/github_cpp_makefile_star2_O1/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, 0x20(%rsp)
movq %rdx, 0x140(%rsp)
movq %rsi, %r15
movq %rdi, 0x130(%rsp)
cmpl $-0x1, %r8d
jne 0x1a4c3
callq 0xd6b0
movl %eax, %r8d
cmpl $0x3, %r8d
movl $0x2, %esi
cmovgel %r8d, %esi
leaq 0x1c0(%rsp), %rdi
movq %rsi, 0x120(%rsp)
callq 0x1de1a
leaq 0xc8(%rsp), %rdi
movq %r15, %rsi
callq 0xe982
movq 0xd0(%rsp), %rax
subq 0xc8(%rsp), %rax
movq %rax, 0x10(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x50(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x20(%rsp), %rax
leaq 0x98(%rax), %r12
movq 0x98(%rax), %rax
movq -0x8(%rax), %rax
movq 0x48(%rax), %rcx
movq (%rcx), %rbx
leaq -0x40(%rbx), %rcx
testq %rbx, %rbx
cmovneq %rcx, %rbx
cmpq %rax, %rbx
je 0x1a582
leaq 0x50(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x1d38c
movq 0x48(%rbx), %rax
addq $0x40, %rbx
movq (%rax), %rcx
cmpq %rbx, %rcx
cmoveq %rax, %rcx
leaq -0x40(%rcx), %rbx
testq %rcx, %rcx
cmoveq %rcx, %rbx
movq (%r12), %rax
cmpq -0x8(%rax), %rbx
jne 0x1a550
movq %r12, 0x128(%rsp)
movq %r15, 0x138(%rsp)
movq 0x10(%rsp), %rax
shlq $0x1b, %rax
movq %rax, %rcx
sarq $0x1d, %rcx
testq %rax, %rax
movq $-0x1, %rdi
cmovnsq %rcx, %rdi
callq 0xd040
movq %rax, %r13
movq 0xc8(%rsp), %r15
cmpq 0xd0(%rsp), %r15
je 0x1a6f9
movq 0x20(%rsp), %rax
addq $0xa0, %rax
movq %rax, 0x18(%rsp)
leaq 0xb8(%rsp), %r12
movq %r13, %rbp
movq 0x18(%rsp), %rdi
movq %r15, %rsi
callq 0x1f1b6
movq %rax, %rbx
movl $0x98, %edi
callq 0xd520
movq %r12, 0xa8(%rsp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xa8(%rsp), %rdi
movq %rax, 0x28(%rsp)
callq 0x28d6a
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq -0x8(%rax), %rax
movq %rax, (%rsp)
cmpq %rax, %rbx
sete %al
movl %eax, 0x8(%rsp)
leaq 0x40(%rsp), %rax
je 0x1a666
movq %rax, 0x30(%rsp)
movq (%rbx), %rsi
movq 0x8(%rbx), %rdx
addq %rsi, %rdx
leaq 0x30(%rsp), %r14
movq %r14, %rdi
callq 0x28d6a
jmp 0x1a682
movq %rax, 0x30(%rsp)
leaq 0x30(%rsp), %r14
movq %r14, %rdi
leaq 0x2f23a(%rip), %rdx     # 0x498b4
movq %rdx, %rsi
callq 0x28dfa
movq 0x28(%rsp), %r12
movq %r12, %rdi
leaq 0xa8(%rsp), %rsi
movq %r14, %rdx
callq 0x202b2
movq %r12, (%rbp)
movq 0x30(%rsp), %rdi
cmpq (%rsp), %rbx
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
leaq 0xb8(%rsp), %r12
je 0x1a6c6
movq 0x40(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0xa8(%rsp), %rdi
cmpq %r12, %rdi
je 0x1a6e3
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0xd550
addq $0x20, %r15
addq $0x8, %rbp
cmpq 0xd0(%rsp), %r15
jne 0x1a5e9
movq 0x50(%rsp), %r14
movq 0x58(%rsp), %rbx
leaq 0xf74a(%rip), %rdi      # 0x29e54
callq 0x29d5e
subq %r14, %rbx
shrq $0x5, %rbx
leaq 0x278(%rsp), %rdi
movl %ebx, %esi
movq %rax, %rdx
callq 0x1e184
movq $0x0, (%rsp)
xorl %edi, %edi
callq 0xd4a0
movl %eax, %edi
callq 0xd4d0
movq 0x50(%rsp), %rdx
cmpq 0x58(%rsp), %rdx
je 0x1acb2
movq 0x10(%rsp), %rcx
shrq $0x5, %rcx
movq 0x20(%rsp), %rax
leaq 0xa0(%rax), %rbx
movq %rcx, 0x10(%rsp)
movl %ecx, %ebp
andl $0x7fffffff, %ebp       # imm = 0x7FFFFFFF
movq $0x0, (%rsp)
leaq 0x68(%rsp), %r15
leaq 0x258(%rsp), %r12
movq %rbx, 0x8(%rsp)
movq %rbp, 0x18(%rsp)
leaq 0x78(%rsp), %rax
movq %rax, 0x68(%rsp)
movq (%rdx), %rsi
movq %rdx, 0x28(%rsp)
movq 0x8(%rdx), %rdx
addq %rsi, %rdx
movq %r15, %rdi
callq 0x28d6a
movq 0x128(%rsp), %rdi
movq %r15, %rsi
callq 0x203f6
leaq 0x98(%rsp), %rcx
movq %rcx, 0x88(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x88(%rsp), %rdi
callq 0x28d6a
callq 0xd190
xorl %ebx, %ebx
movq 0x120(%rsp), %rax
movl %eax, %ebp
movq 0x10(%rsp), %rax
subl %ebx, %eax
cltd
idivl %ebp
movl %eax, %r15d
leaq 0xf0(%rsp), %rax
movq %rax, 0xe0(%rsp)
movq 0x68(%rsp), %rsi
movq 0x70(%rsp), %rdx
addq %rsi, %rdx
leaq 0xe0(%rsp), %rdi
callq 0x28d6a
leaq 0x110(%rsp), %rax
movq %rax, 0x100(%rsp)
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %rdx
addq %rsi, %rdx
leaq 0x100(%rsp), %r14
movq %r14, %rdi
callq 0x28d6a
movslq %ebx, %rax
leaq (,%rax,8), %rax
addq %r13, %rax
leaq 0x148(%rsp), %rdi
leaq -0x48a(%rip), %rsi      # 0x1a3f5
movq 0x130(%rsp), %rdx
movq 0x138(%rsp), %rcx
movq 0x140(%rsp), %r8
movq 0x20(%rsp), %r9
pushq %r15
pushq %rax
pushq %r14
leaq 0xf8(%rsp), %rax
pushq %rax
callq 0x20443
addq $0x20, %rsp
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x1a8d8
movq 0x110(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1a8fd
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x148(%rsp), %rax
movq %rax, 0x1e0(%rsp)
leaq 0x150(%rsp), %rax
movupd (%rax), %xmm0
movupd 0x10(%rax), %xmm1
leaq 0x1e8(%rsp), %rax
movupd %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 0x28d6a
leaq 0x238(%rsp), %rax
movq %rax, 0x228(%rsp)
movq 0x190(%rsp), %rsi
movq 0x198(%rsp), %rdx
addq %rsi, %rdx
leaq 0x228(%rsp), %rdi
callq 0x28d6a
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 0x205da
leaq 0x1c0(%rsp), %rdi
movq %r12, %rsi
callq 0x1e270
movq %r12, %rdi
callq 0x1e464
movq 0x228(%rsp), %rdi
leaq 0x238(%rsp), %rax
cmpq %rax, %rdi
je 0x1a9fc
movq 0x238(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x1aa21
movq 0x218(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x190(%rsp), %rdi
leaq 0x1a0(%rsp), %rax
cmpq %rax, %rdi
je 0x1aa46
movq 0x1a0(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x170(%rsp), %rdi
leaq 0x180(%rsp), %rax
cmpq %rax, %rdi
je 0x1aa6b
movq 0x180(%rsp), %rsi
incq %rsi
callq 0xd550
addl %r15d, %ebx
decl %ebp
jne 0x1a7f8
leaq 0x1c0(%rsp), %rdi
xorl %esi, %esi
callq 0x1e49c
movq 0x8(%rsp), %rbx
movq 0x18(%rsp), %rbp
cmpl $0x0, 0x10(%rsp)
jle 0x1ab36
xorl %eax, %eax
xorl %ecx, %ecx
movq (%r13,%rax,8), %rdx
movsd 0x80(%rdx), %xmm0
ucomisd 0x2e5b5(%rip), %xmm0    # 0x49068
jae 0x1aaba
movq %rcx, %r15
jmp 0x1aad0
testq %rcx, %rcx
je 0x1aacd
movsd 0x80(%rcx), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x1aadd
movq %rdx, %r15
incq %rax
movq %r15, %rcx
cmpq %rax, %rbp
jne 0x1aa9e
jmp 0x1ab39
jne 0x1aab5
jp 0x1aab5
movsd 0x88(%rdx), %xmm2
movsd 0x88(%rcx), %xmm3
ucomisd %xmm3, %xmm2
movq %rdx, %r15
ja 0x1aafd
movq %rcx, %r15
ucomisd %xmm1, %xmm0
jne 0x1aad0
jp 0x1aad0
ucomisd %xmm3, %xmm2
ja 0x1aad0
movsd 0x88(%rdx), %xmm0
ucomisd 0x88(%rcx), %xmm0
jne 0x1aab5
jp 0x1aab5
movsd 0x90(%rdx), %xmm0
ucomisd 0x90(%rcx), %xmm0
movq %rcx, %r15
ja 0x1aacd
jmp 0x1aad0
xorl %r15d, %r15d
testq %r15, %r15
je 0x1ac4b
movq %r15, %rdi
movq 0x20(%rsp), %rsi
callq 0x20702
xorps %xmm0, %xmm0
cvtsi2sdl (%rsp), %xmm0
addsd 0x80(%r15), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%r15), %r14
movq %rbx, %rdi
movq %r14, %rsi
callq 0x1f1b6
movq (%rbx), %rcx
cmpq -0x8(%rcx), %rax
je 0x1aba6
leaq 0x158(%rsp), %rcx
movq %rcx, 0x148(%rsp)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0x148(%rsp), %rdi
callq 0x28d6a
jmp 0x1abcd
leaq 0x158(%rsp), %rax
movq %rax, 0x148(%rsp)
leaq 0x148(%rsp), %rdi
leaq 0x2ecef(%rip), %rdx     # 0x498b4
movq %rdx, %rsi
callq 0x28dfa
cmpl $0x0, 0x10(%rsp)
jle 0x1ac1d
movq 0x28(%r15), %rbp
xorl %ebx, %ebx
movq (%r13,%rbx,8), %r15
movq 0x48(%r15), %rdx
cmpq %rbp, %rdx
jne 0x1abfd
testq %rdx, %rdx
je 0x1ac09
movq (%r14), %rsi
movq 0x40(%r15), %rdi
callq 0xd570
testl %eax, %eax
je 0x1ac09
incq %rbx
cmpq %rbx, 0x18(%rsp)
jne 0x1abda
jmp 0x1ac1d
addq $0x60, %r15
movq %r15, %rdi
leaq 0x148(%rsp), %rsi
callq 0xd2d0
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x1ac42
movq 0x158(%rsp), %rsi
incq %rsi
callq 0xd550
cvttsd2si (%rsp), %eax
movq %rax, (%rsp)
leaq 0x278(%rsp), %rdi
callq 0x10808
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x1ac7d
movq 0x98(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x1ac99
movq 0x78(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x28(%rsp), %rdx
addq $0x20, %rdx
cmpq 0x58(%rsp), %rdx
leaq 0x68(%rsp), %r15
jne 0x1a78f
leaq 0x2a0(%rsp), %rdi
callq 0x28594
leaq 0x50(%rsp), %rdi
callq 0x1d3ca
leaq 0xc8(%rsp), %rdi
callq 0x1d3ca
leaq 0x1d8(%rsp), %rdi
callq 0x2307a
leaq 0x1c8(%rsp), %rdi
callq 0x2307a
movq (%rsp), %rax
addq $0x2c8, %rsp            # imm = 0x2C8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1adf5
movq %rax, %r15
jmp 0x1af1e
jmp 0x1adf5
movq %rax, %r15
movq 0x148(%rsp), %rdi
leaq 0x158(%rsp), %rax
cmpq %rax, %rdi
je 0x1aeb9
movq 0x158(%rsp), %rsi
jmp 0x1aeb1
movq %rax, %r15
jmp 0x1adb2
jmp 0x1ae09
jmp 0x1ae09
movq %rax, %r15
jmp 0x1ad87
movq %rax, %r15
jmp 0x1aefa
movq %rax, %r15
jmp 0x1add7
movq %rax, %r15
cmpq (%rsp), %rbx
je 0x1ad8f
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1ad87
movq 0x40(%rsp), %rsi
incq %rsi
callq 0xd550
movl $0x0, 0x8(%rsp)
cmpb $0x0, 0x8(%rsp)
je 0x1adb2
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0x1adb2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0xa8(%rsp), %rdi
leaq 0xb8(%rsp), %rax
cmpq %rax, %rdi
je 0x1add7
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0xd550
movl $0x98, %esi
movq 0x28(%rsp), %rdi
callq 0xd550
jmp 0x1af07
jmp 0x1adf5
movq %rax, %r15
jmp 0x1aede
movq %rax, %r15
jmp 0x1af07
jmp 0x1ae09
movq %rax, %r15
jmp 0x1ae26
movq %rax, %r15
jmp 0x1ae5d
movq %rax, %r15
jmp 0x1aeb9
movq %rax, %r15
jmp 0x1ae94
movq %rax, %r15
leaq 0x258(%rsp), %rdi
callq 0x1e464
leaq 0x1e0(%rsp), %rdi
callq 0x206ca
jmp 0x1ae5d
movq %rax, %r15
movq 0x208(%rsp), %rdi
leaq 0x218(%rsp), %rax
cmpq %rax, %rdi
je 0x1ae5d
movq 0x218(%rsp), %rsi
incq %rsi
callq 0xd550
leaq 0x148(%rsp), %rdi
callq 0x206ca
jmp 0x1aeb9
movq %rax, %r15
movq 0x100(%rsp), %rdi
leaq 0x110(%rsp), %rax
cmpq %rax, %rdi
je 0x1ae94
movq 0x110(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0xe0(%rsp), %rdi
leaq 0xf0(%rsp), %rax
cmpq %rax, %rdi
je 0x1aeb9
movq 0xf0(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x88(%rsp), %rdi
leaq 0x98(%rsp), %rax
cmpq %rax, %rdi
je 0x1aede
movq 0x98(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x1aefa
movq 0x78(%rsp), %rsi
incq %rsi
callq 0xd550
leaq 0x2a0(%rsp), %rdi
callq 0x28594
leaq 0x50(%rsp), %rdi
callq 0x1d3ca
leaq 0xc8(%rsp), %rdi
callq 0x1d3ca
leaq 0x1d8(%rsp), %rdi
callq 0x2307a
leaq 0x1c8(%rsp), %rdi
callq 0x2307a
movq %r15, %rdi
callq 0xd9c0