// File: /workspace/github_cpp_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %r14
movq %rdi, %rbx
movq (%rsi), %rax
movq 0x18(%rax), %rsi
leaq 0x10(%rsp), %rdi
leaq 0xc(%rsp), %rdx
callq 0x4ad8
movl 0x10(%r14), %eax
cmpq $0x4, %rax
ja 0x3e88
leaq 0x24f3(%rip), %rcx      # 0x6238
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rax
movq 0x10(%rax), %r12
testq %r12, %r12
je 0x3e72
movq 0x10(%rsp), %r13
movq 0x20(%r14), %r15
addq $0x8, %r13
movl 0x8(%r12), %eax
movl %eax, -0x8(%r13)
leaq 0x10(%r12), %rsi
movq %r15, %rdx
callq 0x3ff6
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3d6b
jmp 0x3e72
movq (%r14), %rax
movq 0x10(%rax), %r15
testq %r15, %r15
je 0x3e72
movq 0x10(%rsp), %rax
xorl %r12d, %r12d
movl 0x8(%r15), %ecx
movl %ecx, (%rax,%r12)
leaq 0x10(%r15), %rsi
movq 0x20(%r14), %rdx
movq %r14, %rdi
callq 0x4516
movq 0x10(%rsp), %rax
movsd %xmm0, 0x8(%rax,%r12)
movq (%r15), %r15
addq $0x10, %r12
testq %r15, %r15
jne 0x3db1
jmp 0x3e72
movq (%r14), %rax
movq 0x10(%rax), %r12
movb $0x1, %bpl
testq %r12, %r12
je 0x3e74
movq 0x10(%rsp), %r13
movq 0x20(%r14), %r15
addq $0x8, %r13
movl 0x8(%r12), %eax
movl %eax, -0x8(%r13)
leaq 0x10(%r12), %rsi
movq %r15, %rdx
callq 0x42ba
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3e02
jmp 0x3e74
movq (%r14), %rax
movq 0x10(%rax), %r12
testq %r12, %r12
je 0x3e72
movq 0x10(%rsp), %r13
movq 0x20(%r14), %r15
addq $0x8, %r13
movl 0x8(%r12), %eax
movl %eax, -0x8(%r13)
leaq 0x10(%r12), %rsi
movq %r14, %rdi
movq %r15, %rdx
callq 0x4376
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3e46
xorl %ebp, %ebp
movl 0xc(%r14), %esi
incl %esi
movzbl %bpl, %edx
leaq 0x10(%rsp), %rdi
callq 0x4113
movslq 0xc(%r14), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4b5a
movl 0xc(%r14), %eax
testl %eax, %eax
jle 0x3ee1
xorl %r12d, %r12d
leaq 0xc(%rsp), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rcx
movl (%rcx,%r12), %ecx
movl %ecx, 0xc(%rsp)
cmpl 0x18(%r14), %ecx
je 0x3ed9
movq (%r14), %rdi
movq %r15, %rsi
callq 0x2fc4
movslq %ebp, %rcx
incl %ebp
movq (%rbx), %rdx
movq %rax, (%rdx,%rcx,8)
movl 0xc(%r14), %eax
addq $0x10, %r12
cmpl %eax, %ebp
jl 0x3eab
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3ef0
callq 0x21b0
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%r14), %rax
movq 0x10(%rax), %r12
movb $0x1, %bpl
testq %r12, %r12
je 0x3e74
movq 0x10(%rsp), %r13
movq 0x20(%r14), %r15
addq $0x8, %r13
movl 0x8(%r12), %eax
movl %eax, -0x8(%r13)
leaq 0x10(%r12), %rsi
movq %r15, %rdx
callq 0x41f2
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3f22
jmp 0x3e74
jmp 0x3f54
jmp 0x3f54
movq %rax, %r14
jmp 0x3f69
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x3f69
callq 0x21b0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3f78
callq 0x21b0
movq %r14, %rdi
callq 0x2320