// File: /workspace/github_c_makefile_star2_O2/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, %r14d
movq %rdx, %r15
movl %esi, %ebp
movq %rdi, %rbx
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 0x70654
movl %eax, %r12d
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movupd (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
leaq 0x44(%rsp), %rdx
movq %r15, 0x60(%rsp)
movq %r15, %rdi
movl %ebp, %esi
callq 0x4956c
cmpl $0x2, %r14d
je 0x4a474
cmpl $0x1, %r14d
jne 0x4a488
cvtsi2sd %r12d, %xmm1
callq 0x40bcb
jmp 0x4a482
cvtsi2sd %r12d, %xmm1
movl 0x44(%rsp), %edi
callq 0x40fa5
movsd %xmm0, 0x48(%rsp)
movq %rbx, %r15
movq (%r15), %r15
testq %r15, %r15
je 0x4a5d1
cmpl %ebp, (%r15)
je 0x4a4a2
addq $0x30, %r15
jmp 0x4a48b
movq 0x8(%rbx), %r13
movl %r14d, 0x54(%rsp)
movq %r13, %r12
testq %r13, %r13
je 0x4a5d1
cmpq %r15, 0x30(%r12)
je 0x4a5d1
movq (%rbx), %rax
cmpq %r12, %rax
je 0x4a4d8
movq %rax, %r13
movq 0x30(%rax), %rax
cmpq %r12, %rax
jne 0x4a4ca
jmp 0x4a4db
xorl %r13d, %r13d
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x721ae
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movups (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movl %ebp, %edi
callq 0x70654
movl %eax, %r14d
movq 0x20(%rbx), %rax
movq %rax, 0x20(%rsp)
movupd (%rbx), %xmm0
movups 0x10(%rbx), %xmm1
movups %xmm1, 0x10(%rsp)
movupd %xmm0, (%rsp)
movq 0x60(%rsp), %rdi
movl %ebp, %esi
leaq 0x44(%rsp), %rdx
callq 0x4956c
cvtsi2sd %r14d, %xmm1
movl 0x54(%rsp), %eax
cmpl $0x2, %eax
je 0x4a558
cmpl $0x1, %eax
movsd 0x58(%rsp), %xmm2
jne 0x4a565
callq 0x40bcb
jmp 0x4a561
movl 0x44(%rsp), %edi
callq 0x40fa5
movapd %xmm0, %xmm2
movsd %xmm2, 0x58(%rsp)
ucomisd 0x48(%rsp), %xmm2
jbe 0x4a586
movq %rbx, %rdi
movq %r13, %rsi
movq %r12, %rdx
callq 0x7217f
jmp 0x4a4ab
movq 0x30(%r12), %rax
movq %rax, 0x30(%rsp)
movups (%r12), %xmm0
movupd 0x10(%r12), %xmm1
movupd 0x20(%r12), %xmm2
movupd %xmm2, 0x20(%rsp)
movupd %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
callq 0x71be8
movq %r12, %rdi
callq 0x34ff7
movsd 0x58(%rsp), %xmm0
movsd %xmm0, 0x48(%rsp)
jmp 0x4a4ab
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq