// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/univariatetree.c
// Function: find_best_ldt_feature
int find_best_ldt_feature(Instanceptr instances,double* split)
{
/*!Last Changed 26.01.2003*/
 int i,j,bestfeature=-1,improved;
 double bestgain=+INT_MAX,gain,bestpartitiongain,currentsplit,bestsplit;
 Partition initial,current,best;
 initial = get_initial_partition(instances);
 for (i=0;i<current_dataset->featurecount;i++)
   switch (current_dataset->features[i].type)
    {
     case REAL   :
     case INTEGER:if (initial.count <= 2)
                   {
                    bestpartitiongain = find_gain_for_partition(instances,initial,i,&bestsplit, UNIVARIATE_CONDITION);
                    if (dless(bestpartitiongain,bestgain))
                     {
                      bestgain = bestpartitiongain;
                      bestfeature = i;
                      (*split) = bestsplit;
                      if (bestpartitiongain == 0)
                       {
                        free_partition(initial);
                        return bestfeature;
                       }
                     }
                    continue;
                   }
                  current = create_copy(initial);
                  bestpartitiongain = find_gain_for_partition(instances,current,i,&bestsplit, UNIVARIATE_CONDITION);
                  best = create_copy(current);
                  improved = 1;
                  while (improved)
                   {
                    improved = 0;
                    for (j = 0; j < current.count; j++)
                     {
                      current.assignments[j] = 1-current.assignments[j];
                      gain = find_gain_for_partition(instances,current,i,&currentsplit, UNIVARIATE_CONDITION);
                      if (dless(gain,bestpartitiongain))
                       {
                        bestsplit = currentsplit;
                        bestpartitiongain = gain;
                        free_partition(best);
                        best = create_copy(current);
                        improved = 1;
                       }
                      current.assignments[j]=1-current.assignments[j];
                     }
                    if (improved)
                     {
                      free_partition(current);
                      current = create_copy(best);
                     }
                   }
                  if (dless(bestpartitiongain,bestgain))
                   {
                    bestgain = bestpartitiongain;
                    bestfeature = i;
                    (*split) = bestsplit;
                    if (bestgain == 0)
                     {
                      free_partition(best);
                      free_partition(current);
                      free_partition(initial);
                      return bestfeature;
                     }
                   }
                  free_partition(best);
                  free_partition(current);
                  break;
     case STRING :gain=information_gain_for_discrete_feature(instances,i);
                  if (dless(gain,bestgain))
                   {
                    bestgain=gain;
                    bestfeature=i;
                    (*split)=0;
                    if (gain==0)
                      return bestfeature;
                   }
                  break;
    }
 free_partition(initial);
 if (bestgain==ISELL)
   return -1;
 else
   return bestfeature;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x4ec8, %rsp           # imm = 0x4EC8
movq %rsi, %r14
movq %rdi, %r15
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x1e10a
leaq 0x332d4(%rip), %rbp     # 0xd5870
movq (%rbp), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0xa29ba
leaq 0xa0(%rsp), %r12
leaq 0xc8(%r12), %r13
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movsd 0x2f4b(%rip), %xmm0     # 0xa5518
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
movq %r14, 0x90(%rsp)
imulq $0x340, %rbx, %rcx      # imm = 0x340
movl 0x30f08(%rax,%rcx), %eax
cmpl $0x2, %eax
je 0xa2601
cmpl $0x1, %eax
je 0xa268f
testl %eax, %eax
jne 0xa2984
cmpl $0x2, 0x88(%rsp)
jg 0xa26e9
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0xa1f40
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x20(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xa11fa
movq %r12, %rdi
callq 0x1df2d
movsd %xmm0, 0x68(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
je 0xa2984
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x68(%rsp), %xmm0
ucomisd 0x3682(%rip), %xmm0     # 0xa5d08
jne 0xa26da
jp 0xa26da
jmp 0xa29bf
movq %r15, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x9fcd9
movq %r12, %rdi
callq 0x1dc4b
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
je 0xa2984
movq $0x0, (%r14)
movsd 0x20(%rsp), %xmm0
ucomisd 0x3636(%rip), %xmm0     # 0xa5d08
jne 0xa26da
jnp 0xa29dc
movl %ebx, 0x1c(%rsp)
movsd %xmm0, 0x28(%rsp)
jmp 0xa2984
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x559be
movq 0xb0(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0xa1f40
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x70(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xa11fa
movq %r12, %rdi
callq 0x1df2d
movsd %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x559be
movq 0xb0(%rsp), %rax
movq %rax, 0x60(%rsp)
movupd 0xa0(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
cmpl $0x0, 0x40(%rsp)
jle 0xa2903
xorl %ebp, %ebp
movq 0x38(%rsp), %rax
xorl %r14d, %r14d
movl $0x1, %ecx
subl (%rax,%rbp,4), %ecx
movl %ecx, (%rax,%rbp,4)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
xorl %edx, %edx
callq 0xa1f40
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x68(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0xa11fa
movq %r12, %rdi
callq 0x1df2d
movsd %xmm0, 0x98(%rsp)
movsd 0x20(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
je 0xa2886
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x559be
movq 0xb0(%rsp), %rax
movq %rax, 0x60(%rsp)
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x1, %r14d
movsd 0x68(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
movsd 0x98(%rsp), %xmm0
movsd %xmm0, 0x20(%rsp)
movq 0x38(%rsp), %rax
movl $0x1, %ecx
subl (%rax,%rbp,4), %ecx
movl %ecx, (%rax,%rbp,4)
incq %rbp
movslq 0x40(%rsp), %rcx
cmpq %rcx, %rbp
jl 0xa27b3
testl %r14d, %r14d
je 0xa2903
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x559be
movq 0xb0(%rsp), %rax
movq %rax, 0x40(%rsp)
movupd 0xa0(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
testl %eax, %eax
jg 0xa27a9
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
movq 0x90(%rsp), %r14
leaq 0x32f4b(%rip), %rbp     # 0xd5870
je 0xa2952
movsd 0x70(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x20(%rsp), %xmm0
ucomisd 0x33c8(%rip), %xmm0     # 0xa5d08
jne 0xa2948
jnp 0xa29f0
movl %ebx, 0x1c(%rsp)
movsd %xmm0, 0x28(%rsp)
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x55a69
incq %rbx
movq (%rbp), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbx
jl 0xa25dd
movsd 0x28(%rsp), %xmm0
ucomisd 0x3347(%rip), %xmm0     # 0xa5cf0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x1c(%rsp), %eax
cmovnel %eax, %ebx
cmovpl %eax, %ebx
jmp 0xa29bf
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x55a69
movl %ebx, %eax
addq $0x4ec8, %rsp           # imm = 0x4EC8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
jmp 0xa29bf