// File: aalto-speech[P]ftk/src/EM.cc
// Function: likelihood_fb(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, MultiStringFactorGraph const&)
flt_type
likelihood_fb(const string &text,
              const MultiStringFactorGraph &msfg)
{
    map<msfg_node_idx_t, flt_type> fw;
    int text_end_node = msfg.string_end_nodes.at(text);
    set<int> nodes_to_process; nodes_to_process.insert(text_end_node);
    fw[text_end_node] = 0.0;

    while(nodes_to_process.size() > 0) {

        int i = *(nodes_to_process.rbegin());

        const MultiStringFactorGraph::Node &node = msfg.nodes[i];

        for (auto arc = node.incoming.begin(); arc != node.incoming.end(); ++arc) {
            int src_node = (**arc).source_node;
            flt_type cost = fw[i] + *(**arc).cost;
            if (fw.find(src_node) == fw.end()) fw[src_node] = cost;
            else fw[src_node] = add_log_domain_probs(fw[src_node], cost);
            nodes_to_process.insert(src_node);
        }

        nodes_to_process.erase(i);
    }

    return fw.at(0);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x49290
movq -0x10(%rbp), %rdi
addq $0x38, %rdi
movq -0x8(%rbp), %rsi
callq 0x30970
movq %rax, -0x120(%rbp)
jmp 0x45676
movq -0x120(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x44(%rbp)
leaq -0x88(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x492d0
movq -0x138(%rbp), %rdi
leaq -0x44(%rbp), %rsi
callq 0x492f0
movb %dl, -0x129(%rbp)
movq %rax, -0x128(%rbp)
jmp 0x456b4
movb -0x129(%rbp), %al
movq -0x128(%rbp), %rcx
movq %rcx, -0x98(%rbp)
movb %al, -0x90(%rbp)
movl -0x44(%rbp), %eax
movl %eax, -0x9c(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x9c(%rbp), %rsi
callq 0x48fd0
movq %rax, -0x140(%rbp)
jmp 0x456f0
movq -0x140(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
leaq -0x88(%rbp), %rdi
callq 0x49340
cmpq $0x0, %rax
jbe 0x459ee
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x150(%rbp)
leaq -0x88(%rbp), %rsi
callq 0x49360
movq -0x150(%rbp), %rdi
callq 0x49390
movq %rax, -0x148(%rbp)
jmp 0x45743
movq -0x148(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movslq -0xa0(%rbp), %rsi
callq 0x30c00
movq %rax, -0xb0(%rbp)
movq -0xb0(%rbp), %rdi
addq $0x20, %rdi
callq 0x30260
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rdi
addq $0x20, %rdi
callq 0x302c0
movq %rax, -0xc0(%rbp)
leaq -0xb8(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x30290
testb $0x1, %al
jne 0x457b7
jmp 0x459d4
leaq -0xb8(%rbp), %rdi
callq 0x302f0
movq (%rax), %rax
movl (%rax), %eax
movl %eax, -0xc4(%rbp)
movl -0xa0(%rbp), %eax
movl %eax, -0xd4(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xd4(%rbp), %rsi
callq 0x48fd0
movq %rax, -0x158(%rbp)
jmp 0x457f3
movq -0x158(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x168(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x302f0
movsd -0x168(%rbp), %xmm0
movq (%rax), %rax
movq 0x8(%rax), %rax
movsd (%rax), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, -0xd0(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xe4(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xe4(%rbp), %rsi
callq 0x48f70
movq %rax, -0x160(%rbp)
jmp 0x45856
movq -0x160(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x48fa0
movq %rax, -0xf0(%rbp)
leaq -0xe0(%rbp), %rdi
leaq -0xf0(%rbp), %rsi
callq 0x48f40
testb $0x1, %al
jne 0x4588d
jmp 0x45908
movsd -0xd0(%rbp), %xmm0
movsd %xmm0, -0x178(%rbp)
movl -0xc4(%rbp), %eax
movl %eax, -0xf4(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xf4(%rbp), %rsi
callq 0x48fd0
movq %rax, -0x170(%rbp)
jmp 0x458c2
movq -0x170(%rbp), %rax
movsd -0x178(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x45987
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x45a4a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x493f0
jmp 0x45a4a
movl -0xc4(%rbp), %eax
movl %eax, -0xf8(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
callq 0x48fd0
movq %rax, -0x180(%rbp)
jmp 0x4592d
movq -0x180(%rbp), %rax
movsd (%rax), %xmm0
movsd -0xd0(%rbp), %xmm1
callq 0x412e0
movsd %xmm0, -0x188(%rbp)
jmp 0x4594f
movl -0xc4(%rbp), %eax
movl %eax, -0xfc(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0xfc(%rbp), %rsi
callq 0x48fd0
movq %rax, -0x190(%rbp)
jmp 0x45974
movq -0x190(%rbp), %rax
movsd -0x188(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0x88(%rbp), %rdi
leaq -0xc4(%rbp), %rsi
callq 0x492f0
movb %dl, -0x199(%rbp)
movq %rax, -0x198(%rbp)
jmp 0x459a9
movb -0x199(%rbp), %al
movq -0x198(%rbp), %rcx
movq %rcx, -0x110(%rbp)
movb %al, -0x108(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x30320
jmp 0x45784
leaq -0x88(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x493c0
jmp 0x459e9
jmp 0x456fe
movl $0x0, -0x114(%rbp)
leaq -0x40(%rbp), %rdi
leaq -0x114(%rbp), %rsi
callq 0x490b0
movq %rax, -0x1a8(%rbp)
jmp 0x45a11
movq -0x1a8(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x1b0(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x493f0
leaq -0x40(%rbp), %rdi
callq 0x492b0
movsd -0x1b0(%rbp), %xmm0
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x492b0
movq -0x50(%rbp), %rdi
callq 0x46e0
nopl (%rax)