// File: /workspace/github_c_makefile_star2_O1/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, 0x68(%rsp)
movq %rdi, %r15
leaq 0x78(%rsp), %rdi
movq %r15, %rsi
callq 0x1d994
leaq 0x332ae(%rip), %rax     # 0xd2870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9f9ea
leaq 0xa0(%rsp), %r12
leaq 0xc8(%r12), %r13
movl $0xffffffff, 0x1c(%rsp) # imm = 0xFFFFFFFF
movsd 0x2f26(%rip), %xmm0     # 0xa2518
movsd %xmm0, 0x28(%rsp)
xorl %ebx, %ebx
imulq $0x340, %rbx, %rcx      # imm = 0x340
movl 0x30f08(%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x9f61e
cmpl $0x1, %eax
je 0x9f6b0
testl %eax, %eax
jne 0x9f9ae
cmpl $0x2, 0x88(%rsp)
jg 0x9f70f
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 0x9ef42
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x20(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x9e1bf
movq %r12, %rdi
callq 0x1d7dc
movsd %xmm0, 0x70(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x9f9ae
movq 0x68(%rsp), %rax
movsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x70(%rsp), %xmm0
ucomisd 0x3661(%rip), %xmm0     # 0xa2d08
jne 0x9f700
jp 0x9f700
jmp 0x9f9ef
movq %r15, %rdi
movl %ebx, %esi
movq %r12, %rdx
callq 0x9ccd7
movq %r12, %rdi
callq 0x1d4c4
movsd %xmm0, 0x20(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x9f9ae
movq 0x68(%rsp), %rax
movq $0x0, (%rax)
movsd 0x20(%rsp), %xmm0
ucomisd 0x3610(%rip), %xmm0     # 0xa2d08
jne 0x9f700
jnp 0x9fa0c
movl %ebx, 0x1c(%rsp)
movsd %xmm0, 0x28(%rsp)
jmp 0x9f9ae
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x78(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x544be
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 0x9ef42
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x90(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x9e1bf
movq %r12, %rdi
callq 0x1d7dc
movsd %xmm0, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x544be
movq 0xb0(%rsp), %rax
movq %rax, 0x60(%rsp)
movupd 0xa0(%rsp), %xmm0
movapd %xmm0, 0x50(%rsp)
cmpl $0x0, 0x40(%rsp)
jle 0x9f8db
xorl %ebp, %ebp
xorl %r14d, %r14d
movq 0x38(%rsp), %rax
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 0x9ef42
movq %r15, %rdi
movl %ebx, %esi
movsd %xmm0, 0x70(%rsp)
movq %r12, %rdx
movq %r13, %rcx
xorl %r8d, %r8d
callq 0x9e1bf
movq %r12, %rdi
callq 0x1d7dc
movsd %xmm0, 0x98(%rsp)
movsd 0x20(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x9f8b2
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x544be
movq 0xb0(%rsp), %rax
movq %rax, 0x60(%rsp)
movups 0xa0(%rsp), %xmm0
movaps %xmm0, 0x50(%rsp)
movl $0x1, %r14d
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x90(%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), %rax
cmpq %rax, %rbp
jl 0x9f7d7
testl %r14d, %r14d
sete %al
jmp 0x9f8dd
movb $0x1, %al
testb %al, %al
jne 0x9f935
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r12, %rdi
callq 0x544be
movq 0xb0(%rsp), %rax
movq %rax, 0x40(%rsp)
movupd 0xa0(%rsp), %xmm0
movapd %xmm0, 0x30(%rsp)
jmp 0x9f7c7
movsd 0x20(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x9f97c
movq 0x68(%rsp), %rax
movsd 0x90(%rsp), %xmm0
movsd %xmm0, (%rax)
movsd 0x20(%rsp), %xmm0
ucomisd 0x339e(%rip), %xmm0     # 0xa2d08
movl %ebx, 0x1c(%rsp)
movsd %xmm0, 0x28(%rsp)
jne 0x9f97c
jnp 0x9fa20
movq 0x60(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x50(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x54550
incq %rbx
leaq 0x32eb8(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbx
jl 0x9f5fa
movsd 0x28(%rsp), %xmm0
ucomisd 0x3317(%rip), %xmm0     # 0xa2cf0
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movl 0x1c(%rsp), %eax
cmovnel %eax, %ebx
cmovpl %eax, %ebx
jmp 0x9f9ef
movl $0xffffffff, %ebx       # imm = 0xFFFFFFFF
movq 0x88(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x78(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x54550
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 0x54550
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
jmp 0x9f9ef