// 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>>, 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>>>>>> 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>>>>>>&, std::vector<double, std::allocator<double>>&)
flt_type forward_backward(const transitions_t &transitions,
                          FactorGraph &text,
                          transitions_t &stats,
                          vector<flt_type> &post_scores)
{
    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(transitions, text, fw);
    backward(text, fw, bw, stats);

    post_scores.clear();
    post_scores.resize(text.text.size());
    for (unsigned int i=1; i<text.nodes.size()-1; i++) {
        int idx = int(text.nodes[i].start_pos) + int(text.nodes[i].len) - 1;
        if (post_scores[idx] == 0.0) post_scores[idx] = bw[i];
        else post_scores[idx] = add_log_domain_probs(post_scores[idx], bw[i]);
    }

    return fw.back();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq 0x48(%rsi), %rax
cmpq 0x40(%rsi), %rax
je 0x16a7d
movq %rcx, %rbx
movq %rsi, %r14
movq %rdi, -0x38(%rbp)
movq %rdx, -0x58(%rbp)
movq %rdx, %rdi
callq 0x1a3dc
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
pushq $0x38
popq %r12
cqto
idivq %r12
movabsq $-0x10000000000001, %r15 # imm = 0xFFEFFFFFFFFFFFFF
leaq -0x50(%rbp), %rdx
movq %r15, (%rdx)
leaq -0x78(%rbp), %rdi
leaq -0x60(%rbp), %r13
movq %rax, %rsi
movq %r13, %rcx
callq 0x18ee6
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
cqto
idivq %r12
movq %r15, (%r13)
leaq -0x50(%rbp), %rdi
leaq -0x60(%rbp), %rdx
leaq -0x29(%rbp), %rcx
movq %rax, %rsi
callq 0x18ee6
leaq -0x78(%rbp), %rcx
movq (%rcx), %rax
andq $0x0, (%rax)
movq 0x48(%r14), %rax
subq 0x40(%r14), %rax
movq -0x50(%rbp), %rsi
pushq $0x7
popq %rdi
cqto
idivq %rdi
andq $0x0, -0x8(%rsi,%rax)
movq -0x38(%rbp), %rdi
movq %r14, %rsi
movq %rcx, %rdx
callq 0x16453
leaq -0x78(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movq %r14, %rdi
movq -0x58(%rbp), %rcx
callq 0x165fe
movq (%rbx), %rax
cmpq %rax, 0x8(%rbx)
je 0x169d2
movq %rax, 0x8(%rbx)
movq 0x8(%r14), %rsi
movq %rbx, %rdi
callq 0x191bc
pushq $0x1
popq %r15
xorpd %xmm2, %xmm2
movl %r15d, %r15d
movq 0x40(%r14), %rcx
movq 0x48(%r14), %rax
subq %rcx, %rax
cqto
idivq %r12
decq %rax
cmpq %r15, %rax
jbe 0x16a53
imulq $0x38, %r15, %rax
movzwl (%rcx,%rax), %edx
movzbl 0x2(%rcx,%rax), %eax
leaq (%rdx,%rax), %rcx
leaq (%rdx,%rax), %r13
decq %r13
movq (%rbx), %rax
movsd -0x8(%rax,%rcx,8), %xmm0
ucomisd %xmm2, %xmm0
movq -0x50(%rbp), %rcx
movsd (%rcx,%r15,8), %xmm1
jne 0x16a3c
jp 0x16a3c
movsd %xmm1, (%rax,%r13,8)
jmp 0x16a4e
callq 0x15a53
xorpd %xmm2, %xmm2
movq (%rbx), %rax
movsd %xmm0, (%rax,%r13,8)
incl %r15d
jmp 0x169e6
leaq -0x78(%rbp), %rbx
movq 0x8(%rbx), %rax
movsd -0x8(%rax), %xmm0
movsd %xmm0, -0x38(%rbp)
leaq -0x50(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x1a10a
movsd -0x38(%rbp), %xmm0
jmp 0x16a85
movsd 0xcd0b(%rip), %xmm0     # 0x23790
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x16aa5
movq %rax, %rbx
leaq -0x50(%rbp), %rdi
callq 0x1a10a
leaq -0x78(%rbp), %rdi
callq 0x1a10a
movq %rbx, %rdi
callq 0x45f0