// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/classification.c
// Function: train_qdaclass
void* train_qdaclass(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
 /*!Last Changed 05.08.2007*/
 Model_qdaclassptr m;
 matrix Si, mi, mitranspose, tmpmat;
 int i, *counts, size = data_size(*trdata);
 Instanceptr classmeans, tmp;
 double det;
 m = safemalloc(sizeof(Model_qdaclass), "train_qdaclass", 2);
 m->w0 = (double *)safemalloc(current_dataset->classno * sizeof(double), "qdaclass", 3);
 m->priors = (double *)safemalloc(current_dataset->classno * sizeof(double), "qdaclass", 4);
 m->w = (matrix *)safemalloc(current_dataset->classno * sizeof(matrix), "qdaclass", 5);
 m->W = (matrix *)safemalloc(current_dataset->classno * sizeof(matrix), "qdaclass", 6);
 counts = find_class_counts(*trdata);
 for (i = 0; i < current_dataset->classno; i++)
   m->priors[i] = counts[i] / (size + 0.0);
 classmeans = find_class_means(*trdata, counts);
 tmp = classmeans;
 for (i = 0; i < current_dataset->classno; i++)
  {
   mi = instance_to_matrix(tmp);
   mitranspose = matrix_transpose(mi);
   Si = class_covariance(*trdata, i, tmp);
   while (matrix_determinant(Si) < DBL_DELTA)
     matrix_perturbate(Si);
   det = matrix_determinant(Si);
   matrix_inverse(&Si);
   m->W[i] = matrix_copy(Si);
   matrix_multiply_constant(&(m->W[i]), -0.5);
   m->w[i] = matrix_multiply(mi, Si);
   tmpmat = matrix_multiply(m->w[i], mitranspose);
   m->w0[i] = -0.5 * (tmpmat.values[0][0] + log(det)) + log((counts[i] + 0.0) / size);
   tmp = tmp->next;
   matrix_free(mi);
   matrix_free(Si);
   matrix_free(mitranspose);
   matrix_free(tmpmat);
  }
 safe_free(counts);
 deallocate(classmeans);
 return m;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %r15
movq (%rdi), %rdi
callq 0x30309
movl %eax, %ebx
leaq 0x9bed7(%rip), %rsi     # 0xa5eeb
movl $0x20, %edi
movl $0x2, %edx
callq 0x3a0e1
movq %rax, %r12
leaq 0xcb843(%rip), %r13     # 0xd5870
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9fd52(%rip), %r14     # 0xa9d92
movq %r14, %rsi
movl $0x3, %edx
callq 0x3a0e1
movq %rax, 0x10(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, 0x18(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
movq %r14, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, 0x8(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
movq %r14, %rsi
movl $0x6, %edx
callq 0x3a0e1
movq %r12, 0x18(%rsp)
movq %rax, (%r12)
movq %r15, 0x38(%rsp)
movq (%r15), %rdi
callq 0x115a6
movq %rax, %rsi
movq (%r13), %rax
movslq 0x10(%rax), %rax
cvtsi2sd %ebx, %xmm1
testq %rax, %rax
jle 0xa0f5
movq 0x18(%rsp), %rcx
movq 0x18(%rcx), %rcx
xorl %edx, %edx
xorps %xmm0, %xmm0
cvtsi2sdl (%rsi,%rdx,4), %xmm0
divsd %xmm1, %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0xa0dc
movsd %xmm1, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq %rsi, 0x30(%rsp)
callq 0x118da
movq %rax, 0x28(%rsp)
leaq 0xcb757(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jle 0xa303
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x2f0c1
movq %rax, %r15
movq %rax, %rdi
movq %rdx, %r12
movq %rdx, %rsi
callq 0x3ed5e
movq %rax, 0x70(%rsp)
movq %rdx, 0x68(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movl %r13d, %esi
movq %r14, 0x60(%rsp)
movq %r14, %rdx
callq 0x10d4d
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rax, %rdi
movq %rdx, %rsi
callq 0x4078e
movsd 0x9bc52(%rip), %xmm1    # 0xa5dd8
ucomisd %xmm0, %xmm1
jbe 0xa1a7
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x40745
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
jmp 0xa179
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x4078e
movsd %xmm0, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x409b7
movq 0x18(%rsp), %r14
movq (%r14), %rbp
movq %r13, %rbx
shlq $0x4, %rbx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3dae3
movq %rax, (%rbp,%rbx)
movq %rdx, 0x8(%rbp,%rbx)
movq (%r14), %rdi
addq %rbx, %rdi
movsd 0x9bbd4(%rip), %xmm0    # 0xa5dd0
callq 0x3f7c2
movq 0x8(%r14), %rbp
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3ee2f
movq %rax, (%rbp,%rbx)
movq %rdx, 0x8(%rbp,%rbx)
movq 0x8(%r14), %rax
movq (%rax,%rbx), %rdi
movq 0x8(%rax,%rbx), %rsi
movq %r15, 0x50(%rsp)
movq 0x70(%rsp), %r15
movq %r15, %rdx
movq 0x68(%rsp), %rbx
movq %rbx, %rcx
callq 0x3ee2f
movq %rax, 0x58(%rsp)
movq %rdx, %rbp
movq (%rdx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x48(%rsp)
movsd 0x20(%rsp), %xmm0
callq 0x4160
addsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x30(%rsp), %rax
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r13,4), %xmm0
divsd 0x40(%rsp), %xmm0
callq 0x4160
movsd 0x20(%rsp), %xmm1
mulsd 0x9bb32(%rip), %xmm1    # 0xa5dd0
addsd %xmm0, %xmm1
movq 0x10(%r14), %rax
movsd %xmm1, (%rax,%r13,8)
movq 0x60(%rsp), %r14
movq 0x10(%r14), %r14
movq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x3ed51
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3ed51
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3ed51
movq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ed51
incq %r13
leaq 0xcb57d(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r13
jl 0xa12e
movq 0x30(%rsp), %rdi
callq 0x3a180
movq 0x28(%rsp), %rdi
callq 0x2ff55
movq 0x18(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq