// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/multivariatetree.c
// Function: best_multivariate_split_lda_with_pca
int best_multivariate_split_lda_with_pca(Instanceptr positives, Instanceptr negatives, matrix* w, double* w0, MULTIVARIATE_TYPE multivariate_type, int* newdim, double variance_explained)
{
 /*!Last Changed 12.01.2009 added pooled_covariance*/
 /*!Last Changed 21.09.2004*/
 int positivecount, negativecount, newdimension, dim, matrixdim;
 Instance meanpositive, meannegative; 
 /* 1 x 1 matrices*/
 matrix splitmatrix;
 /* 1 x d matrices*/
 matrix meanposmatrix, meannegmatrix, meandifference, meansum;
 /* 1 x k matrices*/
 matrix bmatrix, tmpresult2, tmpresult3;
 /* k x 1 matrices*/
 matrix transposeresult;
 /* d x d matrices*/
 matrix covariancenegative, covariancepositive, totalcovariance, tmpeigenvec;
 /* d x k matrices*/
 matrix eigenvec;
 /* k x d matrices*/
 matrix transposeeigenvec, tmpresult;
 /* k x k matrices*/
 matrix sw;
 double* eigenval = NULL, posratio, negratio;
 positivecount = data_size(positives);
 negativecount = data_size(negatives);
 dim = current_dataset->multifeaturecount - 1;
 if (positivecount <= 1 || negativecount <= 1)
  {
   *w = identity(1);
   return 0;
  }
 posratio = (positivecount + 0.0) / (positivecount + negativecount);
 negratio = (negativecount + 0.0) / (positivecount + negativecount);
 if (multivariate_type == MULTIVARIATE_LINEAR)
  {
   meanpositive = find_mean(positives);
   meannegative = find_mean(negatives);
   meanposmatrix = instance_to_matrix(&meanpositive);
   meannegmatrix = instance_to_matrix(&meannegative);
   covariancepositive = covariance(positives, meanpositive);
   covariancenegative = covariance(negatives, meannegative);
   matrixdim = dim;
   safe_free(meanpositive.values);
   safe_free(meannegative.values);
  }
 else /*QUADRATIC*/
  {   
   meanposmatrix = find_mean_2d(positives);
   meannegmatrix = find_mean_2d(negatives);
   matrixdim = multifeaturecount_2d(current_dataset);
   covariancepositive = covariance_2d(positives, meanposmatrix);
   covariancenegative = covariance_2d(negatives, meannegmatrix);
  }
 totalcovariance = pooled_covariance(covariancepositive, positivecount, covariancenegative, negativecount);
 matrix_free(covariancepositive);
 matrix_free(covariancenegative);
 eigenval = find_eigenvalues_eigenvectors(&tmpeigenvec, totalcovariance, &newdimension, variance_explained);
 safe_free(eigenval);
 *newdim = newdimension + 1;
 eigenvec = matrix_partial(tmpeigenvec, 0, matrixdim - 1, 0, newdimension);
 matrix_free(tmpeigenvec);
 transposeeigenvec = matrix_transpose(eigenvec);
 tmpresult = matrix_multiply(transposeeigenvec, totalcovariance);
 matrix_free(totalcovariance);
 sw = matrix_multiply(tmpresult, eigenvec);
 matrix_free(tmpresult);
 meandifference = matrix_difference(meanposmatrix, meannegmatrix);
 bmatrix = matrix_multiply(meandifference, eigenvec);
 matrix_free(meandifference);
 matrix_inverse(&sw);
 tmpresult2 = matrix_multiply(bmatrix, sw);
 *w = matrix_multiply(tmpresult2, transposeeigenvec);
 matrix_free(transposeeigenvec);
 matrix_free(bmatrix);
 matrix_free(sw);
 meansum = matrix_sum(meanposmatrix, meannegmatrix);
 matrix_free(meanposmatrix);
 matrix_free(meannegmatrix);
 tmpresult3 = matrix_multiply(meansum, eigenvec);
 matrix_free(eigenvec);
 matrix_free(meansum);
 transposeresult = matrix_transpose(tmpresult2);
 matrix_free(tmpresult2);
 splitmatrix = matrix_multiply(tmpresult3, transposeresult);
 matrix_free(tmpresult3);
 matrix_free(transposeresult);
 *w0 = -(-0.5*splitmatrix.values[0][0]-log(negratio / posratio));
 matrix_free(splitmatrix);
 return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x3f0, %rsp            # imm = 0x3F0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movl %r8d, -0x2c(%rbp)
movq %r9, -0x38(%rbp)
movsd %xmm0, -0x40(%rbp)
movq $0x0, -0x1d0(%rbp)
movq -0x10(%rbp), %rdi
callq 0x449f0
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
callq 0x449f0
movl %eax, -0x48(%rbp)
leaq 0x9729e(%rip), %rax     # 0x105840
movq (%rax), %rax
movl 0x1c0(%rax), %eax
subl $0x1, %eax
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x44(%rbp)
jle 0x6e5bd
cmpl $0x1, -0x48(%rbp)
jg 0x6e60b
movq -0x20(%rbp), %rax
movq %rax, -0x3a8(%rbp)
movl $0x1, %edi
callq 0x59f70
movq %rax, %rcx
movq -0x3a8(%rbp), %rax
movq %rcx, -0x1f0(%rbp)
movq %rdx, -0x1e8(%rbp)
movq -0x1f0(%rbp), %rcx
movq %rcx, (%rax)
movq -0x1e8(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6eeb6
cvtsi2sdl -0x44(%rbp), %xmm0
xorps %xmm1, %xmm1
addsd %xmm1, %xmm0
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x1d8(%rbp)
cvtsi2sdl -0x48(%rbp), %xmm0
xorps %xmm1, %xmm1
addsd %xmm1, %xmm0
movl -0x44(%rbp), %eax
addl -0x48(%rbp), %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x1e0(%rbp)
cmpl $-0x2, -0x2c(%rbp)
jne 0x6e7de
movq -0x10(%rbp), %rsi
leaq -0x220(%rbp), %rdi
callq 0x19b30
leaq -0x88(%rbp), %rdi
leaq -0x220(%rbp), %rsi
movl $0x30, %edx
callq 0x42b0
movq -0x18(%rbp), %rsi
leaq -0x250(%rbp), %rdi
callq 0x19b30
leaq -0xb8(%rbp), %rdi
leaq -0x250(%rbp), %rsi
movl $0x30, %edx
callq 0x42b0
leaq -0x88(%rbp), %rdi
callq 0x43160
movq %rax, -0x260(%rbp)
movq %rdx, -0x258(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x258(%rbp), %rax
movq %rax, -0xd0(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x43160
movq %rax, -0x270(%rbp)
movq %rdx, -0x268(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x10(%rbp), %rdi
movups -0x88(%rbp), %xmm0
movups -0x78(%rbp), %xmm1
movups -0x68(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x18040
movq %rax, -0x280(%rbp)
movq %rdx, -0x278(%rbp)
movq -0x280(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x278(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x18(%rbp), %rdi
movups -0xb8(%rbp), %xmm0
movups -0xa8(%rbp), %xmm1
movups -0x98(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x18040
movq %rax, -0x290(%rbp)
movq %rdx, -0x288(%rbp)
movq -0x290(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x288(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x50(%rbp), %eax
movl %eax, -0x54(%rbp)
movq -0x88(%rbp), %rdi
callq 0x52e80
movq -0xb8(%rbp), %rdi
callq 0x52e80
jmp 0x6e8d8
movq -0x10(%rbp), %rdi
callq 0x19730
movq %rax, -0x2a0(%rbp)
movq %rdx, -0x298(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x298(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x19730
movq %rax, -0x2b0(%rbp)
movq %rdx, -0x2a8(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0xe0(%rbp)
leaq 0x96ff5(%rip), %rax     # 0x105840
movq (%rax), %rdi
callq 0x1b690
movl %eax, -0x54(%rbp)
movq -0x10(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
callq 0x17ba0
movq %rax, -0x2c0(%rbp)
movq %rdx, -0x2b8(%rbp)
movq -0x2c0(%rbp), %rax
movq %rax, -0x168(%rbp)
movq -0x2b8(%rbp), %rax
movq %rax, -0x160(%rbp)
movq -0x18(%rbp), %rdi
movq -0xe8(%rbp), %rsi
movq -0xe0(%rbp), %rdx
callq 0x17ba0
movq %rax, -0x2d0(%rbp)
movq %rdx, -0x2c8(%rbp)
movq -0x2d0(%rbp), %rax
movq %rax, -0x158(%rbp)
movq -0x2c8(%rbp), %rax
movq %rax, -0x150(%rbp)
movl -0x44(%rbp), %edx
movl -0x48(%rbp), %r9d
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
movq -0x158(%rbp), %rcx
movq -0x150(%rbp), %r8
callq 0x5bde0
movq %rax, -0x2e0(%rbp)
movq %rdx, -0x2d8(%rbp)
movq -0x2e0(%rbp), %rax
movq %rax, -0x178(%rbp)
movq -0x2d8(%rbp), %rax
movq %rax, -0x170(%rbp)
movq -0x168(%rbp), %rdi
movq -0x160(%rbp), %rsi
callq 0x59ea0
movq -0x158(%rbp), %rdi
movq -0x150(%rbp), %rsi
callq 0x59ea0
movsd -0x40(%rbp), %xmm0
movq -0x178(%rbp), %rsi
movq -0x170(%rbp), %rdx
leaq -0x188(%rbp), %rdi
leaq -0x4c(%rbp), %rcx
callq 0x5fba0
movq %rax, -0x1d0(%rbp)
movq -0x1d0(%rbp), %rdi
callq 0x52e80
movl -0x4c(%rbp), %ecx
addl $0x1, %ecx
movq -0x38(%rbp), %rax
movl %ecx, (%rax)
movl -0x54(%rbp), %ecx
subl $0x1, %ecx
movl -0x4c(%rbp), %r9d
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rsi
xorl %r8d, %r8d
movl %r8d, %edx
callq 0x59de0
movq %rax, -0x2f0(%rbp)
movq %rdx, -0x2e8(%rbp)
movq -0x2f0(%rbp), %rax
movq %rax, -0x198(%rbp)
movq -0x2e8(%rbp), %rax
movq %rax, -0x190(%rbp)
movq -0x188(%rbp), %rdi
movq -0x180(%rbp), %rsi
callq 0x59ea0
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rsi
callq 0x59ed0
movq %rax, -0x300(%rbp)
movq %rdx, -0x2f8(%rbp)
movq -0x300(%rbp), %rax
movq %rax, -0x1a8(%rbp)
movq -0x2f8(%rbp), %rax
movq %rax, -0x1a0(%rbp)
movq -0x1a8(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
movq -0x178(%rbp), %rdx
movq -0x170(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x310(%rbp)
movq %rdx, -0x308(%rbp)
movq -0x310(%rbp), %rax
movq %rax, -0x1b8(%rbp)
movq -0x308(%rbp), %rax
movq %rax, -0x1b0(%rbp)
movq -0x178(%rbp), %rdi
movq -0x170(%rbp), %rsi
callq 0x59ea0
movq -0x1b8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x190(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x320(%rbp)
movq %rdx, -0x318(%rbp)
movq -0x320(%rbp), %rax
movq %rax, -0x1c8(%rbp)
movq -0x318(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq -0x1b8(%rbp), %rdi
movq -0x1b0(%rbp), %rsi
callq 0x59ea0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
callq 0x5aea0
movq %rax, -0x330(%rbp)
movq %rdx, -0x328(%rbp)
movq -0x330(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x328(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x190(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x340(%rbp)
movq %rdx, -0x338(%rbp)
movq -0x340(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x338(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x59ea0
leaq -0x1c8(%rbp), %rdi
callq 0x5c470
movq -0x118(%rbp), %rdi
movq -0x110(%rbp), %rsi
movq -0x1c8(%rbp), %rdx
movq -0x1c0(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x350(%rbp)
movq %rdx, -0x348(%rbp)
movq -0x350(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x348(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x3b8(%rbp)
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
movq -0x1a8(%rbp), %rdx
movq -0x1a0(%rbp), %rcx
callq 0x59fe0
movq %rax, %rcx
movq -0x3b8(%rbp), %rax
movq %rcx, -0x360(%rbp)
movq %rdx, -0x358(%rbp)
movq -0x360(%rbp), %rcx
movq %rcx, (%rax)
movq -0x358(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x1a8(%rbp), %rdi
movq -0x1a0(%rbp), %rsi
callq 0x59ea0
movq -0x118(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x59ea0
movq -0x1c8(%rbp), %rdi
movq -0x1c0(%rbp), %rsi
callq 0x59ea0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq -0xe0(%rbp), %rcx
callq 0x5acf0
movq %rax, -0x370(%rbp)
movq %rdx, -0x368(%rbp)
movq -0x370(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x368(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x59ea0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x59ea0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
movq -0x198(%rbp), %rdx
movq -0x190(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x380(%rbp)
movq %rdx, -0x378(%rbp)
movq -0x380(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x378(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x198(%rbp), %rdi
movq -0x190(%rbp), %rsi
callq 0x59ea0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x59ea0
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0x59ed0
movq %rax, -0x390(%rbp)
movq %rdx, -0x388(%rbp)
movq -0x390(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x388(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0x59ea0
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x148(%rbp), %rdx
movq -0x140(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x3a0(%rbp)
movq %rdx, -0x398(%rbp)
movq -0x3a0(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x398(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x59ea0
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
callq 0x59ea0
movq -0xc0(%rbp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x3b0(%rbp)
movsd -0x1e0(%rbp), %xmm0
divsd -0x1d8(%rbp), %xmm0
callq 0x4120
movaps %xmm0, %xmm1
movsd -0x3b0(%rbp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x73bf3(%rip), %xmm2    # 0xe2a68
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x28(%rbp), %rax
movsd %xmm0, (%rax)
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x59ea0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x3f0, %rsp            # imm = 0x3F0
popq %rbp
retq
nopw %cs:(%rax,%rax)