// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/instancelist.c
// Function: find_nearest_neighbors
Instanceptr* find_nearest_neighbors(Instanceptr list, Instanceptr item, int count)
{
 /*!Last Changed 10.03.2004*/
 Instanceptr* neighbors, data;
 double* distances, d;
 int i, j;
 neighbors = (Instanceptr*) safemalloc (count * sizeof(Instanceptr), "find_nearest_neighbors", 4);
 distances = (double *) safemalloc(count * sizeof(double), "find_nearest_neighbors", 5);
 for (i = 0; i < count; i++)
  {
   distances[i] = (double) +LONG_MAX;
   neighbors[i] = NULL;
  }
 data = list;
 while (data)
  {
   d = distance_between_instances(data, item);
   if (d < distances[count - 1])
    {
     i = 0;
     while (distances[i] < d)
       i++;
     for (j = count - 1; j > i; j--)
      {
       neighbors[j] = neighbors[j - 1];
       distances[j] = distances[j - 1];
      }
     neighbors[i] = data;
     distances[i] = d;
    }
   data = data->next;
  }
 safe_free(distances);
 return neighbors;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movslq -0x14(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x9ef20(%rip), %rsi     # 0xe5722
movl $0x4, %edx
callq 0x52d70
movq %rax, -0x20(%rbp)
movslq -0x14(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x9ef03(%rip), %rsi     # 0xe5722
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x14(%rbp), %eax
jge 0x4686c
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd 0x9c764(%rip), %xmm0    # 0xe2fb0
movsd %xmm0, (%rax,%rcx,8)
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq $0x0, (%rax,%rcx,8)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x46834
movq -0x8(%rbp), %rax
movq %rax, -0x28(%rbp)
cmpq $0x0, -0x28(%rbp)
je 0x46967
movq -0x28(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x442e0
movsd %xmm0, -0x38(%rbp)
movsd -0x38(%rbp), %xmm1
movq -0x30(%rbp), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x46956
movl $0x0, -0x3c(%rbp)
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movsd -0x38(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x468dc
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x468b9
movl -0x14(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x3c(%rbp), %eax
jle 0x46934
movq -0x20(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rdx
movq -0x20(%rbp), %rax
movslq -0x40(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x30(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x40(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x468e5
movq -0x28(%rbp), %rdx
movq -0x20(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movsd -0x38(%rbp), %xmm0
movq -0x30(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movq 0x10(%rax), %rax
movq %rax, -0x28(%rbp)
jmp 0x46874
movq -0x30(%rbp), %rdi
callq 0x52e80
movq -0x20(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nopw (%rax,%rax)