// File: aalto-speech[P]ftk/src/Bigrams.cc
// Function: Bigrams::collect_trans_stats(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&, 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)
flt_type
Bigrams::collect_trans_stats(const map<string, flt_type> &words,
                             MultiStringFactorGraph &msfg,
                             transitions_t &trans_stats,
                             map<string, flt_type> &unigram_stats,
                             bool fb)
{
    trans_stats.clear();
    unigram_stats.clear();

    flt_type total_lp = 0.0;
    if (fb) {
        vector<flt_type> fw(msfg.nodes.size(), MIN_FLOAT);
        fw[0] = 0.0;
        forward(msfg, fw);
        transitions_t word_stats;
        for (auto it = msfg.string_end_nodes.begin(); it != msfg.string_end_nodes.end(); ++it)
            total_lp += words.at(it->first) * backward(msfg, it->first, fw, word_stats, words.at(it->first));
        update_trans_stats(word_stats, 1.0, trans_stats, unigram_stats);
    }
    else {
        total_lp = viterbi(msfg, words, trans_stats);
        finalize_viterbi_stats(msfg, trans_stats);
        get_unigram_stats(trans_stats, unigram_stats);
    }

    return total_lp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movb %r8b, %al
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x18(%rbp), %rdi
callq 0x48490
movq -0x20(%rbp), %rdi
callq 0x47d90
xorps %xmm0, %xmm0
movsd %xmm0, -0x30(%rbp)
testb $0x1, -0x21(%rbp)
je 0x5cbd1
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x30500
movq %rax, -0xb8(%rbp)
callq 0x47bf0
movaps 0x9df9(%rip), %xmm1     # 0x66790
pxor %xmm1, %xmm0
movlpd %xmm0, -0x50(%rbp)
leaq -0x51(%rbp), %rdi
movq %rdi, -0xb0(%rbp)
callq 0x48220
movq -0xb8(%rbp), %rsi
movq -0xb0(%rbp), %rcx
leaq -0x48(%rbp), %rdi
leaq -0x50(%rbp), %rdx
callq 0x48240
jmp 0x5c9cd
leaq -0x51(%rbp), %rdi
callq 0x482c0
xorl %eax, %eax
movl %eax, %esi
leaq -0x48(%rbp), %rdi
movq %rdi, -0xc0(%rbp)
callq 0x47eb0
movq -0xc0(%rbp), %rsi
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0x44eb0
jmp 0x5ca03
leaq -0x98(%rbp), %rdi
callq 0x48ab0
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
callq 0x60930
movq %rax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
callq 0x301f0
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x301c0
testb $0x1, %al
jne 0x5ca53
jmp 0x5cb91
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x30220
movq -0xd0(%rbp), %rdi
movq %rax, %rsi
callq 0x48880
movq %rax, -0xc8(%rbp)
jmp 0x5ca82
movq -0xc8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x100(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0xa0(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x30220
movq -0xf0(%rbp), %rdi
movq %rax, -0xe8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xe0(%rbp)
callq 0x30220
movq -0xe0(%rbp), %rdi
movq %rax, %rsi
callq 0x48880
movq %rax, -0xd8(%rbp)
jmp 0x5cae9
movq -0xe8(%rbp), %rsi
movq -0xf8(%rbp), %rdi
movq -0xd8(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x48(%rbp), %rdx
leaq -0x98(%rbp), %rcx
callq 0x45fb0
movsd %xmm0, -0x108(%rbp)
jmp 0x5cb1c
movsd -0x108(%rbp), %xmm2
movsd -0x100(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0xa0(%rbp), %rdi
callq 0x38fb0
jmp 0x5ca23
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x51(%rbp), %rdi
callq 0x482c0
jmp 0x5cc0f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
jmp 0x5cbc6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x48ad0
jmp 0x5cbc6
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
leaq -0x98(%rbp), %rdi
movsd 0x9bd8(%rip), %xmm0     # 0x66780
callq 0x5d670
jmp 0x5cbaf
leaq -0x98(%rbp), %rdi
callq 0x48ad0
leaq -0x48(%rbp), %rdi
callq 0x48320
jmp 0x5cc01
leaq -0x48(%rbp), %rdi
callq 0x48320
jmp 0x5cc0f
movq -0x10(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x18(%rbp), %rdx
callq 0x47420
movsd %xmm0, -0x30(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x5da80
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x5dd10
movsd -0x30(%rbp), %xmm0
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x46e0
nopl (%rax,%rax)