// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/Unigrams.cc
// Function: Unigrams::rank_candidates(std::vector<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>>>>&, 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(std::vector<std::string> &sents,
                          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 sentiter = sents.cbegin(); sentiter != sents.cend(); ++sentiter) {

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

        if (stats.size() == 0) {
            cerr << "warning, no segmentation for sentence: " << *sentiter << endl;
            continue;
        }

        curr_ll += orig_score;
        token_count += stats.size();

        // Update statistics
        for (auto it = stats.cbegin(); it != stats.cend(); ++it)
            new_freqs[it->first] += 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, *sentiter, hypo_stats, this->utf8);

                if (hypo_stats.size() > 0) {
                    ll_diffs[hypoiter->first] += (hypo_score-orig_score);
                    token_diffs[hypoiter->first] += (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 $0x288, %rsp            # imm = 0x288
movq %r9, %rbx
movq %rcx, %r13
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, -0xa8(%rbp)
movq %r8, -0x48(%rbp)
movq %r8, %rdi
callq 0x1c04a
movq %rbx, -0x98(%rbp)
movq %rbx, %rdi
callq 0x1fdd8
leaq -0x2a8(%rbp), %rdi
movq %r14, -0xb0(%rbp)
movq %r14, %rsi
callq 0xc850
leaq -0x120(%rbp), %rcx
xorl %eax, %eax
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x180(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x150(%rbp), %rcx
movl %eax, (%rcx)
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
movq (%r15), %r14
movq %r15, -0xb8(%rbp)
cmpq 0x8(%r15), %r14
je 0x1fa44
leaq -0x70(%rbp), %rbx
leaq 0x8(%r13), %rax
movq %rax, -0xc8(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x78(%rbp), %r15
movsd %xmm0, -0x40(%rbp)
movq %r13, -0xc0(%rbp)
movl $0x0, -0x70(%rbp)
xorl %eax, %eax
movq %rax, -0x68(%rbp)
movq %rbx, -0x60(%rbp)
movq %rbx, -0x58(%rbp)
movq %rax, -0x50(%rbp)
movq -0xa8(%rbp), %rax
movzbl 0x8(%rax), %ecx
leaq -0x2a8(%rbp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq *(%rax)
movsd %xmm0, -0xa0(%rbp)
movq -0x50(%rbp), %rax
testq %rax, %rax
je 0x1f9cc
movq %rax, %xmm0
punpckldq 0x70ec(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x70f4(%rip), %xmm0     # 0x268c0
movapd %xmm0, -0x90(%rbp)
movq -0x60(%rbp), %r15
cmpq %rbx, %r15
je 0x1f812
leaq 0x20(%r15), %rsi
movsd 0x40(%r15), %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x48(%rbp), %rdi
callq 0x1b05e
movsd -0x30(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r15, %rdi
callq 0x4410
movq %rax, %r15
cmpq %rbx, %rax
jne 0x1f7dd
movsd -0x38(%rbp), %xmm0
addsd -0xa0(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movapd -0x90(%rbp), %xmm1
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
movsd -0x40(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x40(%rbp)
movq -0x60(%rbp), %r15
cmpq %rbx, %r15
je 0x1fa21
leaq 0x20(%r15), %r12
movq %r13, %rdi
movq %r12, %rsi
callq 0x10d38
cmpq -0xc8(%rbp), %rax
je 0x1f9b6
leaq -0x2a8(%rbp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0xcfc0
movsd %xmm0, -0x30(%rbp)
movl $0x0, -0xf0(%rbp)
xorl %ecx, %ecx
movq %rcx, -0xe8(%rbp)
leaq -0xf0(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq %rax, -0xd8(%rbp)
movq %rcx, -0xd0(%rbp)
movq -0xa8(%rbp), %rax
movzbl 0x8(%rax), %ecx
movq %rbx, %rdi
movq %r14, %rbx
movq %r14, %rsi
leaq -0xf8(%rbp), %rdx
callq *(%rax)
movsd %xmm0, -0x90(%rbp)
cmpq $0x0, -0xd0(%rbp)
je 0x1f979
leaq -0x128(%rbp), %rdi
movq %r12, %rsi
callq 0x1b05e
movsd -0x90(%rbp), %xmm0
subsd -0xa0(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0xd0(%rbp), %r14
movq -0x50(%rbp), %r13
leaq -0x188(%rbp), %rdi
movq %r12, %rsi
callq 0x1b05e
movq %r14, %xmm0
movq 0x6f7a(%rip), %xmm2     # 0x268b0
punpckldq %xmm2, %xmm0    # xmm0 = xmm0[0],xmm2[0],xmm0[1],xmm2[1]
movapd 0x6f7e(%rip), %xmm3     # 0x268c0
subpd %xmm3, %xmm0
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq %r13, %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
addsd (%rax), %xmm1
movsd %xmm1, (%rax)
jmp 0x1f988
leaq -0x158(%rbp), %rdi
movq %r12, %rsi
callq 0x14092
leaq -0x2a8(%rbp), %rdi
movq %r12, %rsi
movsd -0x30(%rbp), %xmm0
callq 0xcac8
leaq -0xf8(%rbp), %rdi
callq 0x5cea
movq -0xc0(%rbp), %r13
movq %rbx, %r14
leaq -0x70(%rbp), %rbx
movq %r15, %rdi
callq 0x4410
movq %rax, %r15
cmpq %rbx, %rax
jne 0x1f853
jmp 0x1fa21
movl $0x27, %edx
movq 0x14610(%rip), %rdi     # 0x33fe8
leaq 0x6f15(%rip), %rsi      # 0x268f4
callq 0x4400
movq (%r14), %rsi
movq 0x8(%r14), %rdx
movq 0x145f6(%rip), %rdi     # 0x33fe8
callq 0x4400
movq %rax, %r15
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r15, %rdi
movl $0xa, %esi
callq 0x4370
movsbl %al, %esi
movq %r15, %rdi
callq 0x4030
movq %rax, %rdi
callq 0x4260
leaq -0x78(%rbp), %r15
movq %r15, %rdi
callq 0x5cea
addq $0x20, %r14
movq -0xb8(%rbp), %rax
cmpq 0x8(%rax), %r14
jne 0x1f76f
jmp 0x1fa52
xorpd %xmm0, %xmm0
movsd %xmm0, -0x40(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x110(%rbp), %rbx
leaq -0x120(%rbp), %rax
cmpq %rax, %rbx
je 0x1fb4c
leaq -0x68(%rbp), %r15
leaq -0x158(%rbp), %r14
leaq -0x78(%rbp), %r12
leaq 0x20(%rbx), %r13
movq %r14, %rdi
movq %r13, %rsi
callq 0x21436
leaq -0x150(%rbp), %rcx
cmpq %rcx, %rax
jne 0x1fb31
movq -0xb0(%rbp), %rdi
movq %r13, %rsi
callq 0x1b4d8
movsd (%rax), %xmm0
callq 0x1f65e
movsd %xmm0, -0x30(%rbp)
leaq -0x188(%rbp), %rdi
movq %r13, %rsi
callq 0x1b05e
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movsd 0x40(%rbx), %xmm0
movsd %xmm0, -0x90(%rbp)
movq %r15, -0x78(%rbp)
movq 0x20(%rbx), %rsi
movq 0x28(%rbx), %rdx
addq %rsi, %rdx
movq %r12, %rdi
callq 0x5f0a
movsd -0x48(%rbp), %xmm1
addsd -0x40(%rbp), %xmm1
movsd -0x30(%rbp), %xmm0
mulsd %xmm1, %xmm0
movsd -0x90(%rbp), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, -0x58(%rbp)
movq -0x98(%rbp), %rdi
movq %r12, %rsi
callq 0x1fe1e
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x1fb31
callq 0x4350
movq %rbx, %rdi
callq 0x4280
movq %rax, %rbx
leaq -0x120(%rbp), %rax
cmpq %rax, %rbx
jne 0x1fa78
movq -0x98(%rbp), %rax
movq (%rax), %rbx
movq 0x8(%rax), %r14
cmpq %r14, %rbx
je 0x1fba8
movq %r14, %rax
subq %rbx, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
leaq -0x255f(%rip), %rcx     # 0x1d62c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x207e0
leaq -0x2571(%rip), %rdx     # 0x1d62c
movq %rbx, %rdi
movq %r14, %rsi
callq 0x208dc
leaq -0x158(%rbp), %rdi
callq 0x5c80
leaq -0x188(%rbp), %rdi
callq 0x5cea
leaq -0x128(%rbp), %rdi
callq 0x5cea
leaq -0x2a8(%rbp), %rdi
callq 0xcb9c
movsd -0x38(%rbp), %xmm0
addq $0x288, %rsp            # imm = 0x288
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1fc0a
jmp 0x1fc0a
jmp 0x1fc0a
jmp 0x1fc0a
movq %rax, %rbx
movq -0x78(%rbp), %rdi
cmpq %r15, %rdi
je 0x1fc32
callq 0x4350
jmp 0x1fc32
movq %rax, %rbx
jmp 0x1fc32
jmp 0x1fc15
jmp 0x1fc15
jmp 0x1fc15
movq %rax, %rbx
jmp 0x1fc29
movq %rax, %rbx
leaq -0xf8(%rbp), %rdi
callq 0x5cea
leaq -0x78(%rbp), %rdi
callq 0x5cea
leaq -0x158(%rbp), %rdi
callq 0x5c80
leaq -0x188(%rbp), %rdi
callq 0x5cea
leaq -0x128(%rbp), %rdi
callq 0x5cea
leaq -0x2a8(%rbp), %rdi
callq 0xcb9c
movq %rbx, %rdi
callq 0x4650