// File: /workspace/github_cpp_makefile_star2_O3/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, %rbx
leaq -0x70(%rbp), %rcx
movl $0x0, (%rcx)
xorl %eax, %eax
movq %rax, 0x8(%rcx)
movq %rcx, 0x10(%rcx)
movq %rcx, 0x18(%rcx)
movq %rax, 0x20(%rcx)
leaq -0x48(%rbp), %rdi
movq %rbx, %rsi
callq 0x712a
movq -0x48(%rbp), %rax
cmpq %rax, -0x40(%rbp)
jne 0x5b68
leaq 0x19859(%rip), %rdi     # 0x1f348
callq 0x3440
movq -0x60(%rbp), %r14
leaq -0x70(%rbp), %rax
cmpq %rax, %r14
je 0x5c41
movq 0x18(%rbx), %r12
leaq 0x20(%r14), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x8644
addq $0x8, %r12
cmpq %r12, %rax
je 0x5b48
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x70aa
movl (%rax), %r12d
movl 0x40(%r14), %r13d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x70aa
addl %r12d, %r13d
movl %r13d, (%rax)
jmp 0x5b5b
movl 0x40(%r14), %r12d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x70aa
movl %r12d, (%rax)
movq %r14, %rdi
callq 0x3210
movq %rax, %r14
jmp 0x5af8
xorl %r14d, %r14d
leaq -0xa8(%rbp), %r15
imulq $0x58, %r14, %rcx
leaq (%rax,%rcx), %rsi
addq $0x28, %rsi
movq %r15, %rdi
callq 0x7422
movq %r14, -0x30(%rbp)
movq -0x90(%rbp), %r12
leaq -0xa0(%rbp), %rax
cmpq %rax, %r12
je 0x5c00
leaq 0x20(%r12), %r13
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x8644
leaq -0x70(%rbp), %rcx
cmpq %rcx, %rax
je 0x5bdf
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x70aa
movl (%rax), %r14d
movl 0x40(%r12), %r15d
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x70aa
addl %r14d, %r15d
movl %r15d, (%rax)
jmp 0x5bf3
movl 0x40(%r12), %r14d
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x70aa
movl %r14d, (%rax)
movq %r12, %rdi
callq 0x3210
movq %rax, %r12
jmp 0x5b91
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
callq 0x76c2
movq -0x30(%rbp), %r14
incq %r14
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movabsq $0x2e8ba2e8ba2e8ba3, %rdx # imm = 0x2E8BA2E8BA2E8BA3
imulq %rdx, %rcx
cmpq %r14, %rcx
ja 0x5b72
jmp 0x5ae8
leaq 0x19700(%rip), %rdi     # 0x1f348
callq 0x3260
jmp 0x5c60
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x76c2
jmp 0x5c63
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x6fe6
jmp 0x5c71
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x76c2
movq %rbx, %rdi
callq 0x3560