// File: aalto-speech[P]ftk/src/Unigrams.cc
// Function: Unigrams::init_candidates_by_usage(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::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>>>>&, unsigned int, 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&, unsigned int, double)
int
Unigrams::init_candidates_by_usage(const map<string, flt_type> &words,
                                   const map<string, flt_type> &vocab,
                                   set<string> &candidates,
                                   unsigned int n_candidates,
                                   const set<string> &stoplist,
                                   unsigned int min_length,
                                   flt_type max_usage)
{
    map<string, flt_type> words_type = words;
    for (auto it = words_type.begin(); it != words_type.end(); ++it)
        it->second = 1.0;

    map<string, flt_type> type_occ;
    resegment_words(words_type, vocab, type_occ);

    vector<pair<string, flt_type> > sorted_occ;
    sort_vocab(type_occ, sorted_occ, false);

    int selected_candidates = 0;
    for (auto it = sorted_occ.cbegin(); it != sorted_occ.cend(); ++it) {
        const string &subword = it->first;
        if (it->second > max_usage) break;
        if (get_factor_length(subword, this->utf8) < min_length) continue;
        if (candidates.find(subword) != candidates.end()) continue;
        if (stoplist.find(subword) != stoplist.end()) continue;
        candidates.insert(subword);
        selected_candidates++;
        if (candidates.size() >= n_candidates) break;
    }

    return selected_candidates;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1b0, %rsp            # imm = 0x1B0
movl 0x10(%rbp), %eax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq %r9, -0x30(%rbp)
movsd %xmm0, -0x38(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x10(%rbp), %rsi
leaq -0x68(%rbp), %rdi
callq 0x58de0
leaq -0x68(%rbp), %rdi
callq 0x58790
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
callq 0x48c90
movq %rax, -0x78(%rbp)
leaq -0x70(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x48c30
testb $0x1, %al
jne 0x56da0
jmp 0x56dc1
leaq -0x70(%rbp), %rdi
callq 0x587c0
movsd 0xf9cf(%rip), %xmm0     # 0x66780
movsd %xmm0, 0x20(%rax)
leaq -0x70(%rbp), %rdi
callq 0x4bba0
jmp 0x56d80
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x170(%rbp)
callq 0x5fb0
movq -0x18(%rbp), %rax
movq %rax, -0x178(%rbp)
xorps %xmm0, %xmm0
movaps %xmm0, -0xc0(%rbp)
movaps %xmm0, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
leaq -0xe0(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x6050
movq -0x160(%rbp), %rdi
movq -0x178(%rbp), %rdx
movq -0x170(%rbp), %rcx
movq -0x168(%rbp), %r8
leaq -0x68(%rbp), %rsi
callq 0x55a40
jmp 0x56e31
leaq -0xe0(%rbp), %rdi
callq 0x6070
leaq -0x108(%rbp), %rdi
movq %rdi, -0x180(%rbp)
callq 0x587e0
movq -0x180(%rbp), %rsi
leaq -0xa8(%rbp), %rdi
xorl %edx, %edx
callq 0x55590
jmp 0x56e67
movl $0x0, -0x10c(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x58c30
movq %rax, -0x118(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x58ca0
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x58c60
testb $0x1, %al
jne 0x56eb3
jmp 0x57070
leaq -0x118(%rbp), %rdi
callq 0x58cd0
movq %rax, -0x128(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x58cd0
movsd 0x20(%rax), %xmm0
ucomisd -0x38(%rbp), %xmm0
jbe 0x56f29
jmp 0x57070
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0xe0(%rbp), %rdi
callq 0x6070
jmp 0x570ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xe8(%rbp)
movl %eax, -0xec(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x58850
jmp 0x570ac
movq -0x160(%rbp), %rax
movq -0x128(%rbp), %rdi
movzbl 0x8(%rax), %esi
andl $0x1, %esi
callq 0x54dc0
movl %eax, -0x184(%rbp)
jmp 0x56f4b
movl -0x184(%rbp), %eax
cmpl 0x10(%rbp), %eax
jae 0x56f5b
jmp 0x5705f
movq -0x20(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x58b10
movq %rax, -0x190(%rbp)
jmp 0x56f74
movq -0x190(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x20(%rbp), %rdi
callq 0x23610
movq %rax, -0x138(%rbp)
leaq -0x130(%rbp), %rdi
leaq -0x138(%rbp), %rsi
callq 0x235b0
testb $0x1, %al
jne 0x56fab
jmp 0x56fb0
jmp 0x5705f
movq -0x30(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x235e0
movq %rax, -0x198(%rbp)
jmp 0x56fc9
movq -0x198(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x30(%rbp), %rdi
callq 0x23610
movq %rax, -0x148(%rbp)
leaq -0x140(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x235b0
testb $0x1, %al
jne 0x57000
jmp 0x57002
jmp 0x5705f
movq -0x20(%rbp), %rdi
movq -0x128(%rbp), %rsi
callq 0x31820
movb %dl, -0x1a1(%rbp)
movq %rax, -0x1a0(%rbp)
jmp 0x57021
movb -0x1a1(%rbp), %al
movq -0x1a0(%rbp), %rcx
movq %rcx, -0x158(%rbp)
movb %al, -0x150(%rbp)
movl -0x10c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x10c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x58af0
movl -0x24(%rbp), %ecx
cmpq %rcx, %rax
jb 0x5705d
jmp 0x57070
jmp 0x5705f
leaq -0x118(%rbp), %rdi
callq 0x58cf0
jmp 0x56e84
movl -0x10c(%rbp), %eax
movl %eax, -0x1a8(%rbp)
leaq -0x108(%rbp), %rdi
callq 0x58850
leaq -0xa8(%rbp), %rdi
callq 0x6090
leaq -0x68(%rbp), %rdi
callq 0x6090
movl -0x1a8(%rbp), %eax
addq $0x1b0, %rsp            # imm = 0x1B0
popq %rbp
retq
leaq -0xa8(%rbp), %rdi
callq 0x6090
leaq -0x68(%rbp), %rdi
callq 0x6090
movq -0xe8(%rbp), %rdi
callq 0x46e0
nopl (%rax)