// File: /workspace/github_c_makefile_star2_O1/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 $0xa8, %rsp
movq %rdx, 0x60(%rsp)
movl %esi, %r14d
movq %rdi, %rbx
movq $0x0, 0x50(%rsp)
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x1da25
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x7aa9e
movq %rax, %rbp
movq $0x1, 0x3c(%rax)
movl $0x0, %r12d
movq %rbx, %r13
testq %rbx, %rbx
je 0x9bcf8
xorl %r12d, %r12d
movq %r13, %rbx
xorl %r15d, %r15d
incl %r15d
movq %rbx, %rdi
callq 0x2eaca
xorl %ecx, %ecx
cmpl %r14d, %eax
sete %cl
addl %ecx, %r12d
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x9bcd9
testl %r12d, %r12d
je 0x9c251
movl %r12d, 0x58(%rsp)
movl %r12d, %edi
movl %r15d, %esi
callq 0x7adaf
leaq 0x36b58(%rip), %rdx     # 0xd2870
movq (%rdx), %rax
cmpl $0x0, 0x1bc(%rax)
movq 0x60(%rsp), %rdi
jle 0x9c231
leal -0x1(%r15), %ecx
movl %ecx, 0x84(%rsp)
xorl %esi, %esi
movl %r14d, 0x3c(%rsp)
movq %r13, 0x70(%rsp)
movq %r15, 0x68(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %rbp, 0x48(%rsp)
imulq $0x340, %rsi, %rcx      # imm = 0x340
movq %rcx, 0x40(%rsp)
movl 0x30f08(%rax,%rcx), %ecx
cmpl $0x2, %ecx
movq %rsi, 0x20(%rsp)
je 0x9bd7e
cmpl $0x1, %ecx
je 0x9bdd2
testl %ecx, %ecx
jne 0x9c21b
cmpl $0x0, 0x14(%rdi)
je 0x9bd98
cmpl 0x1c(%rdi), %r15d
jge 0x9bf05
cmpl $0x0, 0x18(%rdi)
je 0x9bf05
movq %rdx, %r15
movq %r13, %rdi
leaq 0x5c(%rsp), %rdx
movq %rsi, %rbx
callq 0x9d053
movq %rax, %r13
movq (%r15), %rax
movq 0x40(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%r13), %rax
je 0x9bf3f
movsd (%rax,%rbx,8), %xmm0
jmp 0x9bf47
movq 0x40(%rsp), %r12
addq %r12, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movq %rdx, %rbp
movslq 0x18(%rax), %rdi
movl $0x4, %esi
leaq 0x7232(%rip), %r15      # 0xa3025
movq %r15, %rdx
movl $0x5e, %ecx
callq 0x39210
movq %rax, %rbx
movq (%rbp), %rax
movslq 0x30f20(%rax,%r12), %rdi
movl $0x4, %esi
movq %r15, %rdx
movl $0x5f, %ecx
callq 0x39210
movq 0x20(%rsp), %rbp
movq %rax, %r15
movq %r13, %r12
testq %r13, %r13
je 0x9be64
movq (%r12), %rax
movslq (%rax,%rbp,8), %rax
incl (%rbx,%rax,4)
movq %r12, %rdi
callq 0x2eaca
movq 0x20(%rsp), %rbp
cmpl %r14d, %eax
jne 0x9be5a
movq (%r12), %rax
movslq (%rax,%rbp,8), %rax
incl (%r15,%rax,4)
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x9be31
leaq 0x36a05(%rip), %r12     # 0xd2870
movq (%r12), %rax
movq 0x40(%rsp), %r12
cmpl $0x0, 0x30f20(%rax,%r12)
leaq 0x50(%rsp), %r13
jle 0x9becd
xorl %r14d, %r14d
movl (%r15,%r14,4), %edi
movl (%rbx,%r14,4), %esi
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x30(%rsp), %xmm0
movq %r13, %rdx
movq 0x48(%rsp), %rcx
movl $0x3d, %r8d
movl %ebp, %r9d
callq 0x9b96d
incq %r14
leaq 0x369b3(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x30f20(%rax,%r12), %rax
cmpq %rax, %r14
jl 0x9be87
movq %rbx, %rdi
callq 0x39194
movq %r15, %rdi
callq 0x39194
movl 0x3c(%rsp), %r14d
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %r15
movq %rbp, %rsi
movq 0x48(%rsp), %rbp
leaq 0x36975(%rip), %rdx     # 0xd2870
movq 0x60(%rsp), %rdi
jmp 0x9c21b
cmpl $0x0, 0x20(%rdi)
je 0x9c0f0
movl 0x28(%rdi), %edx
movsd 0x48(%rdi), %xmm0
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x88(%rsp), %xmm1
movupd %xmm1, (%rsp)
movq %r13, %rdi
callq 0x9eb25
jmp 0x9c116
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
callq 0x2eaca
xorl %ebp, %ebp
cmpl %r14d, %eax
sete %bpl
movl $0x1, %r12d
cmpl $0x2, 0x5c(%rsp)
movq %r13, 0xa0(%rsp)
jl 0x9c088
movq %r13, %rbx
addq $0x30, %rbx
movl $0x1, %r13d
movl 0x84(%rsp), %r14d
movl %ebp, %r15d
movq 0x20(%rsp), %r9
leaq 0x368d5(%rip), %rax     # 0xd2870
movq (%rax), %rax
movq 0x40(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%rbx), %rax
je 0x9bfb8
movsd (%rax,%r9,8), %xmm0
jmp 0x9bfc1
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r9,8), %xmm0
movsd 0x28(%rsp), %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
jne 0x9bfd5
jnp 0x9c052
movsd %xmm1, 0x28(%rsp)
addsd 0x133d5(%rip), %xmm1    # 0xaf3b8
movl %r15d, %edi
movl %r13d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl $0x3c, %r8d
callq 0x9b96d
movl 0x58(%rsp), %edi
subl %r15d, %edi
addl %ebp, %edi
addl %r14d, %r12d
movsd 0x28(%rsp), %xmm1
addsd 0x133a2(%rip), %xmm1    # 0xaf3c0
movl %r12d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rcx
movl $0x3e, %r8d
movq 0x20(%rsp), %r9
callq 0x9b96d
xorl %r12d, %r12d
xorl %ebp, %ebp
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
incl %r12d
movq %rbx, %rdi
callq 0x2eaca
xorl %ecx, %ecx
cmpl 0x3c(%rsp), %eax
sete %cl
addl %ecx, %r15d
addl %ecx, %ebp
incq %r13
movslq 0x5c(%rsp), %rax
decl %r14d
addq $0x30, %rbx
cmpq %rax, %r13
movq 0x20(%rsp), %r9
jl 0x9bf94
movsd 0x78(%rsp), %xmm1
addsd 0x1332a(%rip), %xmm1    # 0xaf3c0
movl %ebp, %edi
movl %r12d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x50(%rsp), %rdx
movq 0x48(%rsp), %rbp
movq %rbp, %rcx
movl $0x3e, %r8d
movq 0x20(%rsp), %r9
callq 0x9b96d
movq 0xa0(%rsp), %rdi
callq 0x39194
movq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdi
movl 0x3c(%rsp), %r14d
movq 0x70(%rsp), %r13
movq 0x68(%rsp), %r15
leaq 0x36785(%rip), %rdx     # 0xd2870
jmp 0x9c21b
movl 0x28(%rdi), %edx
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x88(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %r13, %rdi
callq 0x9ef42
movapd %xmm0, %xmm2
testq %r13, %r13
movsd 0x30(%rsp), %xmm0
leaq 0x36746(%rip), %rsi     # 0xd2870
movsd %xmm2, 0x28(%rsp)
movq %rbp, %r12
je 0x9c1a9
xorl %ebx, %ebx
movq %r13, %r15
xorl %ebp, %ebp
movq 0x20(%rsp), %rdx
movq 0x40(%rsp), %r13
movq (%rsi), %rax
cmpl $0x0, 0x30f08(%rax,%r13)
movq (%r15), %rax
je 0x9c15e
movsd (%rax,%rdx,8), %xmm1
jmp 0x9c166
xorps %xmm1, %xmm1
cvtsi2sdl (%rax,%rdx,8), %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm1, 0x78(%rsp)
jbe 0x9c19e
incl %ebx
movq %r15, %rdi
callq 0x2eaca
movsd 0x28(%rsp), %xmm2
leaq 0x366e7(%rip), %rsi     # 0xd2870
movq 0x20(%rsp), %rdx
movsd 0x30(%rsp), %xmm0
xorl %ecx, %ecx
cmpl %r14d, %eax
sete %cl
addl %ecx, %ebp
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0x9c146
jmp 0x9c1ad
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebp, %edi
movl %ebx, %esi
leaq 0x50(%rsp), %r13
movq %r13, %rdx
movq %r12, %rcx
movl $0x3c, %r8d
movapd %xmm2, %xmm1
movq 0x20(%rsp), %r9
callq 0x9b96d
movl 0x58(%rsp), %edi
subl %ebp, %edi
movq 0x68(%rsp), %r15
movl %r15d, %esi
subl %ebx, %esi
movq %r12, %rbp
movsd 0x30(%rsp), %xmm0
movq %r13, %rdx
movq %r12, %rcx
movl $0x3e, %r8d
movsd 0x28(%rsp), %xmm1
movq 0x20(%rsp), %r9
callq 0x9b96d
leaq 0x36664(%rip), %rdx     # 0xd2870
movq 0x20(%rsp), %rsi
movq 0x60(%rsp), %rdi
movq 0x70(%rsp), %r13
incq %rsi
movq (%rdx), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rsi
jl 0x9bd54
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x54550
jmp 0x9c25b
movq %rbp, %rdi
callq 0x39194
xorl %ebp, %ebp
movq %rbp, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq