// File: /workspace/github_cpp_makefile_star2_O1/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 0x5fa8
movq (%rsp), %r14
movq 0x8(%rsp), %rbx
cmpq %rbx, %r14
je 0x6202
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 0x7930
cmpq $0x281, %r15            # imm = 0x281
jl 0x61f7
leaq 0x280(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x7f99
cmpq %rbx, %r15
je 0x6202
movq %r15, %rdi
callq 0x80ed
addq $0x28, %r15
jmp 0x61e4
movq %r14, %rdi
movq %rbx, %rsi
callq 0x7f99
movq (%rsp), %rbp
movq 0x8(%rsp), %rax
xorpd %xmm1, %xmm1
cmpq %rax, %rbp
je 0x622e
movq %rbp, %rcx
movl (%rcx), %edx
xorps %xmm0, %xmm0
cvtsi2sd %rdx, %xmm0
addsd %xmm0, %xmm1
addq $0x28, %rcx
cmpq %rax, %rcx
jne 0x6217
movsd %xmm1, 0x20(%rsp)
cmpq 0x8(%rsp), %rbp
je 0x6317
leaq 0x28(%rsp), %rbx
leaq 0x5f0b(%rip), %r14      # 0xc156
leaq 0x5f07(%rip), %r15      # 0xc159
leaq 0x5f03(%rip), %r12      # 0xc15c
movq 0x28(%rsp), %rax
movq -0x18(%rax), %rax
movq $0x3, 0x30(%rsp,%rax)
movq 0x8(%rbp), %rsi
movq 0x10(%rbp), %rdx
movq %rbx, %rdi
callq 0x32f0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x32f0
movl (%rbp), %esi
movq %r13, %rdi
callq 0x31a0
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %r15, %rsi
callq 0x32f0
movl (%rbp), %eax
xorps %xmm0, %xmm0
cvtsi2sd %rax, %xmm0
divsd 0x20(%rsp), %xmm0
mulsd 0x5d43(%rip), %xmm0     # 0xc008
movq %r13, %rdi
callq 0x3410
movq %rax, %r13
movl $0x2, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x32f0
movq (%r13), %rax
movq -0x18(%rax), %rdi
addq %r13, %rdi
movl $0xa, %esi
callq 0x3260
movsbl %al, %esi
movq %r13, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31b0
addq $0x28, %rbp
cmpq 0x8(%rsp), %rbp
jne 0x6259
movq %rsp, %rdi
callq 0x8266
movq 0x9ca2(%rip), %rax      # 0xffc8
movq (%rax), %rcx
movq 0x18(%rax), %rax
leaq 0x30(%rsp), %rdi
movq %rcx, -0x8(%rdi)
movq -0x18(%rcx), %rcx
movq %rax, 0x28(%rsp,%rcx)
callq 0x3210
leaq 0x120(%rsp), %rdi
callq 0x3100
addq $0x228, %rsp            # imm = 0x228
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x6365
movq %rax, %rbx
movq %rsp, %rdi
callq 0x8266
leaq 0x28(%rsp), %rdi
callq 0x33c0
movq %rbx, %rdi
callq 0x34b0