// File: /workspace/github_c_makefile_star2_O2/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
movq %rsi, %r14
movq %rdi, %rbx
leaq 0x32716(%rip), %r15     # 0x9fa7c
leaq 0x60503(%rip), %r12     # 0xcd870
cmpl $-0x1, 0x68(%rbx)
je 0x6d4b8
cmpl $0x0, (%r14)
movsd 0x2819d(%rip), %xmm0    # 0x95520
je 0x6d391
movq (%r12), %rax
cvtsi2sdl 0x1c0(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x6c5c9
movl %eax, %ebp
movq %rbx, %rdi
callq 0x6c539
movl 0x8(%r14), %esi
cvtsi2sd %ebp, %xmm1
cmpl $0x2, %esi
je 0x6d414
cmpl $0x1, %esi
je 0x6d3e2
testl %esi, %esi
je 0x6d3ca
cmpl $0x1, 0x4(%r14)
jne 0x6d463
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movsd 0x58(%rax), %xmm1
addsd 0x58(%rcx), %xmm1
movsd 0x58(%rbx), %xmm0
jmp 0x6d449
movl 0x78(%rbx), %edi
cvtsi2sd %edi, %xmm2
divsd %xmm2, %xmm0
callq 0x40b9e
movsd %xmm0, (%rsp)
movsd 0x60(%rbx), %xmm0
movl 0x78(%rbx), %edi
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x40b9e
jmp 0x6d444
movl 0x78(%rbx), %edi
cvtsi2sd %edi, %xmm2
divsd %xmm2, %xmm0
callq 0x40f59
movsd %xmm0, (%rsp)
movsd 0x60(%rbx), %xmm0
movl 0x78(%rbx), %edi
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
movsd 0x8(%rsp), %xmm1
callq 0x40f59
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x6d46f
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x6d34d
movq 0x8(%rbx), %rbx
jmp 0x6d36d
movq %r15, %rdi
xorl %eax, %eax
callq 0x4030
jmp 0x6d44f
leaq 0x20(%rbx), %rdi
leaq 0x28(%rbx), %rsi
movq %rbx, %rdx
callq 0x6d312
movq (%rbx), %rdi
callq 0x6d0db
movq (%rbx), %rdi
callq 0x34ff7
movq 0x8(%rbx), %rdi
callq 0x6d0db
movq 0x8(%rbx), %rdi
callq 0x34ff7
movl (%r14), %eax
orl $-0x1, 0x68(%rbx)
movl %eax, 0x6c(%rbx)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rbx)
andq $0x0, 0x10(%rbx)
addq $0x10, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq