// File: /workspace/github_c_makefile_star2_O2/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 %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
movl %ecx, %ebp
andq $0x0, 0x20(%rsp)
movq %rsi, %rbx
andq $0x0, 0x18(%rsp)
movq %rdi, %r14
andq $0x0, 0x10(%rsp)
andq $0x0, 0x8(%rsp)
cmpl $-0x3, %edx
je 0x6d7b2
cmpl $-0x2, %edx
je 0x6d760
testl %edx, %edx
jne 0x6d80d
movq (%r14), %rdi
leaq 0x28(%rsp), %rsi
leaq 0x30(%rsp), %rdx
testl %ebp, %ebp
je 0x6d81f
callq 0x6c660
jmp 0x6d824
movq (%r14), %rdi
leaq 0x28(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x6d8df
movq (%r15), %r15
movq (%r12), %r12
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %r9d, %r9d
callq 0x2ca3c
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
xorl %r9d, %r9d
jmp 0x6d806
movq (%r14), %rdi
leaq 0x28(%rsp), %r15
leaq 0x30(%rsp), %r12
movq %r15, %rsi
movq %r12, %rdx
callq 0x6d91e
movq (%r15), %r15
movq (%r12), %r12
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
pushq $0x1
popq %r13
movq %r14, %rdi
movq %r15, %rcx
movq %r12, %r8
movl %r13d, %r9d
callq 0x2ca3c
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movq %r15, %rcx
movq %r12, %r8
movl %r13d, %r9d
callq 0x2ca3c
jmp 0x6d860
leaq 0x322ce(%rip), %rdi     # 0x9fae2
movl %edx, %esi
xorl %eax, %eax
callq 0x4030
jmp 0x6d860
callq 0x6cbb5
movl %eax, %r15d
movsd 0x28(%rsp), %xmm0
movsd %xmm0, (%rsp)
leaq 0x20(%rsp), %rsi
leaq 0x18(%rsp), %rdx
movq %r14, %rdi
movl %eax, %ecx
callq 0x2caf4
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %rbx, %rdi
movl %r15d, %ecx
movsd (%rsp), %xmm0
callq 0x2caf4
movq 0x20(%rsp), %rdi
movq 0x10(%rsp), %rsi
movl %ebp, %edx
callq 0x6d63d
movsd %xmm0, (%rsp)
movq 0x18(%rsp), %rdi
movq 0x8(%rsp), %rsi
movl %ebp, %edx
callq 0x6d63d
addsd (%rsp), %xmm0
movsd %xmm0, (%rsp)
movq (%r14), %rdi
movq 0x20(%rsp), %rsi
callq 0x2d2da
movq %rax, (%r14)
movq 0x18(%rsp), %rsi
movq %r14, %rdi
callq 0x2c6e4
movq (%rbx), %rdi
movq 0x10(%rsp), %rsi
callq 0x2d2da
movq %rax, (%rbx)
movq 0x8(%rsp), %rsi
movq %rbx, %rdi
callq 0x2c6e4
movsd (%rsp), %xmm0
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq