// File: /workspace/github_c_makefile_star2_O1/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, 0x20(%rsp)
movq %rdi, %r13
movl %ecx, 0x14(%rsp)
imull %edx, %ecx
movl %ecx, 0x2c(%rsp)
movslq %ecx, %r14
leaq (,%r14,8), %rdi
leaq 0x5e39e(%rip), %rbx     # 0xa7581
movq %rbx, %rsi
movl $0x5, %edx
callq 0x390f5
movq %rax, 0x50(%rsp)
shlq $0x2, %r14
leaq (%r14,%r14,4), %rdi
movq %rbx, %rsi
movl $0x6, %edx
callq 0x390f5
movq %rax, 0x48(%rsp)
movl %ebp, 0x10(%rsp)
testl %ebp, %ebp
movq %r13, 0x58(%rsp)
jle 0x49300
movq 0x48(%rsp), %rax
addq $0x8, %rax
movq %rax, 0xa0(%rsp)
movl 0x14(%rsp), %r9d
movl $0x1, %r8d
leaq 0x5e191(%rip), %rsi     # 0xa73d4
xorl %ecx, %ecx
movq %r9, 0x38(%rsp)
cmpl $0x0, 0x14(%rsp)
jle 0x492ee
movl %ecx, 0x30(%rsp)
movslq %ecx, %rax
movq 0x50(%rsp), %rcx
leaq (%rcx,%rax,8), %rcx
movq %rcx, 0x18(%rsp)
leaq (%rax,%rax,4), %rcx
movq 0xa0(%rsp), %rdx
leaq (%rdx,%rcx,4), %rbx
movl %eax, %eax
movq %rax, 0x40(%rsp)
xorl %r15d, %r15d
movq %r15, %rbp
incq %r15
leaq 0xd0(%rsp), %r14
movq %r14, %rdi
movq 0x20(%rsp), %rdx
movl %r15d, %ecx
movq %r8, %r13
xorl %eax, %eax
callq 0x41b0
movq 0x18(%rsp), %r12
movq (%r12,%rbp,8), %rdi
movq %r14, %rsi
callq 0x3a404
movq %r13, %r8
leaq 0x5e112(%rip), %rsi     # 0xa73d4
movq 0x38(%rsp), %r9
movq %rax, (%r12,%rbp,8)
movl %r8d, -0x8(%rbx)
movl %r15d, -0x4(%rbx)
addl 0x40(%rsp), %ebp
movl %ebp, (%rbx)
addq $0x14, %rbx
cmpl %r15d, %r9d
jne 0x49284
movl 0x30(%rsp), %ecx
addl %r15d, %ecx
movq 0x58(%rsp), %r13
leal 0x1(%r8), %eax
cmpl 0x10(%rsp), %r8d
movl %eax, %r8d
jne 0x4924a
leaq 0xf4510(%rsp), %rbx
movw $0x2d, (%rbx)
leaq 0x5e0ed(%rip), %rdi     # 0xa7401
callq 0x535f7
movl %eax, %ebp
leaq 0x59616(%rip), %rdi     # 0xa2938
callq 0x535f7
movl %eax, (%rsp)
leaq 0xac(%rsp), %r8
leaq 0xa8(%rsp), %r9
movq 0x50(%rsp), %r15
movq %r15, %rdi
movl 0x2c(%rsp), %r14d
movl %r14d, %esi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x8c4bc
movq %rax, 0x30(%rsp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x3915f
leaq 0x60(%rsp), %r15
leaq 0x7a3f0(%rsp), %rbx
leaq 0x2d0(%rsp), %r14
xorl %r12d, %r12d
cmpl $0x4, %r12d
ja 0x493fd
movl %r12d, %eax
leaq 0x5dfe0(%rip), %rcx     # 0xa736c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x20(%rsp), %rsi
jmpq *%rax
movq %r13, %rdi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
movq %r15, %r8
callq 0x47812
jmp 0x493fd
movq %r13, %rdi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
movq %r15, %r8
movl $0x1, %r9d
jmp 0x493e7
movq %r13, %rdi
movl 0x10(%rsp), %edx
movq %r15, %rcx
callq 0x489de
jmp 0x493fd
movq %r13, %rdi
movl 0x10(%rsp), %edx
movl 0x14(%rsp), %ecx
movq %r15, %r8
xorl %r9d, %r9d
callq 0x48144
jmp 0x493fd
movq %r13, %rdi
movl 0x10(%rsp), %edx
movq %r15, %rcx
callq 0x487e3
movl 0x8(%r13), %edx
incl %edx
movq 0x30(%rsp), %rdi
movl 0x2c(%rsp), %esi
callq 0x379c4
movl %eax, 0x80(%rsp,%r12,4)
leaq 0x1(%r12), %rbp
movq %rbx, %rdi
leaq 0x5dfa2(%rip), %rsi     # 0xa73ca
movl %ebp, %edx
xorl %eax, %eax
callq 0x41b0
movl 0x80(%rsp,%r12,4), %edx
movq %r14, %rdi
leaq 0x6471a(%rip), %rsi     # 0xadb5d
xorl %eax, %eax
callq 0x41b0
movq %rbx, %rdi
movq %r14, %rsi
callq 0x32e47
leal -0x1(%rbp), %eax
movl %eax, 0xb0(%rsp,%r12,4)
addq $0x4, %r15
movq %rbp, %r12
cmpq $0x5, %rbp
jne 0x4937c
leaq 0xb4(%rsp), %r12
movl $0x4, %eax
movq %rax, 0x40(%rsp)
movq $0x0, 0x38(%rsp)
xorl %eax, %eax
movq %rax, 0x18(%rsp)
cmpq $0x3, %rax
ja 0x49549
movq 0x18(%rsp), %rax
leaq (%rsp,%rax,4), %rbx
addq $0x80, %rbx
leaq (%rsp,%rax,4), %r14
addq $0x60, %r14
leaq (%rsp,%rax,4), %r15
addq $0xb0, %r15
movq 0x40(%rsp), %rbp
movq 0x38(%rsp), %r13
leaq 0x84(%rsp), %rax
leaq (%rax,%r13), %rsi
movl 0x84(%rsp,%r13), %eax
cmpl %eax, (%rbx)
jle 0x49509
movq %rbx, %rdi
callq 0x395a3
leaq (%r12,%r13), %rsi
movq %r15, %rdi
callq 0x395a3
leaq 0x64(%rsp), %rax
leaq (%rax,%r13), %rsi
movq %r14, %rdi
callq 0x395a3
jmp 0x49540
jne 0x49540
movl (%r14), %eax
cmpl 0x64(%rsp,%r13), %eax
jle 0x49540
leaq 0x64(%rsp), %rax
addq %r13, %rax
movq %rax, 0x20(%rsp)
movq %rbx, %rdi
callq 0x395a3
leaq (%r12,%r13), %rsi
movq %r15, %rdi
callq 0x395a3
movq %r14, %rdi
movq 0x20(%rsp), %rsi
jmp 0x49502
addq $0x4, %r13
decq %rbp
jne 0x494ca
movq 0x18(%rsp), %rax
incq %rax
addq $0x4, 0x38(%rsp)
decq 0x40(%rsp)
cmpq $0x5, %rax
jne 0x4948e
leaq 0x5d036(%rip), %r15     # 0xa65a3
xorl %eax, %eax
leal 0x1(%rax), %edx
movslq %eax, %rcx
cmpl $0x3, %eax
jg 0x495b2
movq %rcx, %rbx
movl 0x80(%rsp,%rbx,4), %edi
cmpl 0x84(%rsp,%rbx,4), %edi
jne 0x495b4
movl 0x60(%rsp,%rbx,4), %edi
cmpl 0x64(%rsp,%rbx,4), %edi
jne 0x495b4
addl %ebx, %edx
addl $0x2, %edx
movq %rbx, %rdi
incq %rdi
movq %rdi, %rbx
cmpq $0x4, %rdi
jne 0x4957d
movl $0x4, %ebx
jmp 0x495b4
movl %eax, %ebx
movl %ebx, %ebp
subl %eax, %ebp
leaq 0x7a3f0(%rsp), %r13
jl 0x49640
xorps %xmm1, %xmm1
cvtsi2sd %edx, %xmm1
xorps %xmm0, %xmm0
cvtsi2sd %ebp, %xmm0
addsd 0x58f48(%rip), %xmm0    # 0xa2520
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
leaq (%rsp,%rcx,4), %rax
addq $0xb0, %rax
movq %rax, 0x18(%rsp)
incl %ebp
xorl %r12d, %r12d
movq 0x18(%rsp), %rax
movl (%rax,%r12,4), %edx
incl %edx
movq %r13, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x41b0
leaq 0x2d0(%rsp), %r14
movq %r14, %rdi
leaq 0x5b85f(%rip), %rsi     # 0xa4e7f
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x41b0
movq %r13, %rdi
movq %r14, %rsi
callq 0x32e47
incq %r12
cmpl %r12d, %ebp
jne 0x495f6
leal 0x1(%rbx), %eax
cmpl $0x4, %ebx
jl 0x4956f
movq 0x30(%rsp), %rax
movslq (%rax), %rax
leaq (%rax,%rax,4), %rax
movq 0x48(%rsp), %rdi
movl -0x4(%rdi,%rax,4), %ecx
movq 0x58(%rsp), %rbx
movl %ecx, 0x10(%rbx)
movups -0x14(%rdi,%rax,4), %xmm0
movups %xmm0, (%rbx)
callq 0x39194
movq %rbx, %rax
addq $0x16e638, %rsp         # imm = 0x16E638
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop