// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movsd %xmm0, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movsd 0x16510(%rip), %xmm0    # 0xe2010
movsd %xmm0, -0x50(%rbp)
movl $0x0, -0x2c(%rbp)
movl -0x2c(%rbp), %eax
leaq 0x39d2a(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
cmpl 0x1bc(%rcx), %eax
jge 0xcbd86
leaq 0x39d14(%rip), %rax     # 0x105840
movq (%rax), %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq -0x2c(%rbp), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
addq %rcx, %rax
cmpl $0x4, (%rax)
je 0xcbd76
movq -0x8(%rbp), %rdi
movl -0x2c(%rbp), %esi
leaq -0x38(%rbp), %rdx
callq 0xdc050
movq %rax, -0x28(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x68(%rbp)
movq -0x8(%rbp), %rdi
callq 0x44600
movsd %xmm0, -0x70(%rbp)
movl $0x0, -0x30(%rbp)
movl -0x30(%rbp), %eax
movl -0x38(%rbp), %ecx
subl $0x1, %ecx
cmpl %ecx, %eax
jge 0xcbd6d
movq -0x28(%rbp), %rdi
movslq -0x30(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
callq 0x43580
movsd %xmm0, -0x60(%rbp)
movsd -0x68(%rbp), %xmm0
cvtsi2sdl -0x30(%rbp), %xmm2
movsd -0x60(%rbp), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movl -0x30(%rbp), %eax
addl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x68(%rbp)
movsd -0x70(%rbp), %xmm0
movl -0x38(%rbp), %eax
subl -0x30(%rbp), %eax
cvtsi2sd %eax, %xmm2
movsd -0x60(%rbp), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movl -0x38(%rbp), %eax
subl -0x30(%rbp), %eax
subl $0x1, %eax
cvtsi2sd %eax, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, -0x70(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x58(%rbp)
movl $0x0, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x30(%rbp), %eax
jg 0xcbc87
movq -0x28(%rbp), %rdi
movslq -0x34(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
callq 0x43580
subsd -0x68(%rbp), %xmm0
movaps 0x1720f(%rip), %xmm1    # 0xe2e60
pand %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0xcbc7a
movsd -0x48(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0xcbc7c
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xcbc29
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x38(%rbp), %eax
jge 0xcbcee
movq -0x28(%rbp), %rdi
movslq -0x34(%rbp), %rax
imulq $0x30, %rax, %rax
addq %rax, %rdi
callq 0x43580
subsd -0x70(%rbp), %xmm0
movaps 0x171a8(%rip), %xmm1    # 0xe2e60
pand %xmm1, %xmm0
movsd %xmm0, -0x48(%rbp)
movsd -0x48(%rbp), %xmm0
ucomisd -0x18(%rbp), %xmm0
jbe 0xcbce1
movsd -0x48(%rbp), %xmm0
subsd -0x18(%rbp), %xmm0
addsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0xcbce3
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0xcbc90
movsd -0x58(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0xcbd5d
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x2c(%rbp), %eax
movl %eax, -0x3c(%rbp)
movq -0x28(%rbp), %rax
movslq -0x30(%rbp), %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x28(%rbp), %rax
movl -0x30(%rbp), %ecx
addl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x30, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rax
movslq -0x2c(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm0
movsd 0x16f4f(%rip), %xmm1    # 0xe2ca0
divsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movsd %xmm0, (%rax)
jmp 0xcbd5f
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xcbb7d
movq -0x28(%rbp), %rdi
callq 0x52e80
jmp 0xcbd78
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xcbb0c
movl -0x3c(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nop