// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq $0x0, -0x48(%rbp)
movq $0x0, -0x50(%rbp)
movq $0x0, -0x58(%rbp)
movq $0x0, -0x60(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x64(%rbp)
subl $-0x3, %eax
je 0xa7a19
jmp 0xa7947
movl -0x64(%rbp), %eax
subl $-0x2, %eax
je 0xa79cb
jmp 0xa7951
movl -0x64(%rbp), %eax
testl %eax, %eax
jne 0xa7a6d
jmp 0xa795e
cmpl $0x0, -0x18(%rbp)
jne 0xa797d
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x19(%rbp), %rdx
callq 0xa6720
movl %eax, -0x20(%rbp)
jmp 0xa7994
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x19(%rbp), %rdx
callq 0xa6110
movl %eax, -0x20(%rbp)
movq -0x8(%rbp), %rdi
movl -0x20(%rbp), %ecx
movsd -0x28(%rbp), %xmm0
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
callq 0x456d0
movq -0x10(%rbp), %rdi
movl -0x20(%rbp), %ecx
movsd -0x28(%rbp), %xmm0
leaq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
callq 0x456d0
jmp 0xa7a7e
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xa7b10
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
xorl %r9d, %r9d
callq 0x45590
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
xorl %r9d, %r9d
callq 0x45590
jmp 0xa7a7e
movq -0x8(%rbp), %rax
movq (%rax), %rdi
leaq -0x38(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xa7b90
movq -0x8(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq -0x48(%rbp), %rsi
leaq -0x50(%rbp), %rdx
movl $0x1, %r9d
callq 0x45590
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rcx
movq -0x40(%rbp), %r8
leaq -0x58(%rbp), %rsi
leaq -0x60(%rbp), %rdx
movl $0x1, %r9d
callq 0x45590
jmp 0xa7a7e
movl -0x14(%rbp), %esi
leaq 0x44863(%rip), %rdi     # 0xec2da
movb $0x0, %al
callq 0x4030
movq -0x48(%rbp), %rdi
movq -0x58(%rbp), %rsi
movl -0x18(%rbp), %edx
callq 0xa7830
movsd %xmm0, -0x70(%rbp)
movq -0x50(%rbp), %rdi
movq -0x60(%rbp), %rsi
movl -0x18(%rbp), %edx
callq 0xa7830
movaps %xmm0, %xmm1
movsd -0x70(%rbp), %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rdi
movq -0x48(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x50(%rbp), %rsi
callq 0x44f40
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x58(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x60(%rbp), %rsi
callq 0x44f40
movsd -0x30(%rbp), %xmm0
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)