// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/ripper.c
// Function: learn_ruleset_ripper
Ruleset learn_ruleset_ripper(Instanceptr* instances, int reptype, Ripper_parameterptr param)
{
 /*!Last Changed 02.12.2004 added free_rule and safe_rule*/
 /*!Last Changed 05.05.2004 added unordered classes*/
 /*!Last Changed 03.05.2004 added given permutation*/
 /*!Last Changed 02.02.2004 added safemalloc*/
 /*!Last Changed 18.05.2003*/
 Ruleset result;
 Decisionruleptr newrule;
 BOOLEAN givenperm;
 int* counts, classno, posclass, classcount, *classes, i, j, rcount, first, covered, uncovered, fp, fn, totalinstance, maxcount, lastclass;
 double smallestdl, dlnow, ruledl, *proportions, datadlwith, datadlwithout;
 Instanceptr grow, prune, removed = NULL, totalremoved = NULL, tmp;
 if (strlen(param->classpermutation) == 0)
   givenperm = BOOLEAN_FALSE;
 else
   givenperm = BOOLEAN_TRUE;
 empty_ruleset(&result);
 if (get_parameter_o("usediscrete") == OFF)
   result.possibleconditioncount = possible_condition_count(*instances);
 else
   if (get_parameter_i("smallsetsize") == 0)
     result.possibleconditioncount = find_discrete_split_count(get_parameter_i("hybridspace"));
   else
     result.possibleconditioncount = find_discrete_split_count(get_parameter_i("smallsetsize"));
 classno = all_in_one_class(*instances, &maxcount);
 if (!(classno % 10))
   return result;
 if (reptype < 2)
   rcount = 0;
 else
   rcount = param->optimizecount;
 counts = find_class_counts(*instances);
 if (!givenperm)
   classes = find_max_occured(counts, current_dataset->classno, &classcount);
 else
   classcount = current_dataset->classno;
 proportions = safemalloc(current_dataset->classno*sizeof(double), "learn_ruleset_ripper", 24);
 if (!givenperm)
   result.defaultclass = classes[0];
 else
   result.defaultclass = param->classpermutation[classcount - 1] - '0';
 totalinstance = data_size(*instances);
 uncovered = data_size(*instances);
 if (param->rulesordered)
   lastclass = 1;
 else
   lastclass = 0;
 for (i = classcount - 1; i > lastclass - 1; i--)
  {
   if (!givenperm)
     posclass = classes[i];
   else
     posclass = param->classpermutation[classcount - i - 1] - '0';
   proportions[i] = (counts[posclass] + 0.0) / totalinstance;
   smallestdl = +INT_MAX;
   first = 1;
   covered = 0;
   fp = 0;
   fn = find_class_count(*instances, posclass);
   while (fn > 0)
    {
     divide_instancelist(instances, &prune, &grow, 3);
     newrule = growrule(&grow, posclass, param);
     if (newrule->start)
       prunerule(newrule, prune, posclass, reptype);
     if (!(newrule->start))
      {
       *instances = restore_instancelist(*instances, grow);
       merge_instancelist(instances, prune);
       free_rule(*newrule);
       safe_free(newrule);
       break;
      }
     update_counts(newrule, grow, 1);
     update_counts(newrule, prune, 0);
     if (reptype == 0)
      {
       if (test_rule(*newrule, prune) >= 0.5)
        {
         *instances = restore_instancelist(*instances, grow);
         merge_instancelist(instances, prune);
         free_rule(*newrule);
         safe_free(newrule);
         break;
        }
       else
        {
         *instances = restore_instancelist(*instances, grow);
         merge_instancelist(instances, prune);
         add_rule(&result, newrule);
         remove_covered(instances, &removed, newrule);
        }
      }
     else
      {
       *instances = restore_instancelist(*instances, grow);
       merge_instancelist(instances, prune);
       datadlwithout = description_length_of_exceptions(covered, uncovered, fp, fn, proportions[i]);
       ruledl = description_length_of_rule(*newrule, result.possibleconditioncount);
       datadlwith = description_length_of_exceptions(covered + newrule->covered + newrule->falsepositives, uncovered - newrule->covered - newrule->falsepositives, fp + newrule->falsepositives, fn - newrule->covered, proportions[i]);
       if (first)
         dlnow = datadlwith + ruledl;
       else
         dlnow = dlnow - datadlwithout + datadlwith + ruledl;
       if (dless(dlnow,smallestdl) && (first != 1 || error_rate_of_rule(*newrule) < 0.5))
        {
         smallestdl = dlnow;
         insert_rule_and_update_counts(newrule, &result, &covered, &uncovered, &fp, &fn);
         remove_covered(instances, &removed, newrule);
        }
       else
         if ((dlnow - smallestdl > 64) || (error_rate_of_rule(*newrule) >= 0.5))
          {
           free_rule(*newrule);
           safe_free(newrule);
           break;
          }
         else
          {
           insert_rule_and_update_counts(newrule, &result, &covered, &uncovered, &fp, &fn);
           remove_covered(instances, &removed, newrule);
          }
      }
     first = 0;
    }
   for (j = 0; j < rcount; j++)
    {
     merge_instancelist(instances, removed);
     removed = NULL;
     optimize_ruleset(&result, posclass, instances, proportions[i], param);
     simplify_ruleset(&result, posclass, *instances, removed, proportions[i]);
     remove_covered_by_ruleset(instances, &removed, result, 0);
    }
   if (param->rulesordered)
     merge_instancelist(&totalremoved, removed);
   else
    {
     if (param->rexenabled)
      {
       tmp = *instances;
       while (tmp)
        {
         if (give_classno(tmp) == posclass)
           tmp->isexception = 1;
         tmp = tmp->next;
        }
      }
     merge_instancelist(instances, removed);
    }
   removed = NULL;
  }
 if (param->rulesordered)
   merge_instancelist(instances, totalremoved);
 safe_free(counts);
 safe_free(proportions);
 if (!givenperm)
   safe_free(classes);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xf8, %rsp
movq %rcx, %r13
movl %edx, %ebp
movq %rsi, %r14
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %rax, 0xc8(%rsp)
movb (%rcx), %al
movb %al, 0x3f(%rsp)
movq %rdi, 0x68(%rsp)
callq 0x7c32b
leaq 0x2c1d0(%rip), %rdi     # 0xa58ae
callq 0x54bec
testl %eax, %eax
je 0x79700
leaq 0x2c186(%rip), %rdi     # 0xa5874
callq 0x54920
testl %eax, %eax
je 0x7970a
leaq 0x2c176(%rip), %rdi     # 0xa5874
jmp 0x79711
movq (%r14), %rdi
callq 0x9e1c4
jmp 0x7971d
leaq 0x2f587(%rip), %rdi     # 0xa8c98
callq 0x54920
movl %eax, %edi
callq 0xa0f5d
movq 0x68(%rsp), %rcx
movl %eax, 0x20(%rcx)
movq (%r14), %rdi
leaq 0xf4(%rsp), %rsi
callq 0x115f8
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
addl $0x19999998, %eax       # imm = 0x19999998
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
jb 0x79e3d
movl $0x0, 0x74(%rsp)
cmpl $0x2, %ebp
jl 0x79762
movl 0x10(%r13), %eax
movl %eax, 0x74(%rsp)
movq (%r14), %rdi
callq 0x115a6
movq %rax, %r12
leaq 0x5c0fc(%rip), %r15     # 0xd5870
movq (%r15), %rax
movl 0x10(%rax), %esi
cmpb $0x0, 0x3f(%rsp)
movl %ebp, 0xac(%rsp)
je 0x797b7
movslq %esi, %rdi
movl %edi, 0x64(%rsp)
shlq $0x3, %rdi
leaq 0x3654e(%rip), %rsi     # 0xafce8
movl $0x18, %edx
callq 0x3a0e1
movq %rax, %r15
movslq 0x64(%rsp), %rax
movsbl -0x1(%rax,%r13), %eax
addl $-0x30, %eax
jmp 0x797f1
leaq 0x64(%rsp), %rdx
movq %r12, %rdi
callq 0x38089
movq %rax, %rbp
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x3650f(%rip), %rsi     # 0xafce8
movl $0x18, %edx
callq 0x3a0e1
movq %rax, %r15
movq %rbp, 0xb0(%rsp)
movl (%rbp), %eax
movq 0x68(%rsp), %rcx
movl %eax, 0x14(%rcx)
movq (%r14), %rdi
callq 0x30309
movl %eax, %ebp
movq (%r14), %rdi
callq 0x30309
movl %eax, 0x5c(%rsp)
movl 0xc(%r13), %edx
cmpl $0x1, %edx
movl $0x0, %esi
sbbl %esi, %esi
movl 0x64(%rsp), %eax
leal -0x1(%rax), %ecx
movl %esi, 0xa8(%rsp)
cmpl %esi, %ecx
jle 0x79e05
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xd0(%rsp)
movq %r13, 0xa0(%rsp)
movq %r12, 0xd8(%rsp)
movq %r15, 0xb8(%rsp)
movq %rcx, 0xe0(%rsp)
movl %ecx, %edx
cmpb $0x0, 0x3f(%rsp)
je 0x7987d
movl 0x64(%rsp), %ecx
subl %eax, %ecx
movslq %ecx, %rax
movsbl (%r13,%rax), %ebp
addl $-0x30, %ebp
jmp 0x79888
movq 0xb0(%rsp), %rax
movl (%rax,%rdx,4), %ebp
movslq %ebp, %rsi
xorps %xmm0, %xmm0
cvtsi2sdl (%r12,%rsi,4), %xmm0
divsd 0xd0(%rsp), %xmm0
movq %rdx, 0xc0(%rsp)
movsd %xmm0, (%r15,%rdx,8)
xorl %eax, %eax
movl %eax, 0x60(%rsp)
movl %eax, 0x58(%rsp)
movq (%r14), %rdi
callq 0x114f9
movl %eax, 0x4c(%rsp)
testl %eax, %eax
movl %ebp, 0x8c(%rsp)
jle 0x79c53
movb $0x1, %bl
xorl %r13d, %r13d
movsd 0x40(%rsp), %xmm1
movsd 0x2bc35(%rip), %xmm0    # 0xa5518
movsd %xmm0, 0x98(%rsp)
movsd %xmm1, 0x80(%rsp)
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
leaq 0x90(%rsp), %r15
movq %r15, %rdx
movl $0x3, %ecx
callq 0x31019
movq %r15, %rdi
movl %ebp, %esi
movq 0xa0(%rsp), %rdx
callq 0x9f37f
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
movl 0xac(%rsp), %r15d
je 0x79c5b
movq 0x78(%rsp), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r15d, %ecx
callq 0x9f536
cmpq $0x0, 0x18(%r12)
je 0x79c5b
movq 0x90(%rsp), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x7c9ed
movq 0x78(%rsp), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x7c9ed
testl %r15d, %r15d
je 0x79b13
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x31345
movq %rax, (%r14)
movq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movl 0x60(%rsp), %edi
movl 0x5c(%rsp), %esi
movl 0x58(%rsp), %edx
movl 0x4c(%rsp), %ecx
movq 0xb8(%rsp), %r15
movq 0xc0(%rsp), %rbp
movsd (%r15,%rbp,8), %xmm0
callq 0x7adc2
movsd %xmm0, 0xe8(%rsp)
movq 0x68(%rsp), %rax
movl 0x20(%rax), %edi
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movups (%r12), %xmm0
movupd 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7ac95
movsd %xmm0, 0x40(%rsp)
movl 0x4(%r12), %eax
movl 0x8(%r12), %edx
leal (%rdx,%rax), %ecx
movl 0x60(%rsp), %edi
addl %ecx, %edi
movl 0x5c(%rsp), %esi
addl 0x58(%rsp), %edx
subl %ecx, %esi
movl 0x4c(%rsp), %ecx
subl %eax, %ecx
movsd (%r15,%rbp,8), %xmm0
callq 0x7adc2
testb $0x1, %r13b
je 0x79a61
movsd 0x80(%rsp), %xmm1
subsd 0xe8(%rsp), %xmm1
addsd %xmm1, %xmm0
leaq 0x50(%rsp), %r15
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
movsd 0x98(%rsp), %xmm1
callq 0x39aee
testl %eax, %eax
movl 0x8c(%rsp), %ebp
je 0x79ba8
testb $0x1, %bl
je 0x79ade
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movupd (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7cbcf
movsd 0x2c244(%rip), %xmm1    # 0xa5d18
ucomisd %xmm0, %xmm1
jbe 0x79ba8
movq %r12, %rdi
movq 0x68(%rsp), %rsi
leaq 0x60(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x9fbb0
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x98(%rsp)
jmp 0x79c2a
movq 0x78(%rsp), %rdi
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movups (%r12), %xmm0
movupd 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c7e7
movsd %xmm0, 0x40(%rsp)
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x31345
movsd 0x40(%rsp), %xmm0
ucomisd 0x2c1ac(%rip), %xmm0    # 0xa5d18
jae 0x79c6b
movq %rax, (%r14)
movq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq 0x68(%rsp), %rdi
movq %r12, %rsi
callq 0x7c9c6
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x50(%rsp), %r15
jmp 0x79c2a
movsd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
subsd 0x98(%rsp), %xmm0
ucomisd 0x3611d(%rip), %xmm0    # 0xafce0
ja 0x79ddf
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movupd (%r12), %xmm0
movupd 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7cbcf
ucomisd 0x2c115(%rip), %xmm0    # 0xa5d18
jae 0x79ded
movq %r12, %rdi
movq 0x68(%rsp), %rsi
leaq 0x60(%rsp), %rdx
leaq 0x5c(%rsp), %rcx
leaq 0x58(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x9fbb0
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x9f94e
movb $0x1, %r13b
xorl %ebx, %ebx
cmpl $0x0, 0x4c(%rsp)
movsd 0x40(%rsp), %xmm0
movaps %xmm0, %xmm1
jg 0x798ec
jmp 0x79cba
movsd 0x40(%rsp), %xmm0
jmp 0x79cba
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x31345
movq %rax, (%r14)
movq 0x78(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movups (%r12), %xmm0
movups 0x10(%r12), %xmm1
movups 0x20(%r12), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7c251
movq %r12, %rdi
callq 0x3a180
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
cmpl $0x0, 0x74(%rsp)
movq 0x68(%rsp), %rbx
movq 0xb8(%rsp), %r15
movq 0xc0(%rsp), %r13
jle 0x79d57
movl 0x74(%rsp), %r12d
movq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq $0x0, 0x50(%rsp)
movsd (%r15,%r13,8), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq 0xa0(%rsp), %rcx
callq 0x78b6b
movq (%r14), %rdx
movq 0x50(%rsp), %rcx
movsd (%r15,%r13,8), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7947b
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq %r14, %rdi
leaq 0x50(%rsp), %rsi
xorl %edx, %edx
callq 0x9f84f
decl %r12d
jne 0x79ce1
movq 0xa0(%rsp), %r13
cmpl $0x0, 0xc(%r13)
je 0x79d75
movq 0x50(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
jmp 0x79daf
cmpl $0x0, 0x24(%r13)
movl 0x8c(%rsp), %ebp
je 0x79da7
movq (%r14), %r12
testq %r12, %r12
je 0x79da7
movq %r12, %rdi
callq 0x2f33a
cmpl %ebp, %eax
jne 0x79da0
movl $0x1, 0x20(%r12)
movq 0x10(%r12), %r12
jmp 0x79d86
movq 0x50(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq $0x0, 0x50(%rsp)
movq 0xe0(%rsp), %rax
leal -0x1(%rax), %ecx
cmpl 0xa8(%rsp), %ecx
movq 0xd8(%rsp), %r12
jg 0x79858
jmp 0x79e01
movsd %xmm1, 0x80(%rsp)
jmp 0x79c7b
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
jmp 0x79c7b
movl 0xc(%r13), %edx
testl %edx, %edx
je 0x79e19
movq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq %r12, %rdi
callq 0x3a180
movq %r15, %rdi
callq 0x3a180
cmpb $0x0, 0x3f(%rsp)
jne 0x79e3d
movq 0xb0(%rsp), %rdi
callq 0x3a180
movq 0x68(%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq