// File: aalto-speech[P]ftk/src/Bigrams.cc
// Function: Bigrams::rank_candidate_subwords(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&, MultiStringFactorGraph 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::map<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>>>, 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, 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::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>>>&, bool, bool)
void
Bigrams::rank_candidate_subwords(const map<string, flt_type> &words,
                                 const MultiStringFactorGraph &msfg,
                                 const map<string, flt_type> &unigram_stats,
                                 transitions_t &transitions,
                                 map<string, flt_type> &candidates,
                                 bool forward_backward,
                                 bool normalize_by_bigram_count)
{
    map<string, set<string> > backpointers;
    Bigrams::get_backpointers(msfg, backpointers, 1);
    transitions_t reverse;
    Bigrams::reverse_transitions(transitions, reverse);

    for (auto it = candidates.begin(); it != candidates.end(); ++it) {
        transitions_t changes;
        set<string> words_to_resegment = backpointers.at(it->first);
        flt_type orig_score = likelihood(words, words_to_resegment, msfg, forward_backward);
        flt_type context_score = Bigrams::disable_string(reverse, it->first,
                                                         unigram_stats, transitions, changes);
        flt_type hypo_score = likelihood(words, words_to_resegment, msfg, forward_backward);
        it->second = hypo_score-orig_score + context_score;
        Bigrams::restore_string(transitions, changes);
        if (normalize_by_bigram_count) {
            int num_bigrams = transitions.at(it->first).size() + reverse.at(it->first).size();
            if (it->second < 0) it->second /= num_bigrams;
            else it->second *= num_bigrams;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movl %r9d, %eax
movq %rcx, -0x150(%rbp)
movq %rdx, %rcx
movq -0x150(%rbp), %rdx
movq %rcx, -0x148(%rbp)
movq %rsi, %rcx
movq -0x148(%rbp), %rsi
movq %rcx, -0x140(%rbp)
movq %rdi, %r9
movq -0x140(%rbp), %rdi
movb %al, %cl
movb 0x10(%rbp), %al
movq %r9, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
andb $0x1, %cl
movb %cl, -0x29(%rbp)
andb $0x1, %al
movb %al, -0x2a(%rbp)
leaq -0x60(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x60cb0
movq -0x138(%rbp), %rsi
movq -0x10(%rbp), %rdi
movl $0x1, %edx
callq 0x5fc10
jmp 0x603ac
leaq -0xa0(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x48ab0
movq -0x158(%rbp), %rsi
movq -0x20(%rbp), %rdi
callq 0x5f210
jmp 0x603d1
movq -0x28(%rbp), %rdi
callq 0x58790
movq %rax, -0xa8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x48c90
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x48c30
testb $0x1, %al
jne 0x6040d
jmp 0x606da
leaq -0xe0(%rbp), %rdi
callq 0x48ab0
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0x60cd0
movq %rax, -0x160(%rbp)
jmp 0x6043a
movq -0x160(%rbp), %rsi
leaq -0x110(%rbp), %rdi
callq 0x58ac0
jmp 0x6044f
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movzbl -0x29(%rbp), %ecx
andl $0x1, %ecx
leaq -0x110(%rbp), %rsi
callq 0x45e90
movsd %xmm0, -0x168(%rbp)
jmp 0x60474
movsd -0x168(%rbp), %xmm0
movsd %xmm0, -0x118(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movq %rax, %rsi
movq -0x18(%rbp), %rdx
movq -0x20(%rbp), %rcx
leaq -0xa0(%rbp), %rdi
leaq -0xe0(%rbp), %r8
callq 0x5f320
movsd %xmm0, -0x170(%rbp)
jmp 0x604b8
movsd -0x170(%rbp), %xmm0
movsd %xmm0, -0x120(%rbp)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rdx
movzbl -0x29(%rbp), %ecx
andl $0x1, %ecx
leaq -0x110(%rbp), %rsi
callq 0x45e90
movsd %xmm0, -0x178(%rbp)
jmp 0x604ed
movsd -0x178(%rbp), %xmm0
movsd %xmm0, -0x128(%rbp)
movsd -0x128(%rbp), %xmm0
movsd -0x118(%rbp), %xmm1
subsd %xmm1, %xmm0
movsd -0x120(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0x180(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movsd -0x180(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
movq -0x20(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x5fb10
jmp 0x60550
testb $0x1, -0x2a(%rbp)
je 0x606a3
movq -0x20(%rbp), %rax
movq %rax, -0x190(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movq -0x190(%rbp), %rdi
movq %rax, %rsi
callq 0x60990
movq %rax, -0x188(%rbp)
jmp 0x60589
movq -0x188(%rbp), %rdi
callq 0x5fd0
movq %rax, -0x1a0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movq %rax, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x60990
movq %rax, -0x198(%rbp)
jmp 0x605c0
movq -0x198(%rbp), %rdi
callq 0x5fd0
movq %rax, %rcx
movq -0x1a0(%rbp), %rax
addq %rcx, %rax
movl %eax, -0x12c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
xorps %xmm0, %xmm0
ucomisd 0x20(%rax), %xmm0
jbe 0x60673
cvtsi2sdl -0x12c(%rbp), %xmm0
movsd %xmm0, -0x1a8(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movsd -0x1a8(%rbp), %xmm1
movsd 0x20(%rax), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
jmp 0x606a1
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x60704
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x606f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x606cc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x110(%rbp), %rdi
callq 0x6070
jmp 0x606cc
cvtsi2sdl -0x12c(%rbp), %xmm0
movsd %xmm0, -0x1b0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x587c0
movsd -0x1b0(%rbp), %xmm0
mulsd 0x20(%rax), %xmm0
movsd %xmm0, 0x20(%rax)
jmp 0x606a3
leaq -0x110(%rbp), %rdi
callq 0x6070
leaq -0xe0(%rbp), %rdi
callq 0x48ad0
leaq -0xa8(%rbp), %rdi
callq 0x4bba0
jmp 0x603e1
leaq -0xe0(%rbp), %rdi
callq 0x48ad0
jmp 0x606f8
leaq -0xa0(%rbp), %rdi
callq 0x48ad0
leaq -0x60(%rbp), %rdi
callq 0x60d70
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xa0(%rbp), %rdi
callq 0x48ad0
leaq -0x60(%rbp), %rdi
callq 0x60d70
movq -0x68(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)