// File: /workspace/github_cpp_makefile_star2_O3/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 0x18b59
movq %rsi, %r14
movq %rdx, -0x58(%rbp)
movq %rdx, %rdi
callq 0x1c43c
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
movabsq $0x6db6db6db6db6db7, %r13 # imm = 0x6DB6DB6DB6DB6DB7
imulq %r13, %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 0x1b134
movq 0x48(%r14), %rsi
subq 0x40(%r14), %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
movq %rbx, (%r12)
leaq -0x80(%rbp), %rdi
leaq -0xa0(%rbp), %rdx
leaq -0x29(%rbp), %rcx
callq 0x1b134
movq -0x50(%rbp), %rax
xorl %ebx, %ebx
movq %rbx, (%rax)
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rdx
movq %rdx, %rsi
subq %rcx, %rsi
imulq %r13, %rsi
movq -0x80(%rbp), %rdi
movq %rbx, -0x8(%rdi,%rsi)
cmpq %rcx, %rdx
je 0x18b0f
movq %r14, -0x38(%rbp)
movsd (%rax,%rbx,8), %xmm0
ucomisd 0xde23(%rip), %xmm0     # 0x26800
jne 0x189e5
jnp 0x18af6
imulq $0x38, %rbx, %rsi
movq 0x20(%rcx,%rsi), %r15
cmpq 0x28(%rcx,%rsi), %r15
je 0x18af6
leaq (%rcx,%rsi), %rax
addq $0x20, %rax
movq %rax, -0x68(%rbp)
movq (%r15), %rax
movzwl 0x2(%rax), %r13d
movq %r12, %rdi
movq -0x38(%rbp), %rsi
movl %r13d, %edx
callq 0x10288
movq -0x60(%rbp), %rdi
movq %r12, %r14
movq %r12, %rsi
callq 0x1b3f6
movsd (%rax), %xmm0
movq (%r15), %rax
movsd %xmm0, 0x8(%rax)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18a4f
callq 0x4350
movq -0x50(%rbp), %rax
movsd (%rax,%rbx,8), %xmm1
movq (%r15), %rcx
addsd 0x8(%rcx), %xmm1
movsd (%rax,%r13,8), %xmm2
ucomisd 0xdd92(%rip), %xmm2     # 0x26800
jne 0x18a7a
jp 0x18a7a
movsd %xmm1, (%rax,%r13,8)
jmp 0x18acb
movapd %xmm2, %xmm3
subsd %xmm1, %xmm3
movapd %xmm3, %xmm0
xorpd 0xdd92(%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), %rcx
cmpq 0x8(%rcx), %r15
movq %r14, %r12
jne 0x18a05
movq -0x38(%rbp), %r14
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rdx
movabsq $0x6db6db6db6db6db7, %r13 # imm = 0x6DB6DB6DB6DB6DB7
incl %ebx
movq %rdx, %rsi
subq %rcx, %rsi
sarq $0x3, %rsi
imulq %r13, %rsi
cmpq %rbx, %rsi
ja 0x189d0
leaq -0x50(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movq %r14, %rdi
movq -0x58(%rbp), %rcx
callq 0x17f51
movq -0x48(%rbp), %rax
movsd -0x8(%rax), %xmm0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
movsd %xmm0, -0x38(%rbp)
je 0x18b44
callq 0x4350
movsd -0x38(%rbp), %xmm0
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18b61
callq 0x4350
movsd -0x38(%rbp), %xmm0
jmp 0x18b61
movsd 0xdc9f(%rip), %xmm0     # 0x26800
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x18b7a
movq %rax, %rbx
jmp 0x18ba8
movq %rax, %rbx
jmp 0x18b9a
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18b9a
callq 0x4350
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x18ba8
callq 0x4350
movq -0x50(%rbp), %rdi
testq %rdi, %rdi
je 0x18bb6
callq 0x4350
movq %rbx, %rdi
callq 0x4650