// File: /workspace/github_c_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16e3e8, %rsp         # imm = 0x16E3E8
movq %rcx, 0x48(%rsp)
movl %edx, 0x4(%rsp)
movq %rsi, 0x18(%rsp)
movq %rdi, %r13
leaq 0x333ba(%rip), %rdi     # 0xa8c98
callq 0x54920
movl %eax, %r12d
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
leaq 0x7a1a0(%rsp), %r14
movl $0x7a120, %edx          # imm = 0x7A120
movq %r14, %rdi
xorl %esi, %esi
callq 0x4050
movb $0x2d, (%r14)
movslq %r12d, %rdi
shlq $0x3, %rdi
leaq 0x3a2cf(%rip), %rsi     # 0xafbea
movl $0x5, %edx
callq 0x3a0e1
movq %rax, %rbp
leaq 0x34b2d(%rip), %r15     # 0xaa45c
movq %r15, %rdi
callq 0x54a6f
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4270
movq %r14, %rdi
callq 0x4190
movupd 0x3500b(%rip), %xmm0    # 0xaa965
movupd %xmm0, 0x80(%rsp,%rax)
movq (%rbp), %rdi
movq %r14, %rsi
callq 0x3b494
movq %rax, (%rbp)
movq %r15, %rdi
callq 0x54a6f
movq %r14, %rdi
movq %rax, %rsi
callq 0x4270
movq %r14, %rdi
callq 0x4190
movabsq $0x2e7261656e696c2f, %rcx # imm = 0x2E7261656E696C2F
movq %rcx, 0x80(%rsp,%rax)
movl $0x747874, 0x88(%rsp,%rax) # imm = 0x747874
movq 0x8(%rbp), %rdi
movq %r14, %rsi
callq 0x3b494
movq %rax, 0x8(%rbp)
movl %r12d, %ebx
cmpl $0x3, %r12d
movq %rbp, 0x28(%rsp)
jne 0x75a26
leaq 0x34a8c(%rip), %rdi     # 0xaa45c
callq 0x54a6f
leaq 0x80(%rsp), %r14
movq %r14, %rdi
movq %rax, %rsi
callq 0x4270
movq %r14, %rdi
callq 0x4190
movabsq $0x746172646175712f, %rcx # imm = 0x746172646175712F
movq %rcx, 0x80(%rsp,%rax)
movabsq $0x7478742e636974, %rcx # imm = 0x7478742E636974
movq %rcx, 0x87(%rsp,%rax)
movq 0x10(%rbp), %rdi
movq %r14, %rsi
callq 0x3b494
movq %rax, 0x10(%rbp)
jmp 0x75a2b
testl %r12d, %r12d
jle 0x75a66
xorl %r15d, %r15d
leaq 0x35f38(%rip), %r14     # 0xab96d
movq %r13, %rbp
movq 0x28(%rsp), %rax
movq (%rax,%r15,8), %rdi
movq %r14, %rsi
callq 0x40f0
movq %rax, 0x60(%rsp,%r15,8)
testq %rax, %rax
je 0x75d93
incq %r15
cmpq %r15, %rbx
jne 0x75a38
movb $0x1, %al
movl %eax, (%rsp)
jmp 0x75a70
movl $0x0, (%rsp)
movq %r13, %rbp
leaq 0x10(%rsp), %r14
leaq 0x8(%rsp), %r15
movq 0x18(%rsp), %r13
movq %r13, %rdi
movq %r14, %rsi
movq %r15, %rdx
movl $0x2, %ecx
callq 0x31019
movq (%r14), %rdi
callq 0x30309
movl %eax, %r14d
movq (%r15), %rdi
callq 0x30309
cmpl $0x2, %r14d
setl %cl
cmpl $0x2, %eax
setl %dl
xorl %r15d, %r15d
orb %cl, %dl
jne 0x75c5f
movq %rbp, 0x40(%rsp)
movl %r12d, 0x24(%rsp)
leaq 0x336cd(%rip), %rbp     # 0xa919b
leaq 0xf42c0(%rsp), %r13
xorl %r15d, %r15d
movl %r15d, %ecx
movq %rcx, 0x50(%rsp)
cmpb $0x0, (%rsp)
je 0x75bcd
xorps %xmm0, %xmm0
cvtsi2sd %eax, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x3a051(%rip), %r12     # 0xafb50
xorl %r15d, %r15d
cmpq $0x2, %r15
ja 0x75b25
movl (%r12), %edx
leaq 0x10(%rsp), %rdi
leaq 0x8(%rsp), %rsi
movl 0x4(%rsp), %ecx
callq 0x779c4
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3a535
movq 0x60(%rsp,%r15,8), %rdi
movsd 0x38(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movq %r13, %rsi
movb $0x1, %al
callq 0x42e0
incq %r15
addq $0x4, %r12
cmpq %r15, %rbx
jne 0x75b02
cmpb $0x0, (%rsp)
je 0x75bcd
xorps %xmm0, %xmm0
cvtsi2sd %r14d, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x39fdc(%rip), %r14     # 0xafb50
xorl %r12d, %r12d
cmpq $0x2, %r12
ja 0x75b99
movl (%r14), %edx
leaq 0x8(%rsp), %rdi
leaq 0x10(%rsp), %rsi
movl 0x4(%rsp), %ecx
callq 0x779c4
movsd %xmm0, 0x38(%rsp)
movq %r13, %rdi
xorl %esi, %esi
movq %rbp, %rdx
callq 0x3a535
movq 0x60(%rsp,%r12,8), %rdi
movsd 0x38(%rsp), %xmm0
divsd 0x30(%rsp), %xmm0
movq %r13, %rsi
movb $0x1, %al
callq 0x42e0
incq %r12
addq $0x4, %r14
cmpq %r12, %rbx
jne 0x75b77
movq 0x18(%rsp), %r14
movq (%r14), %rdi
movq 0x10(%rsp), %rsi
callq 0x31345
movq %rax, (%r14)
movq 0x8(%rsp), %rsi
movq %r14, %rdi
callq 0x30648
xorl %eax, %eax
movq %rax, 0x10(%rsp)
movq %rax, 0x8(%rsp)
movq 0x50(%rsp), %r12
leal 0x1(%r12), %r15d
cmpl $0x5, %r15d
je 0x75c80
movq %r14, %rdi
leaq 0x10(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movl $0x2, %ecx
callq 0x31019
movq 0x10(%rsp), %rdi
callq 0x30309
movl %eax, %r14d
movq 0x8(%rsp), %rdi
callq 0x30309
cmpl $0x2, %r14d
jl 0x75c48
cmpl $0x2, %eax
jge 0x75ad9
cmpl $0x4, %r12d
setae %r15b
movl 0x24(%rsp), %r12d
movq 0x18(%rsp), %r13
movq 0x40(%rsp), %rbp
movq (%r13), %rdi
movq 0x10(%rsp), %rsi
callq 0x31345
movq %rax, (%r13)
movq 0x8(%rsp), %rsi
movq %r13, %rdi
callq 0x30648
jmp 0x75c8d
movb $0x1, %r15b
movl 0x24(%rsp), %r12d
movq 0x40(%rsp), %rbp
cmpb $0x0, (%rsp)
movq 0x48(%rsp), %r13
je 0x75cad
xorl %r14d, %r14d
movq 0x60(%rsp,%r14,8), %rdi
callq 0x42a0
incq %r14
cmpq %r14, %rbx
jne 0x75c9b
testb %r15b, %r15b
je 0x75d73
movq %rbp, %r15
leaq 0x347e1(%rip), %rdi     # 0xaa4a1
callq 0x54afc
movl %eax, %ebp
subq $0x8, %rsp
movl $0x3, %ebx
movl %eax, %edi
movl $0x9, %esi
movl $0x3, %edx
movl $0xa, %ecx
movl $0xc, %r8d
movl $0xf, %r9d
xorl %eax, %eax
pushq $0x13
pushq $0x7
pushq $0x6
pushq $0xe
pushq $0x10
callq 0x3aa8c
addq $0x30, %rsp
testl %eax, %eax
cmovel %ebx, %ebp
subq $0x8, %rsp
leaq 0x7a1a8(%rsp), %rcx
leaq 0x64(%rsp), %r8
leaq 0x60(%rsp), %r9
movq 0x30(%rsp), %rbx
movq %rbx, %rdi
movl %r12d, %esi
movl %ebp, %edx
pushq %r13
callq 0x8ec4a
addq $0x10, %rsp
movq %rax, %r14
movl (%rax), %eax
decl %eax
cmpl $0x2, %eax
ja 0x75d5e
movl %eax, %eax
leaq 0x39e06(%rip), %rcx     # 0xafb50
movl (%rcx,%rax,4), %edx
movq %r15, %rdi
movq 0x18(%rsp), %rsi
movl 0x4(%rsp), %ecx
callq 0x7580d
movq %r14, %rdi
callq 0x3a180
movq %rbx, %rdi
movl %r12d, %esi
callq 0x3a14b
jmp 0x75d93
movq 0x28(%rsp), %rdi
movl %r12d, %esi
callq 0x3a14b
movq %rbp, %rdi
movq 0x18(%rsp), %rsi
xorl %edx, %edx
movl 0x4(%rsp), %ecx
callq 0x7580d
addq $0x16e3e8, %rsp         # imm = 0x16E3E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq