// File: /workspace/github_c_makefile_star2_O2/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, %r12
movq %rdi, %r15
callq 0x70638
movl %eax, %ebp
leaq 0x74(%rsp), %rdx
movq %r15, %rdi
movq %r12, %r14
movq %r12, %rsi
callq 0x494a2
cmpl $0x2, %ebx
je 0x4a14d
cmpl $0x1, %ebx
jne 0x4a160
cvtsi2sd %ebp, %xmm1
callq 0x40bcb
jmp 0x4a15a
cvtsi2sd %ebp, %xmm1
movl 0x74(%rsp), %edi
callq 0x40fa5
movsd %xmm0, 0x78(%rsp)
leaq 0x18(%r15), %rax
movq %rax, 0x88(%rsp)
xorl %ebp, %ebp
testb $0x1, %bpl
jne 0x4a28b
movq $0x0, 0x80(%rsp)
movq 0x88(%rsp), %rax
xorl %r12d, %r12d
movq (%rax), %rbp
testq %rbp, %rbp
je 0x4a240
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x720e4
movq %r15, %rdi
callq 0x70638
movl %eax, %r13d
movq %r15, %rdi
movq %r14, %rsi
leaq 0x74(%rsp), %rdx
callq 0x494a2
cvtsi2sd %r13d, %xmm1
cmpl $0x2, %ebx
je 0x4a1e3
cmpl $0x1, %ebx
movsd 0xa0(%rsp), %xmm2
jne 0x4a1f0
callq 0x40bcb
jmp 0x4a1ec
movl 0x74(%rsp), %edi
callq 0x40fa5
movapd %xmm0, %xmm2
movsd 0x78(%rsp), %xmm0
ucomisd %xmm2, %xmm0
jbe 0x4a21d
movsd %xmm2, 0x78(%rsp)
pushq $0x1
popq %rax
movq %rax, 0x80(%rsp)
movq %rbp, 0x98(%rsp)
movq %r12, 0x90(%rsp)
movsd %xmm2, 0xa0(%rsp)
movq %r15, %rdi
movq %r12, %rsi
movq %rbp, %rdx
callq 0x7208c
leaq 0x48(%rbp), %rax
movq %rbp, %r12
jmp 0x4a18f
cmpl $0x0, 0x80(%rsp)
sete %bpl
je 0x4a16e
movq %r15, %rdi
movq 0x90(%rsp), %rsi
movq 0x98(%rsp), %r12
movq %r12, %rdx
callq 0x720e4
pushq $0xe
popq %rcx
movq %rsp, %rdi
movq %r12, %rsi
rep  movsq (%rsi), %es:(%rdi)
callq 0x71b91
movq %r12, %rdi
callq 0x34ff7
jmp 0x4a16e
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq