// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/regressiontree.c
// Function: best_regression_feature_linear_leaves
int best_regression_feature_linear_leaves(Instanceptr instances, double* split, char* comparison)
{
	/*!Last Changed 28.02.2005*/
 int bestfeature = -1, i, size, k;
 Instanceptr sorted;
	matrix w, X, r;
 double value, valuebefore, mse, bestmse = +INT_MAX;
	double lefterror, righterror;
 for (i = 0; i < current_dataset->featurecount;i++)
   switch (current_dataset->features[i].type)
    {
     case REAL   :sorted = sort_instances(instances, i, &size);
						            k = 0;
                  valuebefore = -INT_MAX;
                  while (k < size)
                   {
                    value = sorted[k].values[i].floatvalue;
                    if (value != valuebefore)
                     {
                      if (valuebefore != -INT_MAX)
                       {
                        create_regression_matrices_for_array_of_instances(sorted, 0, k - 1, &X, &r);
      		                w = multivariate_regression(X, r);
																								matrix_free(X);
																								matrix_free(r);
				                    lefterror = variance_of_linear_regression_for_array_of_instances(w, sorted, 0, k - 1, LINEARLEAF);
                        matrix_free(w);
                        create_regression_matrices_for_array_of_instances(sorted, k, size - 1, &X, &r);
      		                w = multivariate_regression(X, r);
																								matrix_free(X);
																								matrix_free(r);
				                    righterror = variance_of_linear_regression_for_array_of_instances(w, sorted, k, size - 1, LINEARLEAF);
                        matrix_free(w);
																							 mse = lefterror + righterror;
																								if (mse < bestmse)
																								 {
																									 if ((lefterror / k) < (righterror / (size - k)))
																											 *comparison = '<';
																										else
																											 *comparison = '>';
																									 bestmse = mse;
																										bestfeature = i;
                          *split = (valuebefore + value) / 2;
																								 }
                       }
                      valuebefore = value;
                     }
                    k++;
                   }
                  safe_free(sorted);
                  break;
    }
 return bestfeature;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movl $0xffffffff, -0x1c(%rbp) # imm = 0xFFFFFFFF
movsd 0x3beda(%rip), %xmm0    # 0xe2010
movsd %xmm0, -0x80(%rbp)
movl $0x0, -0x20(%rbp)
movl -0x20(%rbp), %eax
leaq 0x5f6f4(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
cmpl 0x1bc(%rcx), %eax
jge 0xa640c
leaq 0x5f6de(%rip), %rax     # 0x105840
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
movl 0x30f08(%rax,%rcx), %eax
subl $0x2, %eax
jne 0xa63fc
jmp 0xa6182
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %esi
leaq -0x24(%rbp), %rdx
callq 0xdc050
movq %rax, -0x30(%rbp)
movl $0x0, -0x28(%rbp)
movsd 0x3be63(%rip), %xmm0    # 0xe2008
movsd %xmm0, -0x70(%rbp)
movl -0x28(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0xa63f3
movq -0x30(%rbp), %rax
movslq -0x28(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x68(%rbp), %xmm0
ucomisd -0x70(%rbp), %xmm0
jne 0xa61e9
jp 0xa61e9
jmp 0xa63e5
movsd -0x70(%rbp), %xmm0
movsd 0x3be12(%rip), %xmm1    # 0xe2008
ucomisd %xmm1, %xmm0
jne 0xa6203
jp 0xa6203
jmp 0xa63db
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %edx
subl $0x1, %edx
xorl %esi, %esi
leaq -0x50(%rbp), %rcx
leaq -0x60(%rbp), %r8
callq 0xa6420
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0xa6590
movq %rax, -0xa0(%rbp)
movq %rdx, -0x98(%rbp)
movq -0xa0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x98(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x59ea0
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x59ea0
movq -0x30(%rbp), %rdx
movl -0x28(%rbp), %r8d
subl $0x1, %r8d
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
xorl %ecx, %ecx
movl $0x1, %r9d
callq 0xa6690
movsd %xmm0, -0x88(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x59ea0
movq -0x30(%rbp), %rdi
movl -0x28(%rbp), %esi
movl -0x24(%rbp), %edx
subl $0x1, %edx
leaq -0x50(%rbp), %rcx
leaq -0x60(%rbp), %r8
callq 0xa6420
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
movq -0x60(%rbp), %rdx
movq -0x58(%rbp), %rcx
callq 0xa6590
movq %rax, -0xb0(%rbp)
movq %rdx, -0xa8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x50(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x59ea0
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
callq 0x59ea0
movq -0x30(%rbp), %rdx
movl -0x28(%rbp), %ecx
movl -0x24(%rbp), %r8d
subl $0x1, %r8d
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
movl $0x1, %r9d
callq 0xa6690
movsd %xmm0, -0x90(%rbp)
movq -0x40(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x59ea0
movsd -0x88(%rbp), %xmm0
addsd -0x90(%rbp), %xmm0
movsd %xmm0, -0x78(%rbp)
movsd -0x78(%rbp), %xmm1
movsd -0x80(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa63d9
movsd -0x88(%rbp), %xmm1
cvtsi2sdl -0x28(%rbp), %xmm0
divsd %xmm0, %xmm1
movsd -0x90(%rbp), %xmm0
movl -0x24(%rbp), %eax
subl -0x28(%rbp), %eax
cvtsi2sd %eax, %xmm2
divsd %xmm2, %xmm0
ucomisd %xmm1, %xmm0
jbe 0xa63a4
movq -0x18(%rbp), %rax
movb $0x3c, (%rax)
jmp 0xa63ab
movq -0x18(%rbp), %rax
movb $0x3e, (%rax)
movsd -0x78(%rbp), %xmm0
movsd %xmm0, -0x80(%rbp)
movl -0x20(%rbp), %eax
movl %eax, -0x1c(%rbp)
movsd -0x70(%rbp), %xmm0
addsd -0x68(%rbp), %xmm0
movsd 0x3c8d3(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0xa63db
movsd -0x68(%rbp), %xmm0
movsd %xmm0, -0x70(%rbp)
movl -0x28(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x28(%rbp)
jmp 0xa61aa
movq -0x30(%rbp), %rdi
callq 0x52e80
jmp 0xa63fe
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0xa6142
movl -0x1c(%rbp), %eax
addq $0xb0, %rsp
popq %rbp
retq
nopl (%rax,%rax)