// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/multivariatetree.c
// Function: best_multivariate_split_lda_with_svd
int best_multivariate_split_lda_with_svd(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;
 Instance meanpositive, meannegative; 
 /* 1 x 1 matrices*/
 matrix splitmatrix;
 /* 1 x d matrices*/
 matrix meanposmatrix, meannegmatrix, meandifference, meansum;
 /* d x d matrices*/
 matrix sw, transposeresult, covariancenegative, covariancepositive, totalcovariance;
 double posratio, negratio;
 positivecount = data_size(positives);
 negativecount = data_size(negatives);
 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);
   safe_free(meanpositive.values);
   safe_free(meannegative.values);
  }
 else /*QUADRATIC*/
  {   
   meanposmatrix = find_mean_2d(positives);
   meannegmatrix = find_mean_2d(negatives);
   covariancepositive = covariance_2d(positives, meanposmatrix);
   covariancenegative = covariance_2d(negatives, meannegmatrix);
  }
 totalcovariance = pooled_covariance(covariancepositive, positivecount, covariancenegative, negativecount); 
 matrix_free(covariancepositive);
 matrix_free(covariancenegative);
 sw = pseudoinverse(totalcovariance, variance_explained, newdim);
 matrix_free(totalcovariance);
 meandifference = matrix_difference(meanposmatrix, meannegmatrix);
 *w = matrix_multiply(meandifference, sw);
 matrix_free(sw);
 matrix_free(meandifference);
 meansum = matrix_sum(meanposmatrix, meannegmatrix);
 matrix_free(meanposmatrix);
 matrix_free(meannegmatrix);
 transposeresult = matrix_transpose(*w);
 splitmatrix = matrix_multiply(meansum, transposeresult);
 matrix_free(meansum);
 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 $0x300, %rsp            # imm = 0x300
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 -0x10(%rbp), %rdi
callq 0x449f0
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rdi
callq 0x449f0
movl %eax, -0x48(%rbp)
cmpl $0x1, -0x44(%rbp)
jle 0x6ef1c
cmpl $0x1, -0x48(%rbp)
jg 0x6ef6a
movq -0x20(%rbp), %rax
movq %rax, -0x2c0(%rbp)
movl $0x1, %edi
callq 0x59f70
movq %rax, %rcx
movq -0x2c0(%rbp), %rax
movq %rcx, -0x168(%rbp)
movq %rdx, -0x160(%rbp)
movq -0x168(%rbp), %rcx
movq %rcx, (%rax)
movq -0x160(%rbp), %rcx
movq %rcx, 0x8(%rax)
movl $0x0, -0x4(%rbp)
jmp 0x6f560
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, -0x150(%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, -0x158(%rbp)
cmpl $-0x2, -0x2c(%rbp)
jne 0x6f12b
movq -0x10(%rbp), %rsi
leaq -0x198(%rbp), %rdi
callq 0x19b30
leaq -0x78(%rbp), %rdi
leaq -0x198(%rbp), %rsi
movl $0x30, %edx
callq 0x42b0
movq -0x18(%rbp), %rsi
leaq -0x1c8(%rbp), %rdi
callq 0x19b30
leaq -0xa8(%rbp), %rdi
leaq -0x1c8(%rbp), %rsi
movl $0x30, %edx
callq 0x42b0
leaq -0x78(%rbp), %rdi
callq 0x43160
movq %rax, -0x1d8(%rbp)
movq %rdx, -0x1d0(%rbp)
movq -0x1d8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x1d0(%rbp), %rax
movq %rax, -0xc0(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x43160
movq %rax, -0x1e8(%rbp)
movq %rdx, -0x1e0(%rbp)
movq -0x1e8(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x1e0(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
movups -0x78(%rbp), %xmm0
movups -0x68(%rbp), %xmm1
movups -0x58(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x18040
movq %rax, -0x1f8(%rbp)
movq %rdx, -0x1f0(%rbp)
movq -0x1f8(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x1f0(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x18(%rbp), %rdi
movups -0xa8(%rbp), %xmm0
movups -0x98(%rbp), %xmm1
movups -0x88(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
callq 0x18040
movq %rax, -0x208(%rbp)
movq %rdx, -0x200(%rbp)
movq -0x208(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x200(%rbp), %rax
movq %rax, -0x120(%rbp)
movq -0x78(%rbp), %rdi
callq 0x52e80
movq -0xa8(%rbp), %rdi
callq 0x52e80
jmp 0x6f213
movq -0x10(%rbp), %rdi
callq 0x19730
movq %rax, -0x218(%rbp)
movq %rdx, -0x210(%rbp)
movq -0x218(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0x210(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x18(%rbp), %rdi
callq 0x19730
movq %rax, -0x228(%rbp)
movq %rdx, -0x220(%rbp)
movq -0x228(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x220(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq -0x10(%rbp), %rdi
movq -0xc8(%rbp), %rsi
movq -0xc0(%rbp), %rdx
callq 0x17ba0
movq %rax, -0x238(%rbp)
movq %rdx, -0x230(%rbp)
movq -0x238(%rbp), %rax
movq %rax, -0x138(%rbp)
movq -0x230(%rbp), %rax
movq %rax, -0x130(%rbp)
movq -0x18(%rbp), %rdi
movq -0xd8(%rbp), %rsi
movq -0xd0(%rbp), %rdx
callq 0x17ba0
movq %rax, -0x248(%rbp)
movq %rdx, -0x240(%rbp)
movq -0x248(%rbp), %rax
movq %rax, -0x128(%rbp)
movq -0x240(%rbp), %rax
movq %rax, -0x120(%rbp)
movl -0x44(%rbp), %edx
movl -0x48(%rbp), %r9d
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
movq -0x128(%rbp), %rcx
movq -0x120(%rbp), %r8
callq 0x5bde0
movq %rax, -0x258(%rbp)
movq %rdx, -0x250(%rbp)
movq -0x258(%rbp), %rax
movq %rax, -0x148(%rbp)
movq -0x250(%rbp), %rax
movq %rax, -0x140(%rbp)
movq -0x138(%rbp), %rdi
movq -0x130(%rbp), %rsi
callq 0x59ea0
movq -0x128(%rbp), %rdi
movq -0x120(%rbp), %rsi
callq 0x59ea0
movsd -0x40(%rbp), %xmm0
movq -0x38(%rbp), %rdx
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
callq 0x581b0
movq %rax, -0x268(%rbp)
movq %rdx, -0x260(%rbp)
movq -0x268(%rbp), %rax
movq %rax, -0x108(%rbp)
movq -0x260(%rbp), %rax
movq %rax, -0x100(%rbp)
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
callq 0x59ea0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
callq 0x5aea0
movq %rax, -0x278(%rbp)
movq %rdx, -0x270(%rbp)
movq -0x278(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq -0x270(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x2d0(%rbp)
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
movq -0x108(%rbp), %rdx
movq -0x100(%rbp), %rcx
callq 0x59fe0
movq %rax, %rcx
movq -0x2d0(%rbp), %rax
movq %rcx, -0x288(%rbp)
movq %rdx, -0x280(%rbp)
movq -0x288(%rbp), %rcx
movq %rcx, (%rax)
movq -0x280(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rsi
callq 0x59ea0
movq -0xe8(%rbp), %rdi
movq -0xe0(%rbp), %rsi
callq 0x59ea0
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
movq -0xd8(%rbp), %rdx
movq -0xd0(%rbp), %rcx
callq 0x5acf0
movq %rax, -0x298(%rbp)
movq %rdx, -0x290(%rbp)
movq -0x298(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq -0x290(%rbp), %rax
movq %rax, -0xf0(%rbp)
movq -0xc8(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x59ea0
movq -0xd8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
callq 0x59ea0
movq -0x20(%rbp), %rax
movq (%rax), %rdi
movq 0x8(%rax), %rsi
callq 0x59ed0
movq %rax, -0x2a8(%rbp)
movq %rdx, -0x2a0(%rbp)
movq -0x2a8(%rbp), %rax
movq %rax, -0x118(%rbp)
movq -0x2a0(%rbp), %rax
movq %rax, -0x110(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
movq -0x118(%rbp), %rdx
movq -0x110(%rbp), %rcx
callq 0x59fe0
movq %rax, -0x2b8(%rbp)
movq %rdx, -0x2b0(%rbp)
movq -0x2b8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x2b0(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0xf8(%rbp), %rdi
movq -0xf0(%rbp), %rsi
callq 0x59ea0
movq -0x118(%rbp), %rdi
movq -0x110(%rbp), %rsi
callq 0x59ea0
movq -0xb0(%rbp), %rax
movq (%rax), %rax
movsd (%rax), %xmm0
movsd %xmm0, -0x2c8(%rbp)
movsd -0x158(%rbp), %xmm0
divsd -0x150(%rbp), %xmm0
callq 0x4120
movaps %xmm0, %xmm1
movsd -0x2c8(%rbp), %xmm0
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
movsd 0x73549(%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 -0xb8(%rbp), %rdi
movq -0xb0(%rbp), %rsi
callq 0x59ea0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x300, %rsp            # imm = 0x300
popq %rbp
retq
nopl (%rax)