// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x228, %rsp            # imm = 0x228
movq %rdi, %rbx
leaq 0x28(%rsp), %rdi
movl $0x10, %edx
callq 0x3510
xorpd %xmm0, %xmm0
movq %rsp, %rdx
movapd %xmm0, (%rdx)
movq $0x0, 0x10(%rdx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x5f6e
movq (%rsp), %r14
movq 0x8(%rsp), %rbx
cmpq %rbx, %r14
je 0x61c8
movq %rbx, %r15
subq %r14, %r15
movq %r15, %rax
sarq $0x3, %rax
movabsq $-0x3333333333333333, %rcx # imm = 0xCCCCCCCCCCCCCCCD
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7903
cmpq $0x281, %r15            # imm = 0x281
jl 0x61bd
leaq 0x280(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x7f0b
cmpq %rbx, %r15
je 0x61c8
movq %r15, %rdi
callq 0x805f
addq $0x28, %r15
jmp 0x61aa
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7f0b
movq (%rsp), %rbx
movq 0x8(%rsp), %rax
cmpq %rax, %rbx
je 0x62e2
xorpd %xmm1, %xmm1
movq %rbx, %rcx
movl (%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
addsd %xmm0, %xmm1
addq $0x28, %rcx
cmpq %rax, %rcx
jne 0x61e1
leaq 0x30(%rsp), %r15
cmpq %rax, %rbx
je 0x62e7
movsd %xmm1, 0x20(%rsp)
leaq 0x28(%rsp), %r14
leaq 0x5f3e(%rip), %r15      # 0xc156
leaq 0x5f3a(%rip), %r12      # 0xc159
leaq 0x5f36(%rip), %r13      # 0xc15c
movq 0x28(%rsp), %rax
movq -0x18(%rax), %rax
movq $0x3, 0x30(%rsp,%rax)
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %r14, %rdi
callq 0x32f0
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x32f0
movl (%rbx), %esi
movq %rbp, %rdi
callq 0x31a0
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x32f0
movl (%rbx), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x5d78(%rip), %xmm0     # 0xc008
movq %rbp, %rdi
callq 0x3410
movq %rax, %rbp
movl $0x2, %edx
movq %rax, %rdi
movq %r13, %rsi
callq 0x32f0
movq (%rbp), %rax
movq -0x18(%rax), %rdi
addq %rbp, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %rbp, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
addq $0x28, %rbx
cmpq 0x8(%rsp), %rbx
jne 0x6226
leaq 0x30(%rsp), %r15
movq %rsp, %rdi
callq 0x81dc
movq 0x9cd2(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x120(%rsp), %r14
movq %rcx, -0xf8(%r14)
movq -0x18(%rcx), %rcx
movq %rax, 0x28(%rsp,%rcx)
movq %r15, %rdi
callq 0x3210
movq %r14, %rdi
callq 0x3100
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6339
movq %rax, %rbx
movq %rsp, %rdi
callq 0x81dc
leaq 0x28(%rsp), %rdi
callq 0x33c0
movq %rbx, %rdi
callq 0x34b0