// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/univariatetree.c
// Function: find_best_split_for_feature_i
int find_best_split_for_feature_i(Instanceptr instances, int currentfeature, double* split, double* bestgain)
{
 int j, k, counts[2][MAXCLASSES], size, isbetter = NO;
 Instanceptr sorted;
 double gain, value, valuebefore;
 switch (current_dataset->features[currentfeature].type)
  {
   case REAL   :
   case INTEGER:sorted = sort_instances(instances, currentfeature, &size);
                for (j = 0; j < current_dataset->classno; j++)
                 {
                  counts[0][j]=0;
                  counts[1][j]=0;
                 }
                for (k = 0; k < size; k++)
                 {
                  j = give_classno(&(sorted[k]));
                  counts[0][j]++;
                 }
                k = 0;
                valuebefore = -INT_MAX;
                while (k < size)
                 {
                  if (current_dataset->features[currentfeature].type == INTEGER)
                    value = sorted[k].values[currentfeature].intvalue;
                  else
                    value = sorted[k].values[currentfeature].floatvalue;
                  if (value != valuebefore)
                   {
                    if (valuebefore != -INT_MAX)
                     {
                      gain = information_gain(counts);
                      if (dless(gain, *bestgain))
                       {
                        *bestgain = gain;
                        isbetter = YES;
                        (*split) = (value + valuebefore)/2;
                        if (*bestgain == 0)
                         {
                          safe_free(sorted);
                          return YES;
                         }
                       }
                     }
                    valuebefore = value;
                   }
                  j = give_classno(&(sorted[k]));
                  counts[0][j]--;
                  counts[1][j]++;
                  k++;
                 }
                safe_free(sorted);
                break;
   case STRING :gain = information_gain_for_discrete_feature(instances, currentfeature);
                if (dless(gain, *bestgain))
                 {
                  *bestgain = gain;
                  isbetter = YES;
                  (*split) = 0;
                  if (gain == 0)
                    return YES;
                 }
                break;
  }
 return isbetter;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x1d8, %rsp            # imm = 0x1D8
movq %rcx, %r14
movq %rdx, 0x18(%rsp)
leaq 0x3c4a9(%rip), %rbx     # 0xcd870
movq (%rbx), %rax
movslq %esi, %r12
imulq $0x340, %r12, %rbp      # imm = 0x340
movl 0x30f08(%rax,%rbp), %eax
cmpl $0x2, %eax
je 0x913f4
xorl %r15d, %r15d
cmpl $0x1, %eax
je 0x9157b
testl %eax, %eax
jne 0x915b6
leaq 0x14(%rsp), %rdx
callq 0x90c1a
movq %rax, %r15
movq (%rbx), %rax
movslq 0x10(%rax), %rax
xorl %ecx, %ecx
cmpq %rax, %rcx
jge 0x91421
andl $0x0, 0x40(%rsp,%rcx,4)
andl $0x0, 0x108(%rsp,%rcx,4)
incq %rcx
jmp 0x9140a
movq %r14, 0x28(%rsp)
movl 0x14(%rsp), %eax
xorl %r14d, %r14d
testl %eax, %eax
cmovlel %r14d, %eax
imulq $0x30, %rax, %r13
cmpq %r14, %r13
je 0x91451
leaq (%r15,%r14), %rdi
callq 0x2b47e
cltq
incl 0x40(%rsp,%rax,4)
addq $0x30, %r14
jmp 0x91437
movsd 0x40b7(%rip), %xmm1     # 0x95510
xorl %r14d, %r14d
movl $0x0, 0x10(%rsp)
movq %rbp, 0x20(%rsp)
cmpq %r14, %r13
je 0x9156c
movq (%rbx), %rax
cmpl $0x0, 0x30f08(%rax,%rbp)
movq (%r15,%r14), %rax
je 0x9148b
movsd (%rax,%r12,8), %xmm0
jmp 0x91491
cvtsi2sdl (%rax,%r12,8), %xmm0
ucomisd %xmm1, %xmm0
jne 0x9149d
jnp 0x91541
movsd %xmm0, 0x8(%rsp)
ucomisd 0x4065(%rip), %xmm1     # 0x95510
jne 0x914b3
jnp 0x9153b
movsd %xmm1, 0x38(%rsp)
movq %r12, %rbp
movq %rbx, %r12
leaq 0x40(%rsp), %rdi
callq 0x1ba06
movq 0x28(%rsp), %rbx
movsd (%rbx), %xmm1
movsd %xmm0, 0x30(%rsp)
callq 0x34c76
testl %eax, %eax
je 0x91530
movsd 0x30(%rsp), %xmm0
movsd %xmm0, (%rbx)
movsd 0x8(%rsp), %xmm1
movsd 0x38(%rsp), %xmm0
addsd %xmm1, %xmm0
mulsd 0x481d(%rip), %xmm0     # 0x95d20
movq 0x18(%rsp), %rax
movsd %xmm0, (%rax)
movsd (%rbx), %xmm0
ucomisd 0x4800(%rip), %xmm0     # 0x95d18
pushq $0x1
popq %rax
movl %eax, 0x10(%rsp)
movq %r12, %rbx
movq %rbp, %r12
movq 0x20(%rsp), %rbp
jne 0x91541
jp 0x91541
jmp 0x915aa
movq %r12, %rbx
movq %rbp, %r12
movq 0x20(%rsp), %rbp
movsd 0x8(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
leaq (%r15,%r14), %rdi
callq 0x2b47e
cltq
decl 0x40(%rsp,%rax,4)
incl 0x108(%rsp,%rax,4)
addq $0x30, %r14
movsd 0x8(%rsp), %xmm1
jmp 0x91469
movq %r15, %rdi
callq 0x34ff7
movl 0x10(%rsp), %r15d
jmp 0x915b6
callq 0x9095a
movsd (%r14), %xmm1
movsd %xmm0, 0x8(%rsp)
callq 0x34c76
testl %eax, %eax
je 0x915b6
movsd 0x8(%rsp), %xmm0
movsd %xmm0, (%r14)
movq 0x18(%rsp), %rax
andq $0x0, (%rax)
jmp 0x915b2
movq %r15, %rdi
callq 0x34ff7
pushq $0x1
popq %r15
movl %r15d, %eax
addq $0x1d8, %rsp            # imm = 0x1D8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq