// File: tylerwowen[P]movielens/./movielens/neighborsfinder.cpp
// Function: NeighborsLocator::getNeighbors()
UsersPtr NeighborsLocator::getNeighbors() {
  Distances distances(trainUsers->size());
  
  switch (method) {
    case COS:
      calculateSortableAllDistances(distances, &NeighborsLocator::cosineSimilarity);
      sort_nth_elemet(distances, k+1, false);
      break;
    case L1:
      calculateSortableAllDistances(distances, &NeighborsLocator::cityBlockDistance);
      sort_nth_elemet(distances, k+1, true);
      break;
    case L2:
      calculateSortableAllDistances(distances, &NeighborsLocator::euclideanDistance);
      sort_nth_elemet(distances, k+1, true);
      break;
    case PCC:
      calculateSortableAllDistances(distances, &NeighborsLocator::pcc);
      sort_nth_elemet(distances, k+1, false);
      break;
    case LLR:
      calculateSortableAllDistances(distances, &NeighborsLocator::llr);
      sort_nth_elemet(distances, k+1, false);
      break;
    default:
      break;
  }
  
  UsersPtr neighbors(k);
  for (int i = 0, j = 0; i < k; j++) {
    int userId = distances[j].first;
    if (userId == targetUserId) {
      continue;
    }
    neighbors[i++] = &((*trainUsers)[userId]);
  }
  return neighbors;
}

// Assembly:
subq $0xe8, %rsp
movq %rdi, 0x20(%rsp)
movq %rdi, %rax
movq %rax, 0x28(%rsp)
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x30(%rsp)
movq (%rax), %rdi
callq 0xbc30
movq %rax, 0x38(%rsp)
leaq 0xbf(%rsp), %rdi
movq %rdi, 0x40(%rsp)
callq 0xbc40
movq 0x38(%rsp), %rsi
movq 0x40(%rsp), %rdx
leaq 0xc0(%rsp), %rdi
callq 0xbc50
jmp 0x94d9
leaq 0xbf(%rsp), %rdi
callq 0xbcd0
movq 0x30(%rsp), %rax
movl 0x10(%rax), %eax
movq %rax, 0x18(%rsp)
subq $0x4, %rax
ja 0x970e
movq 0x18(%rsp), %rax
leaq 0x7ccf(%rip), %rcx      # 0x111d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0xbf(%rsp), %rdi
callq 0xbcd0
jmp 0x9865
movq 0x30(%rsp), %rdi
leaq 0x49c(%rip), %rax       # 0x99e0
movq %rax, 0x98(%rsp)
movq $0x0, 0xa0(%rsp)
movq 0x98(%rsp), %rdx
movq 0xa0(%rsp), %rcx
leaq 0xc0(%rsp), %rsi
callq 0x9880
jmp 0x9577
movq 0x30(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
leaq 0xc0(%rsp), %rdi
xorl %edx, %edx
callq 0x9f30
jmp 0x9592
jmp 0x9710
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
jmp 0x9858
movq 0x30(%rsp), %rdi
leaq 0xb14(%rip), %rax       # 0xa0d0
movq %rax, 0x88(%rsp)
movq $0x0, 0x90(%rsp)
movq 0x88(%rsp), %rdx
movq 0x90(%rsp), %rcx
leaq 0xc0(%rsp), %rsi
callq 0x9880
jmp 0x95ef
movq 0x30(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
leaq 0xc0(%rsp), %rdi
movl $0x1, %edx
callq 0x9f30
jmp 0x960d
jmp 0x9710
movq 0x30(%rsp), %rdi
leaq 0xf02(%rip), %rax       # 0xa520
movq %rax, 0x78(%rsp)
movq $0x0, 0x80(%rsp)
movq 0x78(%rsp), %rdx
movq 0x80(%rsp), %rcx
leaq 0xc0(%rsp), %rsi
callq 0x9880
jmp 0x964b
movq 0x30(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
leaq 0xc0(%rsp), %rdi
movl $0x1, %edx
callq 0x9f30
jmp 0x9669
jmp 0x9710
movq 0x30(%rsp), %rdi
leaq 0x12f6(%rip), %rax      # 0xa970
movq %rax, 0x68(%rsp)
movq $0x0, 0x70(%rsp)
movq 0x68(%rsp), %rdx
movq 0x70(%rsp), %rcx
leaq 0xc0(%rsp), %rsi
callq 0x9880
jmp 0x96a1
movq 0x30(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
leaq 0xc0(%rsp), %rdi
xorl %edx, %edx
callq 0x9f30
jmp 0x96bc
jmp 0x9710
movq 0x30(%rsp), %rdi
leaq 0x1926(%rip), %rax      # 0xaff0
movq %rax, 0x58(%rsp)
movq $0x0, 0x60(%rsp)
movq 0x58(%rsp), %rdx
movq 0x60(%rsp), %rcx
leaq 0xc0(%rsp), %rsi
callq 0x9880
jmp 0x96f1
movq 0x30(%rsp), %rax
movl 0xc(%rax), %esi
incl %esi
leaq 0xc0(%rsp), %rdi
xorl %edx, %edx
callq 0x9f30
jmp 0x970c
jmp 0x9710
jmp 0x9710
movq 0x30(%rsp), %rax
movb $0x0, 0x57(%rsp)
movslq 0xc(%rax), %rax
movq %rax, 0x8(%rsp)
leaq 0x56(%rsp), %rdi
movq %rdi, 0x10(%rsp)
callq 0xbce0
movq 0x20(%rsp), %rdi
movq 0x8(%rsp), %rsi
movq 0x10(%rsp), %rdx
callq 0xbcf0
jmp 0x9748
leaq 0x56(%rsp), %rdi
callq 0x8e40
movl $0x0, 0x50(%rsp)
movl $0x0, 0x4c(%rsp)
movq 0x30(%rsp), %rcx
movl 0x50(%rsp), %eax
cmpl 0xc(%rcx), %eax
jge 0x9828
movslq 0x4c(%rsp), %rsi
leaq 0xc0(%rsp), %rdi
callq 0xbd70
movq 0x30(%rsp), %rcx
movl (%rax), %eax
movl %eax, 0x48(%rsp)
movl 0x48(%rsp), %eax
cmpl 0x18(%rcx), %eax
jne 0x97bf
jmp 0x97f8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
leaq 0x56(%rsp), %rdi
callq 0x8e40
jmp 0x9858
movq 0x30(%rsp), %rax
movq (%rax), %rdi
leaq 0x48(%rsp), %rsi
callq 0x5640
movq %rax, (%rsp)
jmp 0x97d7
movq 0x20(%rsp), %rdi
movl 0x50(%rsp), %eax
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x50(%rsp)
movslq %eax, %rsi
callq 0x8020
movq (%rsp), %rcx
movq %rcx, (%rax)
movl 0x4c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x4c(%rsp)
jmp 0x9762
movq 0x20(%rsp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0xb0(%rsp)
movl %eax, 0xac(%rsp)
callq 0x82d0
jmp 0x9858
movb $0x1, 0x57(%rsp)
testb $0x1, 0x57(%rsp)
jne 0x983e
movq 0x20(%rsp), %rdi
callq 0x82d0
leaq 0xc0(%rsp), %rdi
callq 0xbd90
movq 0x28(%rsp), %rax
addq $0xe8, %rsp
retq
leaq 0xc0(%rsp), %rdi
callq 0xbd90
movq 0xb0(%rsp), %rdi
callq 0x2310
nopw %cs:(%rax,%rax)