// 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::vector<double, std::allocator<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 vector<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;
            if (fw[src_node] == MIN_FLOAT) continue;
            flt_type curr_cost = *(**arc).cost + fw[src_node] - fw[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 $0xb8, %rsp
movsd %xmm0, -0x68(%rbp)
movq %rcx, -0x70(%rbp)
movq %rdx, %rbx
movq %rsi, %r14
movq %rdi, -0x40(%rbp)
leaq 0x38(%rdi), %r15
movq %r15, %rdi
callq 0x11d8e
movl (%rax), %eax
leaq -0x4c(%rbp), %rsi
movl %eax, (%rsi)
leaq -0xd8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xe0(%rbp), %rdi
callq 0x19392
movq %r15, -0x58(%rbp)
movq %r14, -0x60(%rbp)
andq $0x0, (%rax)
leaq -0xa8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xb0(%rbp), %rdi
leaq -0x4c(%rbp), %rsi
callq 0x1af16
addq $0x20, -0x40(%rbp)
leaq -0xe0(%rbp), %r12
leaq -0x38(%rbp), %r14
cmpq $0x0, -0x88(%rbp)
je 0x1822f
leaq -0xa8(%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, -0x78(%rbp)
leaq (%rcx,%rax), %r15
addq $0x28, %r15
movq 0x10(%r15), %r13
cmpq %r15, %r13
je 0x1821a
movq 0x20(%r13), %rax
movslq (%rax), %rdx
movl %edx, -0x38(%rbp)
movq (%rbx), %rcx
movsd (%rcx,%rdx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
ucomisd 0xb67c(%rip), %xmm0     # 0x23790
jne 0x1811c
jnp 0x1820a
movq 0x8(%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x48(%rbp)
movslq -0x34(%rbp), %rax
movsd (%rcx,%rax,8), %xmm0
movsd %xmm0, -0x80(%rbp)
movq %r12, %rdi
leaq -0x34(%rbp), %rsi
callq 0x19392
movsd -0x30(%rbp), %xmm0
addsd -0x48(%rbp), %xmm0
subsd -0x80(%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 -0x70(%rbp), %rdi
movq %rax, %rsi
callq 0x19048
movq %rax, %rdi
movq -0x78(%rbp), %rsi
callq 0x18d90
movsd -0x48(%rbp), %xmm0
mulsd -0x68(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
movq %r14, %rsi
callq 0x1b536
leaq -0xd8(%rbp), %rcx
cmpq %rcx, %rax
je 0x181e7
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 0x1820a
movq %r12, %rdi
movq %r14, %rsi
callq 0x19392
movsd -0x30(%rbp), %xmm0
movsd %xmm0, (%rax)
leaq -0xb0(%rbp), %rdi
movq %r14, %rsi
callq 0x1af16
movq %r13, %rdi
callq 0x43b0
movq %rax, %r13
jmp 0x180ec
leaq -0xb0(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x1b0a6
jmp 0x180ac
movq -0x58(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x11d8e
movl (%rax), %esi
movq %rbx, %rdi
callq 0x19406
movsd (%rax), %xmm0
movsd %xmm0, -0x30(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x196aa
leaq -0xe0(%rbp), %rdi
callq 0x19700
movsd -0x30(%rbp), %xmm0
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x18298
jmp 0x18289
jmp 0x18289
jmp 0x18289
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x196aa
leaq -0xe0(%rbp), %rdi
callq 0x19700
movq %rbx, %rdi
callq 0x45f0