// File: /workspace/github_cpp_makefile_star2_O2/aalto-speech[P]ftk/src/Unigrams.cc
// Function: Unigrams::rank_candidates(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>> const&, std::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, double>>>&, std::vector<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, double>>>&)
flt_type
Unigrams::rank_candidates(const map<string, flt_type> &words,
                          const map<string, flt_type> &vocab,
                          const set<string> &candidates,
                          map<string, flt_type> &new_freqs,
                          vector<pair<string, flt_type> > &removal_scores)
{
    new_freqs.clear();
    removal_scores.clear();

    StringSet ss_vocab(vocab);
    map<string, flt_type> ll_diffs;
    map<string, flt_type> token_diffs;
    set<string> problem_hypos;

    flt_type curr_ll = 0.0;
    flt_type token_count = 0.0;

    for (auto worditer = words.cbegin(); worditer != words.cend(); ++worditer) {

        map<string, flt_type> stats;
        flt_type orig_score = segf(ss_vocab, worditer->first, stats, this->utf8);

        if (stats.size() == 0) {
            cerr << "warning, no segmentation for word: " << worditer->first << endl;
            continue;
        }

        curr_ll += worditer->second * orig_score;
        token_count += worditer->second * stats.size();

        // Update statistics
        for (auto it = stats.cbegin(); it != stats.cend(); ++it)
            new_freqs[it->first] += worditer->second * it->second;

        for (auto hypoiter = stats.cbegin(); hypoiter != stats.cend(); ++hypoiter) {

            if (candidates.find(hypoiter->first) != candidates.end()) {

                flt_type stored_value = ss_vocab.remove(hypoiter->first);

                map<string, flt_type> hypo_stats;
                flt_type hypo_score = segf(ss_vocab, worditer->first, hypo_stats, this->utf8);

                if (hypo_stats.size() > 0) {
                    ll_diffs[hypoiter->first] += worditer->second * (hypo_score-orig_score);
                    token_diffs[hypoiter->first] += worditer->second * ((flt_type)(hypo_stats.size())-(flt_type)(stats.size()));
                }
                else
                    problem_hypos.insert(hypoiter->first);

                ss_vocab.add(hypoiter->first, stored_value);
            }
        }
    }

    for (auto iter = ll_diffs.begin(); iter != ll_diffs.end(); ++iter) {
        if (problem_hypos.find(iter->first) != problem_hypos.end()) continue;
        flt_type renormalizer = sub_log_domain_probs(0, vocab.at(iter->first));
        flt_type hypo_token_count = (token_count + token_diffs[iter->first]);
        flt_type normalizer_ll_diff = hypo_token_count * -renormalizer;
        pair<string, flt_type> removal_score = make_pair(iter->first, iter->second + normalizer_ll_diff);
        removal_scores.push_back(removal_score);
    }

    sort(removal_scores.begin(), removal_scores.end(), descending_sort);

    return curr_ll;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2a8, %rsp            # imm = 0x2A8
movq %r9, %rbx
movq %rcx, %r15
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, -0x60(%rbp)
movq %r8, -0x48(%rbp)
movq %r8, %rdi
callq 0x19cca
movq %rbx, -0x50(%rbp)
movq %rbx, %rdi
callq 0x1d9fe
leaq -0x2c8(%rbp), %rbx
movq %rbx, %rdi
movq %r14, -0xc8(%rbp)
movq %r14, %rsi
callq 0xb698
leaq -0x170(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x1a0(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x140(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x18(%r12), %r13
addq $0x8, %r12
movq %r12, -0xd0(%rbp)
leaq -0x90(%rbp), %r14
movq %r15, -0xe8(%rbp)
leaq 0x8(%r15), %rax
movq %rax, -0xe0(%rbp)
xorpd %xmm0, %xmm0
movapd %xmm0, -0xc0(%rbp)
movapd %xmm0, -0xb0(%rbp)
cmpq -0xd0(%rbp), %r13
je 0x1d276
andl $0x0, -0x90(%rbp)
andq $0x0, -0x88(%rbp)
movq %r14, -0x80(%rbp)
movq %r14, -0x78(%rbp)
andq $0x0, -0x70(%rbp)
leaq 0x20(%r13), %rsi
movq -0x60(%rbp), %rax
movzbl 0x8(%rax), %ecx
movq %rbx, %rdi
movq %rsi, -0x68(%rbp)
leaq -0x98(%rbp), %rdx
callq *(%rax)
movsd %xmm0, -0x58(%rbp)
movq -0x70(%rbp), %rax
testq %rax, %rax
je 0x1d233
movsd 0x40(%r13), %xmm0
movq %rax, %xmm1
punpckldq 0x6840(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x6848(%rip), %xmm1     # 0x23850
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
mulsd %xmm0, %xmm2
mulsd -0x58(%rbp), %xmm0
movapd -0xb0(%rbp), %xmm1
addsd %xmm0, %xmm1
movapd %xmm1, -0xb0(%rbp)
movapd -0xc0(%rbp), %xmm0
addsd %xmm2, %xmm0
movapd %xmm0, -0xc0(%rbp)
movq -0x80(%rbp), %r15
cmpq %r14, %r15
je 0x1d090
movsd 0x40(%r13), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq 0x20(%r15), %rsi
movsd 0x40(%r15), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x48(%rbp), %rdi
callq 0x18d90
movsd -0x38(%rbp), %xmm0
mulsd -0x30(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x43b0
movq %rax, %r15
jmp 0x1d049
movq -0x80(%rbp), %r15
cmpq %r14, %r15
je 0x1d25a
leaq 0x20(%r15), %r12
movq -0xe8(%rbp), %rdi
movq %r12, %rsi
callq 0xf572
cmpq -0xe0(%rbp), %rax
je 0x1d223
movq %rbx, %rdi
movq %r12, %rsi
callq 0xbca2
movsd %xmm0, -0x38(%rbp)
movq %r15, -0x30(%rbp)
movq %r13, %r15
andl $0x0, -0x110(%rbp)
andq $0x0, -0x108(%rbp)
leaq -0x110(%rbp), %rax
movq %rax, -0x100(%rbp)
movq %rax, -0xf8(%rbp)
andq $0x0, -0xf0(%rbp)
movq -0x60(%rbp), %rax
movzbl 0x8(%rax), %ecx
movq %rbx, %r13
movq %rbx, %rdi
movq -0x68(%rbp), %rsi
leaq -0x118(%rbp), %rdx
callq *(%rax)
cmpq $0x0, -0xf0(%rbp)
je 0x1d1e7
movsd 0x40(%r15), %xmm1
movsd %xmm1, -0xd8(%rbp)
leaq -0x178(%rbp), %rdi
movq %r12, %rsi
movsd %xmm0, -0x40(%rbp)
callq 0x18d90
movsd -0x40(%rbp), %xmm0
subsd -0x58(%rbp), %xmm0
movsd -0xd8(%rbp), %xmm1
mulsd %xmm0, %xmm1
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
movsd 0x40(%r15), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0xf0(%rbp), %r14
movq -0x70(%rbp), %rbx
leaq -0x1a8(%rbp), %rdi
movq %r12, %rsi
callq 0x18d90
movq %r14, %xmm0
movq 0x66a5(%rip), %xmm2     # 0x23840
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x66a9(%rip), %xmm3     # 0x23850
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %rbx, %xmm0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
subpd %xmm3, %xmm0
movapd %xmm0, %xmm2
unpckhpd %xmm0, %xmm2            # xmm2 = xmm2[1],xmm0[1]
addsd %xmm0, %xmm2
subsd %xmm2, %xmm1
movsd -0x40(%rbp), %xmm0
mulsd %xmm1, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
jmp 0x1d1f6
leaq -0x148(%rbp), %rdi
movq %r12, %rsi
callq 0x123ba
movq %r13, %rdi
movq %r12, %rsi
movsd -0x38(%rbp), %xmm0
callq 0xb89a
leaq -0x118(%rbp), %rdi
callq 0x543e
movq %r13, %rbx
leaq -0x90(%rbp), %r14
movq %r15, %r13
movq -0x30(%rbp), %r15
movq %r15, %rdi
callq 0x43b0
movq %rax, %r15
jmp 0x1d094
movq 0x17dae(%rip), %rdi     # 0x34fe8
leaq 0x661f(%rip), %rsi      # 0x23860
callq 0x4340
movq %rax, %rdi
movq -0x68(%rbp), %rsi
callq 0x4300
movq %rax, %rdi
callq 0x4180
leaq -0x98(%rbp), %rdi
callq 0x543e
movq %r13, %rdi
callq 0x43b0
movq %rax, %r13
jmp 0x1cf96
movq -0x160(%rbp), %r15
leaq -0x148(%rbp), %rbx
leaq -0x1a8(%rbp), %r14
leaq -0x98(%rbp), %r12
leaq -0x170(%rbp), %rax
cmpq %rax, %r15
je 0x1d34c
leaq 0x20(%r15), %r13
movq %rbx, %rdi
movq %r13, %rsi
callq 0x1edee
leaq -0x140(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1d33c
movq -0xc8(%rbp), %rdi
movq %r13, %rsi
callq 0x19102
movsd (%rax), %xmm0
callq 0x1d428
movsd %xmm0, -0x38(%rbp)
movq %r14, %rdi
movq %r13, %rsi
callq 0x18d90
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x40(%r15), %xmm0
movsd %xmm0, -0x30(%rbp)
movq %r12, %rdi
movq %r13, %rsi
callq 0x4460
movsd -0x48(%rbp), %xmm1
addsd -0xc0(%rbp), %xmm1
movsd -0x38(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd -0x30(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x78(%rbp)
movq -0x50(%rbp), %rdi
movq %r12, %rsi
callq 0x1da2e
movq %r12, %rdi
callq 0x46b8
movq %r15, %rdi
callq 0x4270
movq %rax, %r15
jmp 0x1d292
movq -0x50(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
leaq -0x1972(%rip), %rdx     # 0x1b9ec
callq 0x1e41e
leaq -0x148(%rbp), %rdi
callq 0x53c6
leaq -0x1a8(%rbp), %rdi
callq 0x543e
leaq -0x178(%rbp), %rdi
callq 0x543e
leaq -0x2c8(%rbp), %rdi
callq 0xb94c
movaps -0xb0(%rbp), %xmm0
addq $0x2a8, %rsp            # imm = 0x2A8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1d3c5
jmp 0x1d3c5
jmp 0x1d3c5
jmp 0x1d3c5
movq %rax, %rbx
leaq -0x98(%rbp), %rdi
callq 0x46b8
jmp 0x1d3f0
movq %rax, %rbx
jmp 0x1d3f0
jmp 0x1d3d0
jmp 0x1d3d0
jmp 0x1d3d0
movq %rax, %rbx
jmp 0x1d3e4
movq %rax, %rbx
leaq -0x118(%rbp), %rdi
callq 0x543e
leaq -0x98(%rbp), %rdi
callq 0x543e
leaq -0x148(%rbp), %rdi
callq 0x53c6
leaq -0x1a8(%rbp), %rdi
callq 0x543e
leaq -0x178(%rbp), %rdi
callq 0x543e
leaq -0x2c8(%rbp), %rdi
callq 0xb94c
movq %rbx, %rdi
callq 0x45f0