// File: /workspace/github_cpp_makefile_star2_O3/aalto-speech[P]ftk/src/EM.cc
// Function: backward(FactorGraph const&, std::vector<double, std::allocator<double>> const&, std::vector<double, std::allocator<double>>&, 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>>>>>>&)
void backward(const FactorGraph &text,
              const vector<flt_type> &fw,
              vector<flt_type> &bw,
              transitions_t &stats)
{
    for (int i=text.nodes.size()-1; i>0; i--) {

        if (bw[i] == MIN_FLOAT) continue;

        const FactorGraph::Node &node = text.nodes[i];
        string target_node_str = text.get_factor(node);

        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[text.get_factor(src_node)][target_node_str] += exp(curr_cost);
            if (bw[src_node] == MIN_FLOAT) bw[src_node] = curr_cost;
            else bw[src_node] = add_log_domain_probs(bw[src_node], curr_cost);
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rcx, -0x58(%rbp)
movq %rsi, -0x38(%rbp)
movq 0x48(%rdi), %rax
movq %rdi, -0x40(%rbp)
subq 0x40(%rdi), %rax
shrq $0x3, %rax
imull $0xb6db6db7, %eax, %eax # imm = 0xB6DB6DB7
decl %eax
testl %eax, %eax
jle 0x18121
movl %eax, %r12d
movq %rdx, -0x30(%rbp)
movq (%rdx), %rax
movsd (%rax,%r12,8), %xmm0
ucomisd 0xe85e(%rip), %xmm0     # 0x26800
jne 0x17faa
jnp 0x1810f
movq -0x40(%rbp), %rsi
movq 0x40(%rsi), %r13
imulq $0x38, %r12, %r14
leaq (%r14,%r13), %rbx
leaq -0x80(%rbp), %rdi
movq %rbx, %rdx
callq 0x10242
movq -0x30(%rbp), %rdx
movq 0x8(%r13,%r14), %r15
cmpq 0x10(%r13,%r14), %r15
movq -0x38(%rbp), %rsi
je 0x180f9
movq (%r15), %rax
movzwl (%rax), %r13d
movq (%rsi), %rcx
movsd (%rcx,%r13,8), %xmm0
ucomisd 0xe80a(%rip), %xmm0     # 0x26800
jne 0x17ffe
jnp 0x180eb
addsd 0x8(%rax), %xmm0
subsd (%rcx,%r12,8), %xmm0
movq (%rdx), %rax
addsd (%rax,%r12,8), %xmm0
movapd %xmm0, -0x50(%rbp)
callq 0x4660
movsd %xmm0, -0x60(%rbp)
leaq -0xa0(%rbp), %r14
movq %r14, %rdi
movq -0x40(%rbp), %rsi
movl %r13d, %edx
callq 0x10288
movq -0x58(%rbp), %rdi
movq %r14, %rsi
callq 0x1b454
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x1af86
movsd -0x60(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18074
callq 0x4350
movq -0x30(%rbp), %rdx
movq (%rdx), %rax
movsd (%rax,%r13,8), %xmm1
ucomisd 0xe777(%rip), %xmm1     # 0x26800
jne 0x18094
jp 0x18094
movapd -0x50(%rbp), %xmm0
jmp 0x180e1
movapd %xmm1, %xmm2
movapd -0x50(%rbp), %xmm3
subsd %xmm3, %xmm2
movapd %xmm2, %xmm0
xorpd 0xe773(%rip), %xmm0     # 0x26820
movapd %xmm0, %xmm4
cmpltsd %xmm2, %xmm4
andpd %xmm4, %xmm1
andnpd %xmm3, %xmm4
orpd %xmm1, %xmm4
movapd %xmm4, -0x50(%rbp)
minsd %xmm2, %xmm0
callq 0x4660
callq 0x46e0
movq -0x30(%rbp), %rdx
addsd -0x50(%rbp), %xmm0
movq (%rdx), %rax
movsd %xmm0, (%rax,%r13,8)
movq -0x38(%rbp), %rsi
addq $0x8, %r15
cmpq 0x10(%rbx), %r15
jne 0x17fde
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x1810b
callq 0x4350
movq -0x30(%rbp), %rdx
leaq -0x1(%r12), %rax
cmpq $0x1, %r12
movq %rax, %r12
jg 0x17f91
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
jmp 0x18150
movq %rax, %rbx
movq -0xa0(%rbp), %rdi
leaq -0x90(%rbp), %rax
cmpq %rax, %rdi
je 0x18150
callq 0x4350
movq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rax
cmpq %rax, %rdi
je 0x18162
callq 0x4350
movq %rbx, %rdi
callq 0x4650