// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/dataset.c
// Function: fisher_discriminant_ratio
double fisher_discriminant_ratio(Datasetptr d)
{
 /* multiclass is handled by one vs one */
 Instanceptr tempinst, traindata, c_means;
 int *c_counts;
 matrix class_mean, class_cov, class_var, fisher_class_feature;
 int i, j, k, f;
 double result = 0, classsum, maxratio; 
 read_from_train_file(d, &traindata);
 realize(traindata);
 exchange_classdefno(d);
 c_counts = find_class_counts(traindata);
 c_means = find_class_means(traindata, c_counts);
 fisher_class_feature = matrix_alloc(d->multifeaturecount - 1, d->classno * d->classno);
 class_mean = matrix_alloc(d->multifeaturecount - 1, d->classno);
 class_var = matrix_alloc(d->multifeaturecount - 1, d->classno);
 tempinst = c_means;
 for (j = 0; j < d->classno; j++)
  {
   class_cov = class_covariance(traindata, j, tempinst);  /*OLCAY DEGISTIRDIM*/
   for (i = 0, f = 0; i < d->multifeaturecount; i++)
    {
     if (i != d->classdefno)
      {
       class_var.values[f][j] = class_cov.values[f][f];
       class_mean.values[f][j] = tempinst->values[f].floatvalue;
       f++;
      }
    }
   tempinst = tempinst->next;
   matrix_free(class_cov);
  }
 maxratio = 0;
 for (i = 0, f = 0;i < d->multifeaturecount; i++)
  {
   if (i != d->classdefno)
    {
     classsum = 0;
     for (j = 0; j < d->classno; j++)
      {
       for (k = j + 1; k < d->classno; k++)
        {
         classsum += (class_mean.values[f][j] - class_mean.values[f][k]) * (class_mean.values[f][j] - class_mean.values[f][k]) / ((class_var.values[f][j] * class_var.values[f][j]) + (class_var.values[f][k] * class_var.values[f][k]));
        }
      }
     if (classsum > maxratio)
      {
       maxratio = classsum;
      }
     f++;
    }
  }
 exchange_classdefno(d);
 matrix_free(fisher_class_feature);
 matrix_free(class_mean);
 matrix_free(class_var);
 safe_free(c_means);
 safe_free(c_counts);
 deallocate(traindata);
 traindata = NULL;
 result = maxratio / (d->classno * (d->classno - 1) / 2);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x10(%rsp), %r14
movq %r14, %rsi
callq 0x5dcbd
movq (%r14), %rdi
callq 0x10954
leaq 0x1407128(%rbx), %rdi
leaq 0x1407138(%rbx), %rsi
movq %rdi, (%rsp)
movq %rsi, 0x48(%rsp)
callq 0x3a5af
movq (%r14), %rdi
callq 0x115a6
movq (%r14), %rdi
movq %rax, 0x50(%rsp)
movq %rax, %rsi
callq 0x118da
movq %rax, 0x8(%rsp)
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
imull %esi, %esi
callq 0x3d79d
movq %rax, 0x40(%rsp)
movq %rdx, 0x38(%rsp)
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x3d79d
movq %rax, 0x30(%rsp)
movq %rdx, %rbp
movl 0x10(%rbx), %esi
movl 0x1c0(%rbx), %edi
decl %edi
callq 0x3d79d
movq %rax, 0x28(%rsp)
movq %rdx, %r15
movl 0x10(%rbx), %eax
testl %eax, %eax
jle 0x19c55
xorl %r14d, %r14d
movq 0x8(%rsp), %r13
movq 0x10(%rsp), %rdi
movl %r14d, %esi
movq %r13, %rdx
callq 0x10d4d
movl 0x1c0(%rbx), %ecx
testl %ecx, %ecx
jle 0x19c3a
movq (%rsp), %rsi
movl (%rsi), %esi
xorl %edi, %edi
xorl %r8d, %r8d
cmpl %edi, %esi
je 0x19c34
movslq %r8d, %r8
movq (%rdx,%r8,8), %r9
movsd (%r9,%r8,8), %xmm0
movq (%r15,%r8,8), %r9
movsd %xmm0, (%r9,%r14,8)
movq (%r13), %r9
movsd (%r9,%r8,8), %xmm0
movq (%rbp,%r8,8), %r9
movsd %xmm0, (%r9,%r14,8)
incl %r8d
incl %edi
cmpl %edi, %ecx
jne 0x19c01
movq 0x10(%r13), %r13
movq %rax, %rdi
movq %rdx, %rsi
callq 0x3ed51
incq %r14
movslq 0x10(%rbx), %rax
cmpq %rax, %r14
jl 0x19bdc
movq %rbx, 0x20(%rsp)
movl 0x1c0(%rbx), %ebx
testl %ebx, %ebx
jle 0x19d15
movq (%rsp), %rdx
movl (%rdx), %ecx
movslq %eax, %rsi
movl %esi, %edi
xorpd %xmm5, %xmm5
xorl %r8d, %r8d
xorl %r9d, %r9d
cmpl %ecx, %r8d
je 0x19d07
testl %eax, %eax
jle 0x19cf8
movslq %r9d, %r10
xorpd %xmm0, %xmm0
movl $0x1, %edx
xorl %r14d, %r14d
movq %r14, %r11
incq %r14
cmpq %rsi, %r14
jge 0x19cee
movq (%rbp,%r10,8), %r13
movsd (%r13,%r11,8), %xmm1
movq (%r15,%r10,8), %r12
movsd (%r12,%r11,8), %xmm2
mulsd %xmm2, %xmm2
movq %rdx, %r11
movapd %xmm1, %xmm3
subsd (%r13,%r11,8), %xmm3
mulsd %xmm3, %xmm3
movsd (%r12,%r11,8), %xmm4
mulsd %xmm4, %xmm4
addsd %xmm2, %xmm4
divsd %xmm4, %xmm3
addsd %xmm3, %xmm0
incq %r11
cmpq %r11, %rdi
jne 0x19cc1
incq %rdx
cmpq %rdi, %r14
jne 0x19c99
jmp 0x19cfc
xorpd %xmm0, %xmm0
maxsd %xmm5, %xmm0
incl %r9d
movapd %xmm0, %xmm5
incl %r8d
cmpl %ebx, %r8d
jne 0x19c7d
jmp 0x19d19
xorpd %xmm5, %xmm5
movsd %xmm5, 0x18(%rsp)
movq (%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0x3a5af
movq 0x40(%rsp), %rdi
movq 0x38(%rsp), %rsi
callq 0x3ed51
movq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x3ed51
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x3ed51
movq 0x8(%rsp), %rdi
callq 0x3a180
movq 0x50(%rsp), %rdi
callq 0x3a180
movq 0x10(%rsp), %rdi
callq 0x2ff55
movq 0x20(%rsp), %rax
movl 0x10(%rax), %eax
leal -0x1(%rax), %ecx
imull %eax, %ecx
movl %ecx, %eax
shrl $0x1f, %eax
addl %ecx, %eax
sarl %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd 0x18(%rsp), %xmm0
divsd %xmm1, %xmm0
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq