// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/univariaterule.c
// Function: find_best_condition
Decisionconditionptr find_best_condition(Instanceptr growset, int positive, Ripper_parameterptr param)
{
 /*!Last Changed 17.12.1005 added result->freeparam = 1*/
 /*!Last Changed 02.02.2004 added safecalloc*/
 /*!Last Changed 21.01.2004 added empty_condition*/
 /*!Last Changed 10.05.2003*/
 int i, j, size, tpositive, t, tdotpositive, tdot, equal, equalpositive, *featurecounts, *positivecounts;
 Instanceptr instancelist, tmp;
 double bestgain = 0, valuebefore, value, it, split;
 Partition p;
 Decisionconditionptr result;
 p = get_start_partition(growset, positive);
 result = empty_condition();
 result->conditiontype = UNIVARIATE_CONDITION;
 result->freeparam = 1;
 tmp = growset;
 tpositive = 0;
 t = 0;
 while (tmp)
  {
   t++;
   if (give_classno(tmp) == positive)
     tpositive++;
   tmp = tmp->next;
  }
 if (tpositive == 0)
  {
   safe_free(result);
   return NULL;
  }
 it = information(tpositive, t);
 for (i = 0; i < current_dataset->featurecount; i++)
   switch (current_dataset->features[i].type)
    { 
     case INTEGER:
     case    REAL:if ((!param->usefisher) || (t < param->smallsetsize && param->smallset))
                   {
                    instancelist = sort_instances(growset, i, &size);
                    if (current_dataset->features[i].type == INTEGER)
                      valuebefore = instancelist[0].values[i].intvalue;
                    else
                      valuebefore = instancelist[0].values[i].floatvalue;
                    tdot = 1;
                    if (give_classno(&(instancelist[0])) == positive)
                      tdotpositive = 1;
                    else
                      tdotpositive = 0;
                    equalpositive = tdotpositive;
                    equal = 1;
                    for (j = 1; j < size; j++)
                     {
                      if (current_dataset->features[i].type == INTEGER)
                        value = instancelist[j].values[i].intvalue;
                      else
                        value = instancelist[j].values[i].floatvalue;
                      if (value != valuebefore)
                       {
                        check_for_bestgain(tdotpositive, tdot, it, &bestgain, result, '<', valuebefore + DBL_EPSILON, i);
                        check_for_bestgain(tpositive - tdotpositive + equalpositive, t - tdot + equal, it, &bestgain, result, '>', valuebefore - DBL_EPSILON, i);
                        valuebefore = value;
                        equal = 0;
                        equalpositive = 0;
                       }
                      equal++;
                      if (give_classno(&(instancelist[j])) == positive)
                       {
                        tdotpositive++;
                        equalpositive++;
                       }
                      tdot++;
                     }
                    check_for_bestgain(equalpositive, equal, it, &bestgain, result, '>', value - DBL_EPSILON, i);
                    safe_free(instancelist);
                   }
                  else
                   {
                    if (param->withoutoutliers)
                      split = find_split_for_partition_without_outliers(growset, p, i, param->conditiontype, param->variancerange);
                    else
                      split = find_split_for_partition(growset, p, i, param->conditiontype);
                    tdotpositive = 0;
                    tdot = 0;
                    tmp = growset;
                    while (tmp)
                     {
                      if (current_dataset->features[i].type == INTEGER)
                        value = tmp->values[i].intvalue;
                      else
                        value = tmp->values[i].floatvalue;
                      if (value < split)
                       {
                        tdot++;
                        if (give_classno(tmp) == positive)
                          tdotpositive++;
                       }
                      tmp = tmp->next;
                     }
                    check_for_bestgain(tdotpositive, tdot, it, &bestgain, result, '<', split, i);
                    check_for_bestgain(tpositive - tdotpositive, t - tdot, it, &bestgain, result, '>', split, i);
                   }
                  break;
     case  STRING:featurecounts = safecalloc(current_dataset->features[i].valuecount,sizeof(int), "find_best_condition", 94);
                  positivecounts = safecalloc(current_dataset->features[i].valuecount,sizeof(int), "find_best_condition", 95); 
                  tmp = growset;
                  while (tmp)
                   {
                    featurecounts[tmp->values[i].stringindex]++;
                    if (give_classno(tmp) == positive)
                      positivecounts[tmp->values[i].stringindex]++;
                    tmp = tmp->next;
                   }
                  for (j = 0; j < current_dataset->features[i].valuecount; j++)
                    check_for_bestgain(positivecounts[j], featurecounts[j], it, &bestgain, result, '=', j, i);
                  safe_free(featurecounts);
                  safe_free(positivecounts);
                  break;
    }
 free_partition(p);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdx, 0x58(%rsp)
movl %esi, %r15d
movq %rdi, %rbp
andq $0x0, 0x40(%rsp)
leaq 0x88(%rsp), %rdi
movq %rbp, %rsi
movl %r15d, %edx
callq 0x1bc31
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x71cd1
movq %rax, %r13
movq $0x1, 0x3c(%rax)
xorl %r12d, %r12d
movq %rbp, %rbx
testq %rbx, %rbx
je 0x8fa97
incl %r14d
movq %rbx, %rdi
callq 0x2b47e
xorl %ecx, %ecx
cmpl %r15d, %eax
sete %cl
addl %ecx, %r12d
movq 0x10(%rbx), %rbx
jmp 0x8fa76
testl %r12d, %r12d
je 0x8ffa1
leal -0x1(%r14), %eax
movl %eax, 0x78(%rsp)
movl %r12d, 0x50(%rsp)
movl %r12d, %edi
movl %r14d, %esi
callq 0x71fae
movsd %xmm0, 0x30(%rsp)
xorl %r12d, %r12d
movq %r13, 0x80(%rsp)
movq 0x58(%rsp), %rsi
movl %r15d, 0x2c(%rsp)
movq %rbp, 0x60(%rsp)
movq %r14, 0x68(%rsp)
leaq 0x3dd8c(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r12
jge 0x8ff81
imulq $0x340, %r12, %rcx      # imm = 0x340
movq %rcx, 0x48(%rsp)
movl 0x30f08(%rax,%rcx), %ecx
cmpl $0x2, %ecx
movq %r12, 0x20(%rsp)
je 0x8fb21
cmpl $0x1, %ecx
je 0x8fb79
testl %ecx, %ecx
jne 0x8ff79
cmpl $0x0, 0x14(%rsi)
je 0x8fb3b
cmpl 0x1c(%rsi), %r14d
jge 0x8fc82
cmpl $0x0, 0x18(%rsi)
je 0x8fc82
movq %rbp, %rdi
movl %r12d, %esi
leaq 0x7c(%rsp), %rdx
callq 0x90c1a
movq %rax, %r14
leaq 0x3dd1b(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r14), %rax
je 0x8fcbd
movsd (%rax,%r12,8), %xmm0
jmp 0x8fcc3
movq 0x48(%rsp), %rbp
addq %rbp, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
pushq $0x4
popq %r12
movq %r12, %rsi
leaq 0x6494(%rip), %r14      # 0x9602d
movq %r14, %rdx
pushq $0x5e
popq %rcx
callq 0x35067
movq %rax, %rbx
leaq 0x3dcc2(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x30f20(%rax,%rbp), %rdi
movq %r12, %rsi
movq %r14, %rdx
pushq $0x5f
popq %rcx
callq 0x35067
movq %rax, %r14
movq 0x60(%rsp), %r12
testq %r12, %r12
je 0x8fc09
movq (%r12), %rax
movq 0x20(%rsp), %rcx
movslq (%rax,%rcx,8), %rax
incl (%rbx,%rax,4)
movq %r12, %rdi
callq 0x2b47e
cmpl %r15d, %eax
jne 0x8fc02
movq (%r12), %rax
movq 0x20(%rsp), %rcx
movslq (%rax,%rcx,8), %rax
incl (%r14,%rax,4)
movq 0x10(%r12), %r12
jmp 0x8fbcf
xorl %r15d, %r15d
movq 0x60(%rsp), %rbp
movq 0x20(%rsp), %r12
leaq 0x3dc53(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
movslq 0x30f20(%rax,%rcx), %rax
cmpq %rax, %r15
jge 0x8fc5e
movl (%r14,%r15,4), %edi
movl (%rbx,%r15,4), %esi
cvtsi2sd %r15d, %xmm1
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq %r13, %rcx
pushq $0x3d
popq %r8
movl %r12d, %r9d
callq 0x8f732
incq %r15
jmp 0x8fc16
movq %rbx, %rdi
callq 0x34ff7
movq %r14, %rdi
callq 0x34ff7
movl 0x2c(%rsp), %r15d
movq 0x68(%rsp), %r14
movq 0x58(%rsp), %rsi
jmp 0x8ff79
cmpl $0x0, 0x20(%rsi)
movl 0x28(%rsi), %edx
je 0x8fe8f
movsd 0x48(%rsi), %xmm0
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm1
movups %xmm1, (%rsp)
movq %rbp, %rdi
movl %r12d, %esi
callq 0x92576
jmp 0x8feb5
cvtsi2sdl (%rax,%r12,8), %xmm0
movsd %xmm0, 0x38(%rsp)
movq %r14, %rdi
callq 0x2b47e
xorl %ebp, %ebp
cmpl %r15d, %eax
sete %bpl
movq %r14, 0xa0(%rsp)
addq $0x30, %r14
movl 0x78(%rsp), %eax
movl %eax, 0x54(%rsp)
pushq $0x1
popq %r12
pushq $0x1
popq %rbx
movl %ebp, %r15d
movslq 0x7c(%rsp), %rax
cmpq %rax, %r12
movsd 0x70(%rsp), %xmm1
jge 0x8fe35
leaq 0x3db5d(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r14), %rax
je 0x8fd34
movq 0x20(%rsp), %rcx
movsd (%rax,%rcx,8), %xmm0
jmp 0x8fd3e
movq 0x20(%rsp), %rcx
cvtsi2sdl (%rax,%rcx,8), %xmm0
movsd 0x38(%rsp), %xmm1
movq %r14, 0xb0(%rsp)
ucomisd %xmm1, %xmm0
movsd %xmm0, 0x70(%rsp)
jne 0x8fd5e
jnp 0x8fe01
movsd %xmm1, 0x38(%rsp)
addsd 0x12634(%rip), %xmm1    # 0xa23a0
movl %r15d, %r13d
movl %ebp, %edi
movl %r12d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq 0x80(%rsp), %r15
movq %r15, %rcx
pushq $0x3c
popq %r8
movq %r12, 0xa8(%rsp)
movl %ebp, %r14d
movq 0x20(%rsp), %rbp
movl %ebp, %r9d
callq 0x8f732
movl 0x50(%rsp), %edi
subl %r14d, %edi
addl %r13d, %edi
addl 0x54(%rsp), %ebx
movsd 0x38(%rsp), %xmm1
addsd 0x125d6(%rip), %xmm1    # 0xa2398
movl %ebx, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq %r15, %rcx
movl 0x2c(%rsp), %r13d
pushq $0x3e
popq %r8
movl %ebp, %r9d
movl %r14d, %ebp
movq 0xa8(%rsp), %r12
callq 0x8f732
xorl %ebx, %ebx
xorl %r15d, %r15d
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x38(%rsp)
jmp 0x8fe06
movl 0x2c(%rsp), %r13d
incl %ebx
movq 0xb0(%rsp), %r14
movq %r14, %rdi
callq 0x2b47e
xorl %ecx, %ecx
cmpl %r13d, %eax
sete %cl
addl %ecx, %ebp
addl %ecx, %r15d
incq %r12
decl 0x54(%rsp)
addq $0x30, %r14
jmp 0x8fcf8
addsd 0x1255b(%rip), %xmm1    # 0xa2398
movl %r15d, %edi
movl %ebx, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq 0x80(%rsp), %r13
movq %r13, %rcx
pushq $0x3e
popq %r8
movq 0x20(%rsp), %r12
movl %r12d, %r9d
callq 0x8f732
movq 0xa0(%rsp), %rdi
callq 0x34ff7
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rbp
movq 0x68(%rsp), %r14
movl 0x2c(%rsp), %r15d
jmp 0x8ff79
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x88(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %rbp, %rdi
movl %r12d, %esi
callq 0x92966
movapd %xmm0, %xmm1
movq %rbp, %r14
xorl %ebx, %ebx
xorl %ebp, %ebp
movsd %xmm0, 0x20(%rsp)
testq %r14, %r14
je 0x8ff21
leaq 0x3d99e(%rip), %rax     # 0xcd870
movq (%rax), %rax
movq 0x48(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r14), %rax
je 0x8feef
movsd (%rax,%r12,8), %xmm0
jmp 0x8fef5
cvtsi2sdl (%rax,%r12,8), %xmm0
ucomisd %xmm0, %xmm1
movsd %xmm0, 0x70(%rsp)
jbe 0x8ff1b
incl %ebp
movq %r14, %rdi
callq 0x2b47e
movsd 0x20(%rsp), %xmm1
xorl %ecx, %ecx
cmpl %r15d, %eax
sete %cl
addl %ecx, %ebx
movq 0x10(%r14), %r14
jmp 0x8fec6
movl %ebx, %edi
movl %ebp, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq %r13, %rcx
pushq $0x3c
popq %r8
movl %r12d, %r9d
callq 0x8f732
movl 0x50(%rsp), %edi
subl %ebx, %edi
movq 0x68(%rsp), %r14
movl %r14d, %esi
subl %ebp, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x40(%rsp), %rdx
movq %r13, %rcx
pushq $0x3e
popq %r8
movsd 0x20(%rsp), %xmm1
movl %r12d, %r9d
callq 0x8f732
movq 0x58(%rsp), %rsi
movq 0x60(%rsp), %rbp
incq %r12
jmp 0x8fadd
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x4dd42
jmp 0x8ffac
movq %r13, %rdi
callq 0x34ff7
xorl %r13d, %r13d
movq %r13, %rax
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq