// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/model.c
// Function: hmm_model_simulation_multitest
Hmm_model hmm_model_simulation_multitest(char* simulationdirectory, int maxstates, int maxmixture, int* tries)
{
 /*!Last Changed 10.01.2009*/
 char **filenames, directory[500], tmpst[500];
 int filecount, i, j, k, m, c, *model, *models_searched, current_best_index;
 Hmm_modelptr bestmodel;
 Hmm_modelptr models;
 Hmm_model result;
 models = safemalloc(sizeof(Hmm_model) * maxstates * maxmixture, "hmm_model_simulation_multitest", 4);
 models_searched = safemalloc(sizeof(int) * MAX_MODEL_SEARCH, "hmm_model_simulation_multitest", 4);
 k = 0;
 for (i = 1; i <= maxstates; i++)
   for (j = 1; j <= maxmixture; j++)
    {
     models[k].states = i;
     models[k].mixture = j;
     models[k].index = k;
     models[k].selected = BOOLEAN_FALSE;
     models[k].tried = BOOLEAN_FALSE;
     k++;
    }
 bestmodel = &(models[0]);
 bestmodel->selected = BOOLEAN_TRUE;
 filenames = (char **) safemalloc_2d(sizeof(char *), sizeof(char), MAX_MODEL_SEARCH, 500, "hmm_model_simulation_multitest", 3);
 sprintf(directory,"%s", simulationdirectory);
 while (BOOLEAN_TRUE)
  {
   filecount = 0;
   /*Remove one state*/
   if (bestmodel->states > 1)
     hmm_add_candidate_model(filenames, directory, bestmodel->index - maxmixture, models, models_searched, &filecount);
   /*Remove one mixture*/
   if (bestmodel->mixture > 1)
     hmm_add_candidate_model(filenames, directory, bestmodel->index - 1, models, models_searched, &filecount);
   /*Add best model to comparison*/
   hmm_add_candidate_model(filenames, directory, bestmodel->index, models, models_searched, &filecount);
   /*Add one mixture*/
   if (bestmodel->mixture < maxmixture)
     hmm_add_candidate_model(filenames, directory, bestmodel->index + 1, models, models_searched, &filecount);
   /*Add one state*/
   if (bestmodel->states < maxstates)
     hmm_add_candidate_model(filenames, directory, bestmodel->index + maxmixture, models, models_searched, &filecount);
   sprintf(tmpst,"-");
   model = multiple_comparison(filenames, filecount, get_parameter_l("testtype"), tmpst, &m, &c, get_parameter_l("correctiontype"));
   current_best_index = models_searched[model[0] - 1]; 
   if (current_best_index == bestmodel->index)
    {
     safe_free(model);
     break;
    }
   else
    {
     if (models[current_best_index].selected)
       break;
     bestmodel = &(models[current_best_index]);
     bestmodel->selected = BOOLEAN_TRUE;
    }
   safe_free(model);
  }
 *tries = 0;
 for (i = 0; i < maxstates * maxmixture; i++)
   if (models[i].tried)
     (*tries)++;
 result = *bestmodel;
 free_2d((void**)filenames, MAX_MODEL_SEARCH);
 safe_free(models);
 safe_free(models_searched);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x438, %rsp            # imm = 0x438
movq %r8, 0x28(%rsp)
movl %ecx, %r15d
movl %edx, %r12d
movq %rsi, %r13
movq %rdi, 0x30(%rsp)
movslq %edx, %r14
movslq %ecx, %rax
imulq %r14, %rax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rdi
leaq 0x5fb93(%rip), %rbx     # 0xa73e2
movq %rbx, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, 0x20(%rsp)
movl $0x1c, %edi
movq %rbx, %rsi
movl %r12d, %ebx
movl $0x4, %edx
callq 0x390f5
movq %rax, %r12
testl %r14d, %r14d
movl %r15d, %r14d
jle 0x478dd
movq 0x20(%rsp), %rax
addq $0x10, %rax
movl %r14d, %ecx
negl %ecx
xorl %edx, %edx
movl $0x1, %esi
testl %r14d, %r14d
jle 0x478d4
movslq %edx, %rdi
leaq (%rdi,%rdi,4), %rdi
leaq (%rax,%rdi,4), %rdi
movl $0x1, %r8d
movl %esi, -0x10(%rdi)
movl %r8d, -0xc(%rdi)
movl %edx, -0x8(%rdi)
movq $0x0, -0x4(%rdi)
addq $0x14, %rdi
incl %edx
leal (%rcx,%r8), %r9d
incl %r9d
incl %r8d
cmpl $0x1, %r9d
jne 0x478ac
leal 0x1(%rsi), %edi
cmpl %ebx, %esi
movl %edi, %esi
jne 0x47896
movq 0x20(%rsp), %r15
movl $0x1, 0xc(%r15)
leaq 0x5faf1(%rip), %r8      # 0xa73e2
movl $0x8, %edi
movl $0x1, %esi
movl $0x7, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
movl $0x3, %r9d
callq 0x393b5
movq %rax, 0x10(%rsp)
leaq 0x240(%rsp), %rbp
movq %rbp, %rdi
movq %r13, %rsi
movq %r15, %r13
callq 0x4270
movl %ebx, 0x1c(%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x2, (%r15)
jl 0x4795c
movl 0x8(%r15), %edx
subl %r14d, %edx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r12, %r8
leaq 0xc(%rsp), %r9
callq 0x477a7
cmpl $0x2, 0x4(%r15)
jl 0x47981
movl 0x8(%r15), %edx
decl %edx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r12, %r8
leaq 0xc(%rsp), %r9
callq 0x477a7
movl 0x8(%r15), %edx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r12, %r8
leaq 0xc(%rsp), %r9
callq 0x477a7
cmpl %r14d, 0x4(%r15)
jge 0x479c1
movl 0x8(%r15), %edx
incl %edx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r12, %r8
leaq 0xc(%rsp), %r9
callq 0x477a7
cmpl %ebx, (%r15)
jge 0x479e5
movl 0x8(%r15), %edx
addl %r14d, %edx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
movq %r13, %rcx
movq %r12, %r8
leaq 0xc(%rsp), %r9
callq 0x477a7
movw $0x2d, 0x40(%rsp)
movq %r12, %rbx
movl 0xc(%rsp), %r12d
leaq 0x5fa06(%rip), %rdi     # 0xa7401
callq 0x535f7
movl %eax, %r13d
leaq 0x5af2e(%rip), %rdi     # 0xa2938
callq 0x535f7
movl %eax, (%rsp)
movq 0x10(%rsp), %rdi
movl %r12d, %esi
movq %rbx, %r12
movl %r13d, %edx
leaq 0x40(%rsp), %rcx
leaq 0x3c(%rsp), %r8
leaq 0x38(%rsp), %r9
callq 0x8c4bc
movslq (%rax), %rcx
movslq -0x4(%rbx,%rcx,4), %rcx
cmpl 0x8(%r15), %ecx
je 0x47a77
leaq (%rcx,%rcx,4), %rcx
movq 0x20(%rsp), %r13
cmpl $0x0, 0xc(%r13,%rcx,4)
movl 0x1c(%rsp), %ebx
jne 0x47a88
leaq (,%rcx,4), %r15
addq %r13, %r15
movl $0x1, 0xc(%r15)
movq %rax, %rdi
callq 0x39194
jmp 0x4792f
movq %rax, %rdi
callq 0x39194
movl 0x1c(%rsp), %ebx
movq 0x20(%rsp), %r13
movq 0x28(%rsp), %rdx
movl $0x0, (%rdx)
imull %ebx, %r14d
testl %r14d, %r14d
jle 0x47abc
movl %r14d, %eax
shlq $0x2, %rax
leaq (%rax,%rax,4), %rax
xorl %ecx, %ecx
cmpl $0x0, 0x10(%r13,%rcx)
je 0x47ab3
incl (%rdx)
addq $0x14, %rcx
cmpq %rcx, %rax
jne 0x47aa9
movl 0x10(%r15), %eax
movq 0x30(%rsp), %r14
movl %eax, 0x10(%r14)
movups (%r15), %xmm0
movups %xmm0, (%r14)
movq 0x10(%rsp), %rdi
movl $0x7, %esi
callq 0x3915f
movq %r13, %rdi
callq 0x39194
movq %r12, %rdi
callq 0x39194
movq %r14, %rax
addq $0x438, %rsp            # imm = 0x438
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq