// File: /workspace/github_cpp_makefile_star2_O1/tylerwowen[P]movielens/./movielens/main.cpp
// Function: main
int main(int argc, char ** argv) {
  struct arguments args;
  args.method = 0;
  args.matchedOnly = false;
  args.prettyPrint = false;
  args.maxRating = 5;
  
  argp_parse (&argp, argc, argv, 0, 0, &args);
  
  UsersMap trainUsers(args.userNum), testUsers;
  readData(args.trainFile, trainUsers);
  int testSize = readData(args.testFile, testUsers);
  int validTestSize = testSize;

  NeighborsLocator locator(&trainUsers, args.moiveNum, args.k, args.method, args.maxRating);
  double sum = 0, sumSQ = 0;
  int predictedCount = 0;
  int count_not_found = 0;
  if (args.matchedOnly) {
    for (auto& user: testUsers) {
      UsersMap::iterator trainUserItr = trainUsers.find(user.first);
      if (trainUserItr == trainUsers.end()) {
        cout << "not good " << count_not_found++ << " " << user.first << endl;
        validTestSize--;
        continue;
      }
      locator.setTargetUser(user.first, &trainUserItr->second);
      locator.calculateDistancesToNeighbors(args.userNum);
      
      for (auto& rating: user.second.r_list) {
        UsersPtr neighbors = locator.getMatchedKNeighbors(rating.first);
        double actual = rating.second;
        double prediction = getPredication(neighbors, rating.first);
        if (prediction == 0) {
          continue;
        }
        predictedCount++;
        sum += fabs(actual - prediction);
        sumSQ += pow(actual - prediction, 2);
      }
    }
  }
  else {
    for (auto& user: testUsers) {
      UsersMap::iterator trainUserItr = trainUsers.find(user.first);
      if (trainUserItr == trainUsers.end()) {
        cout << "not good\n" ;
        validTestSize--;
        continue;
      }
      locator.setTargetUser(user.first, &trainUserItr->second);
      UsersPtr neighbors = locator.getNeighbors();
      
      for (auto& rating: user.second.r_list) {
        double actual = rating.second;
        double prediction = getPredication(neighbors, rating.first);
        if (prediction == 0) {
          continue;
        }
        predictedCount++;
        sum += fabs(actual - prediction);
        sumSQ += pow(actual - prediction, 2);
      }
    }
  }
  double mae = sum / predictedCount,
  rmse = sqrt(sumSQ / predictedCount),
  recall = (double)predictedCount / (double)validTestSize;
  
  if (args.prettyPrint) {
    cout << "MAE = " << mae << endl;
    cout << "RMSE = " << rmse << endl;
    cout << "Recall = " << recall * 100 << "%" << endl;
  }
  else {
    cout << mae << " " << rmse << " " <<  recall << " ";
  }
  
  exit(0);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x168, %rsp            # imm = 0x168
movq %rsi, %rdx
movl %edi, %esi
leaq 0x58(%rsp), %rbx
movl $0x0, 0x18(%rbx)
movw $0x0, 0x24(%rbx)
movl $0x5, 0x20(%rbx)
leaq 0x5cc6(%rip), %rdi      # 0x91c0
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %rbx, %r9
callq 0x2050
movslq 0x10(%rbx), %rsi
leaq 0xc8(%rsp), %rdi
leaq 0x80(%rsp), %rdx
leaq 0x100(%rsp), %rcx
leaq 0x40(%rsp), %r8
callq 0x3cd6
leaq 0x130(%rsp), %rax
movq %rax, -0x30(%rax)
movq $0x1, -0x28(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, -0x20(%rax)
movl $0x3f800000, -0x10(%rax) # imm = 0x3F800000
movupd %xmm0, -0x8(%rax)
movq (%rbx), %rsi
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x20b0
leaq 0x80(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x2d68
leaq 0x90(%rsp), %r14
movq -0x10(%r14), %rdi
cmpq %r14, %rdi
je 0x3596
callq 0x21b0
movq 0x60(%rsp), %rsi
leaq 0x80(%rsp), %rdi
leaq 0x40(%rsp), %rdx
callq 0x20b0
leaq 0x80(%rsp), %rdi
leaq 0x100(%rsp), %rsi
callq 0x2d68
movl %eax, %ebp
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
je 0x35d6
callq 0x21b0
movl 0x74(%rsp), %ecx
movl 0x6c(%rsp), %edx
movl 0x70(%rsp), %r8d
movl 0x78(%rsp), %r9d
leaq 0x80(%rsp), %rdi
leaq 0xc8(%rsp), %rsi
callq 0x3d88
movq 0x110(%rsp), %rbx
cmpb $0x1, 0x7c(%rsp)
movl %ebp, 0xc(%rsp)
jne 0x381e
testq %rbx, %rbx
je 0x3827
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
leaq 0x40(%rsp), %rbp
leaq 0x150(%rsp), %r15
movl $0x0, 0x1c(%rsp)
movslq 0x8(%rbx), %rsi
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %r8
movq %rsi, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rcx
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x36a4
movq (%rdx), %r9
movq %rdx, %rax
cmpl 0x8(%r9), %esi
je 0x36a4
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x36a2
movslq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rcx, %rdx
jne 0x36a4
movq %r10, %rax
cmpl %edi, %esi
jne 0x3678
jmp 0x36a4
xorl %eax, %eax
testq %rax, %rax
je 0x36ae
movq (%rax), %rdx
jmp 0x36b0
xorl %edx, %edx
testq %rdx, %rdx
je 0x3794
addq $0x10, %rdx
leaq 0x80(%rsp), %rdi
callq 0x3daa
movl 0x68(%rsp), %esi
leaq 0x80(%rsp), %rdi
callq 0x47e8
leaq 0x10(%rbx), %r14
movq 0x10(%rbx), %r13
cmpq %r14, %r13
je 0x3810
movl 0x10(%r13), %edx
movq %rbp, %rdi
leaq 0x80(%rsp), %rsi
callq 0x49a2
movsd 0x18(%r13), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %r15, %rdi
movq %rbp, %rsi
callq 0x3bc4
movl 0x10(%r13), %esi
movq %r15, %rdi
callq 0x33ec
movq 0x150(%rsp), %rdi
testq %rdi, %rdi
je 0x3741
movsd %xmm0, 0x10(%rsp)
callq 0x21b0
movsd 0x10(%rsp), %xmm0
ucomisd 0x2947(%rip), %xmm0     # 0x6090
je 0x377c
incl %r12d
movapd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
andpd 0x290c(%rip), %xmm0     # 0x6070
mulsd %xmm1, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x20(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x378b
callq 0x21b0
movq (%r13), %r13
jmp 0x36e3
movl $0x9, %edx
movq 0x5830(%rip), %rdi      # 0x8fd0
leaq 0x28f1(%rip), %rsi      # 0x6098
callq 0x2210
movq 0x581d(%rip), %rdi      # 0x8fd0
movl 0x1c(%rsp), %esi
callq 0x2300
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
leaq 0x28e3(%rip), %rsi      # 0x60b1
callq 0x2210
movl 0x8(%rbx), %esi
movq %r14, %rdi
callq 0x2300
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x21c0
movsbl %al, %esi
movq %r14, %rdi
callq 0x2030
movq %rax, %rdi
callq 0x2140
incl 0x1c(%rsp)
decl 0xc(%rsp)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x363f
jmp 0x3834
testq %rbx, %rbx
jne 0x39b0
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
cvtsi2sd %r12d, %xmm2
movapd 0x20(%rsp), %xmm1
movapd %xmm1, %xmm3
unpckhpd %xmm1, %xmm3            # xmm3 = xmm3[1],xmm1[1]
movsd 0x2831(%rip), %xmm0     # 0x6080
divsd %xmm2, %xmm0
mulsd %xmm0, %xmm3
mulsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sdl 0xc(%rsp), %xmm1
sqrtsd %xmm0, %xmm0
movsd %xmm0, 0x30(%rsp)
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
cmpb $0x1, 0x7d(%rsp)
jne 0x3940
movapd %xmm3, 0x20(%rsp)
movq 0x5740(%rip), %rdi      # 0x8fd0
leaq 0x2815(%rip), %rsi      # 0x60ac
movl $0x6, %edx
callq 0x2210
movq 0x5728(%rip), %rdi      # 0x8fd0
movapd 0x20(%rsp), %xmm0
callq 0x22b0
movq %rax, %rdi
callq 0x20d0
movq 0x570e(%rip), %rdi      # 0x8fd0
leaq 0x27ea(%rip), %rsi      # 0x60b3
movl $0x7, %edx
callq 0x2210
movq 0x56f6(%rip), %rdi      # 0x8fd0
movsd 0x30(%rsp), %xmm0
callq 0x22b0
movq %rax, %rdi
callq 0x20d0
movq 0x56dc(%rip), %rdi      # 0x8fd0
leaq 0x27c0(%rip), %rsi      # 0x60bb
movl $0x9, %edx
callq 0x2210
movsd 0x10(%rsp), %xmm0
mulsd 0x2775(%rip), %xmm0     # 0x6088
movq 0x56b6(%rip), %rdi      # 0x8fd0
callq 0x22b0
movq %rax, %rbx
leaq 0x279c(%rip), %rsi      # 0x60c5
movl $0x1, %edx
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
callq 0x20d0
jmp 0x39a9
movq 0x5689(%rip), %rdi      # 0x8fd0
movapd %xmm3, %xmm0
callq 0x22b0
movq %rax, %rbx
leaq 0x2757(%rip), %rsi      # 0x60b1
movl $0x1, %edx
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
movsd 0x30(%rsp), %xmm0
callq 0x22b0
movq %rax, %rbx
leaq 0x2732(%rip), %rsi      # 0x60b1
movl $0x1, %edx
movq %rax, %rdi
callq 0x2210
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x22b0
leaq 0x2710(%rip), %rsi      # 0x60b1
movq %rax, %rdi
callq 0x21d0
xorl %edi, %edi
callq 0x2220
xorpd %xmm0, %xmm0
movapd %xmm0, 0x20(%rsp)
xorl %r12d, %r12d
leaq 0x80(%rsp), %r14
leaq 0x40(%rsp), %r13
leaq 0x138(%rsp), %rbp
movslq 0x8(%rbx), %rsi
movq 0xc8(%rsp), %rdi
movq 0xd0(%rsp), %r8
movq %rsi, %rax
xorl %edx, %edx
divq %r8
movq %rdx, %rcx
movq (%rdi,%rdx,8), %rdx
movl $0x0, %eax
testq %rdx, %rdx
je 0x3a37
movq (%rdx), %r9
movq %rdx, %rax
cmpl 0x8(%r9), %esi
je 0x3a37
movq %r9, %r10
movq (%r9), %r9
testq %r9, %r9
je 0x3a35
movslq 0x8(%r9), %rdi
movq %rdi, %rax
xorl %edx, %edx
divq %r8
movl $0x0, %eax
cmpq %rcx, %rdx
jne 0x3a37
movq %r10, %rax
cmpl %edi, %esi
jne 0x3a0b
jmp 0x3a37
xorl %eax, %eax
testq %rax, %rax
je 0x3a41
movq (%rax), %rdx
jmp 0x3a43
xorl %edx, %edx
testq %rdx, %rdx
je 0x3b11
addq $0x10, %rdx
movq %r14, %rdi
callq 0x3daa
movq %r13, %rdi
movq %r14, %rsi
callq 0x3db2
leaq 0x10(%rbx), %r15
movq 0x10(%rbx), %r14
cmpq %r15, %r14
je 0x3af8
movsd 0x18(%r14), %xmm0
movapd %xmm0, 0x30(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3bc4
movl 0x10(%r14), %esi
movq %rbp, %rdi
callq 0x33ec
movq 0x138(%rsp), %rdi
testq %rdi, %rdi
je 0x3ab5
movsd %xmm0, 0x10(%rsp)
callq 0x21b0
movsd 0x10(%rsp), %xmm0
ucomisd 0x25d3(%rip), %xmm0     # 0x6090
je 0x3af0
incl %r12d
movapd 0x30(%rsp), %xmm1
subsd %xmm0, %xmm1
movapd %xmm1, %xmm0
andpd 0x2598(%rip), %xmm0     # 0x6070
mulsd %xmm1, %xmm1
unpcklpd %xmm0, %xmm1            # xmm1 = xmm1[0],xmm0[0]
movapd 0x20(%rsp), %xmm0
addpd %xmm1, %xmm0
movapd %xmm0, 0x20(%rsp)
movq (%r14), %r14
jmp 0x3a6b
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3b07
callq 0x21b0
leaq 0x80(%rsp), %r14
jmp 0x3b2d
movl $0x9, %edx
movq 0x54b3(%rip), %rdi      # 0x8fd0
leaq 0x257e(%rip), %rsi      # 0x60a2
callq 0x2210
decl 0xc(%rsp)
movq (%rbx), %rbx
testq %rbx, %rbx
jne 0x39d2
jmp 0x3834
jmp 0x3b5c
jmp 0x3b5c
jmp 0x3b5c
jmp 0x3b5c
jmp 0x3b48
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x3b5f
callq 0x21b0
jmp 0x3b5f
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
jne 0x3b98
jmp 0x3ba2
jmp 0x3b9f
movq %rax, %rbx
movq 0x80(%rsp), %rdi
cmpq %r14, %rdi
jne 0x3b98
jmp 0x3ba2
jmp 0x3b9f
movq %rax, %rbx
leaq 0x90(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x3ba2
callq 0x21b0
jmp 0x3ba2
movq %rax, %rbx
leaq 0x100(%rsp), %rdi
callq 0x3c44
leaq 0xc8(%rsp), %rdi
callq 0x3c44
movq %rbx, %rdi
callq 0x2320