// File: aalto-speech[P]ftk/src/Bigrams.cc
// Function: Bigrams::init_candidates_num_contexts(unsigned int, 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>>, 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>>, 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::set<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>> const&)
int
Bigrams::init_candidates_num_contexts(unsigned int n_candidates,
                                      const transitions_t &transitions,
                                      const map<string, flt_type> &unigram_stats,
                                      map<string, flt_type> &candidates,
                                      const set<string> &stoplist)
{
    vector<pair<string, flt_type> > sorted_stats;
    Unigrams::sort_vocab(unigram_stats, sorted_stats, false);

    map<string, flt_type> ctxt_estimate;
    for (auto srcit = transitions.begin(); srcit != transitions.end(); ++srcit) {
        ctxt_estimate[srcit->first] += srcit->second.size();
        for (auto tgtit = srcit->second.begin(); tgtit != srcit->second.end(); ++tgtit)
            ctxt_estimate[tgtit->first] += 1;
    }

    for (auto ssit = sorted_stats.begin(); ssit != sorted_stats.end(); ++ssit)
        ssit->second = ctxt_estimate[ssit->first];
    stable_sort(sorted_stats.begin(), sorted_stats.end(), ascending_sort);

    for (auto it = sorted_stats.begin(); it != sorted_stats.end(); ++it) {
        if (stoplist.find(it->first) != stoplist.end()) continue;
        candidates[it->first] = 0.0;
        if (candidates.size() >= n_candidates) break;
    }

    return candidates.size();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movl %edi, -0x4(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
leaq -0x40(%rbp), %rdi
movq %rdi, -0xe8(%rbp)
callq 0x587e0
movq -0xe8(%rbp), %rsi
movq -0x18(%rbp), %rdi
xorl %edx, %edx
callq 0x55590
jmp 0x5ff52
leaq -0x80(%rbp), %rdi
callq 0x5fb0
movq -0x10(%rbp), %rdi
callq 0x60960
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x4fd10
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x60780
testb $0x1, %al
jne 0x5ff97
jmp 0x600f8
leaq -0x88(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x607e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x5fd0
movq -0x100(%rbp), %rdi
movq %rax, %xmm0
movaps 0x6857(%rip), %xmm1     # 0x66820
punpckldq %xmm1, %xmm0    # xmm0 = xmm0[0],xmm1[0],xmm0[1],xmm1[1]
movapd 0x685b(%rip), %xmm1     # 0x66830
subpd %xmm1, %xmm0
movaps %xmm0, %xmm1
unpckhpd %xmm0, %xmm0            # xmm0 = xmm0[1,1]
addsd %xmm1, %xmm0
movsd %xmm0, -0xf8(%rbp)
callq 0x607e0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x47db0
movq %rax, -0xf0(%rbp)
jmp 0x60006
movq -0xf0(%rbp), %rax
movsd -0xf8(%rbp), %xmm0
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq -0x88(%rbp), %rdi
callq 0x607e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x1b450
movq %rax, -0x98(%rbp)
leaq -0x88(%rbp), %rdi
callq 0x607e0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x1b480
movq %rax, -0xa0(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x1b290
testb $0x1, %al
jne 0x60074
jmp 0x600e5
leaq -0x98(%rbp), %rdi
callq 0x1b2f0
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x47db0
movq %rax, -0x108(%rbp)
jmp 0x60095
movq -0x108(%rbp), %rax
movsd 0x66dc(%rip), %xmm0     # 0x66780
addsd (%rax), %xmm0
movsd %xmm0, (%rax)
leaq -0x98(%rbp), %rdi
callq 0x1b320
jmp 0x6003c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x6030c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6090
jmp 0x6030c
jmp 0x600e7
leaq -0x88(%rbp), %rdi
callq 0x60810
jmp 0x5ff6b
leaq -0x40(%rbp), %rdi
callq 0x58a30
movq %rax, -0xa8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x58a60
movq %rax, -0xb0(%rbp)
leaq -0xa8(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x5ad80
testb $0x1, %al
jne 0x60131
jmp 0x6018f
leaq -0xa8(%rbp), %rdi
callq 0x60b10
movq %rax, %rsi
leaq -0x80(%rbp), %rdi
callq 0x47db0
movq %rax, -0x110(%rbp)
jmp 0x60152
movq -0x110(%rbp), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x118(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x60b10
movsd -0x118(%rbp), %xmm0
movsd %xmm0, 0x20(%rax)
leaq -0xa8(%rbp), %rdi
callq 0x5b5a0
jmp 0x60108
leaq -0x40(%rbp), %rdi
movq %rdi, -0x120(%rbp)
callq 0x58a30
movq -0x120(%rbp), %rdi
movq %rax, -0xb8(%rbp)
callq 0x58a60
movq %rax, -0xc0(%rbp)
movq -0xb8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
leaq -0xb67e(%rip), %rdx     # 0x54b50
callq 0x60c60
jmp 0x601d5
leaq -0x40(%rbp), %rdi
callq 0x58a30
movq %rax, -0xc8(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x58a60
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x5ad80
testb $0x1, %al
jne 0x60211
jmp 0x602dc
movq -0x28(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x60b10
movq -0x130(%rbp), %rdi
movq %rax, %rsi
callq 0x235e0
movq %rax, -0x128(%rbp)
jmp 0x60240
movq -0x128(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x28(%rbp), %rdi
callq 0x23610
movq %rax, -0xe0(%rbp)
leaq -0xd8(%rbp), %rdi
leaq -0xe0(%rbp), %rsi
callq 0x235b0
testb $0x1, %al
jne 0x60277
jmp 0x60279
jmp 0x602cb
movq -0x20(%rbp), %rax
movq %rax, -0x140(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x60b10
movq -0x140(%rbp), %rdi
movq %rax, %rsi
callq 0x47db0
movq %rax, -0x138(%rbp)
jmp 0x602a8
movq -0x138(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, (%rax)
movq -0x20(%rbp), %rdi
callq 0x5fd0
movl -0x4(%rbp), %ecx
cmpq %rcx, %rax
jb 0x602c9
jmp 0x602dc
jmp 0x602cb
leaq -0xc8(%rbp), %rdi
callq 0x5b5a0
jmp 0x601e5
movq -0x20(%rbp), %rdi
callq 0x5fd0
movl %eax, -0x144(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x6090
leaq -0x40(%rbp), %rdi
callq 0x58850
movl -0x144(%rbp), %eax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
leaq -0x40(%rbp), %rdi
callq 0x58850
movq -0x48(%rbp), %rdi
callq 0x46e0
nop