// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/regressionrule.c
// Function: best_regression_condition_crossvalidation
void best_regression_condition_crossvalidation(Regressionconditionptr condition, Instanceptr* data, LEAF_TYPE leaftype, int correctiontype)
{
	/*!Last Changed 26.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] = "-", pst[READLINELENGTH], buffer[READLINELENGTH];
	double error;
 files = safemalloc(hybridspace * sizeof(char *), "best_regression_condition_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;
  }
	for (i = 0; i < 5; i++)
	 {
		 divide_instancelist(data, &train, &test, 2);
			trainsize = data_size(train);
			testsize = data_size(test);
			if (trainsize <= 1 || testsize <= 1)
			 {
  			*data = restore_instancelist(*data, train);
	  		merge_instancelist(data, test);	
					bestmodel = 1;
				 break;
			 }
   for (k = 0; k < hybridspace; k++)
    {
     switch (k)
      {
       case MODEL_UNI:error = regression_tree_model_selection_error(&train, &test, UNIVARIATE, leaftype);
                      break;
       case MODEL_LIN:error = regression_tree_model_selection_error(&train, &test, LINEAR, leaftype);
                      break;
       case MODEL_QUA:error = regression_tree_model_selection_error(&train, &test, QUADRATIC, 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, leaftype);
                      break;
       case MODEL_LIN:error = regression_tree_model_selection_error(&test, &train, LINEAR, leaftype);
                      break;
       case MODEL_QUA:error = regression_tree_model_selection_error(&test, &train, QUADRATIC, leaftype);
                      break;
      }
     set_precision(pst, NULL, "\n");
     fprintf(errorfiles[k], pst, error / (trainsize + 0.0));
    }
			*data = restore_instancelist(*data, train);
			merge_instancelist(data, test);	
			train = NULL;
			test = NULL;
	 }
 for (i = 0; i < hybridspace; i++)
   fclose(errorfiles[i]);
 if (bestmodel)
	 {
		 free_2d((void**)files, hybridspace);
   best_single_regression_condition(condition, data, UNIVARIATE, leaftype);
			return;
	 }
 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, correctiontype);
 else
   models = multiple_comparison(files, hybridspace, FTEST, st, &dummy, &dummy2, correctiontype);
	switch (models[0])
	 {
	  case 1:best_single_regression_condition(condition, data, UNIVARIATE, leaftype);
										break;
			case 2:best_single_regression_condition(condition, data, LINEAR, leaftype);
				      break;
			case 3:best_single_regression_condition(condition, data, QUADRATIC, leaftype);
				      break;
	 }
	safe_free(models);
	free_2d((void**)files, hybridspace);
	return;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x16e450, %rsp         # imm = 0x16E450
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
leaq 0x40a90(%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 0x4757a(%rip), %rsi     # 0xec302
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x88(%rbp)
leaq -0x16e3f0(%rbp), %rax
movq %rax, -0x16e408(%rbp)
leaq 0x421ce(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e408(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e3f0(%rbp), %rdi
leaq 0x426a4(%rip), %rsi     # 0xe7474
callq 0x41a0
movq -0x88(%rbp), %rax
movq (%rax), %rdi
leaq -0x16e3f0(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, (%rax)
leaq -0x16e3f0(%rbp), %rax
movq %rax, -0x16e400(%rbp)
leaq 0x4216f(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e400(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e3f0(%rbp), %rdi
leaq 0x42655(%rip), %rsi     # 0xe7484
callq 0x41a0
movq -0x88(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x16e3f0(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0x88(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpl $0x3, -0x1c(%rbp)
jne 0xa4ec0
leaq -0x16e3f0(%rbp), %rax
movq %rax, -0x16e410(%rbp)
leaq 0x42108(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e410(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e3f0(%rbp), %rdi
leaq 0x425fa(%rip), %rsi     # 0xe7490
callq 0x41a0
movq -0x88(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x16e3f0(%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 0xa4f14
movq -0x88(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x432d9(%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 0xa4f07
jmp 0xa533a
jmp 0xa4f09
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa4ec7
movl $0x0, -0x44(%rbp)
cmpl $0x5, -0x44(%rbp)
jge 0xa51a7
movq -0x10(%rbp), %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 0xa4f5f
cmpl $0x1, -0x50(%rbp)
jg 0xa4f92
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x78(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rdi
movq -0x80(%rbp), %rsi
callq 0x44f40
movl $0x1, -0x54(%rbp)
jmp 0xa51a7
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa507a
movl -0x48(%rbp), %eax
movl %eax, -0x16e414(%rbp)
testl %eax, %eax
je 0xa4fce
jmp 0xa4fb4
movl -0x16e414(%rbp), %eax
subl $0x1, %eax
je 0xa4fea
jmp 0xa4fc1
movl -0x16e414(%rbp), %eax
subl $0x2, %eax
je 0xa5009
jmp 0xa5026
movl -0x14(%rbp), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
xorl %edx, %edx
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
jmp 0xa5026
movl -0x14(%rbp), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
jmp 0xa5026
movl -0x14(%rbp), %ecx
leaq -0x78(%rbp), %rdi
leaq -0x80(%rbp), %rsi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
leaq -0xf42d0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x40d03(%rip), %rdx     # 0xe5d3b
callq 0x53310
movslq -0x48(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
leaq -0xf42d0(%rbp), %rsi
movsd -0x16e3f8(%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 0xa4f99
movl $0x0, -0x48(%rbp)
movl -0x48(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa5162
movl -0x48(%rbp), %eax
movl %eax, -0x16e418(%rbp)
testl %eax, %eax
je 0xa50b6
jmp 0xa509c
movl -0x16e418(%rbp), %eax
subl $0x1, %eax
je 0xa50d2
jmp 0xa50a9
movl -0x16e418(%rbp), %eax
subl $0x2, %eax
je 0xa50f1
jmp 0xa510e
movl -0x14(%rbp), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
xorl %edx, %edx
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
jmp 0xa510e
movl -0x14(%rbp), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
jmp 0xa510e
movl -0x14(%rbp), %ecx
leaq -0x80(%rbp), %rdi
leaq -0x78(%rbp), %rsi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0xa7900
movsd %xmm0, -0x16e3f8(%rbp)
leaq -0xf42d0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x40c1b(%rip), %rdx     # 0xe5d3b
callq 0x53310
movslq -0x48(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
leaq -0xf42d0(%rbp), %rsi
movsd -0x16e3f8(%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 0xa5081
movq -0x10(%rbp), %rax
movq (%rax), %rdi
movq -0x78(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %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 0xa4f1b
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0xa51cf
movslq -0x44(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
callq 0x4250
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xa51ae
cmpl $0x0, -0x54(%rbp)
je 0xa51fb
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %ecx
xorl %edx, %edx
callq 0xa4c10
jmp 0xa533a
leaq 0x41dbf(%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 0xa5288
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x6c(%rbp), %edx
leaq -0x7a1b0(%rbp), %rcx
movl -0x18(%rbp), %eax
leaq -0x64(%rbp), %r8
leaq -0x68(%rbp), %r9
movl %eax, (%rsp)
callq 0xc3c40
movq %rax, -0x60(%rbp)
jmp 0xa52b5
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x7a1b0(%rbp), %rcx
movl -0x18(%rbp), %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, -0x16e41c(%rbp)
subl $0x1, %eax
je 0xa52e2
jmp 0xa52c8
movl -0x16e41c(%rbp), %eax
subl $0x2, %eax
je 0xa52f6
jmp 0xa52d5
movl -0x16e41c(%rbp), %eax
subl $0x3, %eax
je 0xa530d
jmp 0xa5322
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %ecx
xorl %edx, %edx
callq 0xa4c10
jmp 0xa5322
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %ecx
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0xa4c10
jmp 0xa5322
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %ecx
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0xa4c10
movq -0x60(%rbp), %rdi
callq 0x52e80
movq -0x88(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
addq $0x16e450, %rsp         # imm = 0x16E450
popq %rbp
retq
nopw %cs:(%rax,%rax)