// File: /workspace/github_cpp_makefile_star2_O2/IlyaSamoylov45[P]MapReduce-Project/main.cpp
// Function: reduce_function_thread(void*)
void *reduce_function_thread(void* thread) {
  struct ReduceThreadArgs *curr_args;
  curr_args = (struct ReduceThreadArgs *) thread;

  std::map<std::string, int> mergeMap;
  std::vector<ThreadData> curData = curr_args->thread_data;

  for(int i = 0; i < curData.size(); i++){
    std::map<std::string, int> curMap = curData[i].counter;

    for(auto it = curMap.begin(); it != curMap.end(); it++){
      if(mergeMap.count(it->first)){
        mergeMap[it->first] = mergeMap[it->first] + it->second;
      } else {
        mergeMap[it->first] = it->second;
      }

    }
  }

  pthread_mutex_lock(&lock1);
  for(auto it = mergeMap.begin(); it != mergeMap.end(); it++){
      if(curr_args->resultMerged->count(it->first)){
        curr_args->resultMerged->operator[](it->first) =  curr_args->resultMerged->operator[](it->first) + it->second;
      } else {
         curr_args->resultMerged->operator[](it->first) = it->second;
      }
  }
  pthread_mutex_unlock(&lock1);

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rsi
leaq -0xa8(%rbp), %rax
andl $0x0, (%rax)
andq $0x0, 0x8(%rax)
movq %rax, 0x10(%rax)
movq %rax, 0x18(%rax)
andq $0x0, 0x20(%rax)
leaq -0x50(%rbp), %rdi
movq %rsi, -0x30(%rbp)
callq 0x629e
xorl %ebx, %ebx
leaq -0x80(%rbp), %r14
leaq -0xb0(%rbp), %r15
movq -0x50(%rbp), %rcx
movq -0x48(%rbp), %rax
subq %rcx, %rax
cqto
pushq $0x58
popq %rsi
idivq %rsi
cmpq %rbx, %rax
jbe 0x50c0
imulq $0x58, %rbx, %rax
leaq (%rcx,%rax), %rsi
addq $0x28, %rsi
movq %r14, %rdi
callq 0x67b2
movq %rbx, -0x38(%rbp)
movq -0x68(%rbp), %r12
leaq -0x78(%rbp), %rax
cmpq %rax, %r12
je 0x50a8
leaq 0x20(%r12), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x6210
testq %rax, %rax
je 0x5089
movq %r15, %rdi
movq %r13, %rsi
callq 0x6234
movl (%rax), %r14d
movl 0x40(%r12), %ebx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6234
addl %r14d, %ebx
jmp 0x5099
movl 0x40(%r12), %ebx
movq %r15, %rdi
movq %r13, %rsi
callq 0x6234
movl %ebx, (%rax)
movq %r12, %rdi
callq 0x31e0
movq %rax, %r12
jmp 0x5048
leaq -0x80(%rbp), %r14
movq %r14, %rdi
callq 0x6adc
movq -0x38(%rbp), %rbx
incq %rbx
jmp 0x5010
leaq 0x1a241(%rip), %rdi     # 0x1f308
callq 0x33e0
movq -0x98(%rbp), %r14
leaq -0xa8(%rbp), %rax
cmpq %rax, %r14
je 0x5149
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
leaq 0x20(%r14), %r15
movq %r15, %rsi
callq 0x6210
testq %rax, %rax
je 0x5126
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0x6234
movl (%rax), %ebx
movl 0x40(%r14), %r12d
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0x6234
addl %ebx, %r12d
movl %r12d, (%rax)
jmp 0x513c
movl 0x40(%r14), %ebx
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rdi
movq %r15, %rsi
callq 0x6234
movl %ebx, (%rax)
movq %r14, %rdi
callq 0x31e0
movq %rax, %r14
jmp 0x50d3
leaq 0x1a1b8(%rip), %rdi     # 0x1f308
callq 0x3220
jmp 0x5157
movq %rax, %rbx
jmp 0x5168
movq %rax, %rbx
leaq -0x80(%rbp), %rdi
callq 0x6adc
leaq -0x50(%rbp), %rdi
callq 0x6156
jmp 0x5176
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
callq 0x6adc
movq %rbx, %rdi
callq 0x34e0