// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/classification.c
// Function: train_naivebayes
void* train_naivebayes(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
 /*!Last Changed 22.01.2008 changed from variance to standard deviation*/
 /*!Last Changed 11.08.2007*/
 int i, j, k, *counts, size = data_size(*trdata);
 int ***feature_counts;
 Instanceptr tmp, classmeans;
 Model_naivebayesptr m;
 Instance s;
 m = safemalloc(sizeof(Model_naivebayes), "train_naivebayes", 5);
 counts = find_class_counts(*trdata); 
 classmeans = find_class_means(*trdata, counts);
 s = find_variance(*trdata);
 feature_counts = find_feature_counts(*trdata);
 m->s = (double *) safemalloc(current_dataset->featurecount * sizeof(double), "train_naivebayes", 9);
 m->m = (double **) safemalloc_2d(sizeof(double *), sizeof(double), current_dataset->classno, current_dataset->featurecount, "train_naivebayes", 10);
 m->priors = (double *)safemalloc(current_dataset->classno * sizeof(double), "train_naivebayes", 11);
 for (i = 0; i < current_dataset->featurecount; i++)
   m->s[i] = sqrt(s.values[i].floatvalue);
 tmp = classmeans;
 m->p = (double ***) safemalloc(current_dataset->classno * sizeof(double **), "train_naivebayes", 15);
 for (i = 0; i < current_dataset->classno; i++)
  {
   m->p[i] = (double **) safemalloc(current_dataset->featurecount * sizeof(double *), "train_naivebayes", 18);
   m->priors[i] = counts[i] / (size + 0.0);
   for (j = 0; j < current_dataset->featurecount; j++)
    {
     if (current_dataset->features[j].type == STRING)
      {
       m->p[i][j] = (double *) safemalloc(current_dataset->features[j].valuecount * sizeof(double), "train_naivebayes", 24);
       for (k = 0; k < current_dataset->features[j].valuecount; k++)
         m->p[i][j][k] = feature_counts[i][j][k] / (counts[i] + 0.0);
      }
     m->m[i][j] = tmp->values[j].floatvalue;
    }
   tmp = tmp->next;
  }
 free_feature_counts(feature_counts);
 safe_free(s.values);
 safe_free(counts);
 deallocate(classmeans);
 return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %r13
movq (%rdi), %rdi
callq 0x2c3cc
movl %eax, %ebp
leaq 0x8c7ed(%rip), %r15     # 0x95ee2
pushq $0x20
popq %rdi
pushq $0x5
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %rbx
movq (%r13), %rdi
callq 0x108c8
movq %rax, %r14
movq (%r13), %rdi
movq %rax, %rsi
callq 0x10bb9
movq %rax, 0x8(%rsp)
movq (%r13), %rsi
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x1197e
movq (%r12), %rax
movq %rax, 0x10(%rsp)
movq (%r13), %rdi
callq 0x10b48
movq %rax, %r13
leaq 0xc4120(%rip), %r12     # 0xcd870
movq (%r12), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
pushq $0x9
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x8(%rbx)
movq (%r12), %rax
movl 0x10(%rax), %edx
movl 0x1bc(%rax), %ecx
pushq $0x8
popq %rdi
pushq $0xa
popq %r9
movq %rdi, %rsi
movq %r15, %r8
callq 0x351c3
movq %rax, (%rbx)
movq (%r12), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
pushq $0xb
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x10(%rbx)
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
leaq 0xc40b7(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jge 0x97f7
movq 0x10(%rsp), %rax
movsd (%rax,%r15,8), %xmm0
ucomisd %xmm1, %xmm0
jb 0x97df
sqrtsd %xmm0, %xmm0
jmp 0x97e8
callq 0x4300
xorpd %xmm1, %xmm1
movq 0x8(%rbx), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
jmp 0x97b2
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x8c6dc(%rip), %rsi     # 0x95ee2
pushq $0xf
popq %rdx
callq 0x34f59
movq %rax, 0x18(%rbx)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0x20(%rsp)
leaq 0xc404d(%rip), %rax     # 0xcd870
movq (%rax), %rax
xorl %r15d, %r15d
movq 0x8(%rsp), %rdx
movslq 0x10(%rax), %rcx
cmpq %rcx, %r15
jge 0x9959
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
leaq 0x8c695(%rip), %rsi     # 0x95ee2
movq %rdx, 0x18(%rsp)
pushq $0x12
popq %rdx
callq 0x34f59
movq 0x18(%rsp), %rdx
movq 0x18(%rbx), %rcx
movq %rax, (%rcx,%r15,8)
cvtsi2sdl (%r14,%r15,4), %xmm0
divsd 0x20(%rsp), %xmm0
movq 0x10(%rbx), %rax
movsd %xmm0, (%rax,%r15,8)
leaq 0xc3fec(%rip), %rax     # 0xcd870
movq (%rax), %rax
xorl %ebp, %ebp
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbp
jge 0x994d
imulq $0x340, %rbp, %r12      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%r12)
jne 0x9931
addq %r12, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
leaq 0x8c61b(%rip), %rsi     # 0x95ee2
pushq $0x18
popq %rdx
callq 0x34f59
movq 0x18(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movq %rax, (%rcx,%rbp,8)
leaq 0xc3f8e(%rip), %rax     # 0xcd870
movq (%rax), %rax
movl 0x30f20(%rax,%r12), %ecx
testl %ecx, %ecx
movl $0x0, %edx
cmovlel %edx, %ecx
xorl %edx, %edx
cmpq %rdx, %rcx
je 0x992c
movq (%r13,%r15,8), %rsi
movq (%rsi,%rbp,8), %rsi
cvtsi2sdl (%rsi,%rdx,4), %xmm0
cvtsi2sdl (%r14,%r15,4), %xmm1
divsd %xmm1, %xmm0
movq 0x18(%rbx), %rsi
movq (%rsi,%r15,8), %rsi
movq (%rsi,%rbp,8), %rsi
movsd %xmm0, (%rsi,%rdx,8)
incq %rdx
jmp 0x98f9
movq 0x18(%rsp), %rdx
movq (%rdx), %rcx
movsd (%rcx,%rbp,8), %xmm0
movq (%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movsd %xmm0, (%rcx,%rbp,8)
incq %rbp
jmp 0x9889
movq 0x10(%rdx), %rdx
incq %r15
jmp 0x982e
movq %r13, %rdi
callq 0x10ad2
movq 0x10(%rsp), %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movq 0x8(%rsp), %rdi
callq 0x2c010
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq