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

    vector<flt_type> fw(text.nodes.size(), MIN_FLOAT);
    vector<flt_type> bw(text.nodes.size(), MIN_FLOAT);
    fw[0] = 0.0; bw[text.nodes.size()-1] = 0.0;

    // Forward
    for (unsigned int i=0; i<text.nodes.size(); i++) {

        if (fw[i] == MIN_FLOAT) continue;

        FactorGraph::Node &node = text.nodes[i];
        for (auto arc = node.outgoing.begin(); arc != node.outgoing.end(); ++arc) {
            int tgt_node = (**arc).target_node;
            (**arc).cost = vocab.at(text.get_factor(tgt_node));
            flt_type cost = fw[i] + (**arc).cost;
            if (fw[tgt_node] == MIN_FLOAT) fw[tgt_node] = cost;
            else fw[tgt_node] = add_log_domain_probs(fw[tgt_node], cost);
        }
    }

    backward(text, fw, bw, stats);

    return fw.back();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, -0x68(%rbp)
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x16ff1
movq %rdx, -0x60(%rbp)
movq %rdx, %rdi
movq %rsi, %r14
callq 0x1a3dc
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
pushq $0x38
popq %r15
cqto
idivq %r15
movabsq $-0x10000000000001, %rbx # imm = 0xFFEFFFFFFFFFFFFF
leaq -0xa0(%rbp), %r12
movq %rbx, (%r12)
leaq -0x58(%rbp), %rdi
leaq -0x80(%rbp), %rcx
movq %rax, %rsi
movq %r12, %rdx
callq 0x18ee6
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
cqto
idivq %r15
movq %rbx, (%r12)
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
leaq -0x29(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
movq -0x58(%rbp), %rcx
andq $0x0, (%rcx)
movq 0x40(%r14), %rsi
movq 0x48(%r14), %r10
movq %r10, %rax
subq %rsi, %rax
movq -0x80(%rbp), %r8
pushq $0x7
popq %r9
cqto
idivq %r9
andq $0x0, -0x8(%r8,%rax)
leaq -0xa0(%rbp), %rdi
movq %r14, %r8
xorl %r9d, %r9d
movl %r9d, %r9d
movq %r10, %rax
subq %rsi, %rax
cqto
idivq %r15
cmpq %r9, %rax
jbe 0x16fb3
movsd (%rcx,%r9,8), %xmm0
ucomisd 0xc8aa(%rip), %xmm0     # 0x23790
jne 0x16eee
jnp 0x16fab
movq %r9, -0x40(%rbp)
imulq $0x38, %r9, %rax
addq %rsi, %rax
addq $0x20, %rax
movq %rax, -0x38(%rbp)
movq (%rax), %r14
movq -0x38(%rbp), %rax
cmpq 0x8(%rax), %r14
je 0x16f9b
movq (%r14), %rax
movzwl 0x2(%rax), %r13d
movq %r8, %r12
movq %r8, %rsi
movl %r13d, %edx
movq %rdi, %r15
callq 0xea5a
movq -0x68(%rbp), %rdi
movq %r15, %rsi
callq 0x19102
movsd (%rax), %xmm0
movq (%r14), %rax
movsd %xmm0, 0x8(%rax)
movq %r15, %rbx
movq %r15, %rdi
callq 0x46b8
movq -0x58(%rbp), %rcx
movq -0x40(%rbp), %rax
movsd (%rcx,%rax,8), %xmm1
movq (%r14), %rax
addsd 0x8(%rax), %xmm1
movsd (%rcx,%r13,8), %xmm0
ucomisd 0xc81f(%rip), %xmm0     # 0x23790
jne 0x16f7d
jp 0x16f7d
movsd %xmm1, (%rcx,%r13,8)
jmp 0x16f8c
callq 0x15a53
movq -0x58(%rbp), %rcx
movsd %xmm0, (%rcx,%r13,8)
addq $0x8, %r14
movq %r12, %r8
movq %rbx, %rdi
jmp 0x16f04
movq 0x40(%r8), %rsi
movq 0x48(%r8), %r10
pushq $0x38
popq %r15
movq -0x40(%rbp), %r9
incl %r9d
jmp 0x16ec1
leaq -0x58(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r8, %rdi
movq -0x60(%rbp), %rcx
callq 0x165fe
leaq -0x58(%rbp), %rbx
movq 0x8(%rbx), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x1a10a
movsd -0x38(%rbp), %xmm0
jmp 0x16ff9
movsd 0xc797(%rip), %xmm0     # 0x23790
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x17020
movq %rax, %rbx
jmp 0x1702c
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x46b8
jmp 0x17023
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x1a10a
leaq -0x58(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x45f0