// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/classification.c
// Function: test_naivebayes
Prediction test_naivebayes(Instanceptr data, void* model, void* parameters, double* posterior)
{
 /*!Last Changed 11.08.2007*/
 Model_naivebayesptr m;
 double max, value, sum = 0.0;
 int i, j;
 Prediction predicted;
 m = (Model_naivebayesptr) model;
 max = -LONG_MAX;
 predicted.classno = -1;
 for (i = 0; i < current_dataset->classno; i++)
  {
   value = log(m->priors[i]);
   for (j = 0; j < current_dataset->featurecount; j++)
     switch (current_dataset->features[j].type)
      {
       case INTEGER:if (m->s[j] != 0)
                      value += -0.5 * ((data->values[j].intvalue - m->m[i][j]) / m->s[j]) * ((data->values[j].intvalue - m->m[i][j]) / m->s[j]);
                    break;
       case    REAL:if (m->s[j] != 0)
                      value += -0.5 * ((data->values[j].floatvalue - m->m[i][j]) / m->s[j]) * ((data->values[j].floatvalue - m->m[i][j]) / m->s[j]);
                    break;
       case  STRING:if (m->p[i][j][data->values[j].stringindex] > 0)
                      value += log(m->p[i][j][data->values[j].stringindex]);
                    break;
      }
   posterior[i] = safeexp(value);
   sum += posterior[i];
   if (value > max)
    {
     max = value;
     predicted.classno = i;
    }
  }
 for (i = 0; i < current_dataset->classno; i++)
   posterior[i] /= sum; 
 return predicted;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movsd 0x8c420(%rip), %xmm0    # 0x95dd0
pushq $-0x1
popq %rcx
xorl %r13d, %r13d
leaq 0xc3eb3(%rip), %r14     # 0xcd870
xorpd %xmm1, %xmm1
movq %r8, 0x20(%rsp)
movq (%r14), %rax
movslq 0x10(%rax), %rdx
cmpq %rdx, %r13
jge 0x9b1f
movsd %xmm0, 0x28(%rsp)
movl %ecx, 0x14(%rsp)
movsd %xmm1, 0x30(%rsp)
movq 0x10(%r15), %rax
movsd (%rax,%r13,8), %xmm0
callq 0x4160
xorpd %xmm2, %xmm2
movapd %xmm0, %xmm3
movq (%r14), %rax
movl $0x61e1, %ebp           # imm = 0x61E1
xorl %ebx, %ebx
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbx
jge 0x9ad3
movl (%rax,%rbp,8), %ecx
cmpl $0x2, %ecx
je 0x9a89
cmpl $0x1, %ecx
je 0x9a4c
testl %ecx, %ecx
jne 0x9ac7
movq 0x8(%r15), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9a41
jnp 0x9ac7
movq (%r12), %rcx
cvtsi2sdl (%rcx,%rbx,8), %xmm1
jmp 0x9aa3
movq 0x18(%r15), %rcx
movq (%rcx,%r13,8), %rcx
movq (%rcx,%rbx,8), %rcx
movq (%r12), %rdx
movslq (%rdx,%rbx,8), %rdx
movsd (%rcx,%rdx,8), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x9ac7
movsd %xmm3, 0x8(%rsp)
callq 0x4160
movsd 0x8(%rsp), %xmm3
xorpd %xmm2, %xmm2
addsd %xmm0, %xmm3
movq (%r14), %rax
jmp 0x9ac7
movq 0x8(%r15), %rcx
movsd (%rcx,%rbx,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9a9a
jnp 0x9ac7
movq (%r12), %rcx
movsd (%rcx,%rbx,8), %xmm1
movq (%r15), %rcx
movq (%rcx,%r13,8), %rcx
subsd (%rcx,%rbx,8), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x8c319(%rip), %xmm0    # 0x95dd8
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm3
incq %rbx
addq $0x68, %rbp
jmp 0x9a07
movapd %xmm3, %xmm0
movsd %xmm3, 0x8(%rsp)
callq 0x34d50
movsd 0x28(%rsp), %xmm2
movsd 0x8(%rsp), %xmm3
ucomisd %xmm2, %xmm3
movq 0x20(%rsp), %r8
movsd %xmm0, (%r8,%r13,8)
movl 0x14(%rsp), %ecx
cmoval %r13d, %ecx
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
maxsd %xmm2, %xmm3
movapd %xmm3, %xmm0
incq %r13
jmp 0x99c6
movq 0x18(%rsp), %rax
movl %ecx, 0x8(%rax)
xorl %ecx, %ecx
testl %edx, %edx
cmovlel %ecx, %edx
cmpq %rcx, %rdx
je 0x9b48
movsd (%r8,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r8,%rcx,8)
incq %rcx
jmp 0x9b2e
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq