// File: IHorvalds[P]RomAna/./processing/InflexEngineUtil.cpp
// Function: InflexEngine::showFreqs(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void InflexEngine::showFreqs(std::string filename) {
  std::ofstream out(filename);

  // Get all frequencies from trie
  std::vector<std::pair<uint32_t, std::string>> init_vector;
  getAllFreqs(ROOT, init_vector);

  // Sort the accumulated frequencies. Where equality between frequencies, prefer lexicografically order on words
  std::sort(init_vector.begin(), init_vector.end(), [](auto& left, auto& right) {
    return (left.first > right.first) || ((left.first == right.first) && (left.second < right.second));
  });

  // Compute the sum of all frequencies
  double sumOfFreqs = 0;
  for (auto iter = init_vector.begin(); iter != init_vector.end(); ++iter)
    sumOfFreqs += iter->first;

  // And print them as word - (frequency, ratio)
  for (auto iter = init_vector.begin(); iter != init_vector.end(); ++iter)
    out << std::setprecision(3) << iter->second << " (" << iter->first << ", " << (iter->first / sumOfFreqs) * 100 << "%)" << std::endl;
}

// Assembly:
subq $0x2d8, %rsp            # imm = 0x2D8
movq %rdi, 0x2d0(%rsp)
movq %rsi, 0x2c8(%rsp)
movq 0x2d0(%rsp), %rax
movq %rax, 0x48(%rsp)
leaq 0xc8(%rsp), %rdi
movl $0x10, %edx
callq 0x4680
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x50(%rsp)
callq 0xb030
movq 0x48(%rsp), %rdi
movq 0x50(%rsp), %rdx
xorl %esi, %esi
callq 0x7bc0
jmp 0x7ddb
leaq 0xb0(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xb130
movq 0x40(%rsp), %rdi
movq %rax, 0x98(%rsp)
callq 0xb160
movq %rax, 0x90(%rsp)
movq 0x98(%rsp), %rdi
movq 0x90(%rsp), %rsi
callq 0x8050
jmp 0x7e1e
xorps %xmm0, %xmm0
movsd %xmm0, 0x80(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xb130
movq %rax, 0x78(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xb160
movq %rax, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x70(%rsp), %rsi
callq 0xb190
testb $0x1, %al
jne 0x7e63
jmp 0x7ec5
leaq 0x78(%rsp), %rdi
callq 0xb1d0
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
addsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
leaq 0x78(%rsp), %rdi
callq 0xb1e0
jmp 0x7e3c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xa8(%rsp)
movl %eax, 0xa4(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xb040
leaq 0xc8(%rsp), %rdi
callq 0x4520
jmp 0x8037
leaq 0xb0(%rsp), %rdi
callq 0xb130
movq %rax, 0x68(%rsp)
leaq 0xb0(%rsp), %rdi
callq 0xb160
movq %rax, 0x60(%rsp)
leaq 0x68(%rsp), %rdi
leaq 0x60(%rsp), %rsi
callq 0xb190
testb $0x1, %al
jne 0x7f01
jmp 0x8015
movl $0x3, %edi
callq 0xb200
movl %eax, 0x3c(%rsp)
jmp 0x7f11
movl 0x3c(%rsp), %eax
movl %eax, 0x5c(%rsp)
movl 0x5c(%rsp), %esi
leaq 0xc8(%rsp), %rdi
callq 0x4570
movq %rax, 0x30(%rsp)
jmp 0x7f31
leaq 0x68(%rsp), %rdi
callq 0xb1d0
movq 0x30(%rsp), %rdi
movq %rax, %rsi
addq $0x8, %rsi
callq 0x4310
movq %rax, 0x28(%rsp)
jmp 0x7f53
movq 0x28(%rsp), %rdi
leaq 0xd233(%rip), %rsi      # 0x15192
callq 0x4330
movq %rax, 0x20(%rsp)
jmp 0x7f6b
leaq 0x68(%rsp), %rdi
callq 0xb1d0
movq 0x20(%rsp), %rdi
movl (%rax), %esi
callq 0x44a0
movq %rax, 0x18(%rsp)
jmp 0x7f88
movq 0x18(%rsp), %rdi
leaq 0xd201(%rip), %rsi      # 0x15195
callq 0x4330
movq %rax, 0x10(%rsp)
jmp 0x7fa0
leaq 0x68(%rsp), %rdi
callq 0xb1d0
movq 0x10(%rsp), %rdi
movl (%rax), %eax
cvtsi2sd %rax, %xmm0
movsd 0x80(%rsp), %xmm1
divsd %xmm1, %xmm0
movsd 0xd03d(%rip), %xmm1     # 0x15008
mulsd %xmm1, %xmm0
callq 0x4660
movq %rax, 0x8(%rsp)
jmp 0x7fdb
movq 0x8(%rsp), %rdi
leaq 0xd1b1(%rip), %rsi      # 0x15198
callq 0x4330
movq %rax, (%rsp)
jmp 0x7ff2
movq (%rsp), %rdi
movq 0x13fab(%rip), %rsi     # 0x1bfa8
callq 0x4380
jmp 0x8004
jmp 0x8006
leaq 0x68(%rsp), %rdi
callq 0xb1e0
jmp 0x7ed7
leaq 0xb0(%rsp), %rdi
callq 0xb040
leaq 0xc8(%rsp), %rdi
callq 0x4520
addq $0x2d8, %rsp            # imm = 0x2D8
retq
movq 0xa8(%rsp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)