// File: /workspace/github_c_makefile_star2_O1/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:
cmpl $-0x1, 0x30(%rdi)
je 0x51d04
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %esi, %r14d
movq %rdi, %rbx
leal -0x1(%r14), %eax
cmpl $0x3, %eax
ja 0x51b00
leaq 0x55fd6(%rip), %rcx     # 0xa78f0
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1d6cb
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1c44f
cvtsi2sd %eax, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x464c1
movsd %xmm0, 0x8(%rsp)
leaq 0x80f1b(%rip), %rax     # 0xd2870
movq (%rax), %rax
movslq 0x10(%rax), %rdi
leaq 0x55ff7(%rip), %rdx     # 0xa795a
movl $0x4, %esi
movl $0xa, %ecx
callq 0x39210
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1d62b
movq %r15, %rdi
callq 0x1d726
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x39194
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
callq 0x464c1
jmp 0x51c0d
movq %rbx, %rdi
callq 0x1c3b2
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 0x51b11
leaq 0x80e8f(%rip), %rax     # 0xd2870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0xa0442
jmp 0x51b27
xorl %eax, %eax
leaq 0x24(%rsp), %r15
movl %eax, (%r15)
leaq 0x20(%rsp), %r12
movl %eax, (%r12)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1d689
movl (%r15), %edi
movl (%r12), %edx
movsd 0x50aff(%rip), %xmm0    # 0xa2520
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x79482
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1c44f
movsd 0x51380(%rip), %xmm1    # 0xa2dc0
movsd 0x8(%rsp), %xmm0
movl %eax, %edi
movl $0x20, %esi
callq 0x47717
movsd %xmm0, 0x8(%rsp)
movl 0x84(%rbx), %edi
movl 0x88(%rbx), %edx
xorl %esi, %esi
xorl %ecx, %ecx
movsd 0x50ab0(%rip), %xmm0    # 0xa2520
callq 0x79482
xorl %edi, %edi
movsd 0x51341(%rip), %xmm1    # 0xa2dc0
movl $0x20, %esi
callq 0x47717
jmp 0x51c0d
movq %rbx, %rdi
callq 0x1d6cb
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1c44f
movl %eax, %ebp
leaq 0x80dc3(%rip), %r12     # 0xd2870
movq (%r12), %rax
movslq 0x10(%rax), %rdi
leaq 0x55e9e(%rip), %rdx     # 0xa795a
movl $0x4, %esi
movl $0x12, %ecx
callq 0x39210
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1d62b
movq (%r12), %rax
movslq 0x10(%rax), %rax
testq %rax, %rax
jle 0x51bca
xorl %ecx, %ecx
xorl %r12d, %r12d
addl (%r15,%rcx,4), %r12d
incq %rcx
cmpq %rcx, %rax
jne 0x51aef
jmp 0x51bcd
xorpd %xmm1, %xmm1
movsd 0x50a14(%rip), %xmm0    # 0xa2520
jmp 0x51c13
testl %eax, %eax
jne 0x51b29
leaq 0x80d54(%rip), %rax     # 0xd2870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0xa02d6
movl %eax, %ebp
movl 0x84(%rbx), %r15d
leaq 0x50f05(%rip), %r12     # 0xa2a3c
movq %r12, %rdi
callq 0x534b6
movsd %xmm0, 0x10(%rsp)
leaq 0x50ef6(%rip), %r13     # 0xa2a42
movq %r13, %rdi
callq 0x534b6
movapd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movl %r15d, %esi
movsd 0x10(%rsp), %xmm1
callq 0x475c7
movsd %xmm0, 0x8(%rsp)
xorps %xmm1, %xmm1
cvtsi2sdl 0x88(%rbx), %xmm1
movl 0x84(%rbx), %ebp
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
divsd %xmm0, %xmm1
movsd %xmm1, 0x10(%rsp)
movq %r12, %rdi
callq 0x534b6
movsd %xmm0, 0x18(%rsp)
movq %r13, %rdi
callq 0x534b6
movapd %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
movl $0x1, %edi
movl %ebp, %esi
movsd 0x18(%rsp), %xmm1
callq 0x475c7
jmp 0x51c0d
xorl %r12d, %r12d
cvtsi2sd %ebp, %xmm1
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
callq 0x46930
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
callq 0x1d726
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x39194
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
movl %r12d, %edi
callq 0x46930
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0x30(%rbx), %edi
jbe 0x51c63
movl $0x2, %esi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
xorl %eax, %eax
callq 0x39a80
testl %eax, %eax
je 0x51c43
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq 0x3dbad
leaq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1c787
movq %rbx, %rdi
callq 0x1d173
movl $0xffffffff, 0x30(%rbx) # imm = 0xFFFFFFFF
jmp 0x51cf6
testl %edi, %edi
js 0x51cdf
cmpl $0x2, 0x98(%rbx)
je 0x51cdf
leaq 0x80bf9(%rip), %r15     # 0xd2870
movq (%r15), %rax
imulq $0x340, %rdi, %rcx      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%rcx)
jne 0x51cdf
movq (%r15), %rax
movslq 0x30(%rbx), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
cmpl $0x0, 0x30f20(%rax,%rcx)
jle 0x51cf6
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x518e8
incq %r13
movq (%r15), %rax
movslq 0x30(%rbx), %rcx
imulq $0x340, %rcx, %rcx      # imm = 0x340
movslq 0x30f20(%rax,%rcx), %rax
addq $0x160, %r12            # imm = 0x160
cmpq %rax, %r13
jl 0x51ca9
jmp 0x51cf6
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x518e8
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0x518e8
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq