// File: /workspace/github_cpp_makefile_star2_O2/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 %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x230, %rsp            # imm = 0x230
movq %rdi, %rbx
leaq 0x30(%rsp), %rdi
pushq $0x10
popq %rdx
callq 0x34d0
xorpd %xmm0, %xmm0
leaq 0x10(%rsp), %rdx
movapd %xmm0, (%rdx)
andq $0x0, 0x10(%rdx)
movq %rbx, %rdi
xorl %esi, %esi
callq 0x519e
movq 0x10(%rsp), %r14
movq 0x18(%rsp), %rbx
cmpq %rbx, %r14
je 0x53bd
movq %rbx, %r15
subq %r14, %r15
pushq $0x28
popq %rcx
movq %r15, %rax
cqto
idivq %rcx
bsrq %rax, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x607a
cmpq $0x281, %r15            # imm = 0x281
jl 0x53b2
leaq 0x280(%r14), %r15
movq %r14, %rdi
movq %r15, %rsi
callq 0x63de
jmp 0x53ab
movq %r15, %rdi
callq 0x647a
addq $0x28, %r15
cmpq %rbx, %r15
jne 0x539f
jmp 0x53bd
movq %r14, %rdi
movq %rbx, %rsi
callq 0x63de
movq 0x10(%rsp), %rbx
movq 0x18(%rsp), %rax
xorpd %xmm0, %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rcx
cmpq %rax, %rcx
je 0x53f6
movl (%rcx), %edx
cvtsi2sd %rdx, %xmm0
movsd 0x8(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
addq $0x28, %rcx
jmp 0x53d4
leaq 0x30(%rsp), %r14
leaq 0x4d47(%rip), %r15      # 0xa149
leaq 0x4d43(%rip), %r12      # 0xa14c
leaq 0x4d3f(%rip), %r13      # 0xa14f
cmpq %rax, %rbx
je 0x549a
movq 0x30(%rsp), %rax
movq -0x18(%rax), %rax
movq $0x3, 0x38(%rsp,%rax)
addq $0x8, %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x3230
movq %rax, %rdi
movq %r15, %rsi
callq 0x3250
movl -0x8(%rbx), %esi
movq %rax, %rdi
callq 0x3190
movq %rax, %rdi
movq %r12, %rsi
callq 0x3250
movl -0x8(%rbx), %ecx
cvtsi2sd %rcx, %xmm0
divsd 0x8(%rsp), %xmm0
mulsd 0x4b97(%rip), %xmm0     # 0xa008
movq %rax, %rdi
callq 0x33f0
movq %rax, %rdi
movq %r13, %rsi
callq 0x3250
movq %rax, %rdi
callq 0x3130
movq 0x18(%rsp), %rax
addq $0x20, %rbx
jmp 0x5410
leaq 0x10(%rsp), %rdi
callq 0x65d2
leaq 0x30(%rsp), %rdi
callq 0x33a0
addq $0x230, %rsp            # imm = 0x230
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
retq
jmp 0x54c1
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x65d2
leaq 0x30(%rsp), %rdi
callq 0x33a0
movq %rbx, %rdi
callq 0x3480