// File: /workspace/github_cpp_makefile_star2_O1/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 0x4bb6
movl 0x10(%r14), %eax
cmpq $0x4, %rax
ja 0x3f34
leaq 0x2447(%rip), %rcx      # 0x6238
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r14), %rax
movq 0x10(%rax), %r12
testq %r12, %r12
je 0x3f1e
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 0x40a0
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3e17
jmp 0x3f1e
movq (%r14), %rax
movq 0x10(%rax), %r15
testq %r15, %r15
je 0x3f1e
xorl %r12d, %r12d
movl 0x8(%r15), %eax
movq 0x10(%rsp), %rcx
movl %eax, (%rcx,%r12)
leaq 0x10(%r15), %rsi
movq 0x20(%r14), %rdx
movq %r14, %rdi
callq 0x45c8
movq 0x10(%rsp), %rax
movsd %xmm0, 0x8(%rax,%r12)
movq (%r15), %r15
addq $0x10, %r12
testq %r15, %r15
jne 0x3e58
jmp 0x3f1e
movq (%r14), %rax
movq 0x10(%rax), %r12
movb $0x1, %bpl
testq %r12, %r12
je 0x3f20
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 0x4368
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3eae
jmp 0x3f20
movq (%r14), %rax
movq 0x10(%rax), %r12
testq %r12, %r12
je 0x3f1e
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 0x4428
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3ef2
xorl %ebp, %ebp
movl 0xc(%r14), %esi
incl %esi
movzbl %bpl, %edx
leaq 0x10(%rsp), %rdi
callq 0x41bd
movslq 0xc(%r14), %rsi
leaq 0xc(%rsp), %rdx
movq %rbx, %rdi
callq 0x4c36
cmpl $0x0, 0xc(%r14)
jle 0x3f8a
xorl %r12d, %r12d
leaq 0xc(%rsp), %r15
xorl %ebp, %ebp
movq 0x10(%rsp), %rax
movl (%rax,%r12), %eax
movl %eax, 0xc(%rsp)
cmpl 0x18(%r14), %eax
je 0x3f80
movq (%r14), %rdi
movq %r15, %rsi
callq 0x301e
movslq %ebp, %rcx
incl %ebp
movq (%rbx), %rdx
movq %rax, (%rdx,%rcx,8)
addq $0x10, %r12
cmpl 0xc(%r14), %ebp
jl 0x3f56
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3f99
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 0x3f20
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 0x429c
movsd %xmm0, (%r13)
movq (%r12), %r12
addq $0x10, %r13
testq %r12, %r12
jne 0x3fcb
jmp 0x3f20
jmp 0x3ffd
jmp 0x3ffd
movq %rax, %r14
jmp 0x4012
movq %rax, %r14
movq (%rbx), %rdi
testq %rdi, %rdi
je 0x4012
callq 0x21b0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x4021
callq 0x21b0
movq %r14, %rdi
callq 0x2320
nop