// File: /workspace/github_c_makefile_star2_O2/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 $0xc8, %rsp
movq %rsi, %r14
movq %rdi, %r15
leaq 0x80(%rsp), %rdi
movq %r15, %rsi
callq 0x1bbad
movsd 0x2597(%rip), %xmm0     # 0x95518
movsd %xmm0, 0x28(%rsp)
pushq $-0x1
popq %rax
movl %eax, 0x24(%rsp)
xorl %ebx, %ebx
leaq 0x3a8d9(%rip), %r12     # 0xcd870
pushq $0x1
popq %r13
leaq 0xc0(%rsp), %rbp
movq %r14, 0xb0(%rsp)
movq (%r12), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rbx
jge 0x93345
imulq $0x340, %rbx, %rcx      # imm = 0x340
movl 0x30f08(%rax,%rcx), %eax
cmpl $0x2, %eax
je 0x92fdf
cmpl $0x1, %eax
je 0x93054
testl %eax, %eax
jne 0x9333d
cmpl $0x2, 0x90(%rsp)
jg 0x930a0
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x80(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
leaq 0x58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x92ace
movsd %xmm0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
je 0x9333d
movsd 0x58(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x18(%rsp), %xmm0
ucomisd 0x2ccd(%rip), %xmm0     # 0x95d18
jne 0x93091
jp 0x93091
jmp 0x933b2
movq %r15, %rdi
movl %ebx, %esi
callq 0x9095a
movsd %xmm0, 0x18(%rsp)
movsd 0x28(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
je 0x9333d
andq $0x0, (%r14)
movsd 0x18(%rsp), %xmm0
ucomisd 0x2c8f(%rip), %xmm0     # 0x95d18
jne 0x93091
jnp 0x933d2
movl %ebx, 0x24(%rsp)
movsd %xmm0, 0x28(%rsp)
jmp 0x9333d
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %r14
movq %r14, %rdi
callq 0x4dcb2
movq 0xa8(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x98(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
xorl %r12d, %r12d
movq %r15, %rdi
movl %ebx, %esi
leaq 0x58(%rsp), %rdx
xorl %ecx, %ecx
callq 0x92ace
movsd %xmm0, 0x50(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r14, %rdi
callq 0x4dcb2
movq 0xa8(%rsp), %rax
movq %rax, 0x70(%rsp)
movups 0x98(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movsd 0x58(%rsp), %xmm0
testb $0x1, %r12b
jne 0x932b4
xorl %r12d, %r12d
xorl %r14d, %r14d
movslq 0x40(%rsp), %rax
cmpq %rax, %r12
movsd %xmm0, 0x18(%rsp)
jge 0x9324a
movq 0x38(%rsp), %rax
movl %r13d, %ecx
subl (%rax,%r12,4), %ecx
movl %ecx, (%rax,%r12,4)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
movq %r15, %rdi
movl %ebx, %esi
movq %rbp, %rdx
xorl %ecx, %ecx
callq 0x92ace
movsd %xmm0, 0xb8(%rsp)
movsd 0x50(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
je 0x9322c
movsd 0xc0(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %rdi
callq 0x4dcb2
movq 0xa8(%rsp), %rax
movq %rax, 0x70(%rsp)
movups 0x98(%rsp), %xmm0
movaps %xmm0, 0x60(%rsp)
movl %r13d, %r14d
movsd 0xb8(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq 0x38(%rsp), %rax
movl %r13d, %ecx
subl (%rax,%r12,4), %ecx
movl %ecx, (%rax,%r12,4)
incq %r12
movsd 0x18(%rsp), %xmm0
jmp 0x9315b
testl %r14d, %r14d
sete %r12b
je 0x9314b
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x30(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
leaq 0x98(%rsp), %rdi
callq 0x4dcb2
movq 0xa8(%rsp), %rax
movq %rax, 0x40(%rsp)
movups 0x98(%rsp), %xmm0
movaps %xmm0, 0x30(%rsp)
movsd 0x18(%rsp), %xmm0
jmp 0x9314b
movsd %xmm0, 0x58(%rsp)
movsd %xmm0, 0x18(%rsp)
movsd 0x50(%rsp), %xmm0
movsd 0x28(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
movq 0xb0(%rsp), %r14
leaq 0x3a58e(%rip), %r12     # 0xcd870
je 0x9330b
movsd 0x18(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd 0x50(%rsp), %xmm0
ucomisd 0x2a1b(%rip), %xmm0     # 0x95d18
jne 0x93301
jnp 0x93380
movl %ebx, 0x24(%rsp)
movsd %xmm0, 0x28(%rsp)
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x4dd42
incq %rbx
jmp 0x92fab
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x80(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movsd 0x28(%rsp), %xmm0
ucomisd 0x2987(%rip), %xmm0     # 0x95cf8
pushq $-0x1
popq %rbx
movl 0x24(%rsp), %eax
cmovnel %eax, %ebx
cmovpl %eax, %ebx
jmp 0x933d2
movq 0x70(%rsp), %rax
movq %rax, 0x10(%rsp)
movaps 0x60(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
movapd 0x30(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x4dd42
movq 0x90(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x80(%rsp), %xmm0
movupd %xmm0, (%rsp)
callq 0x4dd42
movl %ebx, %eax
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq