// File: /workspace/github_c_makefile_star2_O3/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, %rbp
movl %esi, %r14d
movq %rdi, %rbx
movq $0x0, 0x48(%rsp)
leaq 0x88(%rsp), %rdi
movq %rbx, %rsi
movl %r14d, %edx
callq 0x1e19a
xorl %r15d, %r15d
xorl %eax, %eax
callq 0x7c366
movq %rax, %r13
movq $0x1, 0x3c(%rax)
testq %rbx, %rbx
je 0x9f27e
movq %rbx, %r12
xorl %esi, %esi
incl %esi
movq %rsi, 0x58(%rsp)
movq %rbx, %rdi
callq 0x2f33a
xorl %ecx, %ecx
cmpl %r14d, %eax
movq 0x58(%rsp), %rsi
sete %cl
addl %ecx, %r15d
movq 0x10(%rbx), %rbx
testq %rbx, %rbx
jne 0x9ed1a
testl %r15d, %r15d
je 0x9f27e
movq %r12, %rbx
movl %r15d, %edi
callq 0x7c668
leaq 0x36b13(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x1bc(%rax)
jle 0x9f25e
movq 0x58(%rsp), %rcx
decl %ecx
movl %ecx, 0x84(%rsp)
xorl %esi, %esi
movq %rbp, 0x68(%rsp)
movl %r14d, 0x3c(%rsp)
movq %rbx, 0x60(%rsp)
movl %r15d, 0x50(%rsp)
movsd %xmm0, 0x30(%rsp)
movq %r13, 0x40(%rsp)
imulq $0x340, %rsi, %r12      # imm = 0x340
movl 0x30f08(%rax,%r12), %ecx
cmpl $0x2, %ecx
movq %rsi, 0x20(%rsp)
je 0x9edc2
cmpl $0x1, %ecx
je 0x9ee1f
testl %ecx, %ecx
jne 0x9f241
cmpl $0x0, 0x14(%rbp)
je 0x9ede0
movq 0x58(%rsp), %rax
cmpl 0x1c(%rbp), %eax
jge 0x9ef4f
cmpl $0x0, 0x18(%rbp)
je 0x9ef4f
movq %rbx, %rdi
leaq 0x54(%rsp), %rdx
movq %rsi, %rbx
callq 0xa0055
movq %rax, %rbp
leaq 0x36a76(%rip), %rax     # 0xd5870
movq (%rax), %rax
cmpl $0x0, 0x30f08(%rax,%r12)
movq (%rbp), %rax
movq %r12, 0x70(%rsp)
je 0x9ef89
movsd (%rax,%rbx,8), %xmm0
jmp 0x9ef91
addq %r12, %rax
addq $0x30f08, %rax          # imm = 0x30F08
movslq 0x18(%rax), %rdi
movl $0x4, %esi
leaq 0x71ed(%rip), %r15      # 0xa6025
movq %r15, %rdx
movl $0x5e, %ecx
callq 0x3a1fc
movq %rbx, %r13
movq %rax, %rbx
leaq 0x36a1e(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq %r12, 0x70(%rsp)
movslq 0x30f20(%rax,%r12), %rdi
movl $0x4, %esi
movq %r15, %rdx
movl $0x5f, %ecx
callq 0x3a1fc
movq 0x20(%rsp), %rcx
movq %rax, %r15
movq %r13, %r12
testq %r13, %r13
je 0x9eeb7
movq (%r12), %rax
movslq (%rax,%rcx,8), %rax
incl (%rbx,%rax,4)
movq %r12, %rdi
callq 0x2f33a
movq 0x20(%rsp), %rcx
cmpl %r14d, %eax
jne 0x9eead
movq (%r12), %rax
movslq (%rax,%rcx,8), %rax
incl (%r15,%rax,4)
movq 0x10(%r12), %r12
testq %r12, %r12
jne 0x9ee84
leaq 0x369b2(%rip), %rcx     # 0xd5870
movq (%rcx), %rax
movq 0x70(%rsp), %r12
cmpl $0x0, 0x30f20(%rax,%r12)
leaq 0x48(%rsp), %rbp
jle 0x9ef21
xorl %r14d, %r14d
movl (%r15,%r14,4), %edi
movl (%rbx,%r14,4), %esi
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movsd 0x30(%rsp), %xmm0
movq %rbp, %rdx
movq %rcx, %r13
movq 0x40(%rsp), %rcx
movl $0x3d, %r8d
movq 0x20(%rsp), %r9
callq 0x9e9ae
movq %r13, %rcx
incq %r14
movq (%r13), %rax
movslq 0x30f20(%rax,%r12), %rax
cmpq %rax, %r14
jl 0x9eed9
movq %rbx, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
movl 0x3c(%rsp), %r14d
movq 0x60(%rsp), %rbx
movq 0x20(%rsp), %rsi
movq 0x40(%rsp), %r13
movq 0x68(%rsp), %rbp
jmp 0x9f241
cmpl $0x0, 0x20(%rbp)
movl 0x28(%rbp), %edx
je 0x9f129
movsd 0x48(%rbp), %xmm0
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x88(%rsp), %xmm1
movupd %xmm1, (%rsp)
movq %rbx, %rdi
callq 0xa1b3b
jmp 0x9f14c
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%rbx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq %rbp, %rdi
callq 0x2f33a
xorl %r12d, %r12d
cmpl %r14d, %eax
sete %r12b
movl $0x1, %r15d
cmpl $0x2, 0x54(%rsp)
movq %rbp, 0xa0(%rsp)
jl 0x9f0d1
addq $0x30, %rbp
movl $0x1, %r13d
movl 0x84(%rsp), %r14d
movl %r12d, %ebx
movq 0x20(%rsp), %r9
leaq 0x3688d(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x70(%rsp), %rcx
cmpl $0x0, 0x30f08(%rax,%rcx)
movq (%rbp), %rax
je 0x9f001
movsd (%rax,%r9,8), %xmm0
jmp 0x9f00a
xorps %xmm0, %xmm0
cvtsi2sdl (%rax,%r9,8), %xmm0
movsd 0x28(%rsp), %xmm1
ucomisd %xmm1, %xmm0
movsd %xmm0, 0x78(%rsp)
jne 0x9f01e
jnp 0x9f09b
movsd %xmm1, 0x28(%rsp)
addsd 0x1340c(%rip), %xmm1    # 0xb2438
movl %ebx, %edi
movl %r13d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movl $0x3c, %r8d
callq 0x9e9ae
movl 0x50(%rsp), %edi
subl %ebx, %edi
addl %r12d, %edi
addl %r14d, %r15d
movsd 0x28(%rsp), %xmm1
addsd 0x133da(%rip), %xmm1    # 0xb2440
movl %r15d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x48(%rsp), %rdx
movq 0x40(%rsp), %rcx
movl $0x3e, %r8d
movq 0x20(%rsp), %r9
callq 0x9e9ae
xorl %r15d, %r15d
xorl %r12d, %r12d
movsd 0x78(%rsp), %xmm0
movsd %xmm0, 0x28(%rsp)
incl %r15d
movq %rbp, %rdi
callq 0x2f33a
xorl %ecx, %ecx
cmpl 0x3c(%rsp), %eax
sete %cl
addl %ecx, %ebx
addl %ecx, %r12d
incq %r13
movslq 0x54(%rsp), %rax
decl %r14d
addq $0x30, %rbp
cmpq %rax, %r13
movq 0x20(%rsp), %r9
jl 0x9efdc
movsd 0x78(%rsp), %xmm1
addsd 0x13361(%rip), %xmm1    # 0xb2440
movl %r12d, %edi
movl %r15d, %esi
movsd 0x30(%rsp), %xmm0
leaq 0x48(%rsp), %rdx
movq 0x40(%rsp), %r13
movq %r13, %rcx
movl $0x3e, %r8d
movq 0x20(%rsp), %r9
callq 0x9e9ae
movq 0xa0(%rsp), %rdi
callq 0x3a180
movq 0x20(%rsp), %rsi
movq 0x68(%rsp), %rbp
movl 0x3c(%rsp), %r14d
jmp 0x9f23c
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movupd 0x88(%rsp), %xmm0
movupd %xmm0, (%rsp)
movq %rbx, %rdi
callq 0xa1f40
movapd %xmm0, %xmm2
testq %rbx, %rbx
movsd 0x30(%rsp), %xmm0
movsd %xmm2, 0x28(%rsp)
je 0x9f1da
movq %rbx, %r15
leaq 0x36705(%rip), %rax     # 0xd5870
movq (%rax), %rax
xorl %ebx, %ebx
xorl %ebp, %ebp
movq 0x20(%rsp), %rdx
cmpl $0x0, 0x30f08(%rax,%r12)
movq (%r15), %rcx
je 0x9f18c
movsd (%rcx,%rdx,8), %xmm1
jmp 0x9f194
xorps %xmm1, %xmm1
cvtsi2sdl (%rcx,%rdx,8), %xmm1
ucomisd %xmm1, %xmm2
movsd %xmm1, 0x78(%rsp)
jbe 0x9f1cf
incl %ebx
movq %r15, %rdi
callq 0x2f33a
movsd 0x28(%rsp), %xmm2
movq 0x20(%rsp), %rdx
movsd 0x30(%rsp), %xmm0
xorl %ecx, %ecx
cmpl %r14d, %eax
sete %cl
addl %ecx, %ebp
leaq 0x366a4(%rip), %rax     # 0xd5870
movq (%rax), %rax
movq 0x10(%r15), %r15
testq %r15, %r15
jne 0x9f177
jmp 0x9f1de
xorl %ebp, %ebp
xorl %ebx, %ebx
movl %ebp, %edi
movl %ebx, %esi
leaq 0x48(%rsp), %r15
movq %r15, %rdx
movq %r13, %rcx
movl $0x3c, %r8d
movapd %xmm2, %xmm1
movq 0x20(%rsp), %r9
callq 0x9e9ae
movl 0x50(%rsp), %edi
subl %ebp, %edi
movq 0x58(%rsp), %rax
movl %eax, %esi
subl %ebx, %esi
movsd 0x30(%rsp), %xmm0
movq %r15, %rdx
movq %r13, %rcx
movl $0x3e, %r8d
movsd 0x28(%rsp), %xmm1
movq 0x20(%rsp), %r9
callq 0x9e9ae
movq 0x20(%rsp), %rsi
movq 0x68(%rsp), %rbp
movq 0x60(%rsp), %rbx
incq %rsi
leaq 0x36625(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %rsi
jl 0x9ed9c
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movups 0x88(%rsp), %xmm0
movups %xmm0, (%rsp)
callq 0x55a69
jmp 0x9f289
movq %r13, %rdi
callq 0x3a180
xorl %r13d, %r13d
movq %r13, %rax
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq