// File: /workspace/github_cpp_makefile_star2_O1/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 $0x88, %rsp
movq %rdi, -0x60(%rbp)
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x18c89
movq %rsi, %r14
movq %rdx, -0x58(%rbp)
movq %rdx, %rdi
callq 0x1c532
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %r15 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r15, %rsi
movabsq $-0x10000000000001, %rbx # imm = 0xFFEFFFFFFFFFFFFF
leaq -0xa0(%rbp), %r12
movq %rbx, (%r12)
leaq -0x50(%rbp), %rdi
leaq -0x80(%rbp), %rcx
movq %r12, %rdx
callq 0x1b220
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
imulq %r15, %rsi
movq %rbx, (%r12)
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
leaq -0x29(%rbp), %rcx
callq 0x1b220
movq -0x50(%rbp), %rax
xorl %ebx, %ebx
movq %rbx, (%rax)
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
movq -0x80(%rbp), %rcx
imulq %r15, %rax
movq %rbx, -0x8(%rcx,%rax)
movq 0x40(%r14), %rax
cmpq %rax, 0x48(%r14)
je 0x18c3f
movq %r14, -0x38(%rbp)
movq -0x50(%rbp), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd 0xdcef(%rip), %xmm0     # 0x26800
jne 0x18b19
jnp 0x18c13
imulq $0x38, %rbx, %rcx
movq 0x20(%rax,%rcx), %r15
cmpq 0x28(%rax,%rcx), %r15
je 0x18c13
addq %rcx, %rax
addq $0x20, %rax
movq %rax, -0x68(%rbp)
movq (%r15), %rax
movzwl 0x2(%rax), %r13d
movq %r12, %r14
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movl %r13d, %edx
callq 0x10378
movq -0x60(%rbp), %rdi
movq %r14, %r12
movq %r14, %rsi
callq 0x1b4d8
movsd (%rax), %xmm0
movq (%r15), %rax
movsd %xmm0, 0x8(%rax)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18b85
callq 0x4350
movq -0x50(%rbp), %rax
movsd (%rax,%rbx,8), %xmm1
movq (%r15), %rcx
addsd 0x8(%rcx), %xmm1
movsd (%rax,%r13,8), %xmm2
ucomisd 0xdc5c(%rip), %xmm2     # 0x26800
jne 0x18bb0
jp 0x18bb0
movsd %xmm1, (%rax,%r13,8)
jmp 0x18c01
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm0
xorpd 0xdc5c(%rip), %xmm0     # 0x26820
movapd %xmm0, %xmm4
cmpltsd %xmm3, %xmm4
andpd %xmm4, %xmm2
andnpd %xmm1, %xmm4
orpd %xmm2, %xmm4
movapd %xmm4, -0xb0(%rbp)
minsd %xmm3, %xmm0
callq 0x4660
callq 0x46e0
addsd -0xb0(%rbp), %xmm0
movq -0x50(%rbp), %rax
movsd %xmm0, (%rax,%r13,8)
addq $0x8, %r15
movq -0x68(%rbp), %rax
cmpq 0x8(%rax), %r15
jne 0x18b38
incl %ebx
movq -0x38(%rbp), %r14
movq 0x40(%r14), %rax
movq 0x48(%r14), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x6db6db6db6db6db7, %rdx # imm = 0x6DB6DB6DB6DB6DB7
imulq %rdx, %rcx
cmpq %rbx, %rcx
ja 0x18b00
leaq -0x50(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r14, %rdi
movq -0x58(%rbp), %rcx
callq 0x1808e
movq -0x48(%rbp), %rax
movsd -0x8(%rax), %xmm0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
movsd %xmm0, -0x38(%rbp)
je 0x18c74
callq 0x4350
movsd -0x38(%rbp), %xmm0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18c91
callq 0x4350
movsd -0x38(%rbp), %xmm0
jmp 0x18c91
movsd 0xdb6f(%rip), %xmm0     # 0x26800
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18caa
movq %rax, %rbx
jmp 0x18cd8
movq %rax, %rbx
jmp 0x18cca
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18cca
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18cd8
callq 0x4350
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18ce6
callq 0x4350
movq %rbx, %rdi
callq 0x4650