// File: /workspace/github_c_makefile_star2_O3/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 0x41102(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x949e1
movsd 0x10d92(%rip), %xmm1    # 0xa5518
movsd %xmm1, 0x30(%rsp)
xorl %esi, %esi
movsd %xmm0, 0x38(%rsp)
imulq $0x340, %rsi, %rcx      # imm = 0x340
cmpl $0x4, 0x30f08(%rax,%rcx)
je 0x949cc
movq 0x58(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x28(%rsp)
leaq 0xc(%rsp), %rdx
callq 0xa0055
movq %rax, %r14
movq %rbx, %rdi
callq 0x2ffe1
cmpl $0x2, 0xc(%rsp)
jl 0x949b5
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 0x2f35e
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 0x11972(%rip), %xmm0    # 0xa61d0
movapd %xmm0, 0x80(%rsp)
movq %rbx, %rbp
xorpd %xmm1, %xmm1
movapd %xmm1, 0x40(%rsp)
movq %r14, %rdi
callq 0x2f35e
movapd 0x1195c(%rip), %xmm1    # 0xa61e0
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 0x9486e
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 0x94956
movapd %xmm1, 0x40(%rsp)
movq %r14, %rdi
callq 0x2f35e
movsd 0x38(%rsp), %xmm3
movsd 0x10(%rsp), %xmm2
subsd %xmm2, %xmm0
andpd 0x118be(%rip), %xmm0    # 0xa61e0
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 0x948fc
movsd 0x30(%rsp), %xmm0
ucomisd %xmm1, %xmm0
movq 0x68(%rsp), %r14
jbe 0x949a1
movq (%r12), %rcx
movq 0x28(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
leaq (%r15,%r15,2), %rcx
shlq $0x4, %rcx
movq (%r14,%rcx), %rcx
addsd (%rcx,%rdx,8), %xmm0
mulsd 0x1138a(%rip), %xmm0    # 0xa5d18
movq 0x60(%rsp), %rcx
movsd %xmm0, (%rcx)
movl %edx, 0x24(%rsp)
movsd %xmm1, 0x30(%rsp)
decl %eax
cltq
incq %rbx
addq $0x30, %rbp
cmpq %rax, %r15
jl 0x947f5
movq %r14, %rdi
callq 0x3a180
leaq 0x40eac(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x28(%rsp), %rsi
incq %rsi
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rsi
jl 0x94794
jmp 0x949e1
movl 0x24(%rsp), %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq