// File: /workspace/github_c_makefile_star2_O1/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 0x36e60(%rip), %r15     # 0xaca84
leaq 0x5cc45(%rip), %r12     # 0xd2870
cmpl $-0x1, 0x68(%rbx)
je 0x75da0
cmpl $0x0, (%r14)
movsd 0x2c8df(%rip), %xmm0    # 0xa2520
je 0x75c52
movq (%r12), %rax
xorps %xmm0, %xmm0
cvtsi2sdl 0x1c0(%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %rbx, %rdi
callq 0x74d71
movl %eax, %ebp
movq %rbx, %rdi
callq 0x74ce1
movl 0x8(%r14), %esi
cmpl $0x2, %esi
je 0x75ce1
cmpl $0x1, %esi
je 0x75ca2
testl %esi, %esi
je 0x75c87
cmpl $0x1, 0x4(%r14)
jne 0x75d3d
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
movsd 0x58(%rax), %xmm1
addsd 0x58(%rcx), %xmm1
movsd 0x58(%rbx), %xmm0
jmp 0x75d23
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x46491
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 0x46491
jmp 0x75d1e
movl 0x78(%rbx), %edi
xorps %xmm1, %xmm1
cvtsi2sd %edi, %xmm1
divsd %xmm1, %xmm0
xorps %xmm1, %xmm1
cvtsi2sd %ebp, %xmm1
callq 0x468e1
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 0x468e1
movsd (%rsp), %xmm1
ucomisd %xmm0, %xmm1
ja 0x75d51
movq (%rbx), %rdi
movq %r14, %rsi
callq 0x75c0b
movq 0x8(%rbx), %rbx
jmp 0x75c2b
movq %r15, %rdi
xorl %eax, %eax
callq 0x4030
xorpd %xmm0, %xmm0
xorpd %xmm1, %xmm1
jmp 0x75d23
leaq 0x20(%rbx), %rdi
leaq 0x28(%rbx), %rsi
movq %rbx, %rdx
callq 0x75bd0
movq (%rbx), %rdi
callq 0x75950
movq (%rbx), %rdi
callq 0x39194
movq 0x8(%rbx), %rdi
callq 0x75950
movq 0x8(%rbx), %rdi
callq 0x39194
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