// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/omnivariatetree.c
// Function: find_best_hybrid_ldt_split_crossvalidation
int find_best_hybrid_ldt_split_crossvalidation(Decisionnodeptr node, Multildt_parameterptr param)
{
 /*!Last Changed 22.11.2004*/
 int hybridspace = get_parameter_i("hybridspace");
 FILE* errorfiles[3];
 int i, j, k, datasize, trainsize, testsize, error, bestmodel = 0, *models, dummy, dummy2, testtype;
 Instanceptr train = NULL, test = NULL, traindata, testdata;
 char **files, st[READLINELENGTH] = "-", pst[READLINELENGTH], buffer[READLINELENGTH];
 files = safemalloc(hybridspace * sizeof(char *), "find_best_hybrid_ldt_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 (j = 0; j < 2; j++)
    {
     if (j == 0)
      {
       traindata = train;
       testdata = test;
       datasize = testsize;
      }
     else
      {
       traindata = test;
       testdata = train;
       datasize = trainsize;
      }
     for (k = 0; k < hybridspace; k++)
      {
       switch (k)
        {
         case MODEL_UNI:error = find_error_and_free_matrix(&traindata, testdata, UNIVARIATE, param->variance_explained);
                        break;
         case MODEL_LIN:error = find_error_and_free_matrix(&traindata, testdata, LINEAR, param->variance_explained);
                        break;
         case MODEL_QUA:error = find_error_and_free_matrix(&traindata, testdata, QUADRATIC, param->variance_explained);
                        break;
        }
       set_precision(pst, NULL, "\n");
       fprintf(errorfiles[k], pst, error / (datasize + 0.0));
      }
    }
   node->instances = restore_instancelist(node->instances, testdata);
   merge_instancelist(&(node->instances), traindata); 
   train = NULL;
   test = NULL;
  }
 for (i = 0; i < hybridspace; i++)
   fclose(errorfiles[i]);
 if (bestmodel)
  {
   free_2d((void**)files, hybridspace);
   node->featureno = find_best_ldt_feature_for_realized(node->instances, &(node->split));
   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:node->featureno = find_best_ldt_feature_for_realized(node->instances, &(node->split));
          break;
   case 2:node->lineard = find_best_multi_ldt_split(&(node->instances), &(node->w), &(node->w0), MULTIVARIATE_LINEAR, param->variance_explained);
          if (!node->lineard)
           {
            matrix_free(node->w);
            node->featureno = LEAF_NODE;
           }
          else
            node->featureno = LINEAR;
          break;
   case 3:node->quadraticd = find_best_multi_ldt_split(&(node->instances), &(node->w), &(node->w0), MULTIVARIATE_QUADRATIC, param->variance_explained);
          if (!node->quadraticd)
           {
            matrix_free(node->w);
            node->featureno = LEAF_NODE;
           }
          else
            node->featureno = QUADRATIC;
          break;
  }
 safe_free(models);
 free_2d((void**)files, hybridspace);
 return 1;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x16e450, %rsp         # imm = 0x16E450
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
leaq 0x6e026(%rip), %rdi     # 0xe57d0
callq 0x78f10
movl %eax, -0x1c(%rbp)
movl $0x0, -0x60(%rbp)
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
leaq -0x7a1c0(%rbp), %rdi
xorl %esi, %esi
movl $0x7a120, %edx          # imm = 0x7A120
callq 0x4050
movb $0x2d, -0x7a1c0(%rbp)
movslq -0x1c(%rbp), %rdi
shlq $0x3, %rdi
leaq 0x6fc54(%rip), %rsi     # 0xe7449
movl $0x5, %edx
callq 0x52d70
movq %rax, -0xa0(%rbp)
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e410(%rbp)
leaq 0x6f761(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e410(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x6fc37(%rip), %rsi     # 0xe7474
callq 0x41a0
movq -0xa0(%rbp), %rax
movq (%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, (%rax)
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e408(%rbp)
leaq 0x6f702(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e408(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x6fbe8(%rip), %rsi     # 0xe7484
callq 0x41a0
movq -0xa0(%rbp), %rax
movq 0x8(%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x8(%rax)
cmpl $0x3, -0x1c(%rbp)
jne 0x7792d
leaq -0x16e400(%rbp), %rax
movq %rax, -0x16e418(%rbp)
leaq 0x6f69b(%rip), %rdi     # 0xe6f7c
callq 0x79190
movq -0x16e418(%rbp), %rdi
movq %rax, %rsi
callq 0x4220
leaq -0x16e400(%rbp), %rdi
leaq 0x6fb8d(%rip), %rsi     # 0xe7490
callq 0x41a0
movq -0xa0(%rbp), %rax
movq 0x10(%rax), %rdi
leaq -0x16e400(%rbp), %rsi
callq 0x54ba0
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, 0x10(%rax)
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x77988
movq -0xa0(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x7086c(%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 0x7797b
movl $0x0, -0x4(%rbp)
jmp 0x77e61
jmp 0x7797d
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x77934
movl $0x0, -0x44(%rbp)
cmpl $0x5, -0x44(%rbp)
jge 0x77bce
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
leaq -0x80(%rbp), %rsi
leaq -0x88(%rbp), %rdx
movl $0x2, %ecx
callq 0x45f60
movq -0x80(%rbp), %rdi
callq 0x449f0
movl %eax, -0x54(%rbp)
movq -0x88(%rbp), %rdi
callq 0x449f0
movl %eax, -0x58(%rbp)
cmpl $0x1, -0x54(%rbp)
jle 0x779dd
cmpl $0x1, -0x58(%rbp)
jg 0x77a19
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x80(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x88(%rbp), %rsi
callq 0x44f40
movl $0x1, -0x60(%rbp)
jmp 0x77bce
movl $0x0, -0x48(%rbp)
cmpl $0x2, -0x48(%rbp)
jge 0x77b7a
cmpl $0x0, -0x48(%rbp)
jne 0x77a51
movq -0x80(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x88(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x58(%rbp), %eax
movl %eax, -0x50(%rbp)
jmp 0x77a70
movq -0x88(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x80(%rbp), %rax
movq %rax, -0x98(%rbp)
movl -0x54(%rbp), %eax
movl %eax, -0x50(%rbp)
movl $0x0, -0x4c(%rbp)
movl -0x4c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x77b6a
movl -0x4c(%rbp), %eax
movl %eax, -0x16e41c(%rbp)
testl %eax, %eax
je 0x77aac
jmp 0x77a92
movl -0x16e41c(%rbp), %eax
subl $0x1, %eax
je 0x77acf
jmp 0x77a9f
movl -0x16e41c(%rbp), %eax
subl $0x2, %eax
je 0x77af5
jmp 0x77b19
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
leaq -0x90(%rbp), %rdi
xorl %edx, %edx
callq 0x77e70
movl %eax, -0x5c(%rbp)
jmp 0x77b19
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
leaq -0x90(%rbp), %rdi
movl $0xfffffffe, %edx       # imm = 0xFFFFFFFE
callq 0x77e70
movl %eax, -0x5c(%rbp)
jmp 0x77b19
movq -0x98(%rbp), %rsi
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
leaq -0x90(%rbp), %rdi
movl $0xfffffffd, %edx       # imm = 0xFFFFFFFD
callq 0x77e70
movl %eax, -0x5c(%rbp)
leaq -0xf42e0(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
leaq 0x6e210(%rip), %rdx     # 0xe5d3b
callq 0x53310
movslq -0x4c(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
leaq -0xf42e0(%rbp), %rsi
cvtsi2sdl -0x5c(%rbp), %xmm0
cvtsi2sdl -0x50(%rbp), %xmm1
xorps %xmm2, %xmm2
addsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movb $0x1, %al
callq 0x4280
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x77a77
jmp 0x77b6c
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0x77a20
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x98(%rbp), %rsi
callq 0x464e0
movq %rax, %rcx
movq -0x10(%rbp), %rax
movq %rcx, 0x20(%rax)
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x90(%rbp), %rsi
callq 0x44f40
movq $0x0, -0x80(%rbp)
movq $0x0, -0x88(%rbp)
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x7798f
movl $0x0, -0x44(%rbp)
movl -0x44(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x77bf6
movslq -0x44(%rbp), %rax
movq -0x40(%rbp,%rax,8), %rdi
callq 0x4250
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x77bd5
cmpl $0x0, -0x60(%rbp)
je 0x77c4b
movq -0xa0(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0xdec70
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x30(%rax)
jne 0x77c3f
movl $0x0, -0x4(%rbp)
jmp 0x77e61
movl $0x1, -0x4(%rbp)
jmp 0x77e61
leaq 0x6f36f(%rip), %rdi     # 0xe6fc1
callq 0x792b0
movl %eax, -0x74(%rbp)
movl -0x74(%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 0x77cdc
movq -0xa0(%rbp), %rdi
movl -0x1c(%rbp), %esi
movl -0x74(%rbp), %edx
leaq -0x7a1c0(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
leaq -0x6c(%rbp), %r8
leaq -0x70(%rbp), %r9
movl %eax, (%rsp)
callq 0xc3c40
movq %rax, -0x68(%rbp)
jmp 0x77d0d
movq -0xa0(%rbp), %rdi
movl -0x1c(%rbp), %esi
leaq -0x7a1c0(%rbp), %rcx
movq -0x18(%rbp), %rax
movl 0x28(%rax), %eax
movl $0x3, %edx
leaq -0x6c(%rbp), %r8
leaq -0x70(%rbp), %r9
movl %eax, (%rsp)
callq 0xc3c40
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rax
movl (%rax), %eax
movl %eax, -0x16e420(%rbp)
subl $0x1, %eax
je 0x77d41
jmp 0x77d20
movl -0x16e420(%rbp), %eax
subl $0x2, %eax
je 0x77d64
jmp 0x77d2d
movl -0x16e420(%rbp), %eax
subl $0x3, %eax
je 0x77dd3
jmp 0x77e42
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rdi
movq -0x10(%rbp), %rsi
addq $0x28, %rsi
callq 0xdec70
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x30(%rax)
jmp 0x77e42
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
movq -0x10(%rbp), %rdx
addq $0x48, %rdx
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
movl $0xfffffffe, %ecx       # imm = 0xFFFFFFFE
callq 0x6fd20
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x90(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x90(%rax)
jne 0x77dc6
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rax), %rsi
callq 0x59ea0
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x30(%rax) # imm = 0xFFFFFFFF
jmp 0x77dd1
movq -0x10(%rbp), %rax
movl $0xfffffffe, 0x30(%rax) # imm = 0xFFFFFFFE
jmp 0x77e42
movq -0x10(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rsi
addq $0x38, %rsi
movq -0x10(%rbp), %rdx
addq $0x48, %rdx
movq -0x18(%rbp), %rax
movsd 0x20(%rax), %xmm0
movl $0xfffffffd, %ecx       # imm = 0xFFFFFFFD
callq 0x6fd20
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x94(%rax)
movq -0x10(%rbp), %rax
cmpl $0x0, 0x94(%rax)
jne 0x77e35
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rdi
movq 0x40(%rax), %rsi
callq 0x59ea0
movq -0x10(%rbp), %rax
movl $0xffffffff, 0x30(%rax) # imm = 0xFFFFFFFF
jmp 0x77e40
movq -0x10(%rbp), %rax
movl $0xfffffffd, 0x30(%rax) # imm = 0xFFFFFFFD
jmp 0x77e42
movq -0x68(%rbp), %rdi
callq 0x52e80
movq -0xa0(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x52e20
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x16e450, %rsp         # imm = 0x16E450
popq %rbp
retq
nopl (%rax)