// File: /workspace/github_c_makefile_star2_O2/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 $0x448, %rsp            # imm = 0x448
movq %r8, 0x38(%rsp)
movl %ecx, %r12d
movl %edx, %ebx
movq %rsi, 0x18(%rsp)
movq %rdi, 0x40(%rsp)
movslq %edx, %r13
movslq %ecx, %r15
movq %r13, %rax
imulq %r15, %rax
imulq $0x14, %rax, %rdi
leaq 0x58579(%rip), %rsi     # 0x9a3b2
pushq $0x4
popq %r14
movl %r14d, %edx
callq 0x34f59
movq %rax, %rbp
pushq $0x1c
popq %rdi
leaq 0x58560(%rip), %rsi     # 0x9a3b2
movl %r14d, %edx
movq %r12, %r14
callq 0x34f59
movq %rax, 0x30(%rsp)
xorl %eax, %eax
testl %r15d, %r15d
movl $0x0, %ecx
cmovgl %r14d, %ecx
testl %r13d, %r13d
movl $0x0, %edx
movl %ebx, 0x14(%rsp)
cmovgl %ebx, %edx
incl %edx
leaq 0x10(%rbp), %rsi
pushq $0x1
popq %rdi
movl %ecx, %r8d
cmpl %edx, %edi
je 0x41ed2
movslq %r8d, %r9
movslq %eax, %r10
subq %r10, %r9
imulq $0x14, %r10, %r10
addq %rsi, %r10
xorl %r11d, %r11d
cmpq %r11, %r9
je 0x41ec8
leaq 0x1(%r11), %rbx
movl %edi, -0x10(%r10)
movl %ebx, -0xc(%r10)
addl %eax, %r11d
movl %r11d, -0x8(%r10)
andq $0x0, -0x4(%r10)
addq $0x14, %r10
movq %rbx, %r11
jmp 0x41ea2
incl %edi
addl %ecx, %r8d
addq %rcx, %rax
jmp 0x41e8b
movl $0x1, 0xc(%rbp)
leaq 0x584d2(%rip), %r8      # 0x9a3b2
pushq $0x8
popq %rdi
pushq $0x1
popq %rsi
pushq $0x7
popq %rdx
pushq $0x3
popq %r9
movl $0x1f4, %ecx            # imm = 0x1F4
callq 0x351c3
movq %rax, %rbx
leaq 0x250(%rsp), %r12
movq %r12, %rdi
movq 0x18(%rsp), %rsi
callq 0x4270
movq %rbp, %r15
movq 0x30(%rsp), %r13
movq %r14, 0x28(%rsp)
movq %rbx, 0x20(%rsp)
andl $0x0, 0x10(%rsp)
cmpl $0x2, (%r15)
jl 0x41f49
movl 0x8(%r15), %edx
subl %r14d, %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
leaq 0x10(%rsp), %r9
callq 0x41d91
cmpl $0x2, 0x4(%r15)
jl 0x41f6c
movl 0x8(%r15), %edx
decl %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
leaq 0x10(%rsp), %r9
callq 0x41d91
movl 0x8(%r15), %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
leaq 0x10(%rsp), %r9
callq 0x41d91
cmpl %r14d, 0x4(%r15)
jge 0x41fa8
movl 0x8(%r15), %edx
incl %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
leaq 0x10(%rsp), %r9
callq 0x41d91
movl 0x14(%rsp), %eax
cmpl %eax, (%r15)
jge 0x41fce
movl 0x8(%r15), %edx
addl %r14d, %edx
movq %rbx, %rdi
movq %r12, %rsi
movq %rbp, %rcx
movq %r13, %r8
leaq 0x10(%rsp), %r9
callq 0x41d91
movq %rbx, %r13
movw $0x2d, 0x50(%rsp)
movl 0x10(%rsp), %eax
movl %eax, 0x18(%rsp)
leaq 0x583ea(%rip), %rdi     # 0x9a3d1
callq 0x4cf11
movl %eax, %r14d
leaq 0x53942(%rip), %rdi     # 0x95938
callq 0x4cf11
movl %eax, (%rsp)
movq %r15, %rbx
movq %r13, %rdi
movl 0x18(%rsp), %esi
movq 0x30(%rsp), %r15
movl %r14d, %edx
leaq 0x50(%rsp), %rcx
leaq 0x4c(%rsp), %r8
leaq 0x48(%rsp), %r9
callq 0x81133
movslq (%rax), %rcx
movq %r15, %r13
movslq -0x4(%r15,%rcx,4), %rcx
movq %rbx, %r15
cmpl 0x8(%rbx), %ecx
je 0x4206b
imulq $0x14, %rcx, %r14
cmpl $0x0, 0xc(%rbp,%r14)
jne 0x42073
addq %rbp, %r14
movl $0x1, 0xc(%r14)
movq %rax, %rdi
callq 0x34ff7
movq %r14, %rax
movq 0x28(%rsp), %r14
movq 0x20(%rsp), %rbx
movq %rax, %r15
jmp 0x41f21
movq %rax, %rdi
callq 0x34ff7
movq 0x38(%rsp), %rsi
andl $0x0, (%rsi)
movq 0x28(%rsp), %r12
imull 0x14(%rsp), %r12d
xorl %eax, %eax
testl %r12d, %r12d
cmovlel %eax, %r12d
imulq $0x14, %r12, %rcx
xorl %edx, %edx
movq 0x20(%rsp), %rdi
movq %r15, %rbx
cmpq %rax, %rcx
je 0x420b3
cmpl $0x0, 0x10(%rbp,%rax)
je 0x420ad
incl %edx
movl %edx, (%rsi)
addq $0x14, %rax
jmp 0x4209d
movl 0x10(%rbx), %eax
movq 0x40(%rsp), %r14
movl %eax, 0x10(%r14)
movups (%rbx), %xmm0
movups %xmm0, (%r14)
pushq $0x7
popq %rsi
callq 0x34fc3
movq %rbp, %rdi
callq 0x34ff7
movq %r13, %rdi
callq 0x34ff7
movq %r14, %rax
addq $0x448, %rsp            # imm = 0x448
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq