// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/omnivariaterule.c
// Function: optimize_ruleset_modelselection
void optimize_ruleset_modelselection(Ruleset* r, int positive, Instanceptr* instances, Ripper_parameterptr param)
{
 /* Last Changed 19.02.2005*/
 Decisionruleptr rule, before = NULL, replacementrule, revisionrule, next, newrule;
 Instanceptr removed = NULL, newsample;
 double error, revisionerror, replacementerror;
 rule = r->start;
 while (rule && rule->classno != positive)
  {
   before = rule;
   rule = rule->next;
  }
 while (rule && class_exists_in_list(*instances, positive))
  {
   error = generalization_error_after_pruning(*r, *instances, positive, param->modelselectionmethod);
   newsample = bootstrap_sample_without_stratification(*instances);
   replacementrule = growrule_omnivariate(&newsample, positive, param);
   remove_rule_after(r, before, rule);
   add_rule_after(r, before, replacementrule);
   if (replacementrule->decisioncount > 0)
     prunerule_with_modelselection(replacementrule, newsample, param->modelselectionmethod);
   deallocate(newsample);
   replacementerror = generalization_error_after_pruning(*r, *instances, positive, param->modelselectionmethod);
   revisionrule = grow_revision_rule_omnivariate(instances, rule, positive, param);
   remove_rule_after(r, before, replacementrule);
   add_rule_after(r, before, revisionrule);
   prunerule_with_modelselection(revisionrule, *instances, param->modelselectionmethod);
   revisionerror = generalization_error_after_pruning(*r, *instances, positive, param->modelselectionmethod);
   if ((revisionerror < error) || (replacementerror < error))
     if (replacementerror <= revisionerror)
      {
       remove_rule_after(r, before, revisionrule);
       add_rule_after(r, before, replacementrule);
       free_rule(*revisionrule);
       safe_free(revisionrule);
       free_rule(*rule);
       safe_free(rule);
       remove_covered(instances, &removed, replacementrule);
       rule = replacementrule;
      }
     else
      {
       free_rule(*replacementrule);
       safe_free(replacementrule);
       free_rule(*rule);
       safe_free(rule);       
       remove_covered(instances, &removed, revisionrule);
       rule = revisionrule;
      }
   else
    {
     remove_rule_after(r, before, revisionrule);
     add_rule_after(r, before, rule);
     free_rule(*revisionrule);
     safe_free(revisionrule);
     free_rule(*replacementrule);
     safe_free(replacementrule);
     remove_covered(instances, &removed, rule);     
    }
   before = rule;
   rule = rule->next;
  }
 if (!rule)
  {
   while (class_exists_in_list(*instances, positive))
    {
     newrule = growrule_omnivariate(instances, positive, param);
     if (newrule->start)
       prunerule_with_modelselection(newrule, *instances, param->modelselectionmethod);
     update_counts(newrule, *instances, 1);
     if (!(newrule->start) || (error_rate_of_rule(*newrule) >= 0.5))
      {
       free_rule(*newrule);
       safe_free(newrule);
       break;
      }
     add_rule(r, newrule);
     remove_covered(instances, &removed, newrule);
    }
  }
 else
  {
   while (rule)
    {
     next = rule->next;
     if (rule->classno == positive)
      {
       if (before)
         before->next = next;
       else
         r->start = next;
       free_rule(*rule);
       safe_free(rule);
       r->rulecount--;
       if (next == NULL)
         r->end = before;
      }
     else
       before = rule;
     rule = next;
    }
   if (before)
     before->next = NULL;
  }
 merge_instancelist(instances, removed);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, 0x48(%rsp)
movq %rdx, %rbp
movl %esi, %r13d
movq %rdi, %r14
movq $0x0, 0x50(%rsp)
movq (%rdi), %r12
testq %r12, %r12
je 0x4fe27
cmpl %r13d, (%r12)
jne 0x502a8
movq $0x0, 0x38(%rsp)
testq %r12, %r12
je 0x501d4
movl %r13d, 0x74(%rsp)
movq %rbp, 0x40(%rsp)
movq (%rbp), %rdi
movl %r13d, %esi
callq 0x11569
testl %eax, %eax
je 0x502c6
movq (%rbp), %rdi
movq 0x48(%rsp), %rbx
movl 0x38(%rbx), %edx
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %r13d, %esi
callq 0x4fcc0
movsd %xmm0, 0x80(%rsp)
movq (%rbp), %rdi
callq 0x2fede
movq %rax, 0x68(%rsp)
leaq 0x68(%rsp), %rdi
movl %r13d, %esi
movq %rbx, %rdx
callq 0x50397
movq %rax, %rbp
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
movq %r12, 0x58(%rsp)
movq %r12, %rdx
callq 0x7afd2
movq %r14, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x7afad
cmpl $0x0, 0x28(%rbp)
jle 0x4fef4
movq 0x68(%rsp), %rsi
movq 0x48(%rsp), %rax
movl 0x38(%rax), %edx
movq %rbp, %rdi
callq 0x504f6
movq 0x68(%rsp), %rdi
callq 0x2f616
movq 0x48(%rsp), %r12
movq 0x40(%rsp), %rbx
movq (%rbx), %rdi
movl 0x38(%r12), %edx
movq %r15, %r14
movq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %r13d, %esi
callq 0x4fcc0
movsd %xmm0, 0x78(%rsp)
movq %rbx, %rdi
movq 0x58(%rsp), %rsi
movl %r13d, %edx
movq %r12, %rcx
callq 0x50687
movq %rax, %r15
movq %r14, %rdi
movq %rbp, %rdx
movq 0x38(%rsp), %rbp
movq %rbp, %rsi
movq %rdx, 0x60(%rsp)
callq 0x7afd2
movq %r14, %rdi
movq %rbp, %rsi
movq %r15, %rdx
callq 0x7afad
movq (%rbx), %rsi
movl 0x38(%r12), %edx
movq %r15, %rdi
callq 0x504f6
movq (%rbx), %rdi
movl 0x38(%r12), %edx
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movupd (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movl %r13d, %esi
callq 0x4fcc0
movsd 0x78(%rsp), %xmm2
movsd 0x80(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x50080
ucomisd %xmm2, %xmm1
ja 0x50080
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x7afd2
movq %r14, %rdi
movq %rbx, %rsi
movq 0x58(%rsp), %r12
movq %r12, %rdx
callq 0x7afad
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a989
movq %r15, %rdi
callq 0x39194
movq 0x60(%rsp), %rbx
movq 0x30(%rbx), %rax
movq %rax, 0x30(%rsp)
movupd (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7a989
movq %rbx, %rdi
callq 0x39194
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %r12, %rdx
callq 0x9c951
movq %r12, %rbp
jmp 0x501b8
ucomisd %xmm2, %xmm0
jae 0x50115
movq 0x60(%rsp), %rbx
movq 0x30(%rbx), %rax
movq %rax, 0x30(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups 0x20(%rbx), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a989
movq %rbx, %rdi
callq 0x39194
movq 0x58(%rsp), %r12
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 0x7a989
movq %r12, %rdi
callq 0x39194
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %r15, %rdx
callq 0x9c951
movq %r15, %rbp
jmp 0x501b8
movq %r14, %rdi
movq 0x38(%rsp), %rbx
movq %rbx, %rsi
movq %r15, %rdx
callq 0x7afd2
movq %r14, %rdi
movq %rbx, %rsi
movq 0x60(%rsp), %rbp
movq %rbp, %rdx
callq 0x7afad
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x7a989
movq %r15, %rdi
callq 0x39194
movq 0x58(%rsp), %r15
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movupd (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7a989
movq %r15, %rdi
callq 0x39194
movq 0x40(%rsp), %rdi
leaq 0x50(%rsp), %rsi
movq %rbp, %rdx
callq 0x9c951
movq 0x30(%rbp), %r12
movq %rbp, 0x38(%rsp)
testq %r12, %r12
movl 0x74(%rsp), %r13d
movq 0x40(%rsp), %rbp
jne 0x4fe43
movq (%rbp), %rdi
movl %r13d, %esi
callq 0x11569
testl %eax, %eax
je 0x50378
leaq 0x50(%rsp), %r15
movq %rbp, %rdi
movl %r13d, %esi
movq 0x48(%rsp), %rdx
callq 0x50397
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x5021b
movq (%rbp), %rsi
movq 0x48(%rsp), %rax
movl 0x38(%rax), %edx
movq %r12, %rdi
callq 0x504f6
movq (%rbp), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x7b122
cmpq $0x0, 0x18(%r12)
je 0x50340
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
ucomisd 0x52aa8(%rip), %xmm0    # 0xa2d18
jae 0x50340
movq %r14, %rdi
movq %r12, %rsi
callq 0x7b0fb
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x9c951
movq (%rbp), %rdi
movl %r13d, %esi
callq 0x11569
testl %eax, %eax
jne 0x501ed
jmp 0x50378
movq %r12, 0x38(%rsp)
movq 0x30(%r12), %r12
testq %r12, %r12
je 0x4fe30
cmpl %r13d, (%r12)
jne 0x502a8
jmp 0x4fe30
movq 0x38(%rsp), %rbx
movq %r12, %r15
movq 0x30(%r12), %r12
cmpl %r13d, (%r15)
jne 0x50329
leaq 0x30(%rbx), %rax
testq %rbx, %rbx
cmoveq %r14, %rax
movq %r12, (%rax)
movq 0x30(%r15), %rax
movq %rax, 0x30(%rsp)
movupd (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups 0x20(%r15), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
callq 0x7a989
movq %r15, %rdi
callq 0x39194
decl 0x10(%r14)
testq %r12, %r12
jne 0x5032c
movq %rbx, 0x8(%r14)
jmp 0x5032c
movq %r15, %rbx
testq %r12, %r12
jne 0x502cb
testq %rbx, %rbx
je 0x50378
movq $0x0, 0x30(%rbx)
jmp 0x50378
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 0x7a989
movq %r12, %rdi
callq 0x39194
movq 0x50(%rsp), %rsi
movq %rbp, %rdi
callq 0x2fd59
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq