// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/svmtree.c
// Function: find_best_svmtree_feature
int find_best_svmtree_feature(Instanceptr instances, double* split, int positive, double C)
{
 /*!Last Changed 03.07.2009*/
 Instanceptr tmp;
 int counts[2][MAXCLASSES];
 int i, j, t, count = data_size(instances), bestfeature = -1, negativecount, positivecount, splitcount;
 double* splits = safemalloc(count * sizeof(double), "find_best_svmtree_feature", 2);
 Splitpointptr splitpoints = safemalloc(count * sizeof(Splitpoint), "find_best_svmtree_feature", 3);
 double fvalue, bestvalue, bestfsplit, besterror = +INT_MAX, error;
 for (i = 0; i < current_dataset->featurecount; i++)
   if (current_dataset->features[i].type != CLASSDEF)
    {
     for (j = 0, tmp = instances; j < count; j++, tmp = tmp->next)
      {
       if (give_classno(tmp) == positive)
         t = -1;
       else
         t = +1;
       splits[j] = (C - t * tmp->values[i].floatvalue) / t;
      }
     qsort(splits, count, sizeof(double), sort_function_double_ascending);
     if (splits[0] == splits[count - 1])
       continue;
     splitcount = 1;
     splitpoints[0].x = splits[0];
     splitpoints[0].count = 1;
     for (j = 1; j < count; j++)
       if (splitpoints[splitcount - 1].x != splits[j])
        {
         splitpoints[splitcount].x = splits[j];
         splitpoints[splitcount].count = 1;
         splitcount++;
        }
       else
         splitpoints[splitcount - 1].count++;
     bestvalue = +INT_MAX;
     fvalue = 0.0;
     negativecount = 0;
     positivecount = 0;
     for (j = splitcount - 1; j > 0; j--)
       if (splitpoints[j].x > 0)
        {
         positivecount += splitpoints[j].count;
         fvalue += (splitpoints[j].x - splitpoints[0].x) * splitpoints[j].count;
        }
       else
         break;
     for (j = 0; j < splitcount - 1; j++)
      {
       if (fvalue < bestvalue)
        {
         bestvalue = fvalue;
         bestfsplit = -(splitpoints[j].x + splitpoints[j + 1].x) / 2;
        }
       if (splitpoints[j].x < 0)
         negativecount += splitpoints[j].count;
       else
         positivecount -= splitpoints[j].count;
       fvalue += (negativecount - positivecount) * (splitpoints[j + 1].x - splitpoints[j].x);
      }
     find_counts_for_split(instances, i, bestfsplit, counts[0], counts[1], UNIVARIATE_CONDITION);
     error = error_of_split(counts, count);
     if (error < besterror)
      {
       bestfeature = i;
       *split = bestfsplit;
       besterror = error;
      }
    }
 safe_free(splits);
 safe_free(splitpoints);
 return bestfeature;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1f8, %rsp            # imm = 0x1F8
movsd %xmm0, 0x58(%rsp)
movl %edx, %ebx
movq %rsi, 0x40(%rsp)
movq %rdi, 0x30(%rsp)
callq 0x2fa14
movl %eax, %r14d
movslq %eax, %r15
leaq (,%r15,8), %rdi
leaq 0x19f43(%rip), %r13     # 0xaec3a
movq %r13, %rsi
movl $0x2, %edx
callq 0x390f5
movq %rax, %r12
movq %r15, 0x48(%rsp)
movq %r15, %rdi
shlq $0x4, %rdi
movq %r13, %rsi
movl $0x3, %edx
callq 0x390f5
leaq 0x3db49(%rip), %rdx     # 0xd2870
movq (%rdx), %rsi
cmpl $0x0, 0x1bc(%rsi)
movq %rax, 0x20(%rsp)
jle 0x95034
movl %ebx, 0x1c(%rsp)
movl %r14d, %ebx
addq $0x8, %rax
movq %rax, 0x38(%rsp)
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movsd 0xd7bc(%rip), %xmm0     # 0xa2518
leaq 0x19ea5(%rip), %rax     # 0xaec08
xorl %ebp, %ebp
movsd %xmm0, 0x28(%rsp)
movl %r14d, 0x18(%rsp)
movq %rbx, 0x50(%rsp)
imulq $0x340, %rbp, %rcx      # imm = 0x340
cmpl $0x3, 0x30f08(%rsi,%rcx)
je 0x9501c
movsd %xmm0, 0x10(%rsp)
testl %r14d, %r14d
movq %r12, %r15
movl 0x1c(%rsp), %edx
movq %rbp, %r14
movq %rbx, %rcx
jle 0x94e02
movq %rax, %rsi
xorl %ebx, %ebx
movq 0x30(%rsp), %rbp
movq %rbp, %rdi
movl %edx, %r12d
movq %rsi, %r13
callq 0x2eaca
movq %r13, %rsi
movl %r12d, %edx
movsd 0x58(%rsp), %xmm2
xorl %ecx, %ecx
cmpl %r12d, %eax
sete %cl
movsd (%r13,%rcx,8), %xmm0
movq 0x50(%rsp), %rcx
movq (%rbp), %rax
movsd (%rax,%r14,8), %xmm1
mulsd %xmm0, %xmm1
subsd %xmm1, %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, (%r15,%rbx,8)
incq %rbx
movq 0x10(%rbp), %rbp
cmpq %rbx, %rcx
jne 0x94dac
movq %r14, %rbp
movq %rcx, %r13
movl $0x8, %edx
movq %r15, %rdi
movq 0x48(%rsp), %rbx
movq %rbx, %rsi
leaq -0x5b838(%rip), %rcx    # 0x395e7
callq 0x4240
movsd (%r15), %xmm0
ucomisd -0x8(%r15,%rbx,8), %xmm0
movq %r15, %r12
jne 0x94e4b
jp 0x94e4b
movl 0x18(%rsp), %r14d
leaq 0x3da2d(%rip), %rdx     # 0xd2870
movq %r13, %rbx
jmp 0x9500f
movq 0x20(%rsp), %r9
movsd %xmm0, (%r9)
movl $0x1, 0x8(%r9)
movl $0x1, %ecx
movl 0x18(%rsp), %r14d
cmpl $0x2, %r14d
movq %r13, %rbx
movl $0x0, %r10d
xorpd %xmm5, %xmm5
movsd 0xdf50(%rip), %xmm6     # 0xa2dd0
movsd 0x10(%rsp), %xmm0
jl 0x94ecc
movl $0x1, %ecx
movl $0x1, %eax
movslq %ecx, %rsi
shlq $0x4, %rsi
leaq (%r9,%rsi), %rdx
movsd -0x10(%r9,%rsi), %xmm1
movsd (%r12,%rax,8), %xmm2
ucomisd %xmm2, %xmm1
jne 0x94eb2
jnp 0x94ec1
movsd %xmm2, (%rdx)
movl $0x1, 0x8(%rdx)
incl %ecx
jmp 0x94ec4
incl -0x8(%rdx)
incq %rax
cmpq %rax, %rbx
jne 0x94e92
leal -0x1(%rcx), %edx
cmpl $0x2, %ecx
jl 0x94f1e
movl %edx, %esi
leaq 0x1(%rsi), %rdi
shlq $0x4, %rsi
addq 0x38(%rsp), %rsi
xorl %eax, %eax
xorpd %xmm7, %xmm7
movsd -0x8(%rsi), %xmm1
ucomisd %xmm5, %xmm1
jbe 0x94f24
movl (%rsi), %r8d
subsd (%r9), %xmm1
addl %r8d, %eax
xorps %xmm2, %xmm2
cvtsi2sd %r8d, %xmm2
mulsd %xmm1, %xmm2
addsd %xmm2, %xmm7
decq %rdi
addq $-0x10, %rsi
cmpq $0x1, %rdi
jg 0x94ee9
jmp 0x94f24
xorpd %xmm7, %xmm7
xorl %eax, %eax
cmpl $0x2, %ecx
jl 0x94f9f
movl %edx, %ecx
shlq $0x4, %rcx
xorl %edx, %edx
movsd 0xd5df(%rip), %xmm1     # 0xa2518
xorl %esi, %esi
ucomisd %xmm7, %xmm1
jbe 0x94f56
movsd (%r9,%rdx), %xmm0
addsd 0x10(%r9,%rdx), %xmm0
mulsd %xmm6, %xmm0
movapd %xmm7, %xmm1
movsd (%r9,%rdx), %xmm2
ucomisd %xmm2, %xmm5
movl 0x8(%r9,%rdx), %edi
movl $0x0, %r8d
cmoval %edi, %r8d
cmoval %r10d, %edi
addl %r8d, %esi
subl %edi, %eax
movl %esi, %edi
subl %eax, %edi
xorps %xmm3, %xmm3
cvtsi2sd %edi, %xmm3
movsd 0x10(%r9,%rdx), %xmm4
subsd %xmm2, %xmm4
mulsd %xmm3, %xmm4
addsd %xmm4, %xmm7
addq $0x10, %rdx
cmpq %rdx, %rcx
jne 0x94f3b
movsd %xmm0, 0x10(%rsp)
movq 0x30(%rsp), %rdi
movl %ebp, %esi
leaq 0x60(%rsp), %r15
movq %r15, %rdx
leaq 0x128(%rsp), %rcx
xorl %r8d, %r8d
callq 0x9e1bf
movq %r15, %rdi
movl %r14d, %esi
callq 0x1d8fb
movsd 0x28(%rsp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x95008
movq 0x40(%rsp), %rax
movsd 0x10(%rsp), %xmm1
movsd %xmm1, (%rax)
movl %ebp, 0xc(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0x3d875(%rip), %rdx     # 0xd2870
leaq 0x19c06(%rip), %rax     # 0xaec08
movapd %xmm1, %xmm0
jmp 0x9501c
leaq 0x3d861(%rip), %rdx     # 0xd2870
leaq 0x19bf2(%rip), %rax     # 0xaec08
movsd 0x10(%rsp), %xmm0
incq %rbp
movq (%rdx), %rsi
movslq 0x1bc(%rsi), %rcx
cmpq %rcx, %rbp
jl 0x94d75
jmp 0x9503c
movl $0xffffffff, 0xc(%rsp)  # imm = 0xFFFFFFFF
movq %r12, %rdi
callq 0x39194
movq 0x20(%rsp), %rdi
callq 0x39194
movl 0xc(%rsp), %eax
addq $0x1f8, %rsp            # imm = 0x1F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq