// File: /workspace/github_c_makefile_star2_O3/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 0x531ea
movl %esi, %r14d
leal -0x1(%r14), %eax
cmpl $0x3, %eax
ja 0x53159
leaq 0x57b70(%rip), %rcx     # 0xaa990
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %rbx, %rdi
callq 0x1de29
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1cb69
cvtsi2sd %eax, %xmm1
movsd 0x8(%rsp), %xmm0
callq 0x47871
movsd %xmm0, 0x8(%rsp)
leaq 0x82a15(%rip), %rax     # 0xd5870
movq (%rax), %rax
movslq 0x10(%rax), %rdi
leaq 0x57b9d(%rip), %rdx     # 0xaaa06
movl $0x4, %esi
movl $0xa, %ecx
callq 0x3a1fc
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1dd81
movq %r15, %rdi
callq 0x1de84
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x3a180
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
callq 0x47871
jmp 0x53103
movq %rbx, %rdi
callq 0x1cac6
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 0x53006
leaq 0x82989(%rip), %rax     # 0xd5870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0xa33b3
jmp 0x5301c
xorl %eax, %eax
leaq 0x34(%rsp), %r15
movl %eax, (%r15)
leaq 0x30(%rsp), %r12
movl %eax, (%r12)
movq %rbx, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x1dde3
movl (%r15), %edi
movl (%r12), %edx
movsd 0x525f9(%rip), %xmm0    # 0xa5520
xorl %esi, %esi
xorl %ecx, %ecx
callq 0x7adc2
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1cb69
movsd 0x52e7a(%rip), %xmm1    # 0xa5dc0
movsd 0x8(%rsp), %xmm0
movl %eax, %edi
movl $0x20, %esi
callq 0x48abe
movsd %xmm0, 0x8(%rsp)
movl 0x84(%rbx), %edi
movl 0x88(%rbx), %edx
xorl %esi, %esi
xorl %ecx, %ecx
movsd 0x525aa(%rip), %xmm0    # 0xa5520
callq 0x7adc2
xorl %edi, %edi
movsd 0x52e3b(%rip), %xmm1    # 0xa5dc0
movl $0x20, %esi
callq 0x48abe
jmp 0x53103
movq %rbx, %rdi
callq 0x1de29
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x1cb69
movl %eax, %ebp
leaq 0x828bd(%rip), %r12     # 0xd5870
movq (%r12), %rax
movslq 0x10(%rax), %rdi
leaq 0x57a44(%rip), %rdx     # 0xaaa06
movl $0x4, %esi
movl $0x12, %ecx
callq 0x3a1fc
movq %rax, %r15
movq %rbx, %rdi
movq %rax, %rsi
callq 0x1dd81
movq (%r12), %rax
movslq 0x10(%rax), %rax
testq %rax, %rax
jle 0x530c0
xorl %ecx, %ecx
xorl %r12d, %r12d
addl (%r15,%rcx,4), %r12d
incq %rcx
cmpq %rcx, %rax
jne 0x52ff5
jmp 0x530c3
testl %eax, %eax
jne 0x5301e
leaq 0x8285f(%rip), %rax     # 0xd5870
movq (%rax), %rdi
movq %rbx, %rsi
callq 0xa31da
movl %eax, %ebp
movl 0x84(%rbx), %r15d
leaq 0x52a10(%rip), %r12     # 0xa5a3c
movq %r12, %rdi
callq 0x549ba
movsd %xmm0, 0x10(%rsp)
leaq 0x52a01(%rip), %r13     # 0xa5a42
movq %r13, %rdi
callq 0x549ba
movapd %xmm0, %xmm2
movsd 0x8(%rsp), %xmm0
movl %ebp, %edi
movl %r15d, %esi
movsd 0x10(%rsp), %xmm1
callq 0x4896e
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 0x549ba
movsd %xmm0, 0x28(%rsp)
movq %r13, %rdi
callq 0x549ba
movapd %xmm0, %xmm2
movapd 0x10(%rsp), %xmm0
movl $0x1, %edi
movl %r15d, %esi
movsd 0x28(%rsp), %xmm1
callq 0x4896e
jmp 0x53103
xorl %r12d, %r12d
cvtsi2sd %ebp, %xmm1
movsd 0x8(%rsp), %xmm0
movl %r12d, %edi
callq 0x47cd7
movsd %xmm0, 0x8(%rsp)
movq %r15, %rdi
callq 0x1de84
movsd %xmm0, 0x10(%rsp)
movq %r15, %rdi
callq 0x3a180
xorpd %xmm1, %xmm1
movsd 0x10(%rsp), %xmm0
movl %r12d, %edi
callq 0x47cd7
movsd 0x8(%rsp), %xmm1
ucomisd %xmm0, %xmm1
movl 0x30(%rbx), %edi
jbe 0x53159
movl $0x2, %esi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
xorl %eax, %eax
callq 0x3aa8c
testl %eax, %eax
je 0x53139
movq 0x38(%rbx), %rdi
movq 0x40(%rbx), %rsi
callq 0x3ed51
leaq 0x20(%rbx), %rdi
movq %rbx, %rsi
callq 0x1cef5
movq %rbx, %rdi
callq 0x1d8e3
movl $0xffffffff, 0x30(%rbx) # imm = 0xFFFFFFFF
jmp 0x531ea
testl %edi, %edi
js 0x531d3
cmpl $0x2, 0x98(%rbx)
je 0x531d3
leaq 0x82703(%rip), %r15     # 0xd5870
movq (%r15), %rax
movl %edi, %ecx
imulq $0x340, %rcx, %rdx      # imm = 0x340
cmpl $0x1, 0x30f08(%rax,%rdx)
jne 0x531d3
addq $0x30f08, %rax          # imm = 0x30F08
imulq $0x340, %rcx, %rcx      # imm = 0x340
cmpl $0x0, 0x18(%rax,%rcx)
jle 0x531ea
xorl %r12d, %r12d
xorl %r13d, %r13d
movq 0x10(%rbx), %rdi
addq %r12, %rdi
movl %r14d, %esi
callq 0x52dec
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 0x5319d
jmp 0x531ea
movq (%rbx), %rdi
movl %r14d, %esi
callq 0x52dec
movq 0x8(%rbx), %rdi
movl %r14d, %esi
callq 0x52dec
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq