// File: /workspace/github_cpp_makefile_star2_O2/aalto-speech[P]ftk/src/Bigrams.cc
// Function: Bigrams::kn_smooth(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>>>>>> 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, double)
void
Bigrams::kn_smooth(const transitions_t &counts,
                   transitions_t &kn,
                   double D,
                   double min_lp)
{
    kn.clear();

    map<string, double> ctxt_totals;
    map<string, double> ctxt_count;
    map<string, double> unigram_count;
    double u_total = 0;
    for (auto srcit = counts.begin(); srcit != counts.end(); ++srcit) {
        for (auto tgtit = srcit->second.begin(); tgtit != srcit->second.end(); ++tgtit) {
            if (tgtit->second > D) {
                ctxt_totals[srcit->first] += tgtit->second;
                ctxt_count[srcit->first] += D;
                unigram_count[tgtit->first] += D;
                u_total += D;
            }
            else {
                ctxt_totals[srcit->first] += tgtit->second;
                ctxt_count[srcit->first] += tgtit->second;
                unigram_count[tgtit->first] += tgtit->second;
                u_total += tgtit->second;
            }
        }
    }

    for (auto srcit = counts.begin(); srcit != counts.end(); ++srcit) {
        for (auto tgtit = srcit->second.begin(); tgtit != srcit->second.end(); ++tgtit) {
            double term1 = max(tgtit->second-D, 0.0);
            term1 /= ctxt_totals[srcit->first];
            double term2 = ctxt_count[srcit->first] / ctxt_totals[srcit->first];
            term2 *= unigram_count[tgtit->first] / u_total;
            double kn_prob = log(term1+term2);
            if (kn_prob < min_lp || std::isinf(kn_prob) || std::isnan(kn_prob)) kn_prob = min_lp;
            kn[srcit->first][tgtit->first] = kn_prob;
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movapd %xmm1, -0xa0(%rbp)
movsd %xmm0, -0x48(%rbp)
movq %rdi, %rbx
movq %rsi, -0x88(%rbp)
movq %rsi, %rdi
callq 0x1a3dc
leaq -0xf8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0xc8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x128(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
movq 0x18(%rbx), %rcx
movq %rbx, -0x50(%rbp)
leaq 0x8(%rbx), %rax
movq %rax, -0x78(%rbp)
xorpd %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
leaq -0x130(%rbp), %r14
cmpq -0x78(%rbp), %rcx
je 0x1f5dd
leaq 0x20(%rcx), %r15
movq 0x58(%rcx), %rbx
movq %rcx, -0x70(%rbp)
leaq 0x48(%rcx), %r13
cmpq %r13, %rbx
je 0x1f5cc
leaq 0x20(%rbx), %r12
movsd 0x40(%rbx), %xmm0
movsd %xmm0, -0x40(%rbp)
ucomisd -0x48(%rbp), %xmm0
jbe 0x1f545
leaq -0x100(%rbp), %rdi
movq %r15, %rsi
callq 0x18d90
movsd -0x40(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq -0xd0(%rbp), %rdi
movq %r15, %rsi
callq 0x18d90
movsd (%rax), %xmm0
addsd -0x48(%rbp), %xmm0
movsd %xmm0, (%rax)
movq %r14, %rdi
movq %r12, %rsi
callq 0x18d90
movsd (%rax), %xmm0
movsd -0x48(%rbp), %xmm1
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movapd %xmm1, %xmm0
jmp 0x1f5ae
leaq -0x100(%rbp), %rdi
movq %r15, %rsi
callq 0x18d90
movsd -0x40(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd 0x40(%rbx), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0xd0(%rbp), %rdi
movq %r15, %rsi
callq 0x18d90
movsd -0x40(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd 0x40(%rbx), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r14, %rdi
movq %r12, %rsi
callq 0x18d90
movsd -0x40(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
movsd 0x40(%rbx), %xmm0
movsd -0x58(%rbp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, -0x58(%rbp)
movq %rbx, %rdi
callq 0x43b0
movq %rax, %rbx
jmp 0x1f4cd
movq -0x70(%rbp), %rdi
callq 0x43b0
movq %rax, %rcx
jmp 0x1f4b3
movq -0x50(%rbp), %rax
movq 0x18(%rax), %rax
leaq -0x100(%rbp), %r14
cmpq -0x78(%rbp), %rax
je 0x1f753
leaq 0x20(%rax), %r15
movq 0x58(%rax), %r12
movq %rax, -0x80(%rbp)
leaq 0x48(%rax), %r13
cmpq %r13, %r12
je 0x1f745
movsd 0x40(%r12), %xmm0
movsd %xmm0, -0x40(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x18d90
movsd -0x40(%rbp), %xmm1
subsd -0x48(%rbp), %xmm1
xorpd %xmm0, %xmm0
maxsd %xmm1, %xmm0
divsd (%rax), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq -0xd0(%rbp), %rdi
movq %r15, %rsi
callq 0x18d90
movsd (%rax), %xmm0
movsd %xmm0, -0x70(%rbp)
movq %r14, %rdi
movq %r15, %rsi
callq 0x18d90
leaq 0x20(%r12), %rbx
movsd (%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
leaq -0x130(%rbp), %rdi
movq %rbx, %rsi
callq 0x18d90
movsd -0x70(%rbp), %xmm0
divsd -0x50(%rbp), %xmm0
movsd (%rax), %xmm1
divsd -0x58(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
addsd %xmm1, %xmm0
callq 0x42e0
movapd %xmm0, -0x40(%rbp)
movq %xmm0, %rax
btrq $0x3f, %rax
movapd -0xa0(%rbp), %xmm0
movapd %xmm0, -0x70(%rbp)
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
je 0x1f6db
movapd -0x40(%rbp), %xmm0
movapd %xmm0, -0x70(%rbp)
movq -0x88(%rbp), %rdi
movq %r15, %rsi
callq 0x19048
movq %rax, %rdi
movq %rbx, %rsi
callq 0x18d90
movapd -0x40(%rbp), %xmm3
movapd %xmm3, %xmm0
movapd -0xa0(%rbp), %xmm2
cmpltsd %xmm2, %xmm0
movapd %xmm0, %xmm1
andnpd -0x70(%rbp), %xmm1
andpd %xmm2, %xmm0
orpd %xmm1, %xmm0
cmpunordsd %xmm3, %xmm3
movapd %xmm3, %xmm1
andnpd %xmm0, %xmm1
andpd %xmm2, %xmm3
orpd %xmm1, %xmm3
movsd %xmm3, (%rax)
movq %r12, %rdi
callq 0x43b0
movq %rax, %r12
jmp 0x1f606
movq -0x80(%rbp), %rdi
callq 0x43b0
jmp 0x1f5ec
leaq -0x130(%rbp), %rdi
callq 0x543e
leaq -0xd0(%rbp), %rdi
callq 0x543e
leaq -0x100(%rbp), %rdi
callq 0x543e
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x1f78f
jmp 0x1f78f
jmp 0x1f78f
movq %rax, %rbx
leaq -0x130(%rbp), %rdi
callq 0x543e
leaq -0xd0(%rbp), %rdi
callq 0x543e
leaq -0x100(%rbp), %rdi
callq 0x543e
movq %rbx, %rdi
callq 0x45f0