// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/svmregtree.c
// Function: find_best_svmregtree_feature
int find_best_svmregtree_feature(Instanceptr instances, double* split, double C, LEAF_TYPE leaftype)
{
 /*!Last Changed 04.11.2009*/
 Instanceptr sorted;
 int i, j, k, size, bestfeature;
 double difference, besterror = +INT_MAX, error, regvalue, leftmean, rightmean;
 for (i = 0; i < current_dataset->featurecount; i++)
   if (current_dataset->features[i].type != REGDEF)
    {
     sorted = sort_instances(instances, i, &size);
     leftmean = 0;
     rightmean = find_mean_of_regression_value(instances);
     for (j = 0; j < size - 1; j++)
      {
       regvalue = give_regressionvalue(&(sorted[j]));
       leftmean = (leftmean * j + regvalue) / (j + 1);
       rightmean = (rightmean * (size - j) - regvalue) / (size - j - 1);
       error = 0.0;
       for (k = 0; k <= j; k++)
        {
         difference = fabs(give_regressionvalue(&(sorted[k])) - leftmean);
         if (difference > C)
           error += difference - C;
        }
       for (k = j + 1; k < size; k++)
        {
         difference = fabs(give_regressionvalue(&(sorted[k])) - rightmean);
         if (difference > C)
           error += difference - C;
        }
       if (error < besterror)
        {
         besterror = error;
         bestfeature = i;
         *split = (sorted[j].values[i].floatvalue + sorted[j + 1].values[i].floatvalue) / 2;
        }
      }
     safe_free(sorted);
    }
 return bestfeature;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rsi, 0x60(%rsp)
movq %rdi, 0x58(%rsp)
leaq 0x40b52(%rip), %rdx     # 0xd2870
movq (%rdx), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x91f95
movsd 0x107e2(%rip), %xmm1    # 0xa2518
movsd %xmm1, 0x30(%rsp)
xorl %esi, %esi
movsd %xmm0, 0x38(%rsp)
imulq $0x340, %rsi, %rcx      # imm = 0x340
cmpl $0x4, 0x30f08(%rax,%rcx)
je 0x91f7d
movq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x28(%rsp)
leaq 0xc(%rsp), %rdx
callq 0x9d053
movq %rax, %r14
movq %rbx, %rdi
callq 0x2f6a1
cmpl $0x2, 0xc(%rsp)
jl 0x91f69
movapd %xmm0, %xmm2
leaq 0x30(%r14), %rbp
xorpd %xmm0, %xmm0
movsd %xmm0, 0x18(%rsp)
movl $0x1, %ebx
xorl %r15d, %r15d
movq %r14, 0x68(%rsp)
movq %rbp, 0x78(%rsp)
movsd %xmm2, 0x10(%rsp)
leaq (%r15,%r15,2), %r12
shlq $0x4, %r12
addq %r14, %r12
movq %r12, %rdi
callq 0x2eaee
movl %r15d, %eax
xorps %xmm2, %xmm2
cvtsi2sd %r15d, %xmm2
mulsd 0x18(%rsp), %xmm2
incq %r15
xorps %xmm1, %xmm1
cvtsi2sd %r15d, %xmm1
addsd %xmm0, %xmm2
divsd %xmm1, %xmm2
movsd %xmm2, 0x18(%rsp)
movl 0xc(%rsp), %r13d
subl %eax, %r13d
leal -0x1(%r13), %eax
xorps %xmm1, %xmm1
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x70(%rsp)
xorpd 0x113c2(%rip), %xmm0    # 0xa31d0
movapd %xmm0, 0x80(%rsp)
movq %rbx, %rbp
xorpd %xmm1, %xmm1
movapd %xmm1, 0x40(%rsp)
movq %r14, %rdi
callq 0x2eaee
movapd 0x113ac(%rip), %xmm1    # 0xa31e0
movsd 0x38(%rsp), %xmm2
subsd 0x18(%rsp), %xmm0
andpd %xmm1, %xmm0
movapd %xmm2, %xmm1
cmpltsd %xmm0, %xmm1
subsd %xmm2, %xmm0
movapd 0x40(%rsp), %xmm3
addsd %xmm3, %xmm0
andpd %xmm1, %xmm0
andnpd %xmm3, %xmm1
orpd %xmm0, %xmm1
addq $0x30, %r14
decq %rbp
jne 0x91e1e
xorps %xmm0, %xmm0
cvtsi2sd %r13d, %xmm0
movsd 0x10(%rsp), %xmm2
mulsd %xmm0, %xmm2
addsd 0x80(%rsp), %xmm2
divsd 0x70(%rsp), %xmm2
movslq 0xc(%rsp), %rax
movq 0x78(%rsp), %rbp
movq %rbp, %r14
movq %rbx, %r13
cmpq %rax, %r15
movsd %xmm2, 0x10(%rsp)
jge 0x91f06
movapd %xmm1, 0x40(%rsp)
movq %r14, %rdi
callq 0x2eaee
movsd 0x38(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
subsd %xmm2, %xmm0
andpd 0x1130e(%rip), %xmm0    # 0xa31e0
movapd %xmm3, %xmm1
cmpltsd %xmm0, %xmm1
subsd %xmm3, %xmm0
movapd 0x40(%rsp), %xmm3
addsd %xmm3, %xmm0
andpd %xmm1, %xmm0
andnpd %xmm3, %xmm1
orpd %xmm0, %xmm1
incq %r13
movslq 0xc(%rsp), %rax
addq $0x30, %r14
cmpq %rax, %r13
jl 0x91eac
movsd 0x30(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movq 0x68(%rsp), %r14
jbe 0x91f51
movq (%r12), %rax
movq 0x28(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
leaq (%r15,%r15,2), %rax
shlq $0x4, %rax
movq (%r14,%rax), %rax
addsd (%rax,%rcx,8), %xmm0
mulsd 0x10dda(%rip), %xmm0    # 0xa2d18
movq 0x60(%rsp), %rax
movsd %xmm0, (%rax)
movl %ecx, 0x24(%rsp)
movsd %xmm1, 0x30(%rsp)
movslq 0xc(%rsp), %rax
decq %rax
incq %rbx
addq $0x30, %rbp
cmpq %rax, %r15
jl 0x91da5
movq %r14, %rdi
callq 0x39194
leaq 0x408f8(%rip), %rdx     # 0xd2870
movq 0x28(%rsp), %rsi
incq %rsi
movq (%rdx), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rsi
jl 0x91d44
jmp 0x91f95
movl 0x24(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq