// File: IlyaSamoylov45[P]MapReduce-Project/main.cpp
// Function: map_threads(std::vector<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>, std::allocator<std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>>>, int, ThreadData*)
void map_threads(std::vector<std::string> array, int maps, ThreadData thread_data[]){
  pthread_t threads[maps];
  int iret;
  for(int i = 0; i < maps; i++){
    //std::cout << "Creating thread: " << std::endl;
    thread_data[i].id = i;
    thread_data[i].line_array= array[i];

    iret = pthread_create(&threads[i], NULL, map_function_thread, (void*) &thread_data[i]);
    if (iret != 0) {
			std::cout << "Error: Creating thread: " << iret << std::endl;
			exit(EXIT_FAILURE);
		}
  }
  for (int i = 0; i < maps; i++) {
		iret = pthread_join(threads[i], NULL);
		if (iret) {
			std::cout << "Error: Joining thread: " << iret << std::endl;
			exit(EXIT_FAILURE);
		}
		/*
		std::map<std::string, int> testMap = thread_data[i].counter;
		for(auto it = testMap.begin(); it != testMap.end(); it++){
		  std::cout << it->first << " " << it->second << std::endl;
		} */
	}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x48(%rbp)
movq %rdi, -0x8(%rbp)
movl %esi, -0xc(%rbp)
movq %rdx, -0x18(%rbp)
movl -0xc(%rbp), %eax
movq %rsp, %rcx
movq %rcx, -0x20(%rbp)
leaq 0xf(,%rax,8), %rdx
andq $-0x10, %rdx
movq %rsp, %rcx
subq %rdx, %rcx
movq %rcx, -0x40(%rbp)
movq %rcx, %rsp
movq %rax, -0x28(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x66ab
movq -0x48(%rbp), %rdi
movl -0x30(%rbp), %ecx
movq -0x18(%rbp), %rax
movslq -0x30(%rbp), %rdx
imulq $0x58, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movslq -0x30(%rbp), %rsi
callq 0x98f0
movq %rax, %rsi
movq -0x18(%rbp), %rdi
movslq -0x30(%rbp), %rax
imulq $0x58, %rax, %rax
addq %rax, %rdi
addq $0x8, %rdi
callq 0x4040
movq -0x40(%rbp), %rdi
movslq -0x30(%rbp), %rax
shlq $0x3, %rax
addq %rax, %rdi
movq -0x18(%rbp), %rcx
movslq -0x30(%rbp), %rax
imulq $0x58, %rax, %rax
addq %rax, %rcx
xorl %eax, %eax
movl %eax, %esi
leaq 0xf6a(%rip), %rdx       # 0x75c0
callq 0x45f0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x669b
movq 0x39955(%rip), %rdi     # 0x3ffc0
leaq 0x21a89(%rip), %rsi     # 0x280fb
callq 0x4340
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x45b0
movq %rax, %rdi
movq 0x3991c(%rip), %rsi     # 0x3ffa8
callq 0x4370
movl $0x1, %edi
callq 0x43c0
jmp 0x669d
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x65e5
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0xc(%rbp), %eax
jge 0x671c
movq -0x40(%rbp), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x42e0
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x670f
movq 0x398e1(%rip), %rdi     # 0x3ffc0
leaq 0x21a2e(%rip), %rsi     # 0x28114
callq 0x4340
movq %rax, %rdi
movl -0x2c(%rbp), %esi
callq 0x45b0
movq %rax, %rdi
movq 0x398a8(%rip), %rsi     # 0x3ffa8
callq 0x4370
movl $0x1, %edi
callq 0x43c0
jmp 0x6711
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x66b2
movq -0x20(%rbp), %rax
movq %rax, %rsp
movq %rbp, %rsp
popq %rbp
retq
nopl (%rax,%rax)