// File: /workspace/github_c_makefile_star2_O2/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 $0x68, %rsp
movq %rdi, %r12
movq (%rdi), %rdi
callq 0x2c3cc
movl %eax, %ebx
leaq 0x8c37a(%rip), %rsi     # 0x95ef3
pushq $0x20
popq %rdi
pushq $0x2
popq %rdx
callq 0x34f59
movq %rax, %r14
leaq 0xc3ce2(%rip), %r13     # 0xcd870
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x90119(%rip), %r15     # 0x99cba
pushq $0x3
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x10(%r14)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
pushq $0x4
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x18(%r14)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
pushq $0x5
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x8(%r14)
movq (%r13), %rax
movslq 0x10(%rax), %rdi
shlq $0x4, %rdi
pushq $0x6
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %r14, 0x18(%rsp)
movq %rax, (%r14)
movq %r12, 0x30(%rsp)
movq (%r12), %rdi
callq 0x108c8
movq %rax, %rsi
movq (%r13), %rax
movslq 0x10(%rax), %rax
cvtsi2sd %ebx, %xmm0
movsd %xmm0, 0x38(%rsp)
xorl %ecx, %ecx
cmpq %rax, %rcx
jge 0x9c4d
cvtsi2sdl (%rsi,%rcx,4), %xmm0
divsd 0x38(%rsp), %xmm0
movq 0x18(%rsp), %rdx
movq 0x18(%rdx), %rdx
movsd %xmm0, (%rdx,%rcx,8)
incq %rcx
jmp 0x9c2a
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movq %rsi, 0x28(%rsp)
callq 0x10bb9
xorl %r15d, %r15d
movq %rax, 0x48(%rsp)
movq %rax, 0x20(%rsp)
movq 0x18(%rsp), %rbx
leaq 0xc3bf8(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r15
jge 0x9e3a
movq 0x20(%rsp), %r12
movq %r12, %rdi
callq 0x2b20d
movq %rax, %r14
movq %rax, %rdi
movq %rdx, %r13
movq %rdx, %rsi
callq 0x392ac
movq %rax, 0x40(%rsp)
movq %rdx, 0x60(%rsp)
movq 0x30(%rsp), %rax
movq (%rax), %rdi
movl %r15d, %esi
movq %r12, %rdx
callq 0x10068
movq %rax, %rdi
movq %rdx, %rsi
movq %rax, (%rsp)
movq %rdx, 0x8(%rsp)
callq 0x3a822
movsd 0x8c101(%rip), %xmm1    # 0x95de0
ucomisd %xmm0, %xmm1
jbe 0x9cfe
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3a7dc
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
jmp 0x9cd2
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3a822
movsd %xmm0, 0x10(%rsp)
movq %rsp, %rdi
callq 0x3a9f7
movq (%rbx), %rbp
movq %r15, %r12
shlq $0x4, %r12
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x383f4
movq %rax, (%rbp,%r12)
movq %rdx, 0x8(%rbp,%r12)
movq (%rbx), %rdi
addq %r12, %rdi
movsd 0x8c08e(%rip), %xmm0    # 0x95dd8
callq 0x39a42
movq 0x8(%rbx), %rbp
movq (%rsp), %rdx
movq 0x8(%rsp), %rcx
movq %r14, %rdi
movq %r13, %rsi
callq 0x3933d
movq %rax, (%rbp,%r12)
movq %rdx, 0x8(%rbp,%r12)
movq 0x8(%rbx), %rax
movq (%rax,%r12), %rdi
movq 0x8(%rax,%r12), %rsi
movq 0x40(%rsp), %rdx
movq %r14, %rbp
movq 0x60(%rsp), %r14
movq %r14, %rcx
callq 0x3933d
movq %rax, 0x58(%rsp)
movq %rdx, %r12
movq (%rdx), %rax
movsd (%rax), %xmm0
movsd %xmm0, 0x50(%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x4160
addsd 0x50(%rsp), %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x28(%rsp), %rax
cvtsi2sdl (%rax,%r15,4), %xmm0
divsd 0x38(%rsp), %xmm0
callq 0x4160
movsd 0x10(%rsp), %xmm1
mulsd 0x8bff5(%rip), %xmm1    # 0x95dd8
addsd %xmm0, %xmm1
movq 0x10(%rbx), %rax
movsd %xmm1, (%rax,%r15,8)
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x20(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3929f
movq (%rsp), %rdi
movq 0x8(%rsp), %rsi
callq 0x3929f
movq 0x40(%rsp), %rdi
movq %r14, %rsi
callq 0x3929f
movq 0x58(%rsp), %rdi
movq %r12, %rsi
callq 0x3929f
incq %r15
jmp 0x9c71
movq 0x28(%rsp), %rdi
callq 0x34ff7
movq 0x48(%rsp), %rdi
callq 0x2c010
movq 0x18(%rsp), %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq