// File: aalto-speech[P]ftk/src/Bigrams.cc
// Function: Bigrams::remove_least_common(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&, 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>>>>>>&, std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, FactorGraph*, 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, FactorGraph*>>>&)
int
Bigrams::remove_least_common(const map<string, flt_type> &unigram_stats,
                             unsigned int num_removals,
                             transitions_t &transitions,
                             map<string, FactorGraph*> &fg_words)
{
    vector<pair<string, flt_type> > sorted_stats;
    Unigrams::sort_vocab(unigram_stats, sorted_stats, false);
    vector<string> to_remove;
    for (auto it = sorted_stats.begin(); it != sorted_stats.end(); ++it) {
        if (it->first.length() < 3) continue;
        to_remove.push_back(it->first);
        if (to_remove.size() >= num_removals) break;
    }

    remove_transitions(to_remove, transitions);

    for (auto fgit = fg_words.begin(); fgit != fg_words.end(); ++fgit) {
        for (unsigned int i=0; i<num_removals; i++) {
            size_t found = fgit->first.find(sorted_stats[i].first);
            if (found != std::string::npos) fgit->second->remove_arcs(sorted_stats[i].first);
        }
    }

    return to_remove.size();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x98(%rbp)
callq 0x587e0
movq -0x98(%rbp), %rsi
movq -0x8(%rbp), %rdi
xorl %edx, %edx
callq 0x55590
jmp 0x5ed3e
leaq -0x60(%rbp), %rdi
callq 0xa160
leaq -0x38(%rbp), %rdi
callq 0x58a30
movq %rax, -0x68(%rbp)
leaq -0x38(%rbp), %rdi
callq 0x58a60
movq %rax, -0x70(%rbp)
leaq -0x68(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x5ad80
testb $0x1, %al
jne 0x5ed74
jmp 0x5edf2
leaq -0x68(%rbp), %rdi
callq 0x60b10
movq %rax, %rdi
callq 0x45e0
cmpq $0x3, %rax
jae 0x5ed9e
jmp 0x5ede4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x5ef1d
leaq -0x68(%rbp), %rdi
callq 0x60b10
movq %rax, %rsi
leaq -0x60(%rbp), %rdi
callq 0xabb0
jmp 0x5edb5
leaq -0x60(%rbp), %rdi
callq 0x5f70
movl -0xc(%rbp), %ecx
cmpq %rcx, %rax
jb 0x5ede2
jmp 0x5edf2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x6970
jmp 0x5ef1d
jmp 0x5ede4
leaq -0x68(%rbp), %rdi
callq 0x5b5a0
jmp 0x5ed54
movq -0x18(%rbp), %rsi
leaq -0x60(%rbp), %rdi
callq 0x5e820
jmp 0x5ee01
movq -0x20(%rbp), %rdi
callq 0x60840
movq %rax, -0x78(%rbp)
movq -0x20(%rbp), %rdi
callq 0x608a0
movq %rax, -0x80(%rbp)
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x60870
testb $0x1, %al
jne 0x5ee31
jmp 0x5eeed
movl $0x0, -0x84(%rbp)
movl -0x84(%rbp), %eax
cmpl -0xc(%rbp), %eax
jae 0x5eedd
leaq -0x78(%rbp), %rdi
callq 0x608d0
movq %rax, -0xa0(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x58830
movq -0xa0(%rbp), %rdi
movq %rax, %rsi
xorl %eax, %eax
movl %eax, %edx
callq 0x4810
movq %rax, -0x90(%rbp)
cmpq $-0x1, -0x90(%rbp)
je 0x5eec7
leaq -0x78(%rbp), %rdi
callq 0x608d0
movq 0x20(%rax), %rax
movq %rax, -0xa8(%rbp)
movl -0x84(%rbp), %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x58830
movq -0xa8(%rbp), %rdi
movq %rax, %rsi
callq 0x22ae0
jmp 0x5eec5
jmp 0x5eec7
jmp 0x5eec9
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x5ee3b
jmp 0x5eedf
leaq -0x78(%rbp), %rdi
callq 0x60900
jmp 0x5ee0e
leaq -0x60(%rbp), %rdi
callq 0x5f70
movl %eax, -0xac(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x6970
leaq -0x38(%rbp), %rdi
callq 0x58850
movl -0xac(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x58850
movq -0x40(%rbp), %rdi
callq 0x46e0
nop