// File: /workspace/github_c_makefile_star2_O2/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 $0x98, %rsp
movq %rcx, %rbp
movq %rdx, %rbx
andq $0x0, 0x48(%rsp)
movl %esi, %r13d
movq %rdi, %r14
xorl %r15d, %r15d
movq %rdi, %rax
movq (%rax), %r12
testq %r12, %r12
je 0x49a78
cmpl %r13d, (%r12)
je 0x49a78
leaq 0x30(%r12), %rax
movq %r12, %r15
jmp 0x49a60
movl %r13d, 0x44(%rsp)
movq %rbp, 0x58(%rsp)
movq %r14, 0x50(%rsp)
movq %rbx, 0x60(%rsp)
testq %r12, %r12
je 0x49e99
movq (%rbx), %rdi
movl %r13d, %esi
callq 0x10855
testl %eax, %eax
je 0x49e25
movq (%rbx), %rdi
movl 0x38(%rbp), %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 0x49936
movsd %xmm0, 0x90(%rsp)
movq (%rbx), %rdi
callq 0x2c859
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
movl %r13d, %esi
movq %rbp, %rdx
callq 0x49fb2
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x721ae
movq %r14, %rdi
movq %r15, 0x70(%rsp)
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdx
callq 0x7217f
cmpl $0x0, 0x28(%r13)
movq 0x78(%rsp), %r13
jle 0x49b38
movl 0x38(%rbp), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x4a105
movq %r13, %rdi
callq 0x2c010
movq (%rbx), %rdi
movl 0x38(%rbp), %edx
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movups (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl 0x44(%rsp), %r13d
movl %r13d, %esi
callq 0x49936
movsd %xmm0, 0x88(%rsp)
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %edx
movq %rbp, %rcx
callq 0x4a29d
movq %rax, 0x80(%rsp)
movq %r14, %rdi
movq 0x70(%rsp), %r13
movq %r13, %rsi
movq %r15, 0x68(%rsp)
movq %r15, %rdx
callq 0x721ae
movq %r14, %rdi
movq %r13, %rsi
movq 0x80(%rsp), %r13
movq %r13, %rdx
callq 0x7217f
movq (%rbx), %rsi
movl 0x38(%rbp), %edx
movq %r13, %rdi
callq 0x4a105
movq (%rbx), %rdi
movl 0x38(%rbp), %edx
movq 0x20(%r14), %rax
movq %rax, 0x20(%rsp)
movupd (%r14), %xmm0
movups 0x10(%r14), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movl 0x44(%rsp), %esi
callq 0x49936
movsd 0x88(%rsp), %xmm2
movsd 0x90(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x49cca
ucomisd %xmm2, %xmm1
ja 0x49cca
movq 0x50(%rsp), %r14
movq %r14, %rdi
movq 0x70(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x721ae
movq %r14, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x7217f
movq 0x30(%r13), %rax
movq %rax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71be8
movq %r13, %rdi
callq 0x34ff7
movq 0x68(%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 0x71be8
movq %rbx, %rdi
callq 0x34ff7
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
movq %r12, %rdx
callq 0x90582
movq %r12, %r15
jmp 0x49e12
ucomisd %xmm2, %xmm0
jae 0x49d67
movq 0x68(%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 0x71be8
movq %rbx, %rdi
callq 0x34ff7
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 0x71be8
movq %r12, %rdi
callq 0x34ff7
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
movq %r13, %rdx
callq 0x90582
movq %r13, %r15
movq 0x58(%rsp), %rbp
movq 0x50(%rsp), %r14
jmp 0x49e17
movq 0x50(%rsp), %r14
movq %r14, %rdi
movq 0x70(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x721ae
movq %r14, %rdi
movq %rbx, %rsi
movq 0x68(%rsp), %r15
movq %r15, %rdx
callq 0x7217f
movq 0x30(%r13), %rax
movq %rax, 0x30(%rsp)
movups (%r13), %xmm0
movups 0x10(%r13), %xmm1
movups 0x20(%r13), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71be8
movq %r13, %rdi
callq 0x34ff7
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 0x71be8
movq %r12, %rdi
callq 0x34ff7
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x48(%rsp), %rsi
movq %r15, %rdx
callq 0x90582
movq 0x58(%rsp), %rbp
movq 0x30(%r15), %r12
movl 0x44(%rsp), %r13d
jmp 0x49a8c
leaq 0x30(%r15), %r13
movq %r15, %rbp
testq %r15, %r15
cmoveq %r14, %r13
movq %r12, %r15
testq %r15, %r15
je 0x49f4f
movq 0x30(%r15), %r12
movl 0x44(%rsp), %eax
cmpl %eax, (%r15)
jne 0x49e25
movq %r12, (%r13)
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 0x71be8
movq %r15, %rdi
callq 0x34ff7
decl 0x10(%r14)
movq %r12, %r15
testq %r12, %r12
jne 0x49e36
movq %rbp, 0x8(%r14)
movq %r12, %r15
jmp 0x49e36
pushq $0x1
popq %rbp
leaq 0x48(%rsp), %r15
movq 0x58(%rsp), %r14
movq (%rbx), %rdi
movl %r13d, %esi
callq 0x10855
testl %eax, %eax
je 0x49f93
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
callq 0x49fb2
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x49ee0
movq (%rbx), %rsi
movl 0x38(%r14), %edx
movq %r12, %rdi
callq 0x4a105
movq (%rbx), %rsi
movq %r12, %rdi
movl %ebp, %edx
callq 0x722ae
cmpq $0x0, 0x18(%r12)
je 0x49f5b
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
ucomisd 0x4bdf3(%rip), %xmm0    # 0x95d20
jae 0x49f5b
movq 0x50(%rsp), %rdi
movq %r12, %rsi
callq 0x7228a
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x90582
jmp 0x49ea6
testq %rbp, %rbp
je 0x49f93
andq $0x0, 0x30(%rbp)
jmp 0x49f93
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 0x71be8
movq %r12, %rdi
callq 0x34ff7
movq 0x48(%rsp), %rsi
movq %rbx, %rdi
callq 0x2c6e4
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq