// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/regressiontree.c
// Function: best_hybrid_regression_tree_split_crossvalidation
int best_hybrid_regression_tree_split_crossvalidation(Regressionnodeptr node, Regtree_parameterptr param)
{
	/*!Last Changed 24.03.2005*/
 int hybridspace = get_parameter_i("hybridspace");
 FILE* errorfiles[3];
	int i, k, trainsize, testsize, bestmodel = 0, *models, dummy, dummy2, testtype;
	Instanceptr train = NULL, test = NULL;
	char **files, st[READLINELENGTH] = "-", dummy3, pst[READLINELENGTH], buffer[READLINELENGTH];
	double error;
 files = safemalloc(hybridspace * sizeof(char *), "best_hybrid_regression_tree_split_crossvalidation", 5);
 strcpy(buffer, get_parameter_s("tempdirectory"));
 strcat(buffer, "/univariate.txt");
 files[0] = strcopy(files[0], buffer);
 strcpy(buffer, get_parameter_s("tempdirectory"));
 strcat(buffer, "/linear.txt");
 files[1] = strcopy(files[1], buffer);
 if (hybridspace == 3)
  {
   strcpy(buffer, get_parameter_s("tempdirectory"));
   strcat(buffer, "/quadratic.txt");
   files[2] = strcopy(files[2], buffer);
  }
 for (i = 0; i < hybridspace; i++)
  {
   errorfiles[i] = fopen(files[i], "w");
   if (!errorfiles[i])
     return 0;
  }
	for (i = 0; i < 5; i++)
	 {
		 divide_instancelist(&(node->instances), &train, &test, 2);
			trainsize = data_size(train);
			testsize = data_size(test);
			if (trainsize <= 1 || testsize <= 1)
			 {
  			node->instances = restore_instancelist(node->instances, train);
	  		merge_instancelist(&(node->instances), test);	
					bestmodel = 1;
				 break;
			 }
   for (k = 0; k < hybridspace; k++)
    {
     switch (k)
      {
       case MODEL_UNI:error = regression_tree_model_selection_error(&train, &test, UNIVARIATE, param->leaftype);
                      break;
       case MODEL_LIN:error = regression_tree_model_selection_error(&train, &test, LINEAR, param->leaftype);
                      break;
       case MODEL_QUA:error = regression_tree_model_selection_error(&train, &test, QUADRATIC, param->leaftype);
                      break;
      }
     set_precision(pst, NULL, "\n");
     fprintf(errorfiles[k], pst, error / (testsize + 0.0));
    }
   for (k = 0; k < hybridspace; k++)
    {
     switch (k)
      {
       case MODEL_UNI:error = regression_tree_model_selection_error(&test, &train, UNIVARIATE, param->leaftype);
                      break;
       case MODEL_LIN:error = regression_tree_model_selection_error(&test, &train, LINEAR, param->leaftype);
                      break;
       case MODEL_QUA:error = regression_tree_model_selection_error(&test, &train, QUADRATIC, param->leaftype);
                      break;
      }
     set_precision(pst, NULL, "\n");
     fprintf(errorfiles[k], pst, error / (trainsize + 0.0));
    }
			node->instances = restore_instancelist(node->instances, train);
			merge_instancelist(&(node->instances), test);	
			train = NULL;
			test = NULL;
	 }
 for (i = 0; i < hybridspace; i++)
   fclose(errorfiles[i]);
 if (bestmodel)
	 {
		 free_2d((void**)files, hybridspace);
   if (param->leaftype == CONSTANTLEAF)
     node->featureno = best_regression_feature(node->instances, &(node->split), &dummy3);
	  else
		   node->featureno = best_regression_feature_linear_leaves(node->instances, &(node->split), &dummy3);
			if (node->featureno == LEAF_NODE)
				 return 0;
			return 1;
	 }
 testtype = get_parameter_l("testtype");
 if (in_list(testtype, 9, FTEST, PAIREDT5X2, COMBINEDT5X2, PERMUTATIONTEST, PAIREDPERMUTATIONTEST, SIGNTEST, RANKSUMTEST, SIGNEDRANKTEST, NOTEST))
   models = multiple_comparison(files, hybridspace, testtype, st, &dummy, &dummy2, param->correctiontype);
 else
   models = multiple_comparison(files, hybridspace, FTEST, st, &dummy, &dummy2, param->correctiontype);
	switch (models[0])
	 {
	  case 1:if (param->leaftype == CONSTANTLEAF)
            return best_regression_feature(node->instances, &(node->split), &dummy3);
	         else
		          return best_regression_feature_linear_leaves(node->instances, &(node->split), &dummy3);
										break;
			case 2:find_linear_regression_split(node->instances, &(node->leftcenter), &(node->rightcenter));
  				    node->featureno = LINEAR;
				      break;
			case 3:find_quadratic_regression_split(node->instances, &(node->leftcenter), &(node->rightcenter));
  				    node->featureno = QUADRATIC;
				      break;
	 }
	safe_free(models);
	free_2d((void**)files, hybridspace);
	return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x16e460, %rsp         # imm = 0x16E460
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x3db46(%rip), %rdi     # 0xe57d0
callq 0x78f10
movl %eax, -0x1c(%rbp)
movl $0x0, -0x54(%rbp)
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
leaq -0x7a1b0(%rbp), %rdi
xorl %esi, %esi
movl $0x7a120, %edx          # imm = 0x7A120
callq 0x4050
movb $0x2d, -0x7a1b0(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x446c3(%rip), %rsi     # 0xec395
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x88(%rbp)
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e418(%rbp)
leaq 0x3f284(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e418(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x3f75a(%rip), %rsi     # 0xe7474
callq 0x41a0
movq -0x88(%rbp), %rax
movq (%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e410(%rbp)
leaq 0x3f225(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e410(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x3f70b(%rip), %rsi     # 0xe7484
callq 0x41a0
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpl $0x3, -0x1c(%rbp)
jne 0xa7e0a
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e420(%rbp)
leaq 0x3f1be(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e420(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x3f6b0(%rip), %rsi     # 0xe7490
callq 0x41a0
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa7e65
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x4038f(%rip), %rsi     # 0xe81be
callq 0x40c0
movq %rax, %rcx
movslq -0x44(%rbp), %rax
movq %rcx, -0x40(%rbp,%rax,8)
movslq -0x44(%rbp), %rax
cmpq $0x0, -0x40(%rbp,%rax,8)
jne 0xa7e58
movl $0x0, -0x4(%rbp)
jmp 0xa8393
jmp 0xa7e5a
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa7e11
movl $0x0, -0x44(%rbp)
cmpl $0x5, -0x44(%rbp)
jge 0xa811a
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
leaq -0x78(%rbp), %rsi
leaq -0x80(%rbp), %rdx
movl $0x2, %ecx
callq 0x45f60
movq -0x78(%rbp), %rdi
callq 0x449f0
movl %eax, -0x4c(%rbp)
movq -0x80(%rbp), %rdi
callq 0x449f0
movl %eax, -0x50(%rbp)
cmpl $0x1, -0x4c(%rbp)
jle 0xa7eb4
cmpl $0x1, -0x50(%rbp)
jg 0xa7eed
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x78(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x80(%rbp), %rsi
callq 0x44f40
movl $0x1, -0x54(%rbp)
jmp 0xa811a
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa7fde
movl -0x48(%rbp), %eax
movl %eax, -0x16e424(%rbp)
testl %eax, %eax
je 0xa7f29
jmp 0xa7f0f
movl -0x16e424(%rbp), %eax
subl $0x1, %eax
je 0xa7f48
jmp 0xa7f1c
movl -0x16e424(%rbp), %eax
subl $0x2, %eax
je 0xa7f6a
jmp 0xa7f8a
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
jmp 0xa7f8a
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
jmp 0xa7f8a
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
leaq -0xf42e0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x3dd9f(%rip), %rdx     # 0xe5d3b
callq 0x53310
movslq -0x48(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
leaq -0xf42e0(%rbp), %rsi
movsd -0x16e408(%rbp), %xmm0
cvtsi2sdl -0x50(%rbp), %xmm1
xorps %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movb $0x1, %al
callq 0x4280
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa7ef4
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa80cf
movl -0x48(%rbp), %eax
movl %eax, -0x16e428(%rbp)
testl %eax, %eax
je 0xa801a
jmp 0xa8000
movl -0x16e428(%rbp), %eax
subl $0x1, %eax
je 0xa8039
jmp 0xa800d
movl -0x16e428(%rbp), %eax
subl $0x2, %eax
je 0xa805b
jmp 0xa807b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
xorl %edx, %edx
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
jmp 0xa807b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
jmp 0xa807b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0xa7900
movsd %xmm0, -0x16e408(%rbp)
leaq -0xf42e0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x3dcae(%rip), %rdx     # 0xe5d3b
callq 0x53310
movslq -0x48(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
leaq -0xf42e0(%rbp), %rsi
movsd -0x16e408(%rbp), %xmm0
cvtsi2sdl -0x4c(%rbp), %xmm1
xorps %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movb $0x1, %al
callq 0x4280
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xa7fe5
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x78(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x80(%rbp), %rsi
callq 0x44f40
movq $0x0, -0x78(%rbp)
movq $0x0, -0x80(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa7e6c
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa8142
movslq -0x44(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
callq 0x4250
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa8121
cmpl $0x0, -0x54(%rbp)
je 0xa81d2
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xa818b
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
leaq -0x7a1b1(%rbp), %rdx
callq 0xa6720
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
jmp 0xa81b0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
leaq -0x7a1b1(%rbp), %rdx
callq 0xa6110
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x68(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x68(%rax)
jne 0xa81c6
movl $0x0, -0x4(%rbp)
jmp 0xa8393
movl $0x1, -0x4(%rbp)
jmp 0xa8393
leaq 0x3ede8(%rip), %rdi     # 0xe6fc1
callq 0x792b0
movl %eax, -0x6c(%rbp)
movl -0x6c(%rbp), %edi
movl $0x9, %esi
movl $0x3, %edx
movl $0xa, %ecx
movl $0xc, %r8d
movl $0xf, %r9d
movl $0x10, (%rsp)
movl $0xe, 0x8(%rsp)
movl $0x6, 0x10(%rsp)
movl $0x7, 0x18(%rsp)
movl $0x13, 0x20(%rsp)
movb $0x0, %al
callq 0x53e40
cmpl $0x0, %eax
je 0xa8263
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x6c(%rbp), %edx
leaq -0x7a1b0(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
leaq -0x64(%rbp), %r8
leaq -0x68(%rbp), %r9
movl %eax, (%rsp)
callq 0xc3c40
movq %rax, -0x60(%rbp)
jmp 0xa8294
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x7a1b0(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movl $0x3, %edx
leaq -0x64(%rbp), %r8
leaq -0x68(%rbp), %r9
movl %eax, (%rsp)
callq 0xc3c40
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x16e42c(%rbp)
subl $0x1, %eax
je 0xa82c8
jmp 0xa82a7
movl -0x16e42c(%rbp), %eax
subl $0x2, %eax
je 0xa8316
jmp 0xa82b4
movl -0x16e42c(%rbp), %eax
subl $0x3, %eax
je 0xa8346
jmp 0xa8374
movq -0x18(%rbp), %rax
cmpl $0x0, (%rax)
jne 0xa82f5
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
leaq -0x7a1b1(%rbp), %rdx
callq 0xa6720
movl %eax, -0x4(%rbp)
jmp 0xa8393
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x50, %rsi
leaq -0x7a1b1(%rbp), %rdx
callq 0xa6110
movl %eax, -0x4(%rbp)
jmp 0xa8393
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x80, %rsi
movq -0x10(%rbp), %rdx
addq $0x88, %rdx
callq 0xa7b10
movq -0x10(%rbp), %rax
movl $0xfffffffe, 0x68(%rax) # imm = 0xFFFFFFFE
jmp 0xa8374
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x80, %rsi
movq -0x10(%rbp), %rdx
addq $0x88, %rdx
callq 0xa7b90
movq -0x10(%rbp), %rax
movl $0xfffffffd, 0x68(%rax) # imm = 0xFFFFFFFD
movq -0x60(%rbp), %rdi
callq 0x52e80
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x16e460, %rsp         # imm = 0x16E460
popq %rbp
retq
nop