// File: /workspace/github_c_makefile_star2_O3/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 0x7ab90
movl %eax, %ebp
leaq 0x7c(%rsp), %rdx
movq %r15, %rdi
movq %r14, 0x98(%rsp)
movq %r14, %rsi
callq 0x50b33
cmpl $0x2, %ebx
movl %ebx, 0x8c(%rsp)
je 0x519e8
cmpl $0x1, %ebx
jne 0x519fe
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x47871
jmp 0x519f5
cvtsi2sd %ebp, %xmm1
movl 0x7c(%rsp), %edi
callq 0x47cd7
movsd %xmm0, 0x80(%rsp)
movq 0x18(%r15), %rax
testq %rax, %rax
je 0x51b15
xorl %r12d, %r12d
xorl %ebx, %ebx
movq %rax, %r13
movq %r15, %rdi
movq %r12, %rsi
movq %rax, %rdx
callq 0x7c7c4
movq %r15, %rdi
callq 0x7ab90
movl %eax, %r14d
movq %r15, %rdi
movq 0x98(%rsp), %rsi
leaq 0x7c(%rsp), %rdx
callq 0x50b33
movl 0x8c(%rsp), %eax
cmpl $0x2, %eax
je 0x51a6a
cmpl $0x1, %eax
movsd 0xa0(%rsp), %xmm1
jne 0x51a7f
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
callq 0x47871
jmp 0x51a7b
xorps %xmm1, %xmm1
cvtsi2sd %r14d, %xmm1
movl 0x7c(%rsp), %edi
callq 0x47cd7
movapd %xmm0, %xmm1
movsd 0x80(%rsp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x51aa7
movl $0x1, %ebx
movsd %xmm1, 0x80(%rsp)
movq %r13, %rbp
movq %r12, 0x90(%rsp)
movsd %xmm1, 0xa0(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x7c752
movq 0x48(%r13), %rax
movq %r13, %r12
testq %rax, %rax
jne 0x51a10
testl %ebx, %ebx
je 0x51b15
movq %r15, %rdi
movq 0x90(%rsp), %rsi
movq %rbp, %rdx
callq 0x7c7c4
movl $0xe, %ecx
movq %rsp, %rdi
movq %rbp, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x7c1f4
movq %rbp, %rdi
callq 0x3a180
movq 0x18(%r15), %rax
xorl %r12d, %r12d
movl $0x0, %ebx
testq %rax, %rax
jne 0x51a10
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq