// File: /workspace/github_cpp_makefile_star2_O1/aalto-speech[P]ftk/src/EM.cc
// Function: backward(MultiStringFactorGraph const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::map<unsigned int, double, std::less<unsigned int>, std::allocator<std::pair<unsigned int const, double>>> const&, 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>>>>>>&, double)
flt_type
backward(const MultiStringFactorGraph &msfg,
         const string &text,
         const map<msfg_node_idx_t, flt_type> &fw,
         transitions_t &stats,
         flt_type text_weight)
{

    int text_end_node = msfg.string_end_nodes.at(text);
    map<int, flt_type> bw; bw[text_end_node] = 0.0;
    set<int> nodes_to_process; nodes_to_process.insert(text_end_node);

    while(nodes_to_process.size() > 0) {

        int i = *(nodes_to_process.rbegin());

        const MultiStringFactorGraph::Node &node = msfg.nodes[i];

        for (auto arc = node.incoming.begin(); arc != node.incoming.end(); ++arc) {
            int src_node = (**arc).source_node;
            flt_type curr_cost = *(**arc).cost + fw.at(src_node) - fw.at(i) + bw[i];
            stats[msfg.nodes.at(src_node).factor][node.factor] += text_weight * exp(curr_cost);
            if (bw.find(src_node) == bw.end()) {
                bw[src_node] = curr_cost;
                nodes_to_process.insert(src_node);
            }
            else bw[src_node] = add_log_domain_probs(bw[src_node], curr_cost);
        }

        nodes_to_process.erase(i);
    }

    return fw.at(msfg.string_end_nodes.at(text));
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movsd %xmm0, -0x88(%rbp)
movq %rcx, -0x90(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, %r13
leaq 0x38(%rdi), %r15
movq %r15, %rdi
callq 0x139bc
movl (%rax), %eax
leaq -0x4c(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xf8(%rbp), %r12
movl $0x0, (%r12)
xorl %eax, %eax
movq %rax, 0x8(%r12)
movq %r12, 0x10(%r12)
movq %r12, 0x18(%r12)
movq %rax, 0x20(%r12)
leaq -0x100(%rbp), %rdi
callq 0x1b7ca
movq %r15, -0x78(%rbp)
movq %r14, -0x80(%rbp)
xorl %ecx, %ecx
movq %rcx, (%rax)
leaq -0xc8(%rbp), %rax
movl $0x0, (%rax)
movq %rcx, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
movq %rcx, 0x20(%rax)
leaq -0xd0(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x1ce60
cmpq $0x0, -0xa8(%rbp)
je 0x1a65f
leaq -0xc8(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rax
movl %eax, -0x30(%rbp)
movq 0x20(%r13), %r15
shlq $0x7, %rax
leaq (%r15,%rax), %rcx
addq $0x28, %rcx
movq 0x10(%rcx), %r14
movq %rcx, -0x98(%rbp)
cmpq %rcx, %r14
je 0x1a63c
addq %rax, %r15
movq 0x20(%r14), %rax
movl (%rax), %ecx
movl %ecx, -0x2c(%rbp)
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movaps %xmm0, -0x40(%rbp)
movl %ecx, -0x48(%rbp)
movq %rbx, %rdi
leaq -0x48(%rbp), %rsi
callq 0x1b832
movsd (%rax), %xmm0
movsd %xmm0, -0x60(%rbp)
movl -0x30(%rbp), %eax
movl %eax, -0x44(%rbp)
movq %rbx, %rdi
leaq -0x44(%rbp), %rsi
callq 0x1b832
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x1b7ca
movapd -0x40(%rbp), %xmm0
addsd -0x60(%rbp), %xmm0
subsd -0x70(%rbp), %xmm0
addsd (%rax), %xmm0
movapd %xmm0, -0x40(%rbp)
callq 0x4660
movsd %xmm0, -0x60(%rbp)
movslq -0x2c(%rbp), %rsi
movq 0x20(%r13), %rax
movq 0x28(%r13), %rdx
subq %rax, %rdx
sarq $0x7, %rdx
cmpq %rsi, %rdx
jbe 0x1a6af
shlq $0x7, %rsi
addq %rsi, %rax
movq -0x90(%rbp), %rdi
movq %rax, %rsi
callq 0x1b3fa
movq %rax, %rdi
movq %r15, %rsi
callq 0x1b05e
movsd -0x60(%rbp), %xmm0
mulsd -0x88(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0xf0(%rbp), %rcx
movq %r12, %rax
testq %rcx, %rcx
je 0x1a556
movl -0x2c(%rbp), %edx
movq %r12, %rax
xorl %esi, %esi
cmpl %edx, 0x20(%rcx)
setl %sil
cmovgeq %rcx, %rax
movq 0x10(%rcx,%rsi,8), %rcx
testq %rcx, %rcx
jne 0x1a53f
movq %r12, %rcx
cmpq %r12, %rax
je 0x1a56b
movl -0x2c(%rbp), %ecx
cmpl 0x20(%rax), %ecx
cmovlq %r12, %rax
movq %rax, %rcx
cmpq %r12, %rcx
je 0x1a5fb
leaq -0x100(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
movsd (%rax), %xmm0
movapd %xmm0, -0x60(%rbp)
movapd %xmm0, %xmm1
subsd -0x40(%rbp), %xmm1
movapd %xmm1, %xmm0
xorpd 0xc27e(%rip), %xmm0     # 0x26820
movapd %xmm1, -0x70(%rbp)
minsd %xmm1, %xmm0
callq 0x4660
callq 0x46e0
movsd %xmm0, -0xa0(%rbp)
leaq -0x100(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
xorpd %xmm0, %xmm0
cmpltsd -0x70(%rbp), %xmm0
movapd -0x60(%rbp), %xmm1
andpd %xmm0, %xmm1
andnpd -0x40(%rbp), %xmm0
orpd %xmm1, %xmm0
movsd -0xa0(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, (%rax)
jmp 0x1a624
leaq -0x100(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1b7ca
movapd -0x40(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xd0(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x1ce60
movq %r14, %rdi
callq 0x4410
movq %rax, %r14
cmpq -0x98(%rbp), %rax
jne 0x1a45e
leaq -0xd0(%rbp), %r14
movq %r14, %rdi
leaq -0x30(%rbp), %rsi
callq 0x1cf88
movq %r14, %rdi
movq %rax, %rsi
callq 0x1d004
jmp 0x1a416
movq -0x78(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x139bc
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1b832
movsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x1bb50
leaq -0x100(%rbp), %rdi
callq 0x1bba8
movsd -0x40(%rbp), %xmm0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc1a0(%rip), %rdi      # 0x26856
xorl %eax, %eax
callq 0x4530
movq %rax, %rbx
jmp 0x1a6db
jmp 0x1a6cc
jmp 0x1a6cc
jmp 0x1a6cc
jmp 0x1a6cc
jmp 0x1a6cc
movq %rax, %rbx
leaq -0xd0(%rbp), %rdi
callq 0x1bb50
leaq -0x100(%rbp), %rdi
callq 0x1bba8
movq %rbx, %rdi
callq 0x4650