// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movsd %xmm1, 0x28(%rsp)
movsd %xmm0, 0x18(%rsp)
movq %rsi, 0x30(%rsp)
testq %rsi, %rsi
je 0x1337e
movq %rdi, %rbx
movsd 0x18(%rsp), %xmm0
ucomisd 0x2d03b(%rip), %xmm0    # 0x40078
jne 0x1326e
jp 0x1326e
xorpd %xmm0, %xmm0
movq %rsp, %r15
movapd %xmm0, (%r15)
andq $0x0, 0x10(%r15)
movq (%rbx), %r14
xorl %esi, %esi
leaq 0x78(%rsp), %r12
pushq $0x50
popq %r13
cmpq 0x8(%rbx), %r14
je 0x13112
movsd 0x40(%r14), %xmm0
ucomisd 0x2d000(%rip), %xmm0    # 0x40080
jne 0x13084
jnp 0x1309a
movsd %xmm0, 0x78(%rsp)
movq %r15, %rdi
movq %r12, %rsi
callq 0x381ac
movq 0x8(%rsp), %rsi
movq (%rsp), %rdi
callq 0x19b31
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rsi, %rcx
subq %rdi, %rcx
movq 0x8(%rbx), %rax
subq (%rbx), %rax
sarq $0x3, %rcx
cqto
idivq %r13
movq %rax, %xmm0
punpckldq 0x2d091(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2d099(%rip), %xmm0    # 0x40170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x2cff5(%rip), %xmm1    # 0x400e0
cvttsd2si %xmm1, %eax
cltq
cmpq %rax, %rcx
jbe 0x13109
callq 0x19b4f
movq 0x8(%rsp), %rsi
addq $-0x8, %rsi
movq %rsi, 0x8(%rsp)
addq $0x50, %r14
jmp 0x13068
movq (%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x20(%rsp)
cmpq %rax, %rsi
je 0x1312a
movq %rax, 0x8(%rsp)
movq (%rbx), %r15
leaq 0x58(%rsp), %r12
leaq 0x38(%rsp), %r13
leaq 0x78(%rsp), %rbp
cmpq %r14, %r15
je 0x13233
movq %r12, %rdi
movq %r15, %rsi
callq 0xe7a0
addq $0x20, %r15
movq %r13, %rdi
movq %r15, %rsi
callq 0xe7a0
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x21772
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x38f6c
movq %rax, %r14
movq %rbp, %rdi
callq 0x19672
movq %r13, %rdi
callq 0xe290
movq %r12, %rdi
callq 0xe290
testq %r14, %r14
je 0x13226
movsd 0x50(%r14), %xmm0
movsd %xmm0, 0x78(%rsp)
ucomisd 0x2cece(%rip), %xmm0    # 0x40080
jne 0x131b6
jnp 0x131c1
movq %rsp, %rdi
movq %rbp, %rsi
callq 0x18f0c
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x19b31
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
movq %rsi, %rax
subq %rdi, %rax
sarq $0x3, %rax
movq 0x30(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
unpcklps 0x2cf6d(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x2cf75(%rip), %xmm0    # 0x40170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x2ced1(%rip), %xmm1    # 0x400e0
cvttsd2si %xmm1, %ecx
movslq %ecx, %rcx
cmpq %rcx, %rax
jbe 0x13226
callq 0x19b4f
addq $-0x8, 0x8(%rsp)
movq 0x8(%rbx), %r14
addq $0x30, %r15
jmp 0x1313c
movq (%rsp), %rax
cmpq %rax, 0x8(%rsp)
je 0x13258
movsd (%rax), %xmm1
movsd 0x20(%rsp), %xmm0
addsd %xmm1, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
jmp 0x13266
movsd 0x2ce10(%rip), %xmm0    # 0x40070
movsd %xmm0, 0x18(%rsp)
movq %rsp, %rdi
callq 0x29310
movq (%rbx), %r15
movsd 0x2cdff(%rip), %xmm0    # 0x40078
movsd %xmm0, 0x20(%rsp)
leaq 0x58(%rsp), %r12
leaq 0x38(%rsp), %r13
leaq 0x78(%rsp), %rbp
cmpq 0x8(%rbx), %r15
je 0x1331b
movq %r12, %rdi
movq %r15, %rsi
callq 0xe7a0
leaq 0x20(%r15), %rsi
movq %r13, %rdi
callq 0xe7a0
movq %rbp, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x21772
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x38f6c
movq %rax, %r14
movq %rbp, %rdi
callq 0x19672
movq %r13, %rdi
callq 0xe290
movq %r12, %rdi
callq 0xe290
testq %r14, %r14
je 0x13306
movsd 0x28(%rsp), %xmm0
minsd 0x50(%r14), %xmm0
ucomisd 0x20(%rsp), %xmm0
jbe 0x1330c
movsd %xmm0, 0x20(%rsp)
jmp 0x1330c
movsd 0x28(%rsp), %xmm0
movsd %xmm0, 0x48(%r15)
addq $0x50, %r15
jmp 0x1328e
movq (%rbx), %rax
movsd 0x2cd4a(%rip), %xmm0    # 0x40070
subsd 0x18(%rsp), %xmm0
movsd 0x2cdb4(%rip), %xmm1    # 0x400e8
cmpq %rax, %r15
je 0x1337e
movsd 0x48(%rax), %xmm2
movapd %xmm2, %xmm3
divsd 0x20(%rsp), %xmm3
cmpltsd 0x28(%rsp), %xmm2
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movlpd %xmm2, 0x48(%rax)
mulsd %xmm0, %xmm2
movsd 0x40(%rax), %xmm3
mulsd 0x18(%rsp), %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x40(%rax)
addq $0x50, %rax
jmp 0x13334
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x133be
jmp 0x133be
movq %rax, %rbx
jmp 0x133b0
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x19672
leaq 0x38(%rsp), %rdi
callq 0xe290
leaq 0x58(%rsp), %rdi
callq 0xe290
jmp 0x133c1
jmp 0x133be
movq %rax, %rbx
movq %rsp, %rdi
callq 0x29310
jmp 0x133f1
movq %rax, %rbx
jmp 0x133e7
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x19672
leaq 0x38(%rsp), %rdi
callq 0xe290
leaq 0x58(%rsp), %rdi
callq 0xe290
movq %rbx, %rdi
callq 0xe9f0