// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/classification.c
// Function: test_knn
Prediction test_knn(Instanceptr data, void* model, void* parameters, double* posterior)
{
 /*!Last Changed 05.01.2009 added normalize_array*/
 /*!Last Changed 01.11.2005 added posteriors*/
 /*!Last Changed 25.10.2004*/
 /*!Last Changed 21.03.2002*/
 int *ccounts, j, classno, sum;
 Prediction predicted;
 Instanceptr *nearestneighbors, train;
 Knn_parameterptr p;
 p = (Knn_parameterptr) parameters;
 train = (Instanceptr) model;
 ccounts = safemalloc(current_dataset->classno * sizeof(int), "test_knn", 7);
 for (j = 0; j < current_dataset->classno; j++)
   ccounts[j] = 0;
 if (current_dataset->storetype == STORE_KERNEL)
   nearestneighbors = find_all_neighbors(train, data, &(p->nearcount));
 else
   nearestneighbors = find_nearest_neighbors(train, data, p->nearcount);
 predicted.knnloss[0] = 0;
 predicted.knnloss[1] = 0;
 predicted.knnloss[2] = p->nearcount;
 classno = give_classno(data);
 sum = 0;
 for (j = 0; j < p->nearcount; j++)
  {
   if (classno == give_classno(nearestneighbors[j]))
    {
     predicted.knnloss[0] += 1 / (j + 1.0);
     sum--;
     if (sum > 0)
       predicted.knnloss[2]++;
     else
       if (sum < 0)
         predicted.knnloss[2]--;
    }
   else
    {
     predicted.knnloss[0] -= 1 / (j + 1.0);
     sum++;
     if (sum > 0)
       predicted.knnloss[2]++;
     else
       if (sum < 0)
         predicted.knnloss[2]--;
    }
   predicted.knnloss[1] -= sum / (j + 1.0);
   ccounts[give_classno(nearestneighbors[j])]++;
  }
 predicted.classno = find_max_in_list(ccounts, current_dataset->classno);
 normalize_array(ccounts, posterior, current_dataset->classno);
 safe_free(nearestneighbors);
 safe_free(ccounts);
 return predicted;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x60(%rbp)
movq %rdi, -0x58(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq %rcx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
leaq 0xf9909(%rip), %rax     # 0x105840
movq (%rax), %rax
movslq 0x10(%rax), %rdi
shlq $0x2, %rdi
leaq 0xd6bcb(%rip), %rsi     # 0xe2b14
movl $0x7, %edx
callq 0x52d70
movq %rax, -0x28(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
leaq 0xf98d8(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0xbf8a
movq -0x28(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movl $0x0, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xbf5e
leaq 0xf98af(%rip), %rax     # 0x105840
movq (%rax), %rax
cmpl $0x3, 0x140713c(%rax)
jne 0xbfb4
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x50(%rbp), %rdx
callq 0x46670
movq %rax, -0x40(%rbp)
jmp 0xbfcb
movq -0x48(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x50(%rbp), %rax
movl (%rax), %edx
callq 0x467e0
movq %rax, -0x40(%rbp)
movq -0x60(%rbp), %rax
xorps %xmm0, %xmm0
movsd %xmm0, 0x20(%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x28(%rax)
movq -0x50(%rbp), %rcx
cvtsi2sdl (%rcx), %xmm0
movsd %xmm0, 0x30(%rax)
movq -0x8(%rbp), %rdi
callq 0x43530
movl %eax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
movq -0x50(%rbp), %rcx
cmpl (%rcx), %eax
jge 0xc182
movl -0x30(%rbp), %eax
movl %eax, -0x64(%rbp)
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x43530
movl %eax, %ecx
movl -0x64(%rbp), %eax
cmpl %ecx, %eax
jne 0xc0a7
movq -0x60(%rbp), %rax
cvtsi2sdl -0x2c(%rbp), %xmm1
movsd 0xd5fd2(%rip), %xmm0    # 0xe2018
addsd %xmm0, %xmm1
movsd 0xd5fc6(%rip), %xmm0    # 0xe2018
divsd %xmm1, %xmm0
addsd 0x20(%rax), %xmm0
movsd %xmm0, 0x20(%rax)
movl -0x34(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0xc087
movq -0x60(%rbp), %rax
movsd 0xd5f9d(%rip), %xmm0    # 0xe2018
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0xc0a5
cmpl $0x0, -0x34(%rbp)
jge 0xc0a3
movq -0x60(%rbp), %rax
movsd 0xd69af(%rip), %xmm0    # 0xe2a48
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0xc0a5
jmp 0xc11d
movq -0x60(%rbp), %rax
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd 0xd5f60(%rip), %xmm1    # 0xe2018
addsd %xmm1, %xmm0
movsd 0xd5f54(%rip), %xmm1    # 0xe2018
divsd %xmm0, %xmm1
movsd 0x20(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x20(%rax)
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
cmpl $0x0, -0x34(%rbp)
jle 0xc0fd
movq -0x60(%rbp), %rax
movsd 0xd5f27(%rip), %xmm0    # 0xe2018
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0xc11b
cmpl $0x0, -0x34(%rbp)
jge 0xc119
movq -0x60(%rbp), %rax
movsd 0xd6939(%rip), %xmm0    # 0xe2a48
addsd 0x30(%rax), %xmm0
movsd %xmm0, 0x30(%rax)
jmp 0xc11b
jmp 0xc11d
movq -0x60(%rbp), %rax
cvtsi2sdl -0x34(%rbp), %xmm1
cvtsi2sdl -0x2c(%rbp), %xmm0
movsd 0xd5ee5(%rip), %xmm2    # 0xe2018
addsd %xmm2, %xmm0
divsd %xmm0, %xmm1
movsd 0x28(%rax), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x28(%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x40(%rbp), %rax
movslq -0x2c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x43530
movl %eax, %ecx
movq -0x70(%rbp), %rax
movslq %ecx, %rcx
movl (%rax,%rcx,4), %edx
addl $0x1, %edx
movl %edx, (%rax,%rcx,4)
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xc006
movq -0x28(%rbp), %rdi
leaq 0xf96b3(%rip), %rax     # 0x105840
movq (%rax), %rax
movl 0x10(%rax), %esi
callq 0x50070
movl %eax, %ecx
movq -0x60(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x28(%rbp), %rdi
movq -0x20(%rbp), %rsi
leaq 0xf9690(%rip), %rax     # 0x105840
movq (%rax), %rax
movl 0x10(%rax), %edx
callq 0x50a20
movq -0x40(%rbp), %rdi
callq 0x52e80
movq -0x28(%rbp), %rdi
callq 0x52e80
movq -0x58(%rbp), %rax
addq $0x70, %rsp
popq %rbp
retq
nopw (%rax,%rax)