// File: /workspace/github_cpp_makefile_star2_O1/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 0x7264
movq -0x48(%rbp), %rax
cmpq %rax, -0x40(%rbp)
jne 0x5b66
leaq 0x1a85b(%rip), %rdi     # 0x20348
callq 0x3440
movq -0x60(%rbp), %r14
leaq -0x70(%rbp), %rax
cmpq %rax, %r14
je 0x5c3f
movq 0x18(%rbx), %r12
leaq 0x20(%r14), %r15
movq %r12, %rdi
movq %r15, %rsi
callq 0x87ce
addq $0x8, %r12
cmpq %r12, %rax
je 0x5b46
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x71e4
movl (%rax), %r12d
movl 0x40(%r14), %r13d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x71e4
addl %r12d, %r13d
movl %r13d, (%rax)
jmp 0x5b59
movl 0x40(%r14), %r12d
movq 0x18(%rbx), %rdi
movq %r15, %rsi
callq 0x71e4
movl %r12d, (%rax)
movq %r14, %rdi
callq 0x3210
movq %rax, %r14
jmp 0x5af6
xorl %r14d, %r14d
leaq -0xa8(%rbp), %r15
imulq $0x58, %r14, %rcx
leaq (%rax,%rcx), %rsi
addq $0x28, %rsi
movq %r15, %rdi
callq 0x759e
movq %r14, -0x30(%rbp)
movq -0x90(%rbp), %r12
leaq -0xa0(%rbp), %rax
cmpq %rax, %r12
je 0x5bfe
leaq 0x20(%r12), %r13
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x87ce
leaq -0x70(%rbp), %rcx
cmpq %rcx, %rax
je 0x5bdd
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x71e4
movl (%rax), %r14d
movl 0x40(%r12), %r15d
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x71e4
addl %r14d, %r15d
movl %r15d, (%rax)
jmp 0x5bf1
movl 0x40(%r12), %r14d
leaq -0x78(%rbp), %rdi
movq %r13, %rsi
callq 0x71e4
movl %r14d, (%rax)
movq %r12, %rdi
callq 0x3210
movq %rax, %r12
jmp 0x5b8f
leaq -0xa8(%rbp), %r15
movq %r15, %rdi
callq 0x783e
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 0x5b70
jmp 0x5ae6
leaq 0x1a702(%rip), %rdi     # 0x20348
callq 0x3260
jmp 0x5c5e
movq %rax, %rbx
leaq -0xa8(%rbp), %rdi
callq 0x783e
jmp 0x5c61
movq %rax, %rbx
leaq -0x48(%rbp), %rdi
callq 0x712a
jmp 0x5c6f
movq %rax, %rbx
leaq -0x78(%rbp), %rdi
callq 0x783e
movq %rbx, %rdi
callq 0x3560