// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/regressiontree.c
// Function: prune_regression_tree
void prune_regression_tree(Regressionnodeptr root, Regtree_parameterptr param)
{
	/*!Last Changed 02.03.2005*/
	double generalizationerrorbeforeprune = 0.0, generalizationerrorafterprune = 0.0, errorbeforeprune;
	int dafterprune, dbeforeprune;
 if (root->featureno == LEAF_NODE)
   return;
	if (param->leaftype == CONSTANTLEAF)
		 dafterprune = 1;
	else
		 dafterprune = current_dataset->multifeaturecount;
 dbeforeprune = complexity_of_regression_tree(root);
	errorbeforeprune = mse_error_of_regression_tree(root);
	switch (param->modelselectionmethod)
	 {
	  case MODEL_SELECTION_CV :generalizationerrorbeforeprune = root->left->errorforprune + root->right->errorforprune;
				                        generalizationerrorafterprune = root->errorforprune;
										                  break;
	  case MODEL_SELECTION_AIC:generalizationerrorbeforeprune = aic_squared_error(errorbeforeprune / root->covered, dbeforeprune, root->covered);
				                        generalizationerrorafterprune = aic_squared_error(root->mseerror / root->covered, dafterprune, root->covered);
				                        break;
			case MODEL_SELECTION_BIC:generalizationerrorbeforeprune = bic_squared_error(errorbeforeprune / root->covered, dbeforeprune, root->covered);
				                        generalizationerrorafterprune = bic_squared_error(root->mseerror / root->covered, dafterprune, root->covered);
				                        break;
    default                :if (param->prunetype == VALIDATIONPRUNING)
                             {
                              generalizationerrorbeforeprune = root->left->errorforprune + root->right->errorforprune;
                              generalizationerrorafterprune = root->errorforprune;
                             }
                            else
                              printf(m1230, param->modelselectionmethod);
                            break;
	 }
	if (generalizationerrorafterprune < generalizationerrorbeforeprune)
	 {
			accumulate_instances_regression_tree(&(root->instances), &(root->cvinstances), root);
   deallocate_regression_tree(root->left);
			safe_free(root->left);
   deallocate_regression_tree(root->right);
			safe_free(root->right);
			make_leaf_regression_node(root, param->leaftype);
	 }
	else
	 {
		 prune_regression_tree(root->left, param);
		 prune_regression_tree(root->right, param);
	 }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x10, %rsp
cmpl $-0x1, 0x68(%rdi)
je 0x7776d
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x38560(%rip), %r15     # 0xafb5c
leaq 0x5e26d(%rip), %r12     # 0xd5870
cmpl $0x0, (%r14)
movsd 0x2df11(%rip), %xmm0    # 0xa5520
je 0x77620
movq (%r12), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c0(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x76644
movl %eax, %ebp
movq %rbx, %rdi
callq 0x765a1
movl 0x8(%r14), %esi
cmpl $0x2, %esi
je 0x776af
cmpl $0x1, %esi
je 0x77670
testl %esi, %esi
je 0x77655
cmpl $0x1, 0x4(%r14)
jne 0x77712
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movsd 0x58(%rax), %xmm1
addsd 0x58(%rcx), %xmm1
movsd 0x58(%rbx), %xmm0
jmp 0x776f1
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x47841
movsd %xmm0, (%rsp)
movsd 0x60(%rbx), %xmm0
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x47841
jmp 0x776ec
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x47c88
movsd %xmm0, (%rsp)
movsd 0x60(%rbx), %xmm0
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x47c88
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x7771e
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x775d9
movq 0x8(%rbx), %rbx
cmpl $-0x1, 0x68(%rbx)
jne 0x77603
jmp 0x7776d
movq %r15, %rdi
xorl %eax, %eax
callq 0x4030
jmp 0x776f7
leaq 0x20(%rbx), %rdi
leaq 0x28(%rbx), %rsi
movq %rbx, %rdx
callq 0x77559
movq (%rbx), %rdi
callq 0x772d9
movq (%rbx), %rdi
callq 0x3a180
movq 0x8(%rbx), %rdi
callq 0x772d9
movq 0x8(%rbx), %rdi
callq 0x3a180
movl (%r14), %eax
movl $0xffffffff, 0x68(%rbx) # imm = 0xFFFFFFFF
movl %eax, 0x6c(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
movq $0x0, 0x10(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq