// File: /workspace/github_cpp_makefile_star2_O1/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 $0xc8, %rsp
movq %rdi, 0x8(%rsp)
testq %rsi, %rsi
je 0x14b3c
movq %rsi, %rbx
movsd %xmm1, 0xb8(%rsp)
ucomisd 0x34c0f(%rip), %xmm0    # 0x49078
jne 0x148d1
jp 0x148d1
movq %rbx, %rbp
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %rbx
cmpq 0x8(%rax), %rbx
je 0x145d0
leaq 0x10(%rsp), %r15
leaq 0x78(%rsp), %r12
movabsq $-0x3333333333333333, %r14 # imm = 0xCCCCCCCCCCCCCCCD
movsd 0x40(%rbx), %xmm0
ucomisd 0x34baa(%rip), %xmm0    # 0x49068
jne 0x144c2
jnp 0x144ee
movsd %xmm0, 0x78(%rsp)
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x144e3
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x144ee
movq %r15, %rdi
movq %r12, %rdx
callq 0x3f41c
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movsd -0x8(%rdx), %xmm0
movq %rdx, %rax
subq %rdi, %rax
movq %rax, %rcx
sarq $0x3, %rcx
leaq -0x1(%rcx), %rsi
cmpq $0x2, %rcx
jl 0x14541
leaq -0x1(%rsi), %r8
shrq $0x3f, %r8
addq %rsi, %r8
decq %r8
sarq %r8
movsd (%rdi,%r8,8), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14541
movsd %xmm1, (%rdi,%rsi,8)
cmpq $0x2, %rsi
movq %r8, %rsi
jg 0x14514
jmp 0x14544
movq %rsi, %r8
movsd %xmm0, (%rdi,%r8,8)
movq 0x8(%rsp), %r8
movq 0x8(%r8), %rsi
subq (%r8), %rsi
sarq $0x4, %rsi
imulq %r14, %rsi
movq %rsi, %xmm0
punpckldq 0x34bf5(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x34bfd(%rip), %xmm0    # 0x49170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x34b61(%rip), %xmm1    # 0x490e8
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
cmpq %rsi, %rcx
jbe 0x145bd
cmpq $0x9, %rax
jl 0x145b7
addq $-0x8, %rdx
movsd (%rdx), %xmm0
movsd (%rdi), %xmm1
movsd %xmm1, (%rdx)
subq %rdi, %rdx
sarq $0x3, %rdx
xorl %esi, %esi
callq 0x402e0
addq $-0x8, 0x18(%rsp)
addq $0x50, %rbx
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %rbx
jne 0x144b1
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x70(%rsp)
cmpq %rax, 0x18(%rsp)
je 0x145eb
movq %rax, 0x18(%rsp)
movq 0x8(%rsp), %rax
movq (%rax), %r13
cmpq 0x8(%rax), %r13
movq %rbp, %rbx
je 0x1488b
leaq 0x58(%rsp), %r15
leaq 0x38(%rsp), %r12
leaq 0x88(%rsp), %r14
leaq 0xa8(%rsp), %rbp
movq %r15, 0x48(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x28d6a
movq %r12, 0x28(%rsp)
movq 0x20(%r13), %rsi
movq 0x28(%r13), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x28d6a
movq %r14, 0x78(%rsp)
movq 0x48(%rsp), %rax
cmpq %r15, %rax
je 0x14671
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x1467b
movupd (%r15), %xmm0
movupd %xmm0, (%r14)
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %r15, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq %rbp, 0x98(%rsp)
movq 0x28(%rsp), %rax
cmpq %r12, %rax
je 0x146c4
movq %rax, 0x98(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x146cf
movupd (%r12), %xmm0
movupd %xmm0, (%rbp)
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq %r12, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq %rbx, %rdi
leaq 0x78(%rsp), %rsi
callq 0x40396
movq %rax, %rbp
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x14724
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x1473e
movq 0x88(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x14755
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x1476c
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xd550
testq %rbp, %rbp
je 0x14870
movsd 0x50(%rbp), %xmm0
movsd %xmm0, 0x78(%rsp)
ucomisd 0x348e0(%rip), %xmm0    # 0x49068
jne 0x1478c
jnp 0x147b6
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x147a7
movsd %xmm0, (%rsi)
addq $0x8, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x147b6
leaq 0x10(%rsp), %rdi
leaq 0x78(%rsp), %rdx
callq 0x3479e
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rdx
movsd -0x8(%rdx), %xmm0
movq %rdx, %rax
subq %rdi, %rax
movq %rax, %rcx
sarq $0x3, %rcx
leaq -0x1(%rcx), %rsi
cmpq $0x2, %rcx
jl 0x14809
leaq -0x1(%rsi), %r8
shrq $0x3f, %r8
addq %rsi, %r8
decq %r8
sarq %r8
movsd (%rdi,%r8,8), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x14809
movsd %xmm1, (%rdi,%rsi,8)
cmpq $0x2, %rsi
movq %r8, %rsi
jg 0x147dc
jmp 0x1480c
movq %rsi, %r8
movsd %xmm0, (%rdi,%r8,8)
movsd 0x10(%rbx), %xmm0
unpcklps 0x34942(%rip), %xmm0    # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x3494a(%rip), %xmm0    # 0x49170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
mulsd 0x348ae(%rip), %xmm1    # 0x490e8
cvttsd2si %xmm1, %esi
movslq %esi, %rsi
cmpq %rsi, %rcx
jbe 0x14870
cmpq $0x9, %rax
jl 0x1486a
addq $-0x8, %rdx
movsd (%rdx), %xmm0
movsd (%rdi), %xmm1
movsd %xmm1, (%rdx)
subq %rdi, %rdx
sarq $0x3, %rdx
xorl %esi, %esi
callq 0x402e0
addq $-0x8, 0x18(%rsp)
addq $0x50, %r13
movq 0x8(%rsp), %rax
cmpq 0x8(%rax), %r13
leaq 0xa8(%rsp), %rbp
jne 0x1461a
movq 0x10(%rsp), %rdi
cmpq %rdi, 0x18(%rsp)
je 0x148ab
movsd (%rdi), %xmm0
movsd 0x70(%rsp), %xmm1
addsd %xmm0, %xmm1
divsd %xmm1, %xmm0
jmp 0x148b3
movsd 0x347ad(%rip), %xmm0    # 0x49060
testq %rdi, %rdi
je 0x148d1
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
movsd %xmm0, 0x68(%rsp)
callq 0xd550
movsd 0x68(%rsp), %xmm0
movq 0x8(%rsp), %rax
movq (%rax), %r13
movq 0x8(%rax), %rax
cmpq %rax, %r13
je 0x14ac8
movq %rbx, 0xc0(%rsp)
leaq 0x58(%rsp), %r15
leaq 0x38(%rsp), %r12
leaq 0x88(%rsp), %r14
movsd 0x34770(%rip), %xmm6    # 0x49078
leaq 0xa8(%rsp), %rbx
movsd %xmm0, 0x68(%rsp)
movsd %xmm6, 0x70(%rsp)
movq %r15, 0x48(%rsp)
movq (%r13), %rsi
movq 0x8(%r13), %rdx
addq %rsi, %rdx
leaq 0x48(%rsp), %rdi
callq 0x28d6a
movq %r12, 0x28(%rsp)
movq 0x20(%r13), %rsi
movq 0x28(%r13), %rdx
addq %rsi, %rdx
leaq 0x28(%rsp), %rdi
callq 0x28d6a
movq %r14, 0x78(%rsp)
movq 0x48(%rsp), %rax
cmpq %r15, %rax
je 0x14973
movq %rax, 0x78(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x88(%rsp)
jmp 0x1497d
movupd (%r15), %xmm0
movupd %xmm0, (%r14)
movq 0x50(%rsp), %rax
movq %rax, 0x80(%rsp)
movq %r15, 0x48(%rsp)
movq $0x0, 0x50(%rsp)
movb $0x0, 0x58(%rsp)
movq %rbx, 0x98(%rsp)
movq 0x28(%rsp), %rax
cmpq %r12, %rax
je 0x149c6
movq %rax, 0x98(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0xa8(%rsp)
jmp 0x149d0
movupd (%r12), %xmm0
movupd %xmm0, (%rbx)
movq 0x30(%rsp), %rax
movq %rax, 0xa0(%rsp)
movq %r12, 0x28(%rsp)
movq $0x0, 0x30(%rsp)
movb $0x0, 0x38(%rsp)
movq 0xc0(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x40396
movq %rax, %rbp
movq 0x98(%rsp), %rdi
cmpq %rbx, %rdi
je 0x14a22
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0x14a3c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x14a53
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x14a6a
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xd550
testq %rbp, %rbp
je 0x14a95
movsd 0xb8(%rsp), %xmm1
minsd 0x50(%rbp), %xmm1
movsd 0x70(%rsp), %xmm6
ucomisd %xmm6, %xmm1
movsd 0x68(%rsp), %xmm0
jbe 0x14aaa
movapd %xmm1, %xmm6
jmp 0x14aaa
movsd 0xb8(%rsp), %xmm1
movsd 0x68(%rsp), %xmm0
movsd 0x70(%rsp), %xmm6
movsd %xmm1, 0x48(%r13)
addq $0x50, %r13
movq 0x8(%rsp), %rax
movq 0x8(%rax), %rax
cmpq %rax, %r13
jne 0x14916
jmp 0x14ad0
movsd 0x345a8(%rip), %xmm6    # 0x49078
movq 0x8(%rsp), %rcx
movq (%rcx), %rcx
cmpq %rax, %rcx
movsd 0xb8(%rsp), %xmm4
je 0x14b3c
movsd 0x34572(%rip), %xmm5    # 0x49060
subsd %xmm0, %xmm5
movsd 0x345f6(%rip), %xmm1    # 0x490f0
movsd 0x48(%rcx), %xmm2
movapd %xmm2, %xmm3
divsd %xmm6, %xmm3
cmpltsd %xmm4, %xmm2
andpd %xmm2, %xmm3
andnpd %xmm1, %xmm2
orpd %xmm3, %xmm2
movlpd %xmm2, 0x48(%rcx)
mulsd %xmm5, %xmm2
movsd 0x40(%rcx), %xmm3
mulsd %xmm0, %xmm3
addsd %xmm2, %xmm3
movsd %xmm3, 0x40(%rcx)
addq $0x50, %rcx
cmpq %rax, %rcx
jne 0x14afa
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x14b54
jmp 0x14b54
jmp 0x14b54
movq %rax, %rbx
jmp 0x14b99
movq %rax, %rbx
jmp 0x14b82
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1e644
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x14b82
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x14b99
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x14bed
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
jmp 0x14be8
movq %rax, %rbx
jmp 0x14bd6
movq %rax, %rbx
leaq 0x78(%rsp), %rdi
callq 0x1e644
movq 0x28(%rsp), %rdi
cmpq %r12, %rdi
je 0x14bd6
movq 0x38(%rsp), %rsi
incq %rsi
callq 0xd550
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x14bed
movq 0x58(%rsp), %rsi
incq %rsi
callq 0xd550
movq %rbx, %rdi
callq 0xd9c0