// File: /workspace/github_c_makefile_star2_O2/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 $0xe8, %rsp
movq %rcx, %r12
movl %edx, %ebp
movq %rsi, %r14
movq %rdi, %rbx
andq $0x0, 0x60(%rsp)
andq $0x0, 0xc8(%rsp)
movb (%rcx), %al
movb %al, 0x43(%rsp)
callq 0x71c9d
leaq 0x26622(%rip), %rdi     # 0x958ae
callq 0x4cff1
testl %eax, %eax
je 0x6f2ae
leaq 0x265d8(%rip), %rdi     # 0x95874
callq 0x4cd35
testl %eax, %eax
je 0x6f2b8
leaq 0x265c8(%rip), %rdi     # 0x95874
jmp 0x6f2bf
movq (%r14), %rdi
callq 0x8ef98
jmp 0x6f2cb
leaq 0x29959(%rip), %rdi     # 0x98c18
callq 0x4cd35
movl %eax, %edi
callq 0x91a23
movl %eax, 0x20(%rbx)
movq (%r14), %rdi
leaq 0xe4(%rsp), %rsi
callq 0x10916
pushq $0xa
popq %rcx
cltd
idivl %ecx
testl %edx, %edx
je 0x6f9aa
xorl %r13d, %r13d
cmpl $0x2, %ebp
jl 0x6f2f9
movl 0x10(%r12), %r13d
movq (%r14), %rdi
callq 0x108c8
leaq 0x5e568(%rip), %r15     # 0xcd870
movq (%r15), %rcx
movl 0x10(%rcx), %esi
cmpb $0x0, 0x43(%rsp)
movq %rax, 0xa0(%rsp)
je 0x6f323
movl %esi, 0x5c(%rsp)
jmp 0x6f33e
leaq 0x5c(%rsp), %rdx
movq %rax, %rdi
callq 0x3372d
movq %rax, 0x98(%rsp)
movq (%r15), %rax
movl 0x10(%rax), %esi
movslq %esi, %rdi
shlq $0x3, %rdi
leaq 0x308bc(%rip), %rsi     # 0x9fc08
pushq $0x18
popq %rdx
callq 0x34f59
movq %rax, 0x78(%rsp)
cmpb $0x0, 0x43(%rsp)
movl %ebp, 0xc0(%rsp)
je 0x6f377
movslq 0x5c(%rsp), %rax
movsbl -0x1(%rax,%r12), %eax
addl $-0x30, %eax
jmp 0x6f381
movq 0x98(%rsp), %rax
movl (%rax), %eax
movl %eax, 0x14(%rbx)
movq (%r14), %rdi
callq 0x2c3cc
movl %eax, %ebp
movq (%r14), %rdi
callq 0x2c3cc
leaq 0x54(%rsp), %rcx
movl %eax, (%rcx)
xorl %ecx, %ecx
cmpl $0x1, 0xc(%r12)
movl $0x0, %eax
sbbl %eax, %eax
movl %eax, 0xb4(%rsp)
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xd0(%rsp)
movl 0x5c(%rsp), %eax
testl %r13d, %r13d
cmovlel %ecx, %r13d
movl %r13d, 0xb0(%rsp)
movq %r12, 0x88(%rsp)
movq 0xa0(%rsp), %rdi
movq 0x78(%rsp), %r13
leal -0x1(%rax), %ecx
cmpl 0xb4(%rsp), %ecx
jle 0x6f969
movl %ecx, 0xb8(%rsp)
movl %ecx, %edx
cmpb $0x0, 0x43(%rsp)
je 0x6f41b
movl 0x5c(%rsp), %ecx
subl %eax, %ecx
movslq %ecx, %rax
movsbl (%r12,%rax), %ebp
addl $-0x30, %ebp
jmp 0x6f426
movq 0x98(%rsp), %rax
movl (%rax,%rdx,4), %ebp
movslq %ebp, %rsi
cvtsi2sdl (%rdi,%rsi,4), %xmm0
divsd 0xd0(%rsp), %xmm0
movq %rdx, 0x68(%rsp)
movsd %xmm0, (%r13,%rdx,8)
andl $0x0, 0x58(%rsp)
andl $0x0, 0x50(%rsp)
movq (%r14), %rdi
callq 0x10827
movl %eax, 0x44(%rsp)
movb $0x1, %r15b
xorl %ecx, %ecx
movsd 0x260b2(%rip), %xmm0    # 0x95518
movsd %xmm0, 0xa8(%rsp)
movl %ebp, 0xbc(%rsp)
testl %eax, %eax
jle 0x6f803
movl %ecx, 0xc4(%rsp)
movq %r14, %rdi
leaq 0x70(%rsp), %rsi
leaq 0x90(%rsp), %r13
movq %r13, %rdx
pushq $0x3
popq %rcx
callq 0x2cfe5
movq %r13, %rdi
movl %ebp, %esi
movq %r12, %rdx
callq 0x90098
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
movl 0xc0(%rsp), %r13d
je 0x6f7d7
movq 0x70(%rsp), %rsi
movq %r12, %rdi
movl %ebp, %edx
movl %r13d, %ecx
callq 0x90239
cmpq $0x0, 0x18(%r12)
je 0x6f7d7
movq 0x90(%rsp), %rsi
movq %r12, %rdi
pushq $0x1
popq %rdx
callq 0x722ae
movq 0x70(%rsp), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x722ae
testl %r13d, %r13d
je 0x6f68f
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x2d2da
movq %rax, (%r14)
movq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
movl 0x58(%rsp), %edi
movl 0x54(%rsp), %esi
movl 0x50(%rsp), %edx
movl 0x44(%rsp), %ecx
movq 0x78(%rsp), %r13
movq 0x68(%rsp), %rbp
movsd (%r13,%rbp,8), %xmm0
callq 0x7084f
movsd %xmm0, 0xd8(%rsp)
movl 0x20(%rbx), %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 0x7072e
movsd %xmm0, 0x48(%rsp)
movl 0x4(%r12), %eax
movl 0x8(%r12), %edx
leal (%rdx,%rax), %ecx
movl 0x58(%rsp), %edi
addl %ecx, %edi
movl 0x54(%rsp), %esi
addl 0x50(%rsp), %edx
subl %ecx, %esi
movl 0x44(%rsp), %ecx
subl %eax, %ecx
movsd (%r13,%rbp,8), %xmm0
callq 0x7084f
testb $0x1, 0xc4(%rsp)
je 0x6f5e3
movsd 0x80(%rsp), %xmm1
subsd 0xd8(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x48(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
movapd %xmm1, %xmm0
movsd 0xa8(%rsp), %xmm1
callq 0x34c76
testl %eax, %eax
movl 0xbc(%rsp), %ebp
je 0x6f722
testb $0x1, %r15b
je 0x6f65c
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 0x7247e
movsd 0x266ce(%rip), %xmm1    # 0x95d20
ucomisd %xmm0, %xmm1
jbe 0x6f722
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x44(%rsp), %r9
callq 0x907d7
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0xa8(%rsp)
jmp 0x6f7a2
movq 0x70(%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 0x72107
movsd %xmm0, 0x48(%rsp)
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x2d2da
movsd 0x48(%rsp), %xmm0
ucomisd 0x26638(%rip), %xmm0    # 0x95d20
movq 0x78(%rsp), %r13
jae 0x6f7ec
movq %rax, (%r14)
movq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
movq %rbx, %rdi
movq %r12, %rsi
callq 0x7228a
movsd 0x80(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x6f7a2
movsd 0x48(%rsp), %xmm1
movapd %xmm1, %xmm0
subsd 0xa8(%rsp), %xmm0
ucomisd 0x304c3(%rip), %xmm0    # 0x9fc00
ja 0x6f80a
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 0x7247e
ucomisd 0x265a3(%rip), %xmm0    # 0x95d20
jae 0x6f815
movq %r12, %rdi
movq %rbx, %rsi
leaq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x44(%rsp), %r9
callq 0x907d7
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
movq %r12, %rdx
callq 0x90582
movb $0x1, %cl
xorl %r15d, %r15d
movl 0x44(%rsp), %eax
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movq 0x88(%rsp), %r12
jmp 0x6f476
movq (%r14), %rdi
movq 0x90(%rsp), %rsi
callq 0x2d2da
movq 0x78(%rsp), %r13
movq 0x68(%rsp), %r15
movq %rax, (%r14)
movq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
jmp 0x6f829
movq 0x68(%rsp), %r15
jmp 0x6f863
movsd %xmm1, 0x80(%rsp)
jmp 0x6f824
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x80(%rsp)
movq 0x68(%rsp), %r15
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 0x71be8
movq %r12, %rdi
callq 0x34ff7
movl 0xb0(%rsp), %r12d
subl $0x1, %r12d
jb 0x6f8e7
movq 0x60(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
andq $0x0, 0x60(%rsp)
movsd (%r13,%r15,8), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
movq %r14, %rdx
movq 0x88(%rsp), %rcx
callq 0x6e74b
movq (%r14), %rdx
movq 0x60(%rsp), %rcx
movsd (%r13,%r15,8), %xmm0
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6f031
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movupd (%rbx), %xmm0
movupd 0x10(%rbx), %xmm1
movupd %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq %r14, %rdi
leaq 0x60(%rsp), %rsi
xorl %edx, %edx
callq 0x90483
jmp 0x6f86b
movq 0x88(%rsp), %r12
cmpl $0x0, 0xc(%r12)
je 0x6f90b
movq 0x60(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x2c6e4
jmp 0x6f94f
cmpl $0x0, 0x24(%r12)
je 0x6f93a
movq %r14, %r12
movq (%r12), %r12
testq %r12, %r12
je 0x6f93a
movq %r12, %rdi
callq 0x2b47e
cmpl %ebp, %eax
jne 0x6f934
movl $0x1, 0x20(%r12)
addq $0x10, %r12
jmp 0x6f916
movq 0x60(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
movq 0x88(%rsp), %r12
andq $0x0, 0x60(%rsp)
movl 0xb8(%rsp), %eax
movq 0xa0(%rsp), %rdi
jmp 0x6f3e8
cmpl $0x0, 0xc(%r12)
je 0x6f989
movq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
movq 0xa0(%rsp), %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
cmpb $0x0, 0x43(%rsp)
jne 0x6f9aa
movq 0x98(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop