// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/omnivariatetree.c
// Function: prune_tree_according_to_model_selection_method
void prune_tree_according_to_model_selection_method(Decisionnodeptr root, int modelselectionmethod)
{
 /*!Last Changed 24.05.2006 added free_children*/
 /*!Last Changed 10.02.2005*/
 double performancebefore, performance, loglikelihoodbefore, loglikelihood, exceptionlengthbefore, exceptionlength, error;
 int d, *classcounts, N, i, C, fp, h;
 if (root->featureno == LEAF_NODE)
   return;
 switch (modelselectionmethod)
  {
   case MODEL_SELECTION_AIC:loglikelihoodbefore = decisiontree_loglikelihood(root);
                            d = decisiontree_complexity_count(root);
                            performancebefore = aic_loglikelihood(loglikelihoodbefore, d);
                            classcounts = safecalloc(current_dataset->classno, sizeof(int), "prune_tree_according_to_model_selection_method", 10);
                            find_subtree_class_counts(root, classcounts);
                            loglikelihood = log_likelihood_for_classification(classcounts);
                            safe_free(classcounts);
                            performance = aic_loglikelihood(loglikelihood, 0);
                            break;
   case MODEL_SELECTION_BIC:loglikelihoodbefore = decisiontree_loglikelihood(root);
                            d = decisiontree_complexity_count(root);
                            classcounts = safecalloc(current_dataset->classno, sizeof(int), "prune_tree_according_to_model_selection_method", 18);
                            find_subtree_class_counts(root, classcounts);
                            N = 0;
                            for (i = 0; i < current_dataset->classno; i++)
                              N += classcounts[i];
                            performancebefore = bic_loglikelihood(loglikelihoodbefore, d, N);
                            loglikelihood = log_likelihood_for_classification(classcounts);
                            safe_free(classcounts);
                            performance = bic_loglikelihood(loglikelihood, 0, N);
                            break;
   case MODEL_SELECTION_SRM:error = decisiontree_falsepositive_count(root) / (root->covered + 0.0);
                            switch (root->conditiontype)
                             {
                              case   UNIVARIATE_CONDITION:h = decisiontree_vc_dimension_recursive(current_dataset, root);
                                                          break;
                              case MULTIVARIATE_CONDITION:
                              case       HYBRID_CONDITION:h = omnivariatetree_vc_dimension(current_dataset, root);
                                                          break;
                             }
                            performancebefore = srm_classification(error, h, root->covered, get_parameter_f("srma1"), get_parameter_f("srma2"));
                            error = root->falsepositives / (root->covered + 0.0);
                            performance = srm_classification(error, 1, root->covered, get_parameter_f("srma1"), get_parameter_f("srma2"));
                            break;
   case MODEL_SELECTION_MDL:C = 0;
                            fp = 0;
                            subtree_covered_and_false_positives(root, &C, &fp);
                            exceptionlengthbefore = description_length_of_exceptions(C, 0, fp, 0, 1);
                            d = decisiontree_complexity_count(root);
                            performancebefore = mdl(exceptionlengthbefore, d, 0.01, BITS_FOR_REAL_NUMBER);
                            exceptionlength = description_length_of_exceptions(root->covered, 0, root->falsepositives, 0, 1);
                            performance = mdl(exceptionlength, 0, 0.01, BITS_FOR_REAL_NUMBER);
                            break;
   default                 :performance = 1.0;
                            performancebefore = 0.0;
                            break;
  }
 if (performance < performancebefore)
  {
   if (in_list(root->featureno, 2, LINEAR, QUADRATIC))
     matrix_free(root->w);
   accumulate_instances_tree(&(root->instances), root);
   free_children(root);
   root->featureno = LEAF_NODE;
  }
 else
  {
   if (root->featureno >= 0 && (root->conditiontype != HYBRID_CONDITION) && current_dataset->features[root->featureno].type == STRING)
     for (i = 0; i < current_dataset->features[root->featureno].valuecount; i++)
       prune_tree_according_to_model_selection_method(&(root->string[i]), modelselectionmethod);
   else
    {
     prune_tree_according_to_model_selection_method(root->left, modelselectionmethod);
     prune_tree_according_to_model_selection_method(root->right, modelselectionmethod);
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movq %rdi, %rbx
movl 0x30(%rdi), %edi
cmpl $-0x1, %edi
je 0x4b76b
movl %esi, %r14d
leal -0x1(%r14), %eax
cmpl $0x3, %eax
ja 0x4b6ec
leaq 0x4f4ec(%rip), %rcx     # 0x9a8c0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1b906
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1a75b
cvtsi2sd %eax, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x40bcb
movsd %xmm0, 0x8(%rsp)
leaq 0x82461(%rip), %rax     # 0xcd870
movq (%rax), %rax
movslq 0x10(%rax), %rdi
leaq 0x4f519(%rip), %rdx     # 0x9a936
pushq $0x4
popq %rsi
pushq $0xa
popq %rcx
callq 0x35067
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1b86a
movq %r15, %rdi
callq 0x1b961
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x34ff7
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
callq 0x40bcb
jmp 0x4b6a2
movq %rbx, %rdi
callq 0x1a6bc
cvtsi2sd %eax, %xmm1
cvtsi2sdl 0x84(%rbx), %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x8(%rsp)
movl 0x98(%rbx), %eax
leal -0x1(%rax), %ecx
cmpl $0x2, %ecx
jae 0x4b5ec
leaq 0x823d9(%rip), %rax     # 0xcd870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x93c9f
jmp 0x4b602
leaq 0x34(%rsp), %r15
andl $0x0, (%r15)
leaq 0x30(%rsp), %r12
andl $0x0, (%r12)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1b8c4
movl (%r15), %edi
movl (%r12), %edx
movsd 0x4a049(%rip), %xmm0    # 0x95520
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x7084f
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1a75b
movsd 0x4a8d2(%rip), %xmm1    # 0x95dc8
pushq $0x20
popq %rbp
movsd 0x8(%rsp), %xmm0
movl %eax, %edi
movl %ebp, %esi
callq 0x41cf9
movsd %xmm0, 0x8(%rsp)
movl 0x84(%rbx), %edi
movl 0x88(%rbx), %edx
xorl %esi, %esi
xorl %ecx, %ecx
movsd 0x49ffa(%rip), %xmm0    # 0x95520
callq 0x7084f
xorl %edi, %edi
movsd 0x4a893(%rip), %xmm1    # 0x95dc8
movl %ebp, %esi
callq 0x41cf9
jmp 0x4b6a2
movq %rbx, %rdi
callq 0x1b906
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1a75b
movl %eax, %ebp
leaq 0x82310(%rip), %r12     # 0xcd870
movq (%r12), %rax
movslq 0x10(%rax), %rdi
leaq 0x4f3c7(%rip), %rdx     # 0x9a936
pushq $0x4
popq %rsi
pushq $0x12
popq %rcx
callq 0x35067
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1b86a
movq (%r12), %rax
movl 0x10(%rax), %eax
xorl %ecx, %ecx
testl %eax, %eax
cmovlel %ecx, %eax
xorl %r12d, %r12d
cmpq %rcx, %rax
je 0x4b5a7
addl (%r15,%rcx,4), %r12d
incq %rcx
jmp 0x4b599
cvtsi2sd %ebp, %xmm1
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
callq 0x40fa5
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
callq 0x1b961
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x34ff7
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
movl %r12d, %edi
callq 0x40fa5
jmp 0x4b6a2
testl %eax, %eax
jne 0x4b604
leaq 0x82279(%rip), %rax     # 0xcd870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0x93b46
movl %eax, %ebp
movl 0x84(%rbx), %r15d
leaq 0x4a42a(%rip), %r12     # 0x95a3c
movq %r12, %rdi
callq 0x4cdcf
movsd %xmm0, 0x10(%rsp)
leaq 0x4a41b(%rip), %r13     # 0x95a42
movq %r13, %rdi
callq 0x4cdcf
movapd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movl %r15d, %esi
movsd 0x10(%rsp), %xmm1
callq 0x41c3e
movq 0x84(%rbx), %r15
movq %r15, %xmm1
cvtdq2pd %xmm1, %xmm1
movsd %xmm0, 0x8(%rsp)
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
divsd %xmm1, %xmm0
movapd %xmm0, 0x10(%rsp)
movq %r12, %rdi
callq 0x4cdcf
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
callq 0x4cdcf
movapd %xmm0, %xmm2
pushq $0x1
popq %rdi
movapd 0x10(%rsp), %xmm0
movl %r15d, %esi
movsd 0x28(%rsp), %xmm1
callq 0x41c3e
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0x30(%rbx), %edi
jbe 0x4b6ec
pushq $0x2
popq %rsi
pushq $-0x2
popq %rdx
pushq $-0x3
popq %rcx
xorl %eax, %eax
callq 0x35812
testl %eax, %eax
je 0x4b6d2
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq 0x3929f
leaq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1aad3
movq %rbx, %rdi
callq 0x1b42e
orl $-0x1, 0x30(%rbx)
jmp 0x4b76b
testl %edi, %edi
js 0x4b754
cmpl $0x2, 0x98(%rbx)
je 0x4b754
leaq 0x82170(%rip), %r15     # 0xcd870
movq (%r15), %rax
movl %edi, %ecx
imulq $0x340, %rcx, %rcx      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%rcx)
jne 0x4b754
xorl %r12d, %r12d
xorl %r13d, %r13d
movslq %edi, %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
movslq 0x30f20(%rax,%rcx), %rax
cmpq %rax, %r13
jge 0x4b76b
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x4b3a0
incq %r13
movq (%r15), %rax
movl 0x30(%rbx), %edi
addq $0x160, %r12            # imm = 0x160
jmp 0x4b71c
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x4b3a0
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0x4b3a0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq