// File: /workspace/github_c_makefile_star2_O2/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 $0x88, %rsp
movsd %xmm0, 0x38(%rsp)
movq %rsi, 0x58(%rsp)
movq %rdi, 0x50(%rsp)
leaq 0x47590(%rip), %rax     # 0xcd870
movq (%rax), %rax
movsd 0xf22d(%rip), %xmm0     # 0x95518
movsd %xmm0, 0x30(%rsp)
xorl %esi, %esi
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rsi
jge 0x86521
imulq $0x340, %rsi, %rcx      # imm = 0x340
cmpl $0x4, 0x30f08(%rax,%rcx)
je 0x86519
movq 0x50(%rsp), %rbx
movq %rbx, %rdi
movq %rsi, 0x28(%rsp)
leaq 0x4(%rsp), %rdx
callq 0x90c1a
movq %rax, %r14
movq %rbx, %rdi
callq 0x2c08f
movsd %xmm0, 0x18(%rsp)
movl 0x4(%rsp), %eax
movq %r14, 0x8(%rsp)
leaq 0x30(%r14), %r15
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
xorl %ebp, %ebp
pushq $0x1
popq %rbx
decl %eax
cltq
cmpq %rax, %rbp
jge 0x86500
movq %r15, 0x68(%rsp)
imulq $0x30, %rbp, %r12
movq 0x8(%rsp), %r14
addq %r14, %r12
movq %r12, %rdi
callq 0x2b4a0
movl %ebp, %eax
cvtsi2sd %ebp, %xmm1
movsd 0x10(%rsp), %xmm2
mulsd %xmm1, %xmm2
addsd %xmm0, %xmm2
incq %rbp
cvtsi2sd %ebp, %xmm1
divsd %xmm1, %xmm2
movsd %xmm2, 0x10(%rsp)
movl 0x4(%rsp), %r13d
subl %eax, %r13d
leal -0x1(%r13), %eax
cvtsi2sd %eax, %xmm1
movsd %xmm1, 0x60(%rsp)
xorpd 0xfe0b(%rip), %xmm0     # 0x961d0
movapd %xmm0, 0x70(%rsp)
xorpd %xmm1, %xmm1
movq %rbx, %r15
movapd %xmm1, 0x40(%rsp)
subq $0x1, %r15
jb 0x86423
movq %r14, %rdi
callq 0x2b4a0
subsd 0x10(%rsp), %xmm0
andpd 0xfdec(%rip), %xmm0     # 0x961e0
movsd 0x38(%rsp), %xmm2
movapd %xmm2, %xmm1
cmpltsd %xmm0, %xmm1
subsd %xmm2, %xmm0
movapd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm0
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
addq $0x30, %r14
jmp 0x863d2
cvtsi2sd %r13d, %xmm0
movsd 0x18(%rsp), %xmm1
mulsd %xmm0, %xmm1
addsd 0x70(%rsp), %xmm1
divsd 0x60(%rsp), %xmm1
movsd %xmm1, 0x18(%rsp)
movq 0x68(%rsp), %r15
movq %r15, %r14
movq %rbx, %r13
movslq 0x4(%rsp), %rax
cmpq %rax, %r13
jge 0x864a7
movq %r14, %rdi
callq 0x2b4a0
subsd 0x18(%rsp), %xmm0
andpd 0xfd71(%rip), %xmm0     # 0x961e0
movsd 0x38(%rsp), %xmm2
movapd %xmm2, %xmm1
cmpltsd %xmm0, %xmm1
subsd %xmm2, %xmm0
movapd 0x40(%rsp), %xmm2
addsd %xmm2, %xmm0
andpd %xmm1, %xmm0
andnpd %xmm2, %xmm1
orpd %xmm0, %xmm1
incq %r13
addq $0x30, %r14
movapd %xmm1, 0x40(%rsp)
jmp 0x8644f
movsd 0x30(%rsp), %xmm0
movapd 0x40(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x864f4
movq (%r12), %rcx
movq 0x28(%rsp), %rdx
movsd (%rcx,%rdx,8), %xmm0
imulq $0x30, %rbp, %rcx
movq 0x8(%rsp), %rsi
movq (%rsi,%rcx), %rcx
addsd (%rcx,%rdx,8), %xmm0
mulsd 0xf83f(%rip), %xmm0     # 0x95d20
movq 0x58(%rsp), %rcx
movsd %xmm0, (%rcx)
movl %edx, 0x24(%rsp)
movsd %xmm1, 0x30(%rsp)
incq %rbx
addq $0x30, %r15
jmp 0x8635c
movq 0x8(%rsp), %rdi
callq 0x34ff7
leaq 0x4735f(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x28(%rsp), %rsi
incq %rsi
jmp 0x862f3
movl 0x24(%rsp), %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq