// File: /workspace/github_c_makefile_star2_O3/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 0x7aba9
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 0x50c92
cmpl $0x2, %ebx
movl %ebx, 0x5c(%rsp)
je 0x51d15
cmpl $0x1, %ebx
jne 0x51d2c
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
callq 0x47871
jmp 0x51d26
xorps %xmm1, %xmm1
cvtsi2sd %r12d, %xmm1
movl 0x44(%rsp), %edi
callq 0x47cd7
movsd %xmm0, 0x50(%rsp)
movq (%r15), %rbx
testq %rbx, %rbx
je 0x51e86
cmpl %ebp, (%rbx)
je 0x51d42
movq 0x30(%rbx), %rbx
jmp 0x51d2f
movq 0x8(%r15), %r12
testq %r12, %r12
je 0x51e86
cmpq %rbx, 0x30(%r12)
je 0x51e86
movq (%r15), %rax
cmpq %r12, %rax
movsd %xmm0, 0x48(%rsp)
je 0x51d76
movq %rax, %r13
movq 0x30(%rax), %rax
cmpq %r12, %rax
jne 0x51d68
jmp 0x51d79
xorl %r13d, %r13d
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x7c89d
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 0x7aba9
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 0x50c92
movl 0x5c(%rsp), %eax
cmpl $0x2, %eax
je 0x51dfd
cmpl $0x1, %eax
movsd 0x48(%rsp), %xmm1
jne 0x51e12
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
callq 0x47871
jmp 0x51e0e
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movl 0x44(%rsp), %edi
callq 0x47cd7
movapd %xmm0, %xmm1
movsd %xmm1, 0x48(%rsp)
ucomisd 0x50(%rsp), %xmm1
jbe 0x51e36
movq %r15, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x7c86e
movsd 0x48(%rsp), %xmm0
jmp 0x51e7a
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 0x7c251
movq %r12, %rdi
callq 0x3a180
movsd 0x48(%rsp), %xmm0
movsd %xmm0, 0x50(%rsp)
movq %r13, %r12
testq %r13, %r13
jne 0x51d4f
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq