// File: aalto-speech[P]ftk/src/Unigrams.cc
// Function: Unigrams::init_candidates_by_random(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)
int
Unigrams::init_candidates_by_random(const map<string, flt_type> &vocab,
                                    set<string> &candidates,
                                    unsigned int n_candidates,
                                    const set<string> &stoplist,
                                    unsigned int min_length)
{
    vector<string> shuffled_vocab;
    for (auto it = vocab.cbegin(); it != vocab.cend(); ++it)
        shuffled_vocab.push_back(it->first);
    random_shuffle(shuffled_vocab.begin(), shuffled_vocab.end());

    int selected_candidates = 0;
    for (auto it = shuffled_vocab.begin(); it != shuffled_vocab.end(); ++it) {
        const string &subword = *it;
        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 $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq %r8, -0x28(%rbp)
movl %r9d, -0x2c(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xa160
movq -0x10(%rbp), %rdi
callq 0x1b260
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rdi
callq 0x1b2c0
movq %rax, -0x58(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x58(%rbp), %rsi
callq 0x1b290
testb $0x1, %al
jne 0x56a63
jmp 0x56aa1
leaq -0x50(%rbp), %rdi
callq 0x1b2f0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0xabb0
jmp 0x56a7a
jmp 0x56a7c
leaq -0x50(%rbp), %rdi
callq 0x1b320
jmp 0x56a43
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x60(%rbp)
movl %eax, -0x64(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6970
jmp 0x56c8f
leaq -0x48(%rbp), %rdi
movq %rdi, -0xd8(%rbp)
callq 0xb2f0
movq -0xd8(%rbp), %rdi
movq %rax, -0x70(%rbp)
callq 0xb320
movq %rax, -0x78(%rbp)
movq -0x70(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x58d10
jmp 0x56ad4
movl $0x0, -0x7c(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xb2f0
movq %rax, -0x88(%rbp)
leaq -0x48(%rbp), %rdi
callq 0xb320
movq %rax, -0x90(%rbp)
leaq -0x88(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x11960
testb $0x1, %al
jne 0x56b17
jmp 0x56c6e
leaq -0x88(%rbp), %rdi
callq 0x119d0
movq %rax, %rcx
movq -0xd0(%rbp), %rax
movq %rcx, -0x98(%rbp)
movq -0x98(%rbp), %rdi
movzbl 0x8(%rax), %esi
andl $0x1, %esi
callq 0x54dc0
movl %eax, -0xdc(%rbp)
jmp 0x56b4f
movl -0xdc(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jae 0x56b5f
jmp 0x56c5d
movq -0x18(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x58b10
movq %rax, -0xe8(%rbp)
jmp 0x56b78
movq -0xe8(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x23610
movq %rax, -0xa8(%rbp)
leaq -0xa0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x235b0
testb $0x1, %al
jne 0x56baf
jmp 0x56bb4
jmp 0x56c5d
movq -0x28(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x235e0
movq %rax, -0xf0(%rbp)
jmp 0x56bcd
movq -0xf0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x28(%rbp), %rdi
callq 0x23610
movq %rax, -0xb8(%rbp)
leaq -0xb0(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
callq 0x235b0
testb $0x1, %al
jne 0x56c04
jmp 0x56c06
jmp 0x56c5d
movq -0x18(%rbp), %rdi
movq -0x98(%rbp), %rsi
callq 0x31820
movb %dl, -0xf9(%rbp)
movq %rax, -0xf8(%rbp)
jmp 0x56c25
movb -0xf9(%rbp), %al
movq -0xf8(%rbp), %rcx
movq %rcx, -0xc8(%rbp)
movb %al, -0xc0(%rbp)
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
movq -0x18(%rbp), %rdi
callq 0x58af0
movl -0x1c(%rbp), %ecx
cmpq %rcx, %rax
jb 0x56c5b
jmp 0x56c6e
jmp 0x56c5d
leaq -0x88(%rbp), %rdi
callq 0x117f0
jmp 0x56aeb
movl -0x7c(%rbp), %eax
movl %eax, -0x100(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x6970
movl -0x100(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
movq -0x60(%rbp), %rdi
callq 0x46e0
nopl (%rax,%rax)