// File: /workspace/github_c_makefile_star2_O3/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 $0x28, %rsp
leaq 0xcba56(%rip), %r14     # 0xd5870
movq (%r14), %rax
cmpl $0x0, 0x10(%rax)
jle 0x9fd9
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, 0x8(%rsp)
movl $0xffffffff, %ebp       # imm = 0xFFFFFFFF
movsd 0x9bf89(%rip), %xmm0    # 0xa5dc8
xorl %ebx, %ebx
xorpd %xmm1, %xmm1
movq %r8, 0x10(%rsp)
movsd %xmm0, 0x18(%rsp)
movsd %xmm1, 0x20(%rsp)
movq 0x10(%r15), %rax
movsd (%rax,%rbx,8), %xmm0
callq 0x4160
movapd %xmm0, %xmm3
movq (%r14), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9f5a
movl $0x61e1, %r14d          # imm = 0x61E1
xorl %r13d, %r13d
xorpd %xmm2, %xmm2
movl (%rax,%r14,8), %ecx
cmpl $0x2, %ecx
je 0x9f02
cmpl $0x1, %ecx
je 0x9ec0
testl %ecx, %ecx
jne 0x9f43
movq 0x8(%r15), %rcx
movsd (%rcx,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9eb1
jnp 0x9f43
movq (%r12), %rcx
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%r13,8), %xmm1
jmp 0x9f1e
movq 0x18(%r15), %rcx
movq (%rcx,%rbx,8), %rcx
movq (%rcx,%r13,8), %rcx
movq (%r12), %rdx
movslq (%rdx,%r13,8), %rdx
movsd (%rcx,%rdx,8), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x9f43
movsd %xmm3, (%rsp)
callq 0x4160
movsd (%rsp), %xmm3
xorpd %xmm2, %xmm2
addsd %xmm0, %xmm3
leaq 0xcb973(%rip), %rax     # 0xd5870
movq (%rax), %rax
jmp 0x9f43
movq 0x8(%r15), %rcx
movsd (%rcx,%r13,8), %xmm0
ucomisd %xmm2, %xmm0
jne 0x9f14
jnp 0x9f43
movq (%r12), %rcx
movsd (%rcx,%r13,8), %xmm1
movq (%r15), %rcx
movq (%rcx,%rbx,8), %rcx
subsd (%rcx,%r13,8), %xmm1
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
mulsd 0x9be95(%rip), %xmm0    # 0xa5dd0
mulsd %xmm1, %xmm0
addsd %xmm0, %xmm3
incq %r13
movslq 0x1bc(%rax), %rcx
addq $0x68, %r14
cmpq %rcx, %r13
jl 0x9e85
movsd %xmm3, (%rsp)
movapd %xmm3, %xmm0
callq 0x39bb5
movsd 0x18(%rsp), %xmm2
movsd (%rsp), %xmm3
ucomisd %xmm2, %xmm3
cmoval %ebx, %ebp
movq 0x10(%rsp), %r8
movsd %xmm0, (%r8,%rbx,8)
movsd 0x20(%rsp), %xmm1
addsd %xmm0, %xmm1
maxsd %xmm2, %xmm3
movapd %xmm3, %xmm0
incq %rbx
leaq 0xcb8cf(%rip), %r14     # 0xd5870
movq (%r14), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %rbx
jl 0x9e4a
movq 0x8(%rsp), %rdi
movl %ebp, 0x8(%rdi)
testl %eax, %eax
jle 0x9fe0
xorl %ecx, %ecx
movsd (%r8,%rcx,8), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%r8,%rcx,8)
incq %rcx
cmpq %rcx, %rax
jne 0x9fbf
jmp 0x9fe0
movl $0xffffffff, 0x8(%rdi)  # imm = 0xFFFFFFFF
movq %rdi, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq