// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/regressiontree.c
// Function: regression_tree_model_selection_error
double regression_tree_model_selection_error(Instanceptr* train, Instanceptr *test, NODE_TYPE nodetype, LEAF_TYPE leaftype)
{
	/*!Last Changed 24.03.2005*/
	char dummy;
	int fno;
	double split, error;
	Instanceptr left, right, leftinstances = NULL, rightinstances = NULL, testleft = NULL, testright = NULL;
	switch (nodetype)
	 {
	  case UNIVARIATE:if (leaftype == CONSTANTLEAF)
                     fno = best_regression_feature(*train, &split, &dummy);
	                  else
		                   fno = best_regression_feature_linear_leaves(*train, &split, &dummy);
  	                divide_instancelist_according_to_split(train, &leftinstances, &rightinstances, fno, split);
  	                divide_instancelist_according_to_split(test, &testleft, &testright, fno, split);
																			break;
			case LINEAR    :find_linear_regression_split(*train, &left, &right);
				               divide_instancelist_according_centers(train, &leftinstances, &rightinstances, left, right, NO);
				               divide_instancelist_according_centers(test, &testleft, &testright, left, right, NO);
				               break;
			case QUADRATIC :find_quadratic_regression_split(*train, &left, &right);
				               divide_instancelist_according_centers(train, &leftinstances, &rightinstances, left, right, YES);
				               divide_instancelist_according_centers(test, &testleft, &testright, left, right, YES);
				               break;
   default        :printf(m1231, nodetype);
                   break;
	 }
	error = constant_or_linear_model_mse(leftinstances, testleft, leaftype) + constant_or_linear_model_mse(rightinstances, testright, leaftype);
 *train = restore_instancelist(*train, leftinstances);
	merge_instancelist(train, rightinstances);	
 *test = restore_instancelist(*test, testleft);
	merge_instancelist(test, testright);	
	return error;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x40, %rsp
movl %ecx, %ebp
movq %rsi, %rbx
movq %rdi, %r14
xorl %eax, %eax
movq %rax, 0x28(%rsp)
movq %rax, 0x20(%rsp)
movq %rax, 0x18(%rsp)
movq %rax, 0x10(%rsp)
cmpl $-0x3, %edx
je 0x77a71
cmpl $-0x2, %edx
je 0x77a1f
testl %edx, %edx
jne 0x77ace
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x77ae0
callq 0x766e3
jmp 0x77ae5
movq (%r14), %rdi
leaq 0x30(%rsp), %r15
leaq 0x38(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x77ba4
movq (%r15), %r15
movq (%r12), %r12
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x30a0d
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %r9d, %r9d
jmp 0x77ac7
movq (%r14), %rdi
leaq 0x30(%rsp), %r15
leaq 0x38(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x77bea
movq (%r15), %r15
movq (%r12), %r12
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rcx
movq %r12, %r8
movl $0x1, %r9d
callq 0x30a0d
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
movl $0x1, %r9d
callq 0x30a0d
jmp 0x77b23
leaq 0x380ed(%rip), %rdi     # 0xafbc2
movl %edx, %esi
xorl %eax, %eax
callq 0x4030
jmp 0x77b23
callq 0x76c85
movl %eax, %r15d
movsd 0x30(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x28(%rsp), %rsi
leaq 0x20(%rsp), %rdx
movq %r14, %rdi
movl %eax, %ecx
callq 0x30ade
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl %r15d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x30ade
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x77900
movsd %xmm0, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x77900
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r14), %rdi
movq 0x28(%rsp), %rsi
callq 0x31345
movq %rax, (%r14)
movq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
movq (%rbx), %rdi
movq 0x18(%rsp), %rsi
callq 0x31345
movq %rax, (%rbx)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x30648
movsd 0x8(%rsp), %xmm0
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq