// File: IlyaSamoylov45[P]MapReduce-Project/main.cpp
// Function: map_words_to_array(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, int, int)
std::vector<std::string> map_words_to_array(std::string file, int total_maps, int total_words) {
  int words_per_map = total_words/total_maps;
  int remaining_words = total_words%total_maps;


  std::string word;
  std::ifstream infile(file.c_str());

  int count = words_per_map;
  int current_map = 0;
  std::vector<std::string> ary(total_maps);

  if(remaining_words > 0){
    count++;
    remaining_words--;
  }
  while(infile >> word) {
    std::replace( word.begin(), word.end(), '-', ' ');
    std::replace( word.begin(), word.end(), ';', ' ');
    std::replace( word.begin(), word.end(), '.', ' ');
    std::replace( word.begin(), word.end(), ':', ' ');
    std::replace( word.begin(), word.end(), '!', ' ');
    std::replace( word.begin(), word.end(), ')', ' ');
    std::replace( word.begin(), word.end(), ',', ' ');
    //std::replace( word.begin(), word.end(), ';', ' ');
    //word.erase(std::remove_if(word.begin(), word.end(), remove_char), word.end());
    std::transform(word.begin(), word.end(), word.begin(), ::tolower);
    if(word != ""){
      if(count > 0){
        ary[current_map] = ary[current_map] + " " + word;
        //std::cout << ary[current_map] << std::endl;
        count--;
      }
      else{
        //std::cout <<" else" << std::endl;
        //std::cout << ary[current_map] << std::endl;
        count = words_per_map;
        if(remaining_words > 0){
          count++;
          remaining_words--;
        }
        current_map++;
        ary[current_map] = ary[current_map] + " " +  word;
        //std::cout << ary[current_map] << std::endl;
        count--;
      }
    }
  }
  //std::cout << ary[current_map] << std::endl;
  return ary;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x430, %rsp            # imm = 0x430
movq %rsi, -0x3b0(%rbp)
movq %rdi, -0x3c0(%rbp)
movq %rdi, %rax
movq %rax, -0x3b8(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl -0x18(%rbp), %eax
movl -0x14(%rbp), %ecx
cltd
idivl %ecx
movl %eax, -0x1c(%rbp)
movl -0x18(%rbp), %eax
movl -0x14(%rbp), %ecx
cltd
idivl %ecx
movl %edx, -0x20(%rbp)
leaq -0x40(%rbp), %rdi
callq 0x4450
movq -0x3b0(%rbp), %rdi
callq 0x4110
movq %rax, %rsi
leaq -0x248(%rbp), %rdi
movl $0x8, %edx
callq 0x4600
jmp 0x8324
movl -0x1c(%rbp), %eax
movl %eax, -0x258(%rbp)
movl $0x0, -0x25c(%rbp)
movb $0x0, -0x25d(%rbp)
movslq -0x14(%rbp), %rax
movq %rax, -0x3d0(%rbp)
leaq -0x25e(%rbp), %rdi
movq %rdi, -0x3c8(%rbp)
callq 0xa2b0
movq -0x3c0(%rbp), %rdi
movq -0x3d0(%rbp), %rsi
movq -0x3c8(%rbp), %rdx
callq 0xa2d0
jmp 0x8378
leaq -0x25e(%rbp), %rdi
callq 0xa340
cmpl $0x0, -0x20(%rbp)
jle 0x83de
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x83de
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x895c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x25e(%rbp), %rdi
callq 0xa340
jmp 0x8950
jmp 0x83e0
leaq -0x248(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x4400
movq %rax, -0x3d8(%rbp)
jmp 0x83f9
movq -0x3d8(%rbp), %rdi
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x43f0
movb %al, -0x3d9(%rbp)
jmp 0x8417
movb -0x3d9(%rbp), %al
testb $0x1, %al
jne 0x8426
jmp 0x8903
leaq -0x40(%rbp), %rdi
movq %rdi, -0x3e8(%rbp)
callq 0x42a0
movq -0x3e8(%rbp), %rdi
movq %rax, -0x268(%rbp)
callq 0x41b0
movq %rax, -0x270(%rbp)
movb $0x2d, -0x271(%rbp)
movb $0x20, -0x272(%rbp)
movq -0x268(%rbp), %rdi
movq -0x270(%rbp), %rsi
leaq -0x271(%rbp), %rdx
leaq -0x272(%rbp), %rcx
callq 0xa360
jmp 0x8481
leaq -0x40(%rbp), %rdi
movq %rdi, -0x3f0(%rbp)
callq 0x42a0
movq -0x3f0(%rbp), %rdi
movq %rax, -0x280(%rbp)
callq 0x41b0
movq %rax, -0x288(%rbp)
movb $0x3b, -0x289(%rbp)
movb $0x20, -0x28a(%rbp)
movq -0x280(%rbp), %rdi
movq -0x288(%rbp), %rsi
leaq -0x289(%rbp), %rdx
leaq -0x28a(%rbp), %rcx
callq 0xa360
jmp 0x84dc
leaq -0x40(%rbp), %rdi
movq %rdi, -0x3f8(%rbp)
callq 0x42a0
movq -0x3f8(%rbp), %rdi
movq %rax, -0x298(%rbp)
callq 0x41b0
movq %rax, -0x2a0(%rbp)
movb $0x2e, -0x2a1(%rbp)
movb $0x20, -0x2a2(%rbp)
movq -0x298(%rbp), %rdi
movq -0x2a0(%rbp), %rsi
leaq -0x2a1(%rbp), %rdx
leaq -0x2a2(%rbp), %rcx
callq 0xa360
jmp 0x8537
leaq -0x40(%rbp), %rdi
movq %rdi, -0x400(%rbp)
callq 0x42a0
movq -0x400(%rbp), %rdi
movq %rax, -0x2b0(%rbp)
callq 0x41b0
movq %rax, -0x2b8(%rbp)
movb $0x3a, -0x2b9(%rbp)
movb $0x20, -0x2ba(%rbp)
movq -0x2b0(%rbp), %rdi
movq -0x2b8(%rbp), %rsi
leaq -0x2b9(%rbp), %rdx
leaq -0x2ba(%rbp), %rcx
callq 0xa360
jmp 0x8592
leaq -0x40(%rbp), %rdi
movq %rdi, -0x408(%rbp)
callq 0x42a0
movq -0x408(%rbp), %rdi
movq %rax, -0x2c8(%rbp)
callq 0x41b0
movq %rax, -0x2d0(%rbp)
movb $0x21, -0x2d1(%rbp)
movb $0x20, -0x2d2(%rbp)
movq -0x2c8(%rbp), %rdi
movq -0x2d0(%rbp), %rsi
leaq -0x2d1(%rbp), %rdx
leaq -0x2d2(%rbp), %rcx
callq 0xa360
jmp 0x85ed
leaq -0x40(%rbp), %rdi
movq %rdi, -0x410(%rbp)
callq 0x42a0
movq -0x410(%rbp), %rdi
movq %rax, -0x2e0(%rbp)
callq 0x41b0
movq %rax, -0x2e8(%rbp)
movb $0x29, -0x2e9(%rbp)
movb $0x20, -0x2ea(%rbp)
movq -0x2e0(%rbp), %rdi
movq -0x2e8(%rbp), %rsi
leaq -0x2e9(%rbp), %rdx
leaq -0x2ea(%rbp), %rcx
callq 0xa360
jmp 0x8648
leaq -0x40(%rbp), %rdi
movq %rdi, -0x418(%rbp)
callq 0x42a0
movq -0x418(%rbp), %rdi
movq %rax, -0x2f8(%rbp)
callq 0x41b0
movq %rax, -0x300(%rbp)
movb $0x2c, -0x301(%rbp)
movb $0x20, -0x302(%rbp)
movq -0x2f8(%rbp), %rdi
movq -0x300(%rbp), %rsi
leaq -0x301(%rbp), %rdx
leaq -0x302(%rbp), %rcx
callq 0xa360
jmp 0x86a3
leaq -0x40(%rbp), %rdi
movq %rdi, -0x428(%rbp)
callq 0x42a0
movq -0x428(%rbp), %rdi
movq %rax, -0x310(%rbp)
callq 0x41b0
movq -0x428(%rbp), %rdi
movq %rax, -0x318(%rbp)
callq 0x42a0
movq %rax, -0x320(%rbp)
movq -0x310(%rbp), %rdi
movq -0x318(%rbp), %rsi
movq -0x320(%rbp), %rdx
movq 0x378d4(%rip), %rcx     # 0x3ffd0
callq 0xa3d0
movq %rax, -0x420(%rbp)
jmp 0x870a
movq -0x420(%rbp), %rax
movq %rax, -0x328(%rbp)
leaq 0x1face(%rip), %rsi     # 0x281ed
leaq -0x40(%rbp), %rdi
callq 0xa450
movb %al, -0x429(%rbp)
jmp 0x8730
movb -0x429(%rbp), %al
testb $0x1, %al
jne 0x873f
jmp 0x88fe
cmpl $0x0, -0x258(%rbp)
jle 0x8818
movq -0x3c0(%rbp), %rdi
movslq -0x25c(%rbp), %rsi
callq 0x98f0
movq %rax, %rsi
leaq 0x1f9c1(%rip), %rdx     # 0x2812a
leaq -0x368(%rbp), %rdi
callq 0xa4d0
jmp 0x8777
leaq -0x348(%rbp), %rdi
leaq -0x368(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xa480
jmp 0x8790
movq -0x3c0(%rbp), %rdi
movslq -0x25c(%rbp), %rsi
callq 0x98f0
movq %rax, %rdi
leaq -0x348(%rbp), %rsi
callq 0x43d0
leaq -0x348(%rbp), %rdi
callq 0x41f0
leaq -0x368(%rbp), %rdi
callq 0x41f0
movl -0x258(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x88fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
jmp 0x8944
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x368(%rbp), %rdi
callq 0x41f0
jmp 0x8944
movl -0x1c(%rbp), %eax
movl %eax, -0x258(%rbp)
cmpl $0x0, -0x20(%rbp)
jle 0x883f
movl -0x258(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x258(%rbp)
movl -0x20(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x20(%rbp)
movq -0x3c0(%rbp), %rdi
movl -0x25c(%rbp), %eax
incl %eax
movl %eax, -0x25c(%rbp)
movslq -0x25c(%rbp), %rsi
callq 0x98f0
movq %rax, %rsi
leaq 0x1f8c0(%rip), %rdx     # 0x2812a
leaq -0x3a8(%rbp), %rdi
callq 0xa4d0
jmp 0x8878
leaq -0x388(%rbp), %rdi
leaq -0x3a8(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xa480
jmp 0x8891
movq -0x3c0(%rbp), %rdi
movslq -0x25c(%rbp), %rsi
callq 0x98f0
movq %rax, %rdi
leaq -0x388(%rbp), %rsi
callq 0x43d0
leaq -0x388(%rbp), %rdi
callq 0x41f0
leaq -0x3a8(%rbp), %rdi
callq 0x41f0
movl -0x258(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x258(%rbp)
jmp 0x88fc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x250(%rbp)
movl %eax, -0x254(%rbp)
leaq -0x3a8(%rbp), %rdi
callq 0x41f0
jmp 0x8944
jmp 0x88fe
jmp 0x83e0
movb $0x1, -0x25d(%rbp)
testb $0x1, -0x25d(%rbp)
jne 0x891f
movq -0x3c0(%rbp), %rdi
callq 0x97e0
leaq -0x248(%rbp), %rdi
callq 0x4090
leaq -0x40(%rbp), %rdi
callq 0x41f0
movq -0x3b8(%rbp), %rax
addq $0x430, %rsp            # imm = 0x430
popq %rbp
retq
movq -0x3c0(%rbp), %rdi
callq 0x97e0
leaq -0x248(%rbp), %rdi
callq 0x4090
leaq -0x40(%rbp), %rdi
callq 0x41f0
movq -0x250(%rbp), %rdi
callq 0x45c0
nopw %cs:(%rax,%rax)