// File: IHorvalds[P]RomAna/./processing/analyze_poet.hpp
// Function: PoetAnalyzer::saveFrequencies()
void saveFrequencies() {
    std::string filename = "poets/local/frequency/" + poet + "_local_frequencies.txt";
    std::ofstream out(filename);
    
    // Parse all his/her poems
    processPoems();
    
    /** Save in the file "poet_words_frequencies.txt"
      The encoding is:
      On the first line of the file: [countPoems] [sizeOfEachPoem]
      word = [word] count = [number of poems the words appears in] [list of pair(absolute frequency, index of poem)]
    **/
    
    // Print the first 2 lines
    out << countPoems;
    for (auto e : sizeOfPoems)
        out << " " << e;
    out << "\n";
    
    // And the rest
    for (auto iter : wordToFreqs) {
      std::string word = iter.first;
      std::vector<std::pair<uint32_t, uint32_t>> freqs = iter.second;

      // Sort the frequencies
      std::sort(freqs.begin(), freqs.end(), [](auto& left, auto& right) {
        return (left.first < right.first);
      });

      // And print the file
      out << word << " " << freqs.size();
      for (auto elem : freqs)
        out << " " << elem.first << " " << elem.second; 
      out << "\n";
    }
  }

// Assembly:
subq $0x388, %rsp            # imm = 0x388
movq %rdi, 0x380(%rsp)
movq 0x380(%rsp), %rdx
movq %rdx, 0x40(%rsp)
addq $0x10, %rdx
leaq 0x9e37(%rip), %rsi      # 0x155ee
leaq 0x340(%rsp), %rdi
movq %rdi, 0x48(%rsp)
callq 0xb330
movq 0x48(%rsp), %rsi
leaq 0x9e30(%rip), %rdx      # 0x15605
leaq 0x360(%rsp), %rdi
callq 0xb6e0
jmp 0xb7e4
leaq 0x340(%rsp), %rdi
callq 0x4200
leaq 0x130(%rsp), %rdi
leaq 0x360(%rsp), %rsi
movl $0x10, %edx
callq 0x4680
jmp 0xb80d
movq 0x40(%rsp), %rdi
callq 0xe300
jmp 0xb819
movq 0x40(%rsp), %rax
movl (%rax), %esi
leaq 0x130(%rsp), %rdi
callq 0x44a0
jmp 0xb82f
movq 0x40(%rsp), %rax
addq $0x30, %rax
movq %rax, 0x128(%rsp)
movq 0x128(%rsp), %rdi
callq 0xead0
movq %rax, 0x120(%rsp)
movq 0x128(%rsp), %rdi
callq 0xeb00
movq %rax, 0x118(%rsp)
leaq 0x120(%rsp), %rdi
leaq 0x118(%rsp), %rsi
callq 0xeb30
testb $0x1, %al
jne 0xb888
jmp 0xb935
leaq 0x120(%rsp), %rdi
callq 0xeb70
movl (%rax), %eax
movl %eax, 0x114(%rsp)
leaq 0x98f1(%rip), %rsi      # 0x15196
leaq 0x130(%rsp), %rdi
callq 0x4330
movq %rax, 0x38(%rsp)
jmp 0xb8b9
movq 0x38(%rsp), %rdi
movl 0x114(%rsp), %esi
callq 0x44a0
jmp 0xb8cc
jmp 0xb8ce
leaq 0x120(%rsp), %rdi
callq 0xeb80
jmp 0xb86a
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x340(%rsp), %rdi
callq 0x4200
jmp 0xbc35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0xbc28
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0xbc1b
leaq 0x9ce0(%rip), %rsi      # 0x1561c
leaq 0x130(%rsp), %rdi
callq 0x4330
jmp 0xb94b
movq 0x40(%rsp), %rax
addq $0x48, %rax
movq %rax, 0x108(%rsp)
movq 0x108(%rsp), %rdi
callq 0xeba0
movq %rax, 0x100(%rsp)
movq 0x108(%rsp), %rdi
callq 0xebd0
movq %rax, 0xf8(%rsp)
leaq 0x100(%rsp), %rdi
leaq 0xf8(%rsp), %rsi
callq 0xec00
testb $0x1, %al
jne 0xb9a4
jmp 0xbbf9
leaq 0x100(%rsp), %rdi
callq 0xec20
movq %rax, %rsi
leaq 0xc0(%rsp), %rdi
callq 0xec40
jmp 0xb9c3
leaq 0xa0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq 0x4170
jmp 0xb9da
leaq 0xe0(%rsp), %rsi
leaq 0x88(%rsp), %rdi
callq 0xeca0
jmp 0xb9f1
leaq 0x88(%rsp), %rdi
movq %rdi, 0x30(%rsp)
callq 0xede0
movq 0x30(%rsp), %rdi
movq %rax, 0x80(%rsp)
callq 0xee10
movq %rax, 0x78(%rsp)
movq 0x80(%rsp), %rdi
movq 0x78(%rsp), %rsi
callq 0xeda0
jmp 0xba2e
leaq 0x130(%rsp), %rdi
leaq 0xa0(%rsp), %rsi
callq 0x4310
movq %rax, 0x28(%rsp)
jmp 0xba4a
movq 0x28(%rsp), %rdi
leaq 0x9740(%rip), %rsi      # 0x15196
callq 0x4330
movq %rax, 0x20(%rsp)
jmp 0xba62
leaq 0x88(%rsp), %rdi
callq 0xee40
movq 0x20(%rsp), %rdi
movq %rax, %rsi
callq 0x40f0
jmp 0xba7e
leaq 0x88(%rsp), %rax
movq %rax, 0x68(%rsp)
movq 0x68(%rsp), %rdi
callq 0xede0
movq %rax, 0x60(%rsp)
movq 0x68(%rsp), %rdi
callq 0xee10
movq %rax, 0x58(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0xee60
testb $0x1, %al
jne 0xbac1
jmp 0xbb8e
leaq 0x60(%rsp), %rdi
callq 0xeea0
movq (%rax), %rax
movq %rax, 0x50(%rsp)
leaq 0x96bc(%rip), %rsi      # 0x15196
leaq 0x130(%rsp), %rdi
callq 0x4330
movq %rax, 0x18(%rsp)
jmp 0xbaee
movq 0x18(%rsp), %rdi
movl 0x50(%rsp), %esi
callq 0x44a0
movq %rax, 0x10(%rsp)
jmp 0xbb03
movq 0x10(%rsp), %rdi
leaq 0x9687(%rip), %rsi      # 0x15196
callq 0x4330
movq %rax, 0x8(%rsp)
jmp 0xbb1b
movq 0x8(%rsp), %rdi
movl 0x54(%rsp), %esi
callq 0x44a0
jmp 0xbb2b
jmp 0xbb2d
leaq 0x60(%rsp), %rdi
callq 0xeeb0
jmp 0xbaa9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0xbbea
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
jmp 0xbbdd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x338(%rsp)
movl %eax, 0x334(%rsp)
leaq 0x88(%rsp), %rdi
callq 0xe090
jmp 0xbbdd
leaq 0x9a87(%rip), %rsi      # 0x1561c
leaq 0x130(%rsp), %rdi
callq 0x4330
jmp 0xbba4
leaq 0x88(%rsp), %rdi
callq 0xe090
leaq 0xa0(%rsp), %rdi
callq 0x4200
leaq 0xc0(%rsp), %rdi
callq 0xe060
leaq 0x100(%rsp), %rdi
callq 0xeed0
jmp 0xb986
leaq 0xa0(%rsp), %rdi
callq 0x4200
leaq 0xc0(%rsp), %rdi
callq 0xe060
jmp 0xbc1b
leaq 0x130(%rsp), %rdi
callq 0x4520
leaq 0x360(%rsp), %rdi
callq 0x4200
addq $0x388, %rsp            # imm = 0x388
retq
leaq 0x130(%rsp), %rdi
callq 0x4520
leaq 0x360(%rsp), %rdi
callq 0x4200
movq 0x338(%rsp), %rdi
callq 0x4620
nopw %cs:(%rax,%rax)
nopl (%rax)