// File: /workspace/github_c_makefile_star2_O1/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 0x760a4
cmpl $-0x2, %edx
je 0x76052
testl %edx, %edx
jne 0x76101
movq (%r14), %rdi
leaq 0x30(%rsp), %rsi
leaq 0x38(%rsp), %rdx
testl %ebp, %ebp
je 0x76113
callq 0x74e0c
jmp 0x76118
movq (%r14), %rdi
leaq 0x30(%rsp), %r15
leaq 0x38(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x761d7
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 0x3010e
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %r9d, %r9d
jmp 0x760fa
movq (%r14), %rdi
leaq 0x30(%rsp), %r15
leaq 0x38(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x7621d
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 0x3010e
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
movl $0x1, %r9d
callq 0x3010e
jmp 0x76156
leaq 0x369e2(%rip), %rdi     # 0xacaea
movl %edx, %esi
xorl %eax, %eax
callq 0x4030
jmp 0x76156
callq 0x753a6
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 0x301e1
leaq 0x18(%rsp), %rsi
leaq 0x10(%rsp), %rdx
movq %rbx, %rdi
movl %r15d, %ecx
movsd 0x8(%rsp), %xmm0
callq 0x301e1
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl %ebp, %edx
callq 0x75f33
movsd %xmm0, 0x8(%rsp)
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x75f33
addsd 0x8(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r14), %rdi
movq 0x28(%rsp), %rsi
callq 0x30ad5
movq %rax, (%r14)
movq 0x20(%rsp), %rsi
movq %r14, %rdi
callq 0x2fd59
movq (%rbx), %rdi
movq 0x18(%rsp), %rsi
callq 0x30ad5
movq %rax, (%rbx)
movq 0x10(%rsp), %rsi
movq %rbx, %rdi
callq 0x2fd59
movsd 0x8(%rsp), %xmm0
addq $0x40, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq