// File: aalto-speech[P]ftk/src/EM.cc
// Function: forward_backward(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>>>>>>&)
flt_type
forward_backward(const MultiStringFactorGraph &msfg,
                 const map<string, flt_type> &word_freqs,
                 transitions_t &stats)
{
    if (msfg.nodes.size() == 0) return MIN_FLOAT;

    vector<flt_type> fw(msfg.nodes.size(), MIN_FLOAT);
    fw[0] = 0.0;

    forward(msfg, fw);
    flt_type total_lp = 0.0;
    for (auto it = msfg.string_end_nodes.begin(); it != msfg.string_end_nodes.end(); ++it) {
        flt_type lp = backward(msfg, it->first, fw, stats, word_freqs.at(it->first));
        total_lp += word_freqs.at(it->first) * lp;
    }

    return total_lp;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xe0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x30500
cmpq $0x0, %rax
jne 0x46a90
callq 0x47bf0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x46c8f
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
callq 0x30500
movq %rax, -0x88(%rbp)
callq 0x47bf0
movaps 0x1fce0(%rip), %xmm1    # 0x66790
pxor %xmm1, %xmm0
movlpd %xmm0, -0x40(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x80(%rbp)
callq 0x48220
movq -0x88(%rbp), %rsi
movq -0x80(%rbp), %rcx
leaq -0x38(%rbp), %rdi
leaq -0x40(%rbp), %rdx
callq 0x48240
jmp 0x46ae0
leaq -0x41(%rbp), %rdi
callq 0x482c0
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
movq %rdi, -0x90(%rbp)
callq 0x47eb0
movq -0x90(%rbp), %rsi
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
callq 0x44eb0
jmp 0x46b16
xorps %xmm0, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
callq 0x49720
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
callq 0x30940
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x31430
testb $0x1, %al
jne 0x46b56
jmp 0x46c7c
movq -0x10(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0x68(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x31490
movq -0xb8(%rbp), %rdi
movq %rax, -0xb0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xa0(%rbp)
callq 0x31490
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
callq 0x48880
movq %rax, -0x98(%rbp)
jmp 0x46bb2
movq -0xa8(%rbp), %rcx
movq -0xb0(%rbp), %rsi
movq -0xc0(%rbp), %rdi
movq -0x98(%rbp), %rax
movsd (%rax), %xmm0
leaq -0x38(%rbp), %rdx
callq 0x45fb0
movsd %xmm0, -0xc8(%rbp)
jmp 0x46be5
movsd -0xc8(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0xd8(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x31490
movq -0xd8(%rbp), %rdi
movq %rax, %rsi
callq 0x48880
movq %rax, -0xd0(%rbp)
jmp 0x46c1e
movq -0xd0(%rbp), %rax
movsd (%rax), %xmm0
movsd -0x78(%rbp), %xmm2
movsd -0x60(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x314b0
jmp 0x46b2f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x41(%rbp), %rdi
callq 0x482c0
jmp 0x46c9d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x48320
jmp 0x46c9d
movsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x8(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x48320
movsd -0x8(%rbp), %xmm0
addq $0xe0, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x46e0
nopw %cs:(%rax,%rax)