// File: /workspace/github_c_makefile_star2_O3/olcaytaner[P]Isell/model.c
// Function: compare_hmm_model_selection_techniques
Hmm_model compare_hmm_model_selection_techniques(char* simulationdirectory, int maxstates, int maxmixture)
{
 /*!Last Changed 12.04.2009*/
 char** filenames, filename[500], tmpst[READLINELENGTH], varname[MAXLENGTH], varvalue[MAXLENGTH];
 int* model, dummy, dummy2, i, j, k, selectedmodels[MAX_MLP_SIMULATION_ALGORITHMS], modelcount, tries[MAX_MLP_SIMULATION_ALGORITHMS], indexes[MAX_MLP_SIMULATION_ALGORITHMS], sum;
 Hmm_model bestmodel, *models;
 modelcount = maxstates * maxmixture;
 filenames = safemalloc(modelcount * sizeof(char *), "compare_hmm_model_selection_techniques", 5);
 models = safemalloc(modelcount * sizeof(Hmm_model), "compare_hmm_model_selection_techniques", 6);
 k = 0;
 for (i = 1; i <= maxstates; i++)
   for (j = 1; j <= maxmixture; j++)
    {
     sprintf(filename, "%s/%dM%dS.txt", simulationdirectory, j, i);
     filenames[k] = strcopy(filenames[k], filename);
     models[k].states = i;
     models[k].mixture = j;
     models[k].index = k;     
     k++;
    }
 strcpy(tmpst, "-");
 model = multiple_comparison(filenames, modelcount, get_parameter_l("testtype"), tmpst, &dummy, &dummy2, get_parameter_l("correctiontype"));
 free_2d((void**)filenames, modelcount);
 for (i = 0; i < MAX_MLP_SIMULATION_ALGORITHMS; i++)
  {
   switch (i)
    {
     case MULTIMOST    :bestmodel = hmm_model_simulation_multitest(simulationdirectory, maxstates, maxmixture, &(tries[i]));
                        break;
     case ONE_FORWARD  :bestmodel = hmm_model_simulation_one_forward(simulationdirectory, maxstates, &(tries[i]));
                        break;
     case ONE_BACKWARD :bestmodel = hmm_model_simulation_one_backward(simulationdirectory, maxstates, &(tries[i]));
                        break;
     case FORWARD_MOST :bestmodel = hmm_model_simulation_most(simulationdirectory, maxstates, maxmixture, &(tries[i]), FORWARD);
                        break;
     case BACKWARD_MOST:bestmodel = hmm_model_simulation_most(simulationdirectory, maxstates, maxmixture, &(tries[i]), BACKWARD);
                        break;
    }
   selectedmodels[i] = search_list(model, modelcount, bestmodel.index + 1);
   sprintf(varname, "aout2[%d]", i + 1);
   sprintf(varvalue, "%d", selectedmodels[i]);
   set_variable(varname, varvalue);
   indexes[i] = i;
  }
 for (i = 0; i < MAX_MLP_SIMULATION_ALGORITHMS; i++)
   for (j = i + 1; j < MAX_MLP_SIMULATION_ALGORITHMS; j++)
     if (selectedmodels[i] > selectedmodels[j])
      {
       swap_int(&(selectedmodels[i]), &(selectedmodels[j]));
       swap_int(&(indexes[i]), &(indexes[j]));
       swap_int(&(tries[i]), &(tries[j]));
      }
     else
       if (selectedmodels[i] == selectedmodels[j] && tries[i] > tries[j])
        {
         swap_int(&(selectedmodels[i]), &(selectedmodels[j]));
         swap_int(&(indexes[i]), &(indexes[j]));
         swap_int(&(tries[i]), &(tries[j]));
        }
 i = 0;
 while (i < MAX_MLP_SIMULATION_ALGORITHMS)
  {
   j = i;
   sum = j + 1;
   while (j < MAX_MLP_SIMULATION_ALGORITHMS - 1 && selectedmodels[j] == selectedmodels[j + 1] && tries[j] == tries[j + 1])
    {
     j++;
     sum = sum + j + 1;
    }
   for (k = i; k <= j; k++)
    {
     sprintf(varname, "aout1[%d]", indexes[k] + 1);
     sprintf(varvalue, "%.1f", sum / (j - i + 1.0));
     set_variable(varname, varvalue);
    }
   i = j + 1;
  }
 bestmodel = models[model[0] - 1];
 safe_free(models);
 return bestmodel;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x16e638, %rsp         # imm = 0x16E638
movl %edx, %ebp
movq %rsi, 0x18(%rsp)
movq %rdi, %r12
movl %ecx, 0xc(%rsp)
imull %edx, %ecx
movl %ecx, 0x3c(%rsp)
movslq %ecx, %r14
leaq (,%r14,8), %rdi
leaq 0x60033(%rip), %rbx     # 0xaa621
movq %rbx, %rsi
movl $0x5, %edx
callq 0x3a0e1
movq %rax, 0x58(%rsp)
shlq $0x2, %r14
leaq (%r14,%r14,4), %rdi
movq %rbx, %rsi
movl $0x6, %edx
callq 0x3a0e1
movq %rax, 0x50(%rsp)
movl %ebp, 0x10(%rsp)
testl %ebp, %ebp
movq %r12, 0x48(%rsp)
jle 0x4a708
movq 0x50(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xc0(%rsp)
movl 0xc(%rsp), %r9d
movl $0x1, %r13d
leaq 0x5fe26(%rip), %rsi     # 0xaa474
xorl %ecx, %ecx
movq %r9, 0x20(%rsp)
cmpl $0x0, 0xc(%rsp)
jle 0x4a6f6
movl %ecx, 0x40(%rsp)
movslq %ecx, %rax
movq 0x58(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, 0x30(%rsp)
leaq (%rax,%rax,4), %rcx
movq 0xc0(%rsp), %rdx
leaq (%rdx,%rcx,4), %rbx
movl %eax, %eax
movq %rax, 0x28(%rsp)
xorl %r15d, %r15d
movq %r15, %rbp
incq %r15
leaq 0xd0(%rsp), %r12
movq %r12, %rdi
movq 0x18(%rsp), %rdx
movl %r15d, %ecx
movl %r13d, %r8d
xorl %eax, %eax
callq 0x41b0
movq 0x30(%rsp), %r14
movq (%r14,%rbp,8), %rdi
movq %r12, %rsi
callq 0x3b494
leaq 0x5fdaa(%rip), %rsi     # 0xaa474
movq 0x20(%rsp), %r9
movq %rax, (%r14,%rbp,8)
movl %r13d, -0x8(%rbx)
movl %r15d, -0x4(%rbx)
addl 0x28(%rsp), %ebp
movl %ebp, (%rbx)
addq $0x14, %rbx
cmpl %r15d, %r9d
jne 0x4a68f
movl 0x40(%rsp), %ecx
addl %r15d, %ecx
movq 0x48(%rsp), %r12
leal 0x1(%r13), %eax
cmpl 0x10(%rsp), %r13d
movl %eax, %r13d
jne 0x4a655
leaq 0xf4510(%rsp), %rbx
movw $0x2d, (%rbx)
leaq 0x5fd85(%rip), %rdi     # 0xaa4a1
callq 0x54afc
movl %eax, %ebp
leaq 0x5b20e(%rip), %rdi     # 0xa5938
callq 0x54afc
movl %eax, (%rsp)
leaq 0xcc(%rsp), %r8
leaq 0xc8(%rsp), %r9
movq 0x58(%rsp), %r15
movq %r15, %rdi
movl 0x3c(%rsp), %r14d
movl %r14d, %esi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x8ec4a
movq %rax, 0x40(%rsp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x3a14b
leaq 0x60(%rsp), %r15
xorl %ebx, %ebx
movl %ebx, %eax
leaq 0x5fc90(%rip), %rcx     # 0xaa40c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x18(%rsp), %rsi
jmpq *%rax
movq %r12, %rdi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %r15, %r8
callq 0x48bba
jmp 0x4a7ed
movq %r12, %rdi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %r15, %r8
movl $0x1, %r9d
jmp 0x4a7d7
movq %r12, %rdi
movl 0x10(%rsp), %edx
movq %r15, %rcx
callq 0x49dba
jmp 0x4a7ed
movq %r12, %rdi
movl 0x10(%rsp), %edx
movl 0xc(%rsp), %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x4951c
jmp 0x4a7ed
movq %r12, %rdi
movl 0x10(%rsp), %edx
movq %r15, %rcx
callq 0x49bbd
movl 0x8(%r12), %edx
incl %edx
movq 0x40(%rsp), %rdi
movl 0x3c(%rsp), %esi
callq 0x384d0
movl %eax, %ebp
movl %eax, 0x80(%rsp,%rbx,4)
leaq 0x1(%rbx), %r12
leaq 0x7a3f0(%rsp), %r14
movq %r14, %rdi
leaq 0x5fc49(%rip), %rsi     # 0xaa46a
movl %r12d, %edx
xorl %eax, %eax
callq 0x41b0
leaq 0x2d0(%rsp), %r13
movq %r13, %rdi
leaq 0x663b8(%rip), %rsi     # 0xb0bf5
movl %ebp, %edx
xorl %eax, %eax
callq 0x41b0
movq %r14, %rdi
movq %r13, %rsi
callq 0x33827
leal -0x1(%r12), %eax
movl %eax, 0xa0(%rsp,%rbx,4)
addq $0x4, %r15
movq %r12, %rbx
cmpq $0x5, %r12
movq 0x48(%rsp), %r12
jne 0x4a773
movl $0x1, %eax
movq %rax, 0x28(%rsp)
movl $0x4, %eax
movq %rax, 0x20(%rsp)
movq $0x0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x30(%rsp)
cmpq $0x3, %rax
ja 0x4a962
movq 0x30(%rsp), %rax
leaq (%rsp,%rax,4), %rbx
addq $0x80, %rbx
leaq 0x60(%rsp,%rax,4), %r14
leaq 0xa0(%rsp,%rax,4), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rbp
movq 0x10(%rsp), %r13
movq 0x28(%rsp), %r15
leaq 0x84(%rsp), %rax
leaq (%rax,%r13), %rsi
movl 0x84(%rsp,%r13), %eax
cmpl %eax, (%rbx)
jle 0x4a91d
movq %rbx, %rdi
callq 0x3a5af
leaq 0xa4(%rsp), %rax
leaq (%rax,%r13), %rsi
movq 0x18(%rsp), %rdi
callq 0x3a5af
leaq (%rsp,%r15,4), %r12
addq $0x60, %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x3a5af
jmp 0x4a952
jne 0x4a952
movl (%r14), %eax
cmpl 0x64(%rsp,%r13), %eax
jle 0x4a952
leaq 0x64(%rsp), %rax
leaq (%rax,%r13), %r12
movq %rbx, %rdi
callq 0x3a5af
leaq 0xa4(%rsp), %rax
leaq (%rax,%r13), %rsi
movq 0x18(%rsp), %rdi
callq 0x3a5af
jmp 0x4a910
incq %r15
addq $0x4, %r13
decq %rbp
jne 0x4a8d2
movq 0x30(%rsp), %rax
incq %rax
incq 0x28(%rsp)
addq $0x4, 0x10(%rsp)
decq 0x20(%rsp)
cmpq $0x5, %rax
jne 0x4a892
leaq 0x5ec46(%rip), %r15     # 0xa95d1
leaq 0x7a3f0(%rsp), %r13
leaq 0x5d53d(%rip), %rbp     # 0xa7ed7
leaq 0x2d0(%rsp), %r14
xorl %eax, %eax
leal 0x1(%rax), %edx
movslq %eax, %rcx
cmpl $0x3, %eax
jg 0x4a9e9
movl 0x80(%rsp,%rcx,4), %r8d
movq %rcx, %rbx
cmpl 0x84(%rsp,%rbx,4), %r8d
jne 0x4a9eb
movl 0x60(%rsp,%rbx,4), %edi
cmpl 0x64(%rsp,%rbx,4), %edi
jne 0x4a9eb
addl %ebx, %edx
addl $0x2, %edx
movq %rbx, %rdi
incq %rdi
movq %rdi, %rbx
cmpq $0x4, %rdi
jne 0x4a9ba
movl $0x4, %ebx
jmp 0x4a9eb
movl %eax, %ebx
movl %ebx, %edi
subl %eax, %edi
jge 0x4a9f9
leal 0x1(%rbx), %eax
jmp 0x4aa7d
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
addsd 0x5ab11(%rip), %xmm0    # 0xa5520
divsd %xmm0, %xmm1
movsd %xmm1, 0x18(%rsp)
leal 0x1(%rbx), %edx
leaq 0xa0(%rsp,%rcx,4), %rcx
movq %rcx, 0x30(%rsp)
movl %edx, 0x20(%rsp)
movl %edx, %ecx
subl %eax, %ecx
movq %rcx, 0x28(%rsp)
xorl %r12d, %r12d
movq 0x30(%rsp), %rax
movl (%rax,%r12,4), %edx
incl %edx
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41b0
movq %r14, %rdi
movq %rbp, %rsi
movsd 0x18(%rsp), %xmm0
movb $0x1, %al
callq 0x41b0
movq %r13, %rdi
movq %r14, %rsi
callq 0x33827
incq %r12
cmpl %r12d, 0x28(%rsp)
jne 0x4aa39
movl 0x20(%rsp), %eax
cmpl $0x4, %ebx
jl 0x4a9a4
movq 0x40(%rsp), %rax
movslq (%rax), %rax
leaq (%rax,%rax,4), %rax
movq 0x50(%rsp), %rdi
movl -0x4(%rdi,%rax,4), %ecx
movq 0x48(%rsp), %rbx
movl %ecx, 0x10(%rbx)
movups -0x14(%rdi,%rax,4), %xmm0
movups %xmm0, (%rbx)
callq 0x3a180
movq %rbx, %rax
addq $0x16e638, %rsp         # imm = 0x16E638
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)