// File: Kingsford-Group[P]ghost2/src/spectralToDistance.hpp
// Function: getDistances(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::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, double, 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>>>*, int)
vector<D_alpha> getDistances(string file1, string file2, string outputname, double a, double b, blastmap* blastscores, int numP)
{
  ptime t = bclock::local_time();
  cout << "loading sigs file: " << file1 << "\n";
  spectramap m1 = loadSigs(file1);
  cout << "loaded " << m1.size() << " vertices in " <<
    (bclock::local_time() - t).total_milliseconds() << "ms\n";

  t = bclock::local_time();
  cout << "loading sigs file: " << file2 << "\n";
  spectramap m2 = loadSigs(file2);
  cout << "loaded " << m2.size() << " vertices in " <<
    (bclock::local_time() - t).total_milliseconds() << "ms\n";

  ofstream out(outputname.c_str());

  t = bclock::local_time();

  vector<D_alpha**> results;
  vector<string*> outputs;
  int numthreads = numP==-1?boost::thread::hardware_concurrency():numP;
  if(numthreads < 2) numthreads = 2;
  cout << "\ncalculating D_alphas on " << numthreads << " threads\n";
  boost::threadpool::pool threads(numthreads);

  ProgressBar pbar(m1.size(), t);
  for(spectramap::iterator it1 = m1.begin(); it1 != m1.end(); ++it1){
    results.push_back(new D_alpha*[m2.size()]);
    outputs.push_back(new string);
    threads.schedule(boost::bind(&distanceWorker, *it1, &m2, results.back(),
        outputs.back(), &pbar));
  }

  threads.wait();
  cout << "\nfinished calculating " << (m1.size()*m2.size()) << " distances in " <<
    (bclock::local_time()-t).total_seconds() << "s\n";

  vector<D_alpha> allDistances;
  for(int i=0; i<results.size(); i++){
    out << *(outputs[i]);
    delete outputs[i];
    for(int j=0; j<m2.size(); j++){allDistances.push_back(*(results[i][j])); delete results[i][j];}
    delete[] results[i];
  }

  applyAlpha(a, b, &allDistances, blastscores);

  out.close();
  return allDistances;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x640, %rsp            # imm = 0x640
movq %rcx, -0x500(%rbp)
movq %rdx, -0x4f8(%rbp)
movq %rsi, -0x4e0(%rbp)
movq %rdi, -0x4f0(%rbp)
movq %rdi, %rax
movq %rax, -0x4e8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movq %r8, -0x38(%rbp)
movl %r9d, -0x3c(%rbp)
callq 0x23b20
movq %rax, -0x48(%rbp)
movq 0x117f55(%rip), %rdi    # 0x130f98
leaq 0xa3843(%rip), %rsi     # 0xbc88d
callq 0x106c0
movq -0x4e0(%rbp), %rsi
movq %rax, %rdi
callq 0x10600
movq %rax, %rdi
leaq 0xa359f(%rip), %rsi     # 0xbc607
callq 0x106c0
movq -0x4e0(%rbp), %rsi
leaq -0x98(%rbp), %rdi
movq %rdi, -0x4d8(%rbp)
callq 0x10300
movq -0x4d8(%rbp), %rsi
leaq -0x78(%rbp), %rdi
callq 0x17970
jmp 0x19099
leaq -0x98(%rbp), %rdi
callq 0x10460
movq 0x117eec(%rip), %rdi    # 0x130f98
leaq 0xa37ee(%rip), %rsi     # 0xbc8a1
callq 0x106c0
movq %rax, -0x508(%rbp)
jmp 0x190c1
leaq -0x78(%rbp), %rdi
callq 0x27ac0
movq -0x508(%rbp), %rdi
movq %rax, %rsi
callq 0x10190
movq %rax, -0x510(%rbp)
jmp 0x190e2
movq -0x510(%rbp), %rdi
leaq 0xa37b9(%rip), %rsi     # 0xbc8a9
callq 0x106c0
movq %rax, -0x518(%rbp)
jmp 0x190fe
callq 0x23b20
movq %rax, -0x520(%rbp)
jmp 0x1910c
movq -0x520(%rbp), %rax
movq %rax, -0xb8(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x23cc0
movq %rax, -0x528(%rbp)
jmp 0x19133
movq -0x528(%rbp), %rax
movq %rax, -0xb0(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x23cf0
movq %rax, -0x530(%rbp)
jmp 0x19156
movq -0x530(%rbp), %rsi
movq -0x518(%rbp), %rdi
callq 0x10d40
movq %rax, -0x538(%rbp)
jmp 0x19172
movq -0x538(%rbp), %rdi
leaq 0xa3737(%rip), %rsi     # 0xbc8b7
callq 0x106c0
jmp 0x19187
callq 0x23b20
movq %rax, -0x540(%rbp)
jmp 0x19195
movq -0x540(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x117de3(%rip), %rdi    # 0x130f98
leaq 0xa36d1(%rip), %rsi     # 0xbc88d
callq 0x106c0
movq %rax, -0x548(%rbp)
jmp 0x191ca
movq -0x4f8(%rbp), %rsi
movq -0x548(%rbp), %rdi
callq 0x10600
movq %rax, -0x550(%rbp)
jmp 0x191e6
movq -0x550(%rbp), %rdi
leaq 0xa3413(%rip), %rsi     # 0xbc607
callq 0x106c0
jmp 0x191fb
movq -0x4f8(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x10300
jmp 0x19210
leaq -0xf0(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x17970
jmp 0x19225
leaq -0x110(%rbp), %rdi
callq 0x10460
movq 0x117d60(%rip), %rdi    # 0x130f98
leaq 0xa3662(%rip), %rsi     # 0xbc8a1
callq 0x106c0
movq %rax, -0x558(%rbp)
jmp 0x1924d
leaq -0xf0(%rbp), %rdi
callq 0x27ac0
movq -0x558(%rbp), %rdi
movq %rax, %rsi
callq 0x10190
movq %rax, -0x560(%rbp)
jmp 0x19271
movq -0x560(%rbp), %rdi
leaq 0xa362a(%rip), %rsi     # 0xbc8a9
callq 0x106c0
movq %rax, -0x568(%rbp)
jmp 0x1928d
callq 0x23b20
movq %rax, -0x570(%rbp)
jmp 0x1929b
movq -0x570(%rbp), %rax
movq %rax, -0x120(%rbp)
leaq -0x120(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x23cc0
movq %rax, -0x578(%rbp)
jmp 0x192c2
movq -0x578(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x23cf0
movq %rax, -0x580(%rbp)
jmp 0x192e5
movq -0x580(%rbp), %rsi
movq -0x568(%rbp), %rdi
callq 0x10d40
movq %rax, -0x588(%rbp)
jmp 0x19301
movq -0x588(%rbp), %rdi
leaq 0xa35a8(%rip), %rsi     # 0xbc8b7
callq 0x106c0
jmp 0x19316
movq -0x500(%rbp), %rdi
callq 0x102f0
movq %rax, %rsi
leaq -0x320(%rbp), %rdi
movl $0x10, %edx
callq 0x10780
jmp 0x19338
callq 0x23b20
movq %rax, -0x590(%rbp)
jmp 0x19346
movq -0x590(%rbp), %rax
movq %rax, -0x328(%rbp)
movq -0x328(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x27ae0
leaq -0x358(%rbp), %rdi
callq 0x27b00
cmpl $-0x1, -0x3c(%rbp)
jne 0x1938a
callq 0x108b0
movl %eax, -0x594(%rbp)
jmp 0x19393
movl -0x3c(%rbp), %eax
movl %eax, -0x594(%rbp)
movl -0x594(%rbp), %eax
movl %eax, -0x35c(%rbp)
cmpl $0x2, -0x35c(%rbp)
jge 0x19446
movl $0x2, -0x35c(%rbp)
jmp 0x19446
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x10460
jmp 0x19b18
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19b0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x10460
jmp 0x19b0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19b03
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19af7
movq 0x117b4b(%rip), %rdi    # 0x130f98
leaq 0xa3467(%rip), %rsi     # 0xbc8bb
callq 0x106c0
movq %rax, -0x5a0(%rbp)
jmp 0x19462
movq -0x5a0(%rbp), %rdi
movl -0x35c(%rbp), %esi
callq 0x10ca0
movq %rax, -0x5a8(%rbp)
jmp 0x1947d
movq -0x5a8(%rbp), %rdi
leaq 0xa344a(%rip), %rsi     # 0xbc8d5
callq 0x106c0
jmp 0x19492
movslq -0x35c(%rbp), %rsi
leaq -0x380(%rbp), %rdi
callq 0x25990
jmp 0x194a7
leaq -0x78(%rbp), %rdi
callq 0x27ac0
movl %eax, %esi
movq -0x48(%rbp), %rax
movq %rax, -0x3d8(%rbp)
movq -0x3d8(%rbp), %rdx
leaq -0x3d0(%rbp), %rdi
callq 0x25dd0
jmp 0x194d2
leaq -0x78(%rbp), %rdi
callq 0x273f0
movq %rax, -0x3e0(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x272e0
movq %rax, -0x3e8(%rbp)
leaq -0x3e0(%rbp), %rdi
leaq -0x3e8(%rbp), %rsi
callq 0x27430
testb $0x1, %al
jne 0x1950e
jmp 0x19734
leaq -0xf0(%rbp), %rdi
callq 0x27ac0
movl $0x8, %ecx
mulq %rcx
movq %rax, %rdi
movq $-0x1, %rax
cmovoq %rax, %rdi
callq 0x10040
movq %rax, -0x5b0(%rbp)
jmp 0x1953e
movq -0x5b0(%rbp), %rax
movq %rax, -0x3f0(%rbp)
leaq -0x340(%rbp), %rdi
leaq -0x3f0(%rbp), %rsi
callq 0x27b20
jmp 0x19561
movl $0x20, %edi
callq 0x106e0
movq %rax, -0x5b8(%rbp)
jmp 0x19574
movq -0x5b8(%rbp), %rdi
callq 0x109f0
movq -0x5b8(%rbp), %rax
movq %rax, -0x3f8(%rbp)
leaq -0x358(%rbp), %rdi
leaq -0x3f8(%rbp), %rsi
callq 0x27b50
jmp 0x195a3
leaq -0x3e0(%rbp), %rdi
callq 0x27cf0
movq %rax, -0x5c0(%rbp)
jmp 0x195b8
movq -0x5c0(%rbp), %rsi
leaq -0x4b0(%rbp), %rdi
callq 0x27d10
jmp 0x195cd
leaq -0x340(%rbp), %rdi
callq 0x27d70
movq (%rax), %rax
movq %rax, -0x5c8(%rbp)
leaq -0x358(%rbp), %rdi
callq 0x27db0
movq -0x5c8(%rbp), %r8
movq (%rax), %r9
movq %rsp, %rax
leaq -0x3d0(%rbp), %rcx
movq %rcx, (%rax)
leaq -0x126d(%rip), %rsi     # 0x183a0
leaq -0x478(%rbp), %rdi
leaq -0x4b0(%rbp), %rdx
leaq -0xf0(%rbp), %rcx
callq 0x27b80
jmp 0x19629
leaq -0x418(%rbp), %rdi
leaq -0x478(%rbp), %rsi
xorl %edx, %edx
callq 0x27df0
jmp 0x19640
leaq -0x380(%rbp), %rdi
leaq -0x418(%rbp), %rsi
callq 0x25f80
jmp 0x19655
leaq -0x418(%rbp), %rdi
callq 0x261a0
leaq -0x478(%rbp), %rdi
callq 0x27e80
leaq -0x4b0(%rbp), %rdi
callq 0x27ea0
leaq -0x3e0(%rbp), %rdi
callq 0x27580
jmp 0x19687
jmp 0x194e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19adf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19ad3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19ac7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19723
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
jmp 0x19717
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
leaq -0x418(%rbp), %rdi
callq 0x261a0
leaq -0x478(%rbp), %rdi
callq 0x27e80
leaq -0x4b0(%rbp), %rdi
callq 0x27ea0
jmp 0x19ac7
xorl %eax, %eax
movl %eax, %esi
leaq -0x380(%rbp), %rdi
callq 0x261f0
jmp 0x19746
movq 0x11784b(%rip), %rdi    # 0x130f98
leaq 0xa318b(%rip), %rsi     # 0xbc8df
callq 0x106c0
movq %rax, -0x5d0(%rbp)
jmp 0x19762
leaq -0x78(%rbp), %rdi
callq 0x27ac0
movq %rax, -0x5e0(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x27ac0
movq -0x5e0(%rbp), %rsi
movq -0x5d0(%rbp), %rdi
imulq %rax, %rsi
callq 0x10190
movq %rax, -0x5d8(%rbp)
jmp 0x1979e
movq -0x5d8(%rbp), %rdi
leaq 0xa314a(%rip), %rsi     # 0xbc8f6
callq 0x106c0
movq %rax, -0x5e8(%rbp)
jmp 0x197ba
callq 0x23b20
movq %rax, -0x5f0(%rbp)
jmp 0x197c8
movq -0x5f0(%rbp), %rax
movq %rax, -0x4c0(%rbp)
leaq -0x4c0(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x23cc0
movq %rax, -0x5f8(%rbp)
jmp 0x197ef
movq -0x5f8(%rbp), %rax
movq %rax, -0x4b8(%rbp)
leaq -0x4b8(%rbp), %rdi
callq 0x24480
movq %rax, -0x600(%rbp)
jmp 0x19812
movq -0x600(%rbp), %rsi
movq -0x5e8(%rbp), %rdi
callq 0x10d40
movq %rax, -0x608(%rbp)
jmp 0x1982e
movq -0x608(%rbp), %rdi
leaq 0xa30a0(%rip), %rsi     # 0xbc8dc
callq 0x106c0
jmp 0x19843
movq -0x4f0(%rbp), %rdi
movb $0x0, -0x4c1(%rbp)
callq 0x27ed0
movl $0x0, -0x4c8(%rbp)
movslq -0x4c8(%rbp), %rax
movq %rax, -0x610(%rbp)
leaq -0x340(%rbp), %rdi
callq 0x27ef0
movq %rax, %rcx
movq -0x610(%rbp), %rax
cmpq %rcx, %rax
jae 0x19a20
movslq -0x4c8(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0x27f10
movq (%rax), %rsi
leaq -0x320(%rbp), %rdi
callq 0x10600
jmp 0x198b1
movslq -0x4c8(%rbp), %rsi
leaq -0x358(%rbp), %rdi
callq 0x27f10
movq (%rax), %rax
movq %rax, -0x618(%rbp)
cmpq $0x0, %rax
je 0x198f1
movq -0x618(%rbp), %rdi
callq 0x10460
movq -0x618(%rbp), %rdi
movl $0x20, %esi
callq 0x10710
movl $0x0, -0x4cc(%rbp)
movslq -0x4cc(%rbp), %rax
movq %rax, -0x620(%rbp)
leaq -0xf0(%rbp), %rdi
callq 0x27ac0
movq %rax, %rcx
movq -0x620(%rbp), %rax
cmpq %rcx, %rax
jae 0x199db
movslq -0x4c8(%rbp), %rsi
leaq -0x340(%rbp), %rdi
callq 0x27fa0
movq -0x4f0(%rbp), %rdi
movq (%rax), %rax
movslq -0x4cc(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x27f30
jmp 0x19957
movslq -0x4c8(%rbp), %rsi
leaq -0x340(%rbp), %rdi
callq 0x27fa0
movq (%rax), %rax
movslq -0x4cc(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x628(%rbp)
cmpq $0x0, %rax
je 0x199a2
movq -0x628(%rbp), %rdi
callq 0x27fc0
movq -0x628(%rbp), %rdi
movl $0x50, %esi
callq 0x10710
jmp 0x199a4
movl -0x4cc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4cc(%rbp)
jmp 0x198fb
movq -0x4f0(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xa0(%rbp)
movl %eax, -0xa4(%rbp)
callq 0x27ff0
jmp 0x19ac7
movslq -0x4c8(%rbp), %rsi
leaq -0x340(%rbp), %rdi
callq 0x27fa0
movq (%rax), %rax
movq %rax, -0x630(%rbp)
cmpq $0x0, %rax
je 0x19a0a
movq -0x630(%rbp), %rdi
callq 0x10940
jmp 0x19a0c
movl -0x4c8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c8(%rbp)
jmp 0x19860
movq -0x4f0(%rbp), %rdi
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movq -0x38(%rbp), %rsi
callq 0x187a0
jmp 0x19a3c
leaq -0x320(%rbp), %rdi
callq 0x10a40
jmp 0x19a4a
movb $0x1, -0x4c1(%rbp)
testb $0x1, -0x4c1(%rbp)
jne 0x19a66
movq -0x4f0(%rbp), %rdi
callq 0x27ff0
leaq -0x3d0(%rbp), %rdi
callq 0x26640
leaq -0x380(%rbp), %rdi
callq 0x26680
leaq -0x358(%rbp), %rdi
callq 0x28050
leaq -0x340(%rbp), %rdi
callq 0x280b0
leaq -0x320(%rbp), %rdi
callq 0x10ad0
leaq -0xf0(%rbp), %rdi
callq 0x27280
leaq -0x78(%rbp), %rdi
callq 0x27280
movq -0x4e8(%rbp), %rax
addq $0x640, %rsp            # imm = 0x640
popq %rbp
retq
leaq -0x3d0(%rbp), %rdi
callq 0x26640
leaq -0x380(%rbp), %rdi
callq 0x26680
leaq -0x358(%rbp), %rdi
callq 0x28050
leaq -0x340(%rbp), %rdi
callq 0x280b0
leaq -0x320(%rbp), %rdi
callq 0x10ad0
leaq -0xf0(%rbp), %rdi
callq 0x27280
leaq -0x78(%rbp), %rdi
callq 0x27280
movq -0xa0(%rbp), %rdi
callq 0x10cc0
nopw %cs:(%rax,%rax)