// File: /workspace/github_c_makefile_star2_O3/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 0x30309
movl %eax, (%rsp)
leaq 0x9c39f(%rip), %rbp     # 0xa5eda
movl $0x20, %edi
movq %rbp, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, %rbx
movq (%r13), %rdi
callq 0x115a6
movq (%r13), %rdi
movq %rax, 0x8(%rsp)
movq %rax, %rsi
callq 0x118da
movq %rax, 0x10(%rsp)
movq (%r13), %rsi
leaq 0x28(%rsp), %r12
movq %r12, %rdi
callq 0x127bd
movq (%r12), %r14
movq (%r13), %rdi
callq 0x1185c
movq %rax, 0x18(%rsp)
leaq 0xcbcd7(%rip), %r15     # 0xd5870
movq (%r15), %rax
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0x9, %edx
callq 0x3a0e1
movq %rax, 0x8(%rbx)
movq (%r15), %rax
movl 0x10(%rax), %edx
movl 0x1bc(%rax), %ecx
movl $0x8, %edi
movl $0x8, %esi
movq %rbp, %r8
movl $0xa, %r9d
callq 0x3a3ac
movq %rax, (%rbx)
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0xb, %edx
callq 0x3a0e1
movq %rax, 0x10(%rbx)
movq (%r15), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9c4c
xorl %r15d, %r15d
xorpd %xmm1, %xmm1
movsd (%r14,%r15,8), %xmm0
ucomisd %xmm1, %xmm0
jb 0x9c20
sqrtsd %xmm0, %xmm0
jmp 0x9c29
callq 0x4300
xorpd %xmm1, %xmm1
movq 0x8(%rbx), %rax
movsd %xmm0, (%rax,%r15,8)
incq %r15
leaq 0xcbc33(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jl 0x9c0e
movq %r14, 0x20(%rsp)
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9c27a(%rip), %rsi     # 0xa5eda
movl $0xf, %edx
callq 0x3a0e1
movq %rax, 0x18(%rbx)
leaq 0xcbbfb(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jle 0x9dcb
xorps %xmm0, %xmm0
cvtsi2sdl (%rsp), %xmm0
movsd %xmm0, (%rsp)
xorl %r12d, %r12d
leaq 0x9c241(%rip), %rbp     # 0xa5eda
movq 0x10(%rsp), %r15
movslq 0x1bc(%rax), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0x12, %edx
callq 0x3a0e1
movq 0x18(%rbx), %rcx
movq %rax, (%rcx,%r12,8)
movq 0x8(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r12,4), %xmm0
divsd (%rsp), %xmm0
movq 0x10(%rbx), %rax
movsd %xmm0, (%rax,%r12,8)
leaq 0xcbb8e(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9db7
xorl %r13d, %r13d
imulq $0x340, %r13, %r14      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%r14)
jne 0x9d8e
addq %r14, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
shlq $0x3, %rdi
movq %rbp, %rsi
movl $0x18, %edx
callq 0x3a0e1
movq 0x18(%rbx), %rcx
movq (%rcx,%r12,8), %rcx
movq %rax, (%rcx,%r13,8)
leaq 0xcbb34(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x30f20(%rax,%r14), %rcx
testq %rcx, %rcx
jle 0x9d8e
movq 0x18(%rsp), %rdx
movq (%rdx,%r12,8), %rdx
movq (%rdx,%r13,8), %rdx
movq 0x8(%rsp), %rsi
xorps %xmm0, %xmm0
cvtsi2sdl (%rsi,%r12,4), %xmm0
movq 0x18(%rbx), %rsi
movq (%rsi,%r12,8), %rsi
movq (%rsi,%r13,8), %rsi
xorl %edi, %edi
xorps %xmm1, %xmm1
cvtsi2sdl (%rdx,%rdi,4), %xmm1
divsd %xmm0, %xmm1
movsd %xmm1, (%rsi,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x9d75
movq (%r15), %rcx
movsd (%rcx,%r13,8), %xmm0
movq (%rbx), %rcx
movq (%rcx,%r12,8), %rcx
movsd %xmm0, (%rcx,%r13,8)
incq %r13
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r13
jl 0x9cf5
movq 0x10(%r15), %r15
incq %r12
movslq 0x10(%rax), %rcx
cmpq %rcx, %r12
jl 0x9c9e
movq 0x18(%rsp), %rdi
callq 0x117d8
movq 0x20(%rsp), %rdi
callq 0x3a180
movq 0x8(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x2ff55
movq %rbx, %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq