// File: /workspace/github_c_makefile_star2_O1/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
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
leaq 0xc8a74(%rip), %r13     # 0xd2870
movq (%r13), %rax
movl 0x10(%rax), %eax
testl %eax, %eax
jle 0x9f94
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x18(%rsp)
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movsd 0x98fa5(%rip), %xmm0    # 0xa2dc8
xorl %r14d, %r14d
xorpd %xmm1, %xmm1
movq %r8, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
movl %ecx, 0x14(%rsp)
movsd %xmm1, 0x30(%rsp)
movq 0x10(%r15), %rax
movsd (%rax,%r14,8), %xmm0
callq 0x4160
movapd %xmm0, %xmm3
movq (%r13), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9f35
movl $0x61e1, %ebx           # imm = 0x61E1
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
movl (%rax,%rbx,8), %eax
cmpl $0x2, %eax
je 0x9edc
cmpl $0x1, %eax
je 0x9ea6
testl %eax, %eax
jne 0x9f1a
movq 0x8(%r15), %rax
movsd (%rax,%rbp,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9e98
jnp 0x9f1a
movq (%r12), %rax
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%rbp,8), %xmm1
jmp 0x9ef6
movq 0x18(%r15), %rax
movq (%rax,%r14,8), %rax
movq (%rax,%rbp,8), %rax
movq (%r12), %rcx
movslq (%rcx,%rbp,8), %rcx
movsd (%rax,%rcx,8), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x9f1a
movsd %xmm3, 0x8(%rsp)
callq 0x4160
movsd 0x8(%rsp), %xmm3
xorpd %xmm2, %xmm2
jmp 0x9f16
movq 0x8(%r15), %rax
movsd (%rax,%rbp,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9eed
jnp 0x9f1a
movq (%r12), %rax
movsd (%rax,%rbp,8), %xmm1
movq (%r15), %rax
movq (%rax,%r14,8), %rax
subsd (%rax,%rbp,8), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x98ebe(%rip), %xmm0    # 0xa2dd0
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm3
incq %rbp
movq (%r13), %rax
movslq 0x1bc(%rax), %rcx
addq $0x68, %rbx
cmpq %rcx, %rbp
jl 0x9e6e
movsd %xmm3, 0x8(%rsp)
movapd %xmm3, %xmm0
callq 0x38e72
movsd 0x28(%rsp), %xmm2
movsd 0x8(%rsp), %xmm3
ucomisd %xmm2, %xmm3
movl 0x14(%rsp), %ecx
cmoval %r14d, %ecx
movq 0x20(%rsp), %r8
movsd %xmm0, (%r8,%r14,8)
movsd 0x30(%rsp), %xmm1
addsd %xmm0, %xmm1
maxsd %xmm2, %xmm3
movapd %xmm3, %xmm0
incq %r14
movq (%r13), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r14
jl 0x9e2f
movq 0x18(%rsp), %rdi
jmp 0x9f9d
xorpd %xmm1, %xmm1
movl $0xffffffff, %ecx       # imm = 0xFFFFFFFF
movl %ecx, 0x8(%rdi)
testl %eax, %eax
jle 0x9fc0
movl %eax, %eax
xorl %ecx, %ecx
movsd (%r8,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r8,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x9fa8
movq %rdi, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq