// File: /workspace/github_c_makefile_star2_O1/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, %r12
movl %edx, 0x7c(%rsp)
movq %rsi, %r14
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movq %rax, 0xc8(%rsp)
movb (%rcx), %al
movb %al, 0x3f(%rsp)
movq %rdi, 0x60(%rsp)
callq 0x7aa63
leaq 0x2ab1c(%rip), %rdi     # 0xa28ae
callq 0x536e7
testl %eax, %eax
je 0x77db4
leaq 0x2aad2(%rip), %rdi     # 0xa2874
callq 0x5341c
testl %eax, %eax
je 0x77dbe
leaq 0x2aac2(%rip), %rdi     # 0xa2874
jmp 0x77dc5
movq (%r14), %rdi
callq 0x9b1b4
jmp 0x77dd1
leaq 0x2de5b(%rip), %rdi     # 0xa5c20
callq 0x5341c
movl %eax, %edi
callq 0x9df45
movq 0x60(%rsp), %rcx
movl %eax, 0x20(%rcx)
movq (%r14), %rdi
leaq 0xf4(%rsp), %rsi
callq 0x11633
imull $0xcccccccd, %eax, %eax # imm = 0xCCCCCCCD
addl $0x19999998, %eax       # imm = 0x19999998
rorl %eax
cmpl $0x19999999, %eax       # imm = 0x19999999
jb 0x784ff
movl $0x0, 0x74(%rsp)
cmpl $0x2, 0x7c(%rsp)
jl 0x77e19
movl 0x10(%r12), %eax
movl %eax, 0x74(%rsp)
movq (%r14), %rdi
callq 0x115e1
movq %rax, %r13
leaq 0x5aa45(%rip), %r15     # 0xd2870
movq (%r15), %rax
movl 0x10(%rax), %esi
cmpb $0x0, 0x3f(%rsp)
je 0x77e3e
movl %esi, 0x5c(%rsp)
jmp 0x77e53
leaq 0x5c(%rsp), %rdx
movq %r13, %rdi
callq 0x3758b
movq %rax, 0xa8(%rsp)
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x34dab(%rip), %rsi     # 0xacc10
movl $0x18, %edx
callq 0x390f5
movq %rax, 0x90(%rsp)
cmpb $0x0, 0x3f(%rsp)
je 0x77e8e
movslq 0x5c(%rsp), %rax
movsbl -0x1(%rax,%r12), %eax
addl $-0x30, %eax
jmp 0x77e98
movq 0xa8(%rsp), %rax
movl (%rax), %eax
movq 0x60(%rsp), %rcx
movl %eax, 0x14(%rcx)
movq (%r14), %rdi
callq 0x2fa14
movl %eax, %ebp
movq (%r14), %rdi
callq 0x2fa14
movl %eax, 0x54(%rsp)
cmpl $0x1, 0xc(%r12)
movl $0x0, %edx
sbbl %edx, %edx
movl 0x5c(%rsp), %eax
leal -0x1(%rax), %ecx
movl %edx, 0xbc(%rsp)
cmpl %edx, %ecx
jle 0x784be
cvtsi2sd %ebp, %xmm0
movsd %xmm0, 0xd0(%rsp)
movq %r12, 0x98(%rsp)
movq %r13, 0xd8(%rsp)
movq %rcx, 0xe0(%rsp)
movl %ecx, %edx
cmpb $0x0, 0x3f(%rsp)
je 0x77f1a
movl 0x5c(%rsp), %ecx
subl %eax, %ecx
movslq %ecx, %rax
movsbl (%r12,%rax), %eax
addl $-0x30, %eax
jmp 0x77f25
movq 0xa8(%rsp), %rax
movl (%rax,%rdx,4), %eax
movl %eax, 0x78(%rsp)
movslq %eax, %rsi
xorps %xmm0, %xmm0
cvtsi2sdl (%r13,%rsi,4), %xmm0
divsd 0xd0(%rsp), %xmm0
movq 0x90(%rsp), %rax
movq %rdx, 0xc0(%rsp)
movsd %xmm0, (%rax,%rdx,8)
xorl %eax, %eax
movl %eax, 0x58(%rsp)
movl %eax, 0x50(%rsp)
movq (%r14), %rdi
callq 0x11534
movl %eax, 0x4c(%rsp)
testl %eax, %eax
jle 0x782fe
movb $0x1, %bl
xorl %r15d, %r15d
movsd 0x40(%rsp), %xmm1
movsd 0x2a593(%rip), %xmm0    # 0xa2518
movsd %xmm0, 0xb0(%rsp)
movsd %xmm1, 0x88(%rsp)
movq %r14, %rdi
leaq 0x80(%rsp), %rsi
leaq 0xa0(%rsp), %r13
movq %r13, %rdx
movl $0x3, %ecx
callq 0x30746
movq %r13, %rdi
movl 0x78(%rsp), %r13d
movl %r13d, %esi
movq %r12, %rdx
callq 0x9c351
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x77feb
movq 0x80(%rsp), %rsi
movq %r12, %rdi
movl %r13d, %edx
movl 0x7c(%rsp), %ecx
callq 0x9c4fc
cmpq $0x0, 0x18(%r12)
je 0x78306
movq 0xa0(%rsp), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x7b122
movq 0x80(%rsp), %rsi
movq %r12, %rdi
xorl %edx, %edx
callq 0x7b122
cmpl $0x0, 0x7c(%rsp)
je 0x781b0
movq (%r14), %rdi
movq 0xa0(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r14)
movq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movl 0x58(%rsp), %edi
movl 0x54(%rsp), %esi
movl 0x50(%rsp), %edx
movl 0x4c(%rsp), %ecx
movq 0x90(%rsp), %r13
movq 0xc0(%rsp), %rbp
movsd (%r13,%rbp,8), %xmm0
callq 0x79482
movsd %xmm0, 0xe8(%rsp)
movq 0x60(%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 0x79355
movsd %xmm0, 0x40(%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 0x4c(%rsp), %ecx
subl %eax, %ecx
movsd (%r13,%rbp,8), %xmm0
callq 0x79482
testb $0x1, %r15b
je 0x7810a
movsd 0x88(%rsp), %xmm1
subsd 0xe8(%rsp), %xmm1
addsd %xmm1, %xmm0
movsd 0x40(%rsp), %xmm1
addsd %xmm0, %xmm1
movsd %xmm1, 0x40(%rsp)
movapd %xmm1, %xmm0
movsd 0xb0(%rsp), %xmm1
callq 0x38d8e
testl %eax, %eax
je 0x78246
testb $0x1, %bl
je 0x7817b
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 0x7b300
movsd 0x2aba7(%rip), %xmm1    # 0xa2d18
ucomisd %xmm0, %xmm1
jbe 0x78246
movq %r12, %rdi
movq 0x60(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x9cbb3
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xb0(%rsp)
jmp 0x782c8
movq 0x80(%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 0x7af26
movsd %xmm0, 0x40(%rsp)
movq (%r14), %rdi
movq 0xa0(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r14)
movq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movsd 0x40(%rsp), %xmm0
ucomisd 0x2aaf9(%rip), %xmm0    # 0xa2d18
jae 0x78345
movq 0x60(%rsp), %rdi
movq %r12, %rsi
callq 0x7b0fb
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
jmp 0x782c8
movsd 0x40(%rsp), %xmm1
movapd %xmm1, %xmm0
subsd 0xb0(%rsp), %xmm0
ucomisd 0x349a7(%rip), %xmm0    # 0xacc08
ja 0x7832b
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 0x7b300
ucomisd 0x2aa77(%rip), %xmm0    # 0xa2d18
jae 0x78336
movq %r12, %rdi
movq 0x60(%rsp), %rsi
leaq 0x58(%rsp), %rdx
leaq 0x54(%rsp), %rcx
leaq 0x50(%rsp), %r8
leaq 0x4c(%rsp), %r9
callq 0x9cbb3
movq %r14, %rdi
leaq 0x68(%rsp), %rsi
movq %r12, %rdx
callq 0x9c951
movb $0x1, %r15b
xorl %ebx, %ebx
cmpl $0x0, 0x4c(%rsp)
movsd 0x40(%rsp), %xmm0
movaps %xmm0, %xmm1
movq 0x98(%rsp), %r12
jg 0x77f8e
jmp 0x78384
movsd 0x40(%rsp), %xmm0
jmp 0x78384
movq (%r14), %rdi
movq 0xa0(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r14)
movq 0x80(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
jmp 0x78345
movsd %xmm1, 0x88(%rsp)
jmp 0x78345
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x88(%rsp)
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 0x7a989
movq %r12, %rdi
callq 0x39194
movsd 0x88(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
cmpl $0x0, 0x74(%rsp)
movq 0x90(%rsp), %r13
movq 0x60(%rsp), %rbx
movl 0x78(%rsp), %r12d
movq 0xc0(%rsp), %rbp
jle 0x7842a
movl 0x74(%rsp), %r15d
movq 0x68(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movq $0x0, 0x68(%rsp)
movsd (%r13,%rbp,8), %xmm0
movq %rbx, %rdi
movl %r12d, %esi
movq %r14, %rdx
movq 0x98(%rsp), %rcx
callq 0x77196
movq (%r14), %rdx
movq 0x68(%rsp), %rcx
movsd (%r13,%rbp,8), %xmm0
movq %rbx, %rdi
movl %r12d, %esi
callq 0x77b2a
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 0x68(%rsp), %rsi
xorl %edx, %edx
callq 0x9c7df
decl %r15d
jne 0x783b0
movq 0x98(%rsp), %r12
cmpl $0x0, 0xc(%r12)
movq 0xd8(%rsp), %r13
je 0x78456
movq 0x68(%rsp), %rsi
leaq 0xc8(%rsp), %rdi
callq 0x2fd59
jmp 0x7849d
cmpl $0x0, 0x24(%r12)
movl 0x78(%rsp), %r15d
je 0x78488
movq (%r14), %r12
testq %r12, %r12
je 0x78488
movq %r12, %rdi
callq 0x2eaca
cmpl %r15d, %eax
jne 0x78481
movl $0x1, 0x20(%r12)
movq 0x10(%r12), %r12
jmp 0x78466
movq 0x68(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movq 0x98(%rsp), %r12
movq $0x0, 0x68(%rsp)
movq 0xe0(%rsp), %rax
leal -0x1(%rax), %ecx
cmpl 0xbc(%rsp), %ecx
jg 0x77ef6
cmpl $0x0, 0xc(%r12)
je 0x784d6
movq 0xc8(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movq %r13, %rdi
callq 0x39194
movq 0x90(%rsp), %rdi
callq 0x39194
cmpb $0x0, 0x3f(%rsp)
jne 0x784ff
movq 0xa8(%rsp), %rdi
callq 0x39194
movq 0x60(%rsp), %rax
addq $0xf8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop