// File: IlyaSamoylov45[P]MapReduce-Project/main.cpp
// Function: wordCountPrint(std::map<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, std::less<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>, std::allocator<std::pair<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>> const, int>>>, std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
void wordCountPrint(std::map<std::string, int> result, std::string path) {
  std::ofstream outputFile;
  outputFile.open (path);
  int wordCountFinal = 0;
  //first print numbers
  for(auto it = result.begin(); it != result.end(); it++){
    std::string str = it->first;
    char alphaCheck = str.at(0);
    if(is_number(it->first)){
      outputFile << it->first << '\t' << it->second << "\n";
      wordCountFinal += it->second;
      result.erase(it->first);
    } else if (isalpha(alphaCheck) == 0 && alphaCheck != '(') {
      outputFile << it->first << '\t' << it->second << "\n";
      wordCountFinal += it->second;
      result.erase(it->first);
      
    }
  }
  // next words
  for(auto it = result.begin(); it != result.end(); it++){

      outputFile << it->first << '\t' << it->second << "\n";
      wordCountFinal += it->second;
  }
  std::cout << "final word count " << wordCountFinal << std::endl;
  outputFile.close();
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x310, %rsp            # imm = 0x310
movq %rdi, -0x290(%rbp)
movq %rsi, -0x280(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
leaq -0x210(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x4590
movq -0x288(%rbp), %rdi
movq -0x280(%rbp), %rsi
movl $0x10, %edx
callq 0x4160
jmp 0x6c6e
movq -0x290(%rbp), %rdi
movl $0x0, -0x220(%rbp)
callq 0x9cf0
movq %rax, -0x228(%rbp)
movq -0x290(%rbp), %rdi
callq 0x9d50
movq %rax, -0x230(%rbp)
leaq -0x228(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x9d20
testb $0x1, %al
jne 0x6cba
jmp 0x6f28
leaq -0x228(%rbp), %rdi
callq 0xa290
movq %rax, %rsi
leaq -0x250(%rbp), %rdi
callq 0x4120
jmp 0x6cd7
xorl %eax, %eax
movl %eax, %esi
leaq -0x250(%rbp), %rdi
callq 0x4660
movq %rax, -0x298(%rbp)
jmp 0x6cf0
movq -0x298(%rbp), %rax
movb (%rax), %al
movb %al, -0x251(%rbp)
leaq -0x228(%rbp), %rdi
callq 0xa290
movq %rax, %rdi
callq 0x94b0
movb %al, -0x299(%rbp)
jmp 0x6d1b
movb -0x299(%rbp), %al
testb $0x1, %al
jne 0x6d2a
jmp 0x6e21
leaq -0x228(%rbp), %rdi
callq 0xa290
movq %rax, %rsi
leaq -0x210(%rbp), %rdi
callq 0x42c0
movq %rax, -0x2a8(%rbp)
jmp 0x6d4e
movq -0x2a8(%rbp), %rdi
movl $0x9, %esi
callq 0x43a0
movq %rax, -0x2b0(%rbp)
jmp 0x6d68
leaq -0x228(%rbp), %rdi
callq 0xa290
movq -0x2b0(%rbp), %rdi
movl 0x20(%rax), %esi
callq 0x45b0
movq %rax, -0x2b8(%rbp)
jmp 0x6d8c
movq -0x2b8(%rbp), %rdi
leaq 0x21452(%rip), %rsi     # 0x281ec
callq 0x4340
jmp 0x6da1
leaq -0x228(%rbp), %rdi
movq %rdi, -0x2c0(%rbp)
callq 0xa290
movq -0x2c0(%rbp), %rdi
movl 0x20(%rax), %ecx
movl -0x220(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x220(%rbp)
callq 0xa290
movq -0x290(%rbp), %rdi
movq %rax, %rsi
callq 0xad10
jmp 0x6de2
jmp 0x6f02
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
jmp 0x7085
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x218(%rbp)
movl %eax, -0x21c(%rbp)
leaq -0x250(%rbp), %rdi
callq 0x41f0
jmp 0x7085
movsbl -0x251(%rbp), %edi
callq 0x4520
cmpl $0x0, %eax
jne 0x6f00
movsbl -0x251(%rbp), %eax
cmpl $0x28, %eax
je 0x6f00
leaq -0x228(%rbp), %rdi
callq 0xa290
movq %rax, %rsi
leaq -0x210(%rbp), %rdi
callq 0x42c0
movq %rax, -0x2c8(%rbp)
jmp 0x6e6a
movq -0x2c8(%rbp), %rdi
movl $0x9, %esi
callq 0x43a0
movq %rax, -0x2d0(%rbp)
jmp 0x6e84
leaq -0x228(%rbp), %rdi
callq 0xa290
movq -0x2d0(%rbp), %rdi
movl 0x20(%rax), %esi
callq 0x45b0
movq %rax, -0x2d8(%rbp)
jmp 0x6ea8
movq -0x2d8(%rbp), %rdi
leaq 0x21336(%rip), %rsi     # 0x281ec
callq 0x4340
jmp 0x6ebd
leaq -0x228(%rbp), %rdi
movq %rdi, -0x2e0(%rbp)
callq 0xa290
movq -0x2e0(%rbp), %rdi
movl 0x20(%rax), %ecx
movl -0x220(%rbp), %eax
addl %ecx, %eax
movl %eax, -0x220(%rbp)
callq 0xa290
movq -0x290(%rbp), %rdi
movq %rax, %rsi
callq 0xad10
jmp 0x6efe
jmp 0x6f00
jmp 0x6f02
leaq -0x250(%rbp), %rdi
callq 0x41f0
leaq -0x228(%rbp), %rdi
xorl %esi, %esi
callq 0x9d80
movq %rax, -0x260(%rbp)
jmp 0x6c8b
movq -0x290(%rbp), %rdi
callq 0x9cf0
movq %rax, -0x268(%rbp)
movq -0x290(%rbp), %rdi
callq 0x9d50
movq %rax, -0x270(%rbp)
leaq -0x268(%rbp), %rdi
leaq -0x270(%rbp), %rsi
callq 0x9d20
testb $0x1, %al
jne 0x6f6a
jmp 0x7016
leaq -0x268(%rbp), %rdi
callq 0xa290
movq %rax, %rsi
leaq -0x210(%rbp), %rdi
callq 0x42c0
movq %rax, -0x2e8(%rbp)
jmp 0x6f8e
movq -0x2e8(%rbp), %rdi
movl $0x9, %esi
callq 0x43a0
movq %rax, -0x2f0(%rbp)
jmp 0x6fa8
leaq -0x268(%rbp), %rdi
callq 0xa290
movq -0x2f0(%rbp), %rdi
movl 0x20(%rax), %esi
callq 0x45b0
movq %rax, -0x2f8(%rbp)
jmp 0x6fcc
movq -0x2f8(%rbp), %rdi
leaq 0x21212(%rip), %rsi     # 0x281ec
callq 0x4340
jmp 0x6fe1
leaq -0x268(%rbp), %rdi
callq 0xa290
movl 0x20(%rax), %eax
addl -0x220(%rbp), %eax
movl %eax, -0x220(%rbp)
leaq -0x268(%rbp), %rdi
xorl %esi, %esi
callq 0x9d80
movq %rax, -0x278(%rbp)
jmp 0x6f3b
movq 0x38fa3(%rip), %rdi     # 0x3ffc0
leaq 0x213af(%rip), %rsi     # 0x283d3
callq 0x4340
movq %rax, -0x300(%rbp)
jmp 0x7032
movq -0x300(%rbp), %rdi
movl -0x220(%rbp), %esi
callq 0x45b0
movq %rax, -0x308(%rbp)
jmp 0x704d
movq -0x308(%rbp), %rdi
movq 0x38f4d(%rip), %rsi     # 0x3ffa8
callq 0x4370
jmp 0x7062
leaq -0x210(%rbp), %rdi
callq 0x4470
jmp 0x7070
leaq -0x210(%rbp), %rdi
callq 0x44c0
addq $0x310, %rsp            # imm = 0x310
popq %rbp
retq
leaq -0x210(%rbp), %rdi
callq 0x44c0
movq -0x218(%rbp), %rdi
callq 0x45c0
nopl (%rax)