// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %r8, %r14
movq %rcx, 0x18(%rsp)
movq %rdx, %r13
movq %rsi, %rbp
movq %rdi, %rbx
leaq 0xccaa1(%rip), %r12     # 0xd5870
movq (%r12), %rax
movslq 0x10(%rax), %rdi
shlq $0x2, %rdi
leaq 0x9d09a(%rip), %rsi     # 0xa5e7c
movl $0x7, %edx
callq 0x3a0e1
movq %rax, %r15
movq (%r12), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8e0f
xorl %ecx, %ecx
movl $0x0, (%r15,%rcx,4)
incq %rcx
movslq 0x10(%rax), %rdx
cmpq %rdx, %rcx
jl 0x8dfb
cmpl $0x3, 0x140713c(%rax)
movq %rbx, 0x30(%rsp)
movq %r14, 0x28(%rsp)
jne 0x8e37
movq %r13, %rdi
movq %rbp, %rsi
movq 0x18(%rsp), %rbx
movq %rbx, %rdx
callq 0x313ff
jmp 0x8e49
movq 0x18(%rsp), %rbx
movl (%rbx), %edx
movq %r13, %rdi
movq %rbp, %rsi
callq 0x3151c
movq %rax, %r13
cvtsi2sdl (%rbx), %xmm0
movsd %xmm0, (%rsp)
movq %rbp, %rdi
callq 0x2f33a
movl %eax, 0x24(%rsp)
cmpl $0x0, (%rbx)
jle 0x8f7c
xorpd %xmm1, %xmm1
xorl %ebx, %ebx
xorl %ebp, %ebp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movsd %xmm1, 0x8(%rsp)
movq %rbx, %r14
movq (%r13,%rbx,8), %rdi
callq 0x2f33a
incq %rbx
xorps %xmm0, %xmm0
cvtsi2sd %ebx, %xmm0
movsd 0x9c67f(%rip), %xmm1    # 0xa5520
divsd %xmm0, %xmm1
cmpl %eax, 0x24(%rsp)
jne 0x8ecf
addsd 0x8(%rsp), %xmm1
leal -0x1(%rbp), %r12d
cmpl $0x2, %ebp
movsd %xmm1, 0x8(%rsp)
jl 0x8ef0
movsd (%rsp), %xmm1
addsd 0x9c653(%rip), %xmm1    # 0xa5520
jmp 0x8f26
movsd 0x8(%rsp), %xmm2
subsd %xmm1, %xmm2
leal 0x1(%rbp), %r12d
testl %ebp, %ebp
js 0x8efa
movsd (%rsp), %xmm1
addsd 0x9c632(%rip), %xmm1    # 0xa5520
jmp 0x8f0c
cmpl $0x1, %ebp
jne 0x8f19
xorl %r12d, %r12d
jmp 0x8f2b
cmpl $-0x1, %ebp
je 0x8f77
movsd (%rsp), %xmm1
addsd 0x9ce9c(%rip), %xmm1    # 0xa5da8
movsd %xmm1, (%rsp)
movsd %xmm2, 0x8(%rsp)
jmp 0x8f2b
movsd (%rsp), %xmm1
addsd 0x9ce82(%rip), %xmm1    # 0xa5da8
movsd %xmm1, (%rsp)
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
divsd %xmm0, %xmm1
movsd 0x10(%rsp), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, 0x10(%rsp)
movq (%r13,%r14,8), %rdi
callq 0x2f33a
cltq
incl (%r15,%rax,4)
movq 0x18(%rsp), %rax
movslq (%rax), %rax
movl %r12d, %ebp
movsd 0x8(%rsp), %xmm0
movapd %xmm0, %xmm1
cmpq %rax, %rbx
jl 0x8e7c
jmp 0x8f86
xorl %r12d, %r12d
jmp 0x8f11
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rbx
movsd %xmm0, 0x20(%rbx)
movsd (%rsp), %xmm0
movsd %xmm0, 0x30(%rbx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x28(%rbx)
leaq 0xcc8c4(%rip), %r14     # 0xd5870
movq (%r14), %rax
movl 0x10(%rax), %esi
movq %r15, %rdi
callq 0x38002
movl %eax, 0x8(%rbx)
movq (%r14), %rax
movl 0x10(%rax), %edx
movq %r15, %rdi
movq 0x28(%rsp), %rsi
callq 0x38540
movq %r13, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq