// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
movsd %xmm0, -0x70(%rbp)
movq %rcx, -0x78(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x40(%rbp)
leaq 0x38(%rdi), %r15
movq %r15, %rdi
callq 0x11d8e
movl (%rax), %eax
leaq -0x54(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xe0(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xe8(%rbp), %rdi
callq 0x19392
movq %r15, -0x60(%rbp)
movq %r14, -0x68(%rbp)
andq $0x0, (%rax)
leaq -0xb0(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xb8(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x1af16
addq $0x20, -0x40(%rbp)
leaq -0xe8(%rbp), %r12
leaq -0x38(%rbp), %r14
cmpq $0x0, -0x90(%rbp)
je 0x184e7
leaq -0xb0(%rbp), %rdi
callq 0x4210
movslq 0x20(%rax), %rax
movl %eax, -0x34(%rbp)
movq -0x40(%rbp), %rcx
movq (%rcx), %rcx
shlq $0x7, %rax
leaq (%rcx,%rax), %rdx
movq %rdx, -0x80(%rbp)
leaq (%rcx,%rax), %r15
addq $0x28, %r15
movq 0x10(%r15), %r13
cmpq %r15, %r13
je 0x184d2
movq 0x20(%r13), %rax
movl (%rax), %ecx
movl %ecx, -0x38(%rbp)
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
movl %ecx, -0x50(%rbp)
movq %rbx, %rdi
leaq -0x50(%rbp), %rsi
callq 0x19428
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x4c(%rbp)
movq %rbx, %rdi
leaq -0x4c(%rbp), %rsi
callq 0x19428
movsd (%rax), %xmm0
movsd %xmm0, -0x88(%rbp)
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x19392
movsd -0x30(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
subsd -0x88(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
callq 0x4600
movsd %xmm0, -0x48(%rbp)
movslq -0x38(%rbp), %rsi
movq -0x40(%rbp), %rdi
callq 0x193e4
movq -0x78(%rbp), %rdi
movq %rax, %rsi
callq 0x19048
movq %rax, %rdi
movq -0x80(%rbp), %rsi
callq 0x18d90
movsd -0x48(%rbp), %xmm0
mulsd -0x70(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
movq %r14, %rsi
callq 0x1b536
leaq -0xe0(%rbp), %rcx
cmpq %rcx, %rax
je 0x1849f
movq %r12, %rdi
movq %r14, %rsi
callq 0x19392
movsd (%rax), %xmm0
movsd -0x30(%rbp), %xmm1
callq 0x15a53
movsd %xmm0, -0x30(%rbp)
movq %r12, %rdi
movq %r14, %rsi
callq 0x19392
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
jmp 0x184c2
movq %r12, %rdi
movq %r14, %rsi
callq 0x19392
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xb8(%rbp), %rdi
movq %r14, %rsi
callq 0x1af16
movq %r13, %rdi
callq 0x43b0
movq %rax, %r13
jmp 0x18397
leaq -0xb8(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x1b0a6
jmp 0x18357
movq -0x60(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x11d8e
movq %rbx, %rdi
movq %rax, %rsi
callq 0x19428
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x196aa
leaq -0xe8(%rbp), %rdi
callq 0x19700
movsd -0x30(%rbp), %xmm0
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x18555
jmp 0x18546
jmp 0x18546
jmp 0x18546
jmp 0x18546
jmp 0x18546
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
callq 0x196aa
leaq -0xe8(%rbp), %rdi
callq 0x19700
movq %rbx, %rdi
callq 0x45f0