// File: 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
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x23a90
cmpq $0x0, %rax
jne 0x42f64
callq 0x47bf0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movsd %xmm0, -0x8(%rbp)
jmp 0x432b1
movq -0x20(%rbp), %rdi
callq 0x48490
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x23a90
movq %rax, -0xa0(%rbp)
callq 0x47bf0
movaps 0x23803(%rip), %xmm1    # 0x66790
pxor %xmm1, %xmm0
movlpd %xmm0, -0x48(%rbp)
leaq -0x49(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x48220
movq -0xa0(%rbp), %rsi
movq -0x98(%rbp), %rcx
leaq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x48240
jmp 0x42fc3
leaq -0x49(%rbp), %rdi
callq 0x482c0
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x23a90
movq %rax, -0xb0(%rbp)
callq 0x47bf0
movaps 0x237a4(%rip), %xmm1    # 0x66790
pxor %xmm1, %xmm0
movlpd %xmm0, -0x80(%rbp)
leaq -0x81(%rbp), %rdi
movq %rdi, -0xa8(%rbp)
callq 0x48220
movq -0xb0(%rbp), %rsi
movq -0xa8(%rbp), %rcx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rdx
callq 0x48240
jmp 0x43025
leaq -0x81(%rbp), %rdi
callq 0x482c0
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
movq %rdi, -0xb8(%rbp)
callq 0x47eb0
movq $0x0, (%rax)
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x23a90
movq %rax, %rsi
decq %rsi
leaq -0x78(%rbp), %rdi
callq 0x47eb0
movq -0xb8(%rbp), %rdx
movq $0x0, (%rax)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x42640
jmp 0x43085
movq -0x18(%rbp), %rdi
movq -0x20(%rbp), %rcx
leaq -0x40(%rbp), %rsi
leaq -0x78(%rbp), %rdx
callq 0x42980
jmp 0x4309c
movq -0x28(%rbp), %rdi
callq 0x48a00
movq -0x28(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x42d0
movq -0xc0(%rbp), %rdi
movq %rax, %rsi
callq 0x48a20
jmp 0x430ca
movl $0x1, -0x88(%rbp)
movl -0x88(%rbp), %eax
movq %rax, -0xc8(%rbp)
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
callq 0x23a90
movq %rax, %rcx
movq -0xc8(%rbp), %rax
subq $0x1, %rcx
cmpq %rcx, %rax
jae 0x43280
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
movl -0x88(%rbp), %eax
movl %eax, %esi
callq 0x23ae0
movzwl (%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x18(%rbp), %rdi
addq $0x40, %rdi
movl -0x88(%rbp), %eax
movl %eax, %esi
callq 0x23ae0
movq %rax, %rcx
movl -0xcc(%rbp), %eax
movzbl 0x2(%rcx), %ecx
addl %ecx, %eax
subl $0x1, %eax
movl %eax, -0x8c(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x8c(%rbp), %rsi
callq 0x47eb0
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x43206
jp 0x43206
movl -0x88(%rbp), %eax
movl %eax, %esi
leaq -0x78(%rbp), %rdi
callq 0x47eb0
movsd (%rax), %xmm0
movsd %xmm0, -0xd8(%rbp)
movq -0x28(%rbp), %rdi
movslq -0x8c(%rbp), %rsi
callq 0x47eb0
movsd -0xd8(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x4326a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x49(%rbp), %rdi
callq 0x482c0
jmp 0x432bf
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x81(%rbp), %rdi
callq 0x482c0
jmp 0x432a6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x48320
jmp 0x432a6
movq -0x28(%rbp), %rdi
movslq -0x8c(%rbp), %rsi
callq 0x47eb0
movsd (%rax), %xmm0
movsd %xmm0, -0xe8(%rbp)
movl -0x88(%rbp), %eax
movl %eax, %esi
leaq -0x78(%rbp), %rdi
callq 0x47eb0
movsd -0xe8(%rbp), %xmm0
movsd (%rax), %xmm1
callq 0x412e0
movsd %xmm0, -0xe0(%rbp)
jmp 0x4324e
movq -0x28(%rbp), %rdi
movslq -0x8c(%rbp), %rsi
callq 0x47eb0
movsd -0xe0(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x4326c
movl -0x88(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x88(%rbp)
jmp 0x430d4
leaq -0x40(%rbp), %rdi
callq 0x482e0
movsd (%rax), %xmm0
movsd %xmm0, -0x8(%rbp)
leaq -0x78(%rbp), %rdi
callq 0x48320
leaq -0x40(%rbp), %rdi
callq 0x48320
jmp 0x432b1
leaq -0x40(%rbp), %rdi
callq 0x48320
jmp 0x432bf
movsd -0x8(%rbp), %xmm0
addq $0xf0, %rsp
popq %rbp
retq
movq -0x58(%rbp), %rdi
callq 0x46e0
nopl (%rax,%rax)