// File: /workspace/github_c_makefile_star2_O3/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
movl %esi, %r13d
movq %rdi, %r14
movq $0x0, 0x38(%rsp)
movq (%rdi), %r12
testq %r12, %r12
je 0x51692
cmpl %r13d, (%r12)
jne 0x51322
xorl %r15d, %r15d
jmp 0x51339
movq %r12, %r15
movq 0x30(%r12), %r12
testq %r12, %r12
je 0x51692
cmpl %r13d, (%r12)
jne 0x51322
movl %r13d, 0x44(%rsp)
movq %rbx, 0x60(%rsp)
movq %r14, 0x58(%rsp)
movq %rbp, 0x50(%rsp)
movq (%rbx), %rdi
movl %r13d, %esi
callq 0x1152e
testl %eax, %eax
je 0x5178d
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 0x511b8
movsd %xmm0, 0x90(%rsp)
movq (%rbx), %rdi
callq 0x307e8
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
movl %r13d, %esi
movq %rbp, %rdx
callq 0x51829
movq %rax, %r13
movq %r14, %rdi
movq %r15, %rsi
movq %r12, 0x48(%rsp)
movq %r12, %rdx
callq 0x7c89d
movq %r14, %rdi
movq %r15, 0x70(%rsp)
movq %r15, %rsi
movq %r13, %r15
movq %r13, %rdx
callq 0x7c86e
cmpl $0x0, 0x28(%r13)
movq 0x78(%rsp), %r13
jle 0x513f5
movl 0x38(%rbp), %edx
movq %r15, %rdi
movq %r13, %rsi
callq 0x51991
movq %r13, %rdi
callq 0x2ff55
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), %r12d
movl %r12d, %esi
callq 0x511b8
movsd %xmm0, 0x88(%rsp)
movq %rbx, %rdi
movq 0x48(%rsp), %rsi
movl %r12d, %edx
movq %rbp, %rcx
callq 0x51b27
movq %rax, 0x80(%rsp)
movq %r14, %rdi
movq 0x70(%rsp), %r13
movq %r13, %rsi
movq %r15, 0x68(%rsp)
movq %r15, %rdx
callq 0x7c89d
movq %r14, %rdi
movq %r13, %rsi
movq 0x80(%rsp), %r13
movq %r13, %rdx
callq 0x7c86e
movq (%rbx), %rsi
movl 0x38(%rbp), %edx
movq %r13, %rdi
callq 0x51991
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 %r12d, %esi
callq 0x511b8
movsd 0x88(%rsp), %xmm2
movsd 0x90(%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x5153c
ucomisd %xmm2, %xmm1
ja 0x5153c
movq 0x58(%rsp), %r14
movq %r14, %rdi
movq 0x70(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7c89d
movq %r14, %rdi
movq %rbx, %rsi
movq 0x48(%rsp), %r15
movq %r15, %rdx
callq 0x7c86e
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 0x7c251
movq %r13, %rdi
callq 0x3a180
movq 0x68(%rsp), %rbx
jmp 0x51635
ucomisd %xmm2, %xmm0
jae 0x515d2
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 0x7c251
movq %rbx, %rdi
callq 0x3a180
movq 0x48(%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 0x7c251
movq %rbx, %rdi
callq 0x3a180
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
movq %r13, %rdx
callq 0x9f94e
movq %r13, %r15
movq 0x58(%rsp), %r14
jmp 0x5167b
movq 0x58(%rsp), %r14
movq %r14, %rdi
movq 0x70(%rsp), %rbx
movq %rbx, %rsi
movq %r13, %rdx
callq 0x7c89d
movq %r14, %rdi
movq %rbx, %rsi
movq 0x68(%rsp), %r15
movq %r15, %rdx
callq 0x7c86e
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 0x7c251
movq %r13, %rdi
callq 0x3a180
movq 0x48(%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 0x7c251
movq %rbx, %rdi
callq 0x3a180
movq 0x60(%rsp), %rbx
movq %rbx, %rdi
leaq 0x38(%rsp), %rsi
movq %r15, %rdx
callq 0x9f94e
movq 0x50(%rsp), %rbp
movq 0x30(%r15), %r12
testq %r12, %r12
movl 0x44(%rsp), %r13d
jne 0x5134d
movq (%rbx), %rdi
movl %r13d, %esi
callq 0x1152e
testl %eax, %eax
je 0x5180a
leaq 0x38(%rsp), %r15
movq %rbx, %rdi
movl %r13d, %esi
movq %rbp, %rdx
callq 0x51829
movq %rax, %r12
cmpq $0x0, 0x18(%rax)
je 0x516d0
movq (%rbx), %rsi
movl 0x38(%rbp), %edx
movq %r12, %rdi
callq 0x51991
movq (%rbx), %rsi
movq %r12, %rdi
movl $0x1, %edx
callq 0x7c9ed
cmpq $0x0, 0x18(%r12)
je 0x51753
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
ucomisd 0x545f8(%rip), %xmm0    # 0xa5d18
jae 0x51753
movq %r14, %rdi
movq %r12, %rsi
callq 0x7c9c6
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x9f94e
movq (%rbx), %rdi
movl %r13d, %esi
callq 0x1152e
testl %eax, %eax
jne 0x516aa
jmp 0x5180a
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 0x7c251
movq %r12, %rdi
callq 0x3a180
jmp 0x5180a
movq %r15, %rbp
movq 0x30(%r12), %r15
cmpl %r13d, (%r12)
jne 0x517ec
leaq 0x30(%rbp), %rax
testq %rbp, %rbp
cmoveq %r14, %rax
movq %r15, (%rax)
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 0x7c251
movq %r12, %rdi
callq 0x3a180
decl 0x10(%r14)
testq %r15, %r15
jne 0x517ef
jmp 0x517f9
movq %r12, %rbp
movq %r15, %r12
testq %r15, %r15
jne 0x51790
jmp 0x517fd
movq %rbp, 0x8(%r14)
testq %rbp, %rbp
je 0x5180a
movq $0x0, 0x30(%rbp)
movq 0x38(%rsp), %rsi
movq %rbx, %rdi
callq 0x30648
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq