// File: Kingsford-Group[P]ghost2/src/spectralToDistance.hpp
// Function: applyAlpha(double, double, std::vector<D_alpha, std::allocator<D_alpha>>*, 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>>>*)
void applyAlpha(double a, double b, vector<D_alpha> *scores, blastmap* blastscores)
{
  if(!blastscores) return;

  if(a == -1){
    vector<double> maxheap;
    for(auto it = scores->begin(); it != scores->end(); it++){
      if(it->get_da() != 0) maxheap.push_back(it->get_da());
      push_heap(maxheap.begin(), maxheap.end());
      if(maxheap.size() > (int)(.0005 * scores->size())){
        pop_heap(maxheap.begin(), maxheap.end());
        maxheap.pop_back();
      }
    }
    double structval = maxheap.front();

    maxheap.clear();
    for(auto it = scores->begin(); it != scores->end(); it++){
      auto sc = blastscores->find(make_pair(it->get_n1(), it->get_n2()));
      if(sc == blastscores->end()) continue;
      double score = sc->second;
      if(score != 0) maxheap.push_back(score);
      push_heap(maxheap.begin(), maxheap.end());
      if(maxheap.size() > (int)(.0005 * blastscores->size())){
        pop_heap(maxheap.begin(), maxheap.end());
        maxheap.pop_back();
      }
    }
    if(maxheap.size() == 0) a = 1;
    else {
      double seqval = maxheap.front();
      a = seqval / (seqval + structval);
    }
  }

  double maxScore = -1;
  for(auto it = scores->begin(); it != scores->end(); it++){
    double seq;
    auto d = blastscores->find(make_pair(it->get_n1(), it->get_n2()));
    if(d != blastscores->end()){
      seq = d->second;
      if(seq > b) seq = b;
      if(seq > maxScore) maxScore = seq;
    }else seq = b;
    it->set_seq(seq);
  }

  for(auto it = scores->begin(); it != scores->end(); it++){
    double seq = it->get_ds();
    if(seq < b) it->set_seq(seq/maxScore);
    else it->set_seq(1.1);
    it->update_da(a);
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2b0, %rsp            # imm = 0x2B0
movsd %xmm0, -0x8(%rbp)
movsd %xmm1, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq %rsi, -0x20(%rbp)
cmpq $0x0, -0x20(%rbp)
jne 0x187c9
jmp 0x18fca
movsd -0x8(%rbp), %xmm0
movsd 0xa38a2(%rip), %xmm1    # 0xbc078
ucomisd %xmm1, %xmm0
jne 0x18ccf
jp 0x18ccf
leaq -0x38(%rbp), %rdi
callq 0x251f0
movq -0x18(%rbp), %rdi
callq 0x275a0
movq %rax, -0x40(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27610
movq %rax, -0x48(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x275d0
testb $0x1, %al
jne 0x1881f
jmp 0x18983
leaq -0x40(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
callq 0x27660
movsd %xmm0, -0x248(%rbp)
jmp 0x1883a
movsd -0x248(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x1884f
jp 0x1884f
jmp 0x18899
leaq -0x40(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
callq 0x27660
movsd %xmm0, -0x250(%rbp)
jmp 0x1886a
movsd -0x250(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x38(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x26c10
jmp 0x18886
jmp 0x18899
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x18cc1
leaq -0x38(%rbp), %rdi
movq %rdi, -0x258(%rbp)
callq 0x276f0
movq -0x258(%rbp), %rdi
movq %rax, -0x68(%rbp)
callq 0x27720
movq %rax, -0x70(%rbp)
movq -0x68(%rbp), %rdi
movq -0x70(%rbp), %rsi
callq 0x27680
jmp 0x188cc
leaq -0x38(%rbp), %rdi
callq 0x254e0
movq %rax, -0x260(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27750
movq %rax, %rcx
movq -0x260(%rbp), %rax
movq %rcx, %xmm1
movaps 0xa3835(%rip), %xmm0    # 0xbc130
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xa3839(%rip), %xmm0    # 0xbc140
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0xa37ba(%rip), %xmm0    # 0xbc0d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x1896a
leaq -0x38(%rbp), %rdi
movq %rdi, -0x268(%rbp)
callq 0x276f0
movq -0x268(%rbp), %rdi
movq %rax, -0x78(%rbp)
callq 0x27720
movq %rax, -0x80(%rbp)
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x27780
jmp 0x18961
leaq -0x38(%rbp), %rdi
callq 0x277e0
jmp 0x1896c
leaq -0x40(%rbp), %rdi
xorl %esi, %esi
callq 0x27810
movq %rax, -0x88(%rbp)
jmp 0x187fc
leaq -0x38(%rbp), %rdi
callq 0x27850
movsd (%rax), %xmm0
movsd %xmm0, -0x90(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x27880
movq -0x18(%rbp), %rdi
callq 0x275a0
movq %rax, -0x98(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27610
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x275d0
testb $0x1, %al
jne 0x189dd
jmp 0x18c62
movq -0x20(%rbp), %rax
movq %rax, -0x270(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x27640
movq %rax, %rsi
leaq -0x108(%rbp), %rdi
callq 0x27920
jmp 0x18a05
leaq -0x98(%rbp), %rdi
callq 0x27640
movq %rax, %rsi
leaq -0x128(%rbp), %rdi
callq 0x27950
jmp 0x18a22
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
leaq -0x128(%rbp), %rdx
callq 0x278e0
jmp 0x18a3e
movq -0x270(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
callq 0x278a0
movq %rax, -0x278(%rbp)
jmp 0x18a5a
movq -0x278(%rbp), %rax
movq %rax, -0xa8(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x267e0
leaq -0x128(%rbp), %rdi
callq 0x10460
leaq -0x108(%rbp), %rdi
callq 0x10460
movq -0x20(%rbp), %rdi
callq 0x279b0
movq %rax, -0x130(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0x130(%rbp), %rsi
callq 0x27980
testb $0x1, %al
jne 0x18ab5
jmp 0x18b0b
jmp 0x18c48
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x18afa
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x18aee
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xe8(%rbp), %rdi
callq 0x267e0
leaq -0x128(%rbp), %rdi
callq 0x10460
leaq -0x108(%rbp), %rdi
callq 0x10460
jmp 0x18cc1
leaq -0xa8(%rbp), %rdi
callq 0x279d0
movq %rax, -0x280(%rbp)
jmp 0x18b20
movq -0x280(%rbp), %rax
movsd 0x40(%rax), %xmm0
movsd %xmm0, -0x138(%rbp)
movsd -0x138(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x18b49
jp 0x18b49
jmp 0x18b5d
leaq -0x38(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x253d0
jmp 0x18b5b
jmp 0x18b5d
leaq -0x38(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x276f0
movq -0x288(%rbp), %rdi
movq %rax, -0x140(%rbp)
callq 0x27720
movq %rax, -0x148(%rbp)
movq -0x140(%rbp), %rdi
movq -0x148(%rbp), %rsi
callq 0x27680
jmp 0x18b9c
leaq -0x38(%rbp), %rdi
callq 0x254e0
movq %rax, -0x290(%rbp)
movq -0x20(%rbp), %rdi
callq 0x279f0
movq %rax, %rcx
movq -0x290(%rbp), %rax
movq %rcx, %xmm1
movaps 0xa3565(%rip), %xmm0    # 0xbc130
punpckldq %xmm0, %xmm1    # xmm1 = xmm1[0],xmm0[0],xmm1[1],xmm0[1]
movapd 0xa3569(%rip), %xmm0    # 0xbc140
subpd %xmm0, %xmm1
movaps %xmm1, %xmm0
unpckhpd %xmm1, %xmm1            # xmm1 = xmm1[1,1]
addsd %xmm0, %xmm1
movsd 0xa34ea(%rip), %xmm0    # 0xbc0d8
mulsd %xmm1, %xmm0
cvttsd2si %xmm0, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x18c46
leaq -0x38(%rbp), %rdi
movq %rdi, -0x298(%rbp)
callq 0x276f0
movq -0x298(%rbp), %rdi
movq %rax, -0x150(%rbp)
callq 0x27720
movq %rax, -0x158(%rbp)
movq -0x150(%rbp), %rdi
movq -0x158(%rbp), %rsi
callq 0x27780
jmp 0x18c3d
leaq -0x38(%rbp), %rdi
callq 0x277e0
jmp 0x18c48
leaq -0x98(%rbp), %rdi
xorl %esi, %esi
callq 0x27810
movq %rax, -0x160(%rbp)
jmp 0x189b1
leaq -0x38(%rbp), %rdi
callq 0x254e0
cmpq $0x0, %rax
jne 0x18c80
movsd 0xa33f7(%rip), %xmm0    # 0xbc070
movsd %xmm0, -0x8(%rbp)
jmp 0x18cb6
leaq -0x38(%rbp), %rdi
callq 0x27850
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
movsd -0x168(%rbp), %xmm0
movsd -0x168(%rbp), %xmm1
addsd -0x90(%rbp), %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x25480
jmp 0x18ccf
leaq -0x38(%rbp), %rdi
callq 0x25480
jmp 0x18fd3
movsd 0xa33a1(%rip), %xmm0    # 0xbc078
movsd %xmm0, -0x170(%rbp)
movq -0x18(%rbp), %rdi
callq 0x275a0
movq %rax, -0x178(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27610
movq %rax, -0x180(%rbp)
leaq -0x178(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x275d0
testb $0x1, %al
jne 0x18d1b
jmp 0x18eea
movq -0x20(%rbp), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x178(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x27640
movq %rax, %rsi
leaq -0x1f0(%rbp), %rdi
callq 0x27920
movq -0x2a0(%rbp), %rdi
callq 0x27640
movq %rax, %rsi
leaq -0x210(%rbp), %rdi
callq 0x27950
jmp 0x18d65
leaq -0x1d0(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0x278e0
jmp 0x18d81
movq -0x2a8(%rbp), %rdi
leaq -0x1d0(%rbp), %rsi
callq 0x278a0
movq %rax, -0x2b0(%rbp)
jmp 0x18d9d
movq -0x2b0(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x267e0
leaq -0x210(%rbp), %rdi
callq 0x10460
leaq -0x1f0(%rbp), %rdi
callq 0x10460
movq -0x20(%rbp), %rdi
callq 0x279b0
movq %rax, -0x218(%rbp)
leaq -0x190(%rbp), %rdi
leaq -0x218(%rbp), %rsi
callq 0x27a10
testb $0x1, %al
jne 0x18dfb
jmp 0x18ea7
leaq -0x190(%rbp), %rdi
callq 0x279d0
movsd 0x40(%rax), %xmm0
movsd %xmm0, -0x188(%rbp)
movsd -0x188(%rbp), %xmm0
ucomisd -0x10(%rbp), %xmm0
jbe 0x18e83
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
jmp 0x18e83
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x18e72
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x18e66
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x1d0(%rbp), %rdi
callq 0x267e0
leaq -0x210(%rbp), %rdi
callq 0x10460
leaq -0x1f0(%rbp), %rdi
callq 0x10460
jmp 0x18fd3
movsd -0x188(%rbp), %xmm0
ucomisd -0x170(%rbp), %xmm0
jbe 0x18ea5
movsd -0x188(%rbp), %xmm0
movsd %xmm0, -0x170(%rbp)
jmp 0x18eb4
movsd -0x10(%rbp), %xmm0
movsd %xmm0, -0x188(%rbp)
leaq -0x178(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
movsd -0x188(%rbp), %xmm0
callq 0x27a40
leaq -0x178(%rbp), %rdi
xorl %esi, %esi
callq 0x27810
movq %rax, -0x220(%rbp)
jmp 0x18cef
movq -0x18(%rbp), %rdi
callq 0x275a0
movq %rax, -0x228(%rbp)
movq -0x18(%rbp), %rdi
callq 0x27610
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x275d0
testb $0x1, %al
jne 0x18f26
jmp 0x18fca
leaq -0x228(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
callq 0x27a60
movsd %xmm0, -0x238(%rbp)
movsd -0x238(%rbp), %xmm1
movsd -0x10(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x18f7b
leaq -0x228(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
movsd -0x238(%rbp), %xmm0
divsd -0x170(%rbp), %xmm0
callq 0x27a40
jmp 0x18f97
leaq -0x228(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
movsd 0xa313e(%rip), %xmm0    # 0xbc0d0
callq 0x27a40
leaq -0x228(%rbp), %rdi
callq 0x27640
movq %rax, %rdi
movsd -0x8(%rbp), %xmm0
callq 0x27a80
leaq -0x228(%rbp), %rdi
xorl %esi, %esi
callq 0x27810
movq %rax, -0x240(%rbp)
jmp 0x18efa
addq $0x2b0, %rsp            # imm = 0x2B0
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x10cc0
nopl (%rax)