// File: /workspace/github_c_makefile_star2_O1/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movq %rdi, 0x70(%rsp)
leaq 0x5da3a(%rip), %rdx     # 0xd2870
movq (%rdx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x75135
movsd 0x2d6ca(%rip), %xmm0    # 0xa2518
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
xorl %ebx, %ebx
imulq $0x340, %rbx, %rcx      # imm = 0x340
cmpl $0x2, 0x30f08(%rax,%rcx)
jne 0x7511d
movsd %xmm0, 0x10(%rsp)
movq 0x70(%rsp), %rdi
movl %ebx, %esi
leaq 0x8(%rsp), %rdx
callq 0x9d053
movq %rax, %r15
cmpl $0x0, 0x8(%rsp)
jle 0x750fc
xorl %edx, %edx
movq %r15, %r12
xorl %r14d, %r14d
movsd 0x2d66e(%rip), %xmm2    # 0xa2510
movsd 0x10(%rsp), %xmm0
movq %rbx, 0x38(%rsp)
movq %r15, 0x30(%rsp)
movq (%r12), %rax
movsd (%rax,%rbx,8), %xmm1
ucomisd %xmm2, %xmm1
jne 0x74ec7
jnp 0x750b7
ucomisd 0x2d641(%rip), %xmm2    # 0xa2510
jne 0x74ed7
jnp 0x750c1
movsd %xmm2, 0x88(%rsp)
movsd %xmm1, 0x40(%rsp)
movq %rdx, 0x48(%rsp)
leal -0x1(%r14), %edx
movl %edx, 0x28(%rsp)
movq %r15, %rdi
xorl %esi, %esi
leaq 0x60(%rsp), %rcx
leaq 0x50(%rsp), %r8
movsd %xmm0, 0x10(%rsp)
callq 0x75153
movq 0x60(%rsp), %rbp
movq 0x68(%rsp), %r13
movq 0x50(%rsp), %r15
movq 0x58(%rsp), %rbx
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %rdx
movq %rbx, %rcx
callq 0x7526c
movq %rax, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3dbad
movq %r15, %rdi
movq %rbx, %rsi
callq 0x3dbad
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r15
movq %r15, %rsi
movq 0x30(%rsp), %rdx
xorl %ecx, %ecx
movl 0x28(%rsp), %r8d
movl $0x1, %r9d
callq 0x75321
movsd %xmm0, 0x28(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3dbad
movl 0x8(%rsp), %edx
decl %edx
movq 0x30(%rsp), %rdi
movl %r14d, %esi
leaq 0x60(%rsp), %rcx
leaq 0x50(%rsp), %r8
callq 0x75153
movq 0x60(%rsp), %rbx
movq 0x68(%rsp), %r15
movq 0x50(%rsp), %rbp
movq 0x58(%rsp), %r13
movq %rbx, %rdi
movq %r15, %rsi
movq %rbp, %rdx
movq %r13, %rcx
callq 0x7526c
movq %rax, 0x20(%rsp)
movq %rdx, 0x18(%rsp)
movq %rbx, %rdi
movq %r15, %rsi
movq 0x30(%rsp), %r15
callq 0x3dbad
movq %rbp, %rdi
movq %r13, %rsi
callq 0x3dbad
movl 0x8(%rsp), %r8d
decl %r8d
movq 0x20(%rsp), %rbx
movq %rbx, %rdi
movq 0x18(%rsp), %r13
movq %r13, %rsi
movq %r15, %rdx
movl %r14d, %ecx
movl $0x1, %r9d
callq 0x75321
movsd %xmm0, 0x90(%rsp)
movq %rbx, %rdi
movq %r13, %rsi
callq 0x3dbad
movsd 0x90(%rsp), %xmm2
movsd 0x28(%rsp), %xmm1
movsd 0x10(%rsp), %xmm0
movapd %xmm1, %xmm3
addsd %xmm2, %xmm3
ucomisd %xmm3, %xmm0
jbe 0x750c7
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
divsd %xmm0, %xmm1
movl 0x8(%rsp), %eax
movq 0x48(%rsp), %rdx
addl %edx, %eax
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
divsd %xmm0, %xmm2
ucomisd %xmm1, %xmm2
setbe %al
addb %al, %al
orb $0x3c, %al
movq 0x80(%rsp), %rcx
movb %al, (%rcx)
movsd 0x40(%rsp), %xmm1
movsd 0x88(%rsp), %xmm0
addsd %xmm1, %xmm0
mulsd 0x2dc75(%rip), %xmm0    # 0xa2d18
movq 0x78(%rsp), %rax
movsd %xmm0, (%rax)
movq 0x38(%rsp), %rbx
movl %ebx, 0xc(%rsp)
jmp 0x750db
movapd %xmm0, %xmm3
movapd %xmm2, %xmm1
jmp 0x750db
movapd %xmm0, %xmm3
jmp 0x750db
movapd %xmm0, %xmm3
movq 0x38(%rsp), %rbx
movq 0x48(%rsp), %rdx
movsd 0x40(%rsp), %xmm1
incq %r14
movslq 0x8(%rsp), %rax
decl %edx
addq $0x30, %r12
movapd %xmm1, %xmm2
movapd %xmm3, %xmm0
cmpq %rax, %r14
jl 0x74eb2
jmp 0x75102
movsd 0x10(%rsp), %xmm3
movsd %xmm3, 0x10(%rsp)
movq %r15, %rdi
callq 0x39194
movsd 0x10(%rsp), %xmm0
leaq 0x5d753(%rip), %rdx     # 0xd2870
incq %rbx
movq (%rdx), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbx
jl 0x74e58
jmp 0x7513d
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movl 0xc(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq