// File: /workspace/github_c_makefile_star2_O2/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 $0x16e648, %rsp         # imm = 0x16E648
movl %ecx, %ebp
movl %edx, %r14d
movq %rsi, 0x18(%rsp)
movq %rdi, 0x58(%rsp)
movl %ecx, %eax
imull %edx, %eax
movl %eax, 0x38(%rsp)
movslq %eax, %rbx
leaq (,%rbx,8), %rdi
leaq 0x56e64(%rip), %r15     # 0x9a551
pushq $0x5
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, 0x50(%rsp)
imulq $0x14, %rbx, %rdi
pushq $0x6
popq %rdx
movq %r15, %rsi
callq 0x34f59
testl %ebp, %ebp
movl $0x0, %ecx
movl %ebp, 0x2c(%rsp)
cmovgl %ebp, %ecx
testl %r14d, %r14d
movl $0x0, %edx
movl %r14d, 0x14(%rsp)
cmovgl %r14d, %edx
incl %edx
movl %edx, 0x30(%rsp)
movq %rax, 0xc0(%rsp)
addq $0x8, %rax
movq %rax, 0xc8(%rsp)
pushq $0x1
popq %r15
movq $0x0, 0x20(%rsp)
movq %rcx, 0xd0(%rsp)
cmpl 0x30(%rsp), %r15d
je 0x43802
movl %ecx, 0x40(%rsp)
movslq %ecx, %rcx
movslq 0x20(%rsp), %rax
subq %rax, %rcx
movq %rcx, 0x48(%rsp)
movq 0x50(%rsp), %rcx
leaq (%rcx,%rax,8), %r12
imulq $0x14, %rax, %rbp
addq 0xc8(%rsp), %rbp
xorl %ebx, %ebx
cmpq %rbx, 0x48(%rsp)
je 0x437e7
leaq 0x1(%rbx), %r14
leaq 0xe0(%rsp), %r13
movq %r13, %rdi
leaq 0x56bf7(%rip), %rsi     # 0x9a3a4
movq 0x18(%rsp), %rdx
movl %r14d, %ecx
movl %r15d, %r8d
xorl %eax, %eax
callq 0x41b0
movq (%r12,%rbx,8), %rdi
movq %r13, %rsi
callq 0x3604c
movq %rax, (%r12,%rbx,8)
movl %r15d, -0x8(%rbp)
movl %r14d, -0x4(%rbp)
addl 0x20(%rsp), %ebx
movl %ebx, (%rbp)
addq $0x14, %rbp
movq %r14, %rbx
jmp 0x43790
incl %r15d
movq 0xd0(%rsp), %rax
movl 0x40(%rsp), %ecx
addl %eax, %ecx
addq %rax, 0x20(%rsp)
jmp 0x4375a
leaq 0xf4520(%rsp), %rbx
movw $0x2d, (%rbx)
leaq 0x56bbb(%rip), %rdi     # 0x9a3d1
callq 0x4cf11
movl %eax, %ebp
leaq 0x52114(%rip), %rdi     # 0x95938
callq 0x4cf11
movl %eax, (%rsp)
leaq 0xdc(%rsp), %r8
leaq 0xd8(%rsp), %r9
movq 0x50(%rsp), %r15
movq %r15, %rdi
movl 0x38(%rsp), %r14d
movl %r14d, %esi
movl %ebp, %edx
movq %rbx, %rcx
callq 0x81133
movq %rax, 0x30(%rsp)
movq %r15, %rdi
movl %r14d, %esi
callq 0x34fc3
leaq 0x2e0(%rsp), %r14
xorl %ebp, %ebp
xorl %r15d, %r15d
cmpq $0x14, %rbp
je 0x4397e
leaq (%rsp,%rbp), %r8
addq $0x60, %r8
movl %r15d, %eax
leaq 0x56aad(%rip), %rcx     # 0x9a33c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
movq 0x58(%rsp), %rbx
jmpq *%rax
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movl 0x2c(%rsp), %ecx
callq 0x41dfc
jmp 0x4390e
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movl 0x2c(%rsp), %ecx
pushq $0x1
popq %r9
jmp 0x438f3
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movq %r8, %rcx
callq 0x42f45
jmp 0x4390e
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movl 0x2c(%rsp), %ecx
xorl %r9d, %r9d
callq 0x426c0
jmp 0x4390e
movq %rbx, %rdi
movq 0x18(%rsp), %rsi
movl 0x14(%rsp), %edx
movq %r8, %rcx
callq 0x42d5d
movl 0x8(%rbx), %edx
incl %edx
movq 0x30(%rsp), %rdi
movl 0x38(%rsp), %esi
callq 0x33b22
movl %eax, %ebx
movl %eax, 0x80(%rsp,%rbp)
movq %r15, %r12
incq %r12
leaq 0x7a400(%rsp), %r13
movq %r13, %rdi
leaq 0x56a58(%rip), %rsi     # 0x9a39a
movl %r12d, %edx
xorl %eax, %eax
callq 0x41b0
movq %r14, %rdi
leaq 0x5d203(%rip), %rsi     # 0xa0b59
movl %ebx, %edx
xorl %eax, %eax
callq 0x41b0
movq %r13, %rdi
movq %r14, %rsi
callq 0x2f4fc
movl %r15d, 0xa0(%rsp,%rbp)
addq $0x4, %rbp
movq %r12, %r15
jmp 0x43873
pushq $0x1
popq %r12
pushq $0x4
popq %rbp
xorl %ebx, %ebx
xorl %eax, %eax
cmpq $0x5, %rax
je 0x43a7f
leaq (%rsp,%rax,4), %r14
addq $0x80, %r14
leaq 0x60(%rsp,%rax,4), %r15
movq %rax, 0x38(%rsp)
leaq 0xa0(%rsp,%rax,4), %rax
movq %rax, 0x20(%rsp)
movq %rbx, 0x40(%rsp)
movq %rbp, 0x18(%rsp)
movq %r12, 0x48(%rsp)
subq $0x1, %rbp
jb 0x43a59
leaq 0x84(%rsp), %rax
leaq (%rax,%rbx), %rsi
movl 0x84(%rsp,%rbx), %eax
cmpl %eax, (%r14)
jle 0x43a19
movq %r14, %rdi
callq 0x3537f
leaq 0xa4(%rsp), %rax
leaq (%rax,%rbx), %rsi
movq 0x20(%rsp), %rdi
callq 0x3537f
leaq (%rsp,%r12,4), %r13
addq $0x60, %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x3537f
jmp 0x43a4d
jne 0x43a4d
movl (%r15), %eax
cmpl 0x64(%rsp,%rbx), %eax
jle 0x43a4d
leaq 0x64(%rsp), %rax
leaq (%rax,%rbx), %r13
movq %r14, %rdi
callq 0x3537f
leaq 0xa4(%rsp), %rax
leaq (%rax,%rbx), %rsi
movq 0x20(%rsp), %rdi
callq 0x3537f
jmp 0x43a0c
incq %r12
addq $0x4, %rbx
jmp 0x439c4
movq 0x38(%rsp), %rax
incq %rax
movq 0x48(%rsp), %r12
incq %r12
movq 0x18(%rsp), %rbp
decq %rbp
movq 0x40(%rsp), %rbx
addq $0x4, %rbx
jmp 0x43989
leaq 0x7a400(%rsp), %r15
leaq 0x543c9(%rip), %r12     # 0x97e57
leaq 0x2e0(%rsp), %r13
xorl %eax, %eax
cmpl $0x4, %eax
jg 0x43b45
movslq %eax, %rbp
movq %rbp, %rbx
movl %eax, %ecx
incl %ecx
cmpq $0x4, %rbx
je 0x43ad4
movl 0x80(%rsp,%rbx,4), %edx
cmpl 0x84(%rsp,%rbx,4), %edx
jne 0x43ad9
movl 0x60(%rsp,%rbx,4), %edx
cmpl 0x64(%rsp,%rbx,4), %edx
jne 0x43ad9
addl %ebx, %ecx
incl %ecx
incq %rbx
jmp 0x43aa9
pushq $0x4
popq %rdx
movl %edx, %ebx
cvtsi2sd %ecx, %xmm1
movl %ebx, %ecx
subl %eax, %ecx
cvtsi2sd %ecx, %xmm0
addsd 0x51a33(%rip), %xmm0    # 0x95520
divsd %xmm0, %xmm1
movsd %xmm1, 0x20(%rsp)
movslq %ebx, %r14
cmpq %r14, %rbp
jg 0x43b3c
movl 0xa0(%rsp,%rbp,4), %edx
incl %edx
movq %r15, %rdi
leaq 0x55a2f(%rip), %rsi     # 0x99541
xorl %eax, %eax
callq 0x41b0
movq %r13, %rdi
movq %r12, %rsi
movsd 0x20(%rsp), %xmm0
movb $0x1, %al
callq 0x41b0
movq %r15, %rdi
movq %r13, %rsi
callq 0x2f4fc
incq %rbp
jmp 0x43afa
incl %ebx
movl %ebx, %eax
jmp 0x43a98
movq 0x30(%rsp), %rax
movslq (%rax), %rax
imulq $0x14, %rax, %rax
movq 0xc0(%rsp), %rdi
movl -0x4(%rdi,%rax), %ecx
movq 0x58(%rsp), %rbx
movl %ecx, 0x10(%rbx)
movups -0x14(%rdi,%rax), %xmm0
movups %xmm0, (%rbx)
callq 0x34ff7
movq %rbx, %rax
addq $0x16e648, %rsp         # imm = 0x16E648
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop