// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/omnivariaterule.c
// Function: simplify_ruleset_modelselection
void simplify_ruleset_modelselection(Ruleset* r, int positive, Instanceptr instances, int modelselectionmethod)
{
 /*!Last Changed 19.02.2005*/
 Decisionruleptr firstrule, deleted, tmprule, deletedbefore;
 double minerror, error, loglikelihood;
 int complexity, covered;
 complexity = complexity_of_ruleset(*r, positive);
 loglikelihood = log_likelihood_of_ruleset(*r, instances, positive, &covered);
 switch (modelselectionmethod)
  {
   case MODEL_SELECTION_AIC:minerror = aic_loglikelihood(loglikelihood, complexity);
                            break;
   case MODEL_SELECTION_BIC:minerror = bic_loglikelihood(loglikelihood, complexity, covered);
                            break;
  }
 firstrule = r->start;
 while (firstrule && firstrule->classno != positive)
   firstrule = firstrule->next;
 if (!firstrule)
   return;
 deleted = r->end;
 while (deleted && deleted->next != firstrule)
  {
   tmprule = r->start;
   if (tmprule != deleted)
    {
     while (tmprule->next != deleted)
       tmprule = tmprule->next;
     deletedbefore = tmprule;
    }
   else
     deletedbefore = NULL;
   remove_rule_after(r, deletedbefore, deleted);
   complexity = complexity_of_ruleset(*r, positive);
   loglikelihood = log_likelihood_of_ruleset(*r, instances, positive, &covered);
   switch (modelselectionmethod)
    {
     case MODEL_SELECTION_AIC:error = aic_loglikelihood(loglikelihood, complexity);
                              break;
     case MODEL_SELECTION_BIC:error = bic_loglikelihood(loglikelihood, complexity, covered);
                              break;
    }
   if (error > minerror)
     add_rule_after(r, deletedbefore, deleted);
   else
    {
     free_rule(*deleted);
     safe_free(deleted);
     minerror = error;
    }
   deleted = deletedbefore;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %ecx, %ebx
movq %rdx, %r14
movl %esi, %ebp
movq %rdi, %r15
movq 0x20(%rdi), %rax
movq %rax, 0x20(%rsp)
movups (%rdi), %xmm0
movups 0x10(%rdi), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %esi, %edi
callq 0x79269
movl %eax, %r12d
movq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
leaq 0x44(%rsp), %rdx
movq %r14, 0x60(%rsp)
movq %r14, %rdi
movl %ebp, %esi
callq 0x4f79a
cmpl $0x2, %ebx
movl %ebx, 0x5c(%rsp)
je 0x50868
cmpl $0x1, %ebx
jne 0x5087f
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
callq 0x464c1
jmp 0x50879
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movl 0x44(%rsp), %edi
callq 0x46930
movsd %xmm0, 0x50(%rsp)
movq (%r15), %rbx
testq %rbx, %rbx
je 0x509d9
cmpl %ebp, (%rbx)
je 0x50895
movq 0x30(%rbx), %rbx
jmp 0x50882
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x509d9
cmpq %rbx, 0x30(%r12)
je 0x509d9
movq (%r15), %rax
cmpq %r12, %rax
movsd %xmm0, 0x48(%rsp)
je 0x508c9
movq %rax, %r13
movq 0x30(%rax), %rax
cmpq %r12, %rax
jne 0x508bb
jmp 0x508cc
xorl %r13d, %r13d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x7afd2
movq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
movups (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
callq 0x79269
movl %eax, %r14d
movq 0x20(%r15), %rax
movq %rax, 0x20(%rsp)
movupd (%r15), %xmm0
movups 0x10(%r15), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
movl %ebp, %esi
leaq 0x44(%rsp), %rdx
callq 0x4f79a
movl 0x5c(%rsp), %eax
cmpl $0x2, %eax
je 0x50950
cmpl $0x1, %eax
movsd 0x48(%rsp), %xmm1
jne 0x50965
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
callq 0x464c1
jmp 0x50961
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movl 0x44(%rsp), %edi
callq 0x46930
movapd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
ucomisd 0x50(%rsp), %xmm1
jbe 0x50989
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x7afad
movsd 0x48(%rsp), %xmm0
jmp 0x509cd
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 0x7a989
movq %r12, %rdi
callq 0x39194
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r13, %r12
testq %r13, %r13
jne 0x508a2
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq