// File: /workspace/github_cpp_makefile_star2_O2/aalto-speech[P]ftk/src/EM.cc
// Function: backward(StringSet const&, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const&, std::vector<std::vector<Token, std::allocator<Token>>, std::allocator<std::vector<Token, std::allocator<Token>>>> 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>>, 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 StringSet &vocab,
              const string &text,
              const vector<vector<Token> > &search,
              const vector<flt_type> &fw,
              vector<flt_type> &bw,
              map<string, flt_type> &stats)
{
    int len = text.length();
    if (search[len-1].size() == 0) return;

    // Backward
    for (int i=len-1; i>=0; i--) {
        for (auto tok = search[i].cbegin(); tok != search[i].cend(); ++tok) {
            flt_type normalized = tok->cost - fw[i] + bw[i];
            if (bw[i] != SMALL_LP && fw[i] != SMALL_LP) {
                stats[text.substr(tok->source+1, i-tok->source)] += exp(normalized);
                if (tok->source == -1) continue;
                if (bw[tok->source] != SMALL_LP) bw[tok->source] = add_log_domain_probs(bw[tok->source], normalized);
                else bw[tok->source] = normalized;
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movq %r9, -0x48(%rbp)
movq %rcx, -0x60(%rbp)
movq %rdx, %r12
movq %rsi, -0x40(%rbp)
movl 0x8(%rsi), %esi
decl %esi
movslq %esi, %rcx
movq (%rdx), %rax
imulq $0x18, %rcx, %rcx
movq 0x8(%rax,%rcx), %rdx
cmpq (%rax,%rcx), %rdx
je 0x15c18
movq %r8, %r14
movsd 0xdcb1(%rip), %xmm2     # 0x237a0
testl %esi, %esi
js 0x15c18
movl %esi, %r13d
imulq $0x18, %r13, %r15
movq (%rax,%r15), %rbx
movl %esi, -0x2c(%rbp)
movslq %esi, %rcx
movq %rcx, -0x58(%rbp)
movq %r13, -0x50(%rbp)
cmpq 0x8(%rax,%r15), %rbx
je 0x15c0e
movq (%r14), %rax
movsd (%rax,%r13,8), %xmm3
ucomisd %xmm2, %xmm3
jne 0x15b30
jnp 0x15c01
movq -0x60(%rbp), %rax
movq (%rax), %rax
movsd (%rax,%r13,8), %xmm1
ucomisd %xmm2, %xmm1
jne 0x15b49
jnp 0x15c01
movq %r14, %r13
movq %r15, %r14
movq %r12, %r15
movsd 0x8(%rbx), %xmm0
subsd %xmm1, %xmm0
addsd %xmm3, %xmm0
movsd %xmm0, -0x38(%rbp)
callq 0x4600
movsd %xmm0, -0x68(%rbp)
movslq (%rbx), %rdx
movq -0x58(%rbp), %rcx
subq %rdx, %rcx
incq %rdx
leaq -0x88(%rbp), %r12
movq %r12, %rdi
movq -0x40(%rbp), %rsi
callq 0x4360
movq -0x48(%rbp), %rdi
movq %r12, %rsi
callq 0x18e2a
movsd -0x68(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movq %r12, %rdi
callq 0x46b8
movslq (%rbx), %rax
cmpq $-0x1, %rax
movsd 0xdbe2(%rip), %xmm2     # 0x237a0
movq %r15, %r12
movq %r14, %r15
movq %r13, %r14
movq -0x50(%rbp), %r13
je 0x15c01
movq (%r14), %rcx
movsd (%rcx,%rax,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x15bdd
jnp 0x15bf7
movsd -0x38(%rbp), %xmm1
callq 0x15a53
movsd 0xdbb1(%rip), %xmm2     # 0x237a0
movslq (%rbx), %rax
movq (%r14), %rcx
jmp 0x15bfc
movsd -0x38(%rbp), %xmm0
movsd %xmm0, (%rcx,%rax,8)
addq $0x10, %rbx
movq (%r12), %rax
jmp 0x15b10
movl -0x2c(%rbp), %esi
decl %esi
jmp 0x15aef
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
callq 0x46b8
movq %rbx, %rdi
callq 0x45f0