// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/omnivariaterule.c
// Function: prunerule_with_modelselection
void prunerule_with_modelselection(Decisionruleptr rule, Instanceptr dataset, int modelselectionmethod)
{
 /*!Last Changed 19.02.2005*/
 double bestgen, gen, loglikelihood;
 int complexity, improved = 1, covered;
 Decisionconditionptr best, bestbefore, tmpcondition, tmpbefore;
 complexity = complexity_of_rule(rule);
 loglikelihood = log_likelihood_of_rule(rule, dataset, &covered);
 switch (modelselectionmethod)
  {
   case MODEL_SELECTION_AIC:bestgen = aic_loglikelihood(loglikelihood, complexity);
                            break;
   case MODEL_SELECTION_BIC:bestgen = bic_loglikelihood(loglikelihood, complexity, covered);
                            break;
  }
 while (improved)
  {
   improved = 0;
   tmpbefore = NULL;
   tmpcondition = rule->start;
   while (tmpcondition)
    {
     remove_condition_after(rule, tmpbefore, tmpcondition);
     complexity = complexity_of_rule(rule);
     loglikelihood = log_likelihood_of_rule(rule, dataset, &covered);
     switch (modelselectionmethod)
      {
       case MODEL_SELECTION_AIC:gen = aic_loglikelihood(loglikelihood, complexity);
                                break;
       case MODEL_SELECTION_BIC:gen = bic_loglikelihood(loglikelihood, complexity, covered);
                                break;
      } 
     if (gen < bestgen)
      {
       bestgen = gen;
       bestbefore = tmpbefore;
       best = tmpcondition;
       improved = 1;
      }
     add_condition_after(rule, tmpbefore, tmpcondition);
     tmpbefore = tmpcondition;
     tmpcondition = tmpcondition->next;
    }
   if (improved)
    {
     remove_condition_after(rule, bestbefore, best);
     free_condition(*best);
     safe_free(best);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %edx, %ebx
movq %rsi, %r14
movq %rdi, %r15
callq 0x79250
movl %eax, %ebp
leaq 0x7c(%rsp), %rdx
movq %r15, %rdi
movq %r14, 0x98(%rsp)
movq %r14, %rsi
callq 0x4f63b
cmpl $0x2, %ebx
je 0x50546
cmpl $0x1, %ebx
jne 0x5055c
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x464c1
jmp 0x50553
cvtsi2sd %ebp, %xmm1
movl 0x7c(%rsp), %edi
callq 0x46930
movsd %xmm0, 0x80(%rsp)
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x50634
xorl %r12d, %r12d
xorl %r14d, %r14d
movq %rax, %rbp
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7af03
movq %r15, %rdi
callq 0x79250
movl %eax, %r13d
movq %r15, %rdi
movq 0x98(%rsp), %rsi
leaq 0x7c(%rsp), %rdx
callq 0x4f63b
cmpl $0x2, %ebx
je 0x505c2
cmpl $0x1, %ebx
movsd 0xa0(%rsp), %xmm1
jne 0x505d7
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
callq 0x464c1
jmp 0x505d3
xorps %xmm1, %xmm1
cvtsi2sd %r13d, %xmm1
movl 0x7c(%rsp), %edi
callq 0x46930
movapd %xmm0, %xmm1
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x50605
movl $0x1, %r14d
movsd %xmm1, 0x80(%rsp)
movq %rbp, 0x90(%rsp)
movq %r12, 0x88(%rsp)
movsd %xmm1, 0xa0(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x7ae99
movq 0x48(%rbp), %rax
movq %rbp, %r12
testq %rax, %rax
jne 0x5056f
testl %r14d, %r14d
sete %al
jmp 0x50636
movb $0x1, %al
testb %al, %al
jne 0x50675
movq %r15, %rdi
movq 0x88(%rsp), %rsi
movq 0x90(%rsp), %r14
movq %r14, %rdx
callq 0x7af03
movl $0xe, %ecx
movq %rsp, %rdi
movq %r14, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7a935
movq %r14, %rdi
callq 0x39194
jmp 0x5055c
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq