// File: /workspace/github_c_makefile_star2_O1/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 0x2fa14
movl %eax, %ebx
leaq 0x98ef7(%rip), %rsi     # 0xa2eeb
movl $0x20, %edi
movl $0x2, %edx
callq 0x390f5
movq %rax, %r12
leaq 0xc8863(%rip), %r13     # 0xd2870
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9cd02(%rip), %r14     # 0xa6d22
movq %r14, %rsi
movl $0x3, %edx
callq 0x390f5
movq %rax, 0x10(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, 0x18(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
movq %r14, %rsi
movl $0x5, %edx
callq 0x390f5
movq %rax, 0x8(%r12)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
movq %r14, %rsi
movl $0x6, %edx
callq 0x390f5
movq %r12, 0x18(%rsp)
movq %rax, (%r12)
movq %r15, 0x38(%rsp)
movq (%r15), %rdi
callq 0x115e1
movq %rax, %rsi
movq (%r13), %rax
movslq 0x10(%rax), %rax
cvtsi2sd %ebx, %xmm1
testq %rax, %rax
jle 0xa0d5
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 0xa0bc
movsd %xmm1, 0x40(%rsp)
movq 0x38(%rsp), %rax
movq (%rax), %rdi
movq %rsi, 0x30(%rsp)
callq 0x11918
movq %rax, 0x28(%rsp)
leaq 0xc8777(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x10(%rax)
jle 0xa2e3
xorl %r13d, %r13d
movq 0x28(%rsp), %r14
movq %r14, %rdi
callq 0x2e851
movq %rax, %r15
movq %rax, %rdi
movq %rdx, %r12
movq %rdx, %rsi
callq 0x3dbba
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 0x10d5a
movq %rax, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3f436
movsd 0x98c72(%rip), %xmm1    # 0xa2dd8
ucomisd %xmm0, %xmm1
jbe 0xa187
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3f3ed
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
jmp 0xa159
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3f436
movsd %xmm0, 0x20(%rsp)
leaq 0x8(%rsp), %rdi
callq 0x3f648
movq 0x18(%rsp), %r14
movq (%r14), %rbp
movq %r13, %rbx
shlq $0x4, %rbx
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3ca3c
movq %rax, (%rbp,%rbx)
movq %rdx, 0x8(%rbp,%rbx)
movq (%r14), %rdi
addq %rbx, %rdi
movsd 0x98bf4(%rip), %xmm0    # 0xa2dd0
callq 0x3e50d
movq 0x8(%r14), %rbp
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rcx
movq %r15, %rdi
movq %r12, %rsi
callq 0x3dc8b
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 0x3dc8b
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 0x98b52(%rip), %xmm1    # 0xa2dd0
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 0x3dbad
movq 0x8(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x3dbad
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3dbad
movq 0x58(%rsp), %rdi
movq %rbp, %rsi
callq 0x3dbad
incq %r13
leaq 0xc859d(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r13
jl 0xa10e
movq 0x30(%rsp), %rdi
callq 0x39194
movq 0x28(%rsp), %rdi
callq 0x2f616
movq 0x18(%rsp), %rax
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq