// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/model.c
// Function: hmm_model_simulation_most
Hmm_model hmm_model_simulation_most(char* simulationdirectory, int maxstates, int maxmixture, int* tries, MODEL_SEARCH_DIRECTION_TYPE searchdirection)
{
 /*!Last Changed 10.01.2009*/
 char **two_file;
 int *list, modelcount, i, j, k, bestoftwo;
 BOOLEAN improved = BOOLEAN_TRUE;
 Hmm_modelptr bestmodel;
 Hmm_model result;
 Hmm_modelptr models;
 list = safemalloc(sizeof(int) * MAX_MODEL_SEARCH, "hmm_model_simulation_most", 4);
 models = safemalloc(sizeof(Hmm_model) * maxstates * maxmixture, "hmm_model_simulation_most", 5);
 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++;
    }
 if (searchdirection == FORWARD)
   bestmodel = &(models[0]);
 else
   bestmodel = &(models[k - 1]);
 bestmodel->tried = BOOLEAN_TRUE;
 bestmodel->selected = BOOLEAN_TRUE;
 two_file = (char**) safemalloc_2d(sizeof(char *), sizeof(char), 2, 500, "hmm_model_simulation_most", 20);
 while (improved)
  {
   modelcount = 0;
   /*Remove one state*/
   if (bestmodel->states > 1)
     list[modelcount++] = bestmodel->index - maxmixture;
   /*Remove one mixture*/
   if (bestmodel->mixture > 1)
     list[modelcount++] = bestmodel->index - 1;
   /*Add best model to comparison*/
   list[modelcount++] = bestmodel->index;
   /*Add one mixture*/
   if (bestmodel->mixture < maxmixture)
     list[modelcount++] = bestmodel->index + 1;
   /*Add one state*/
   if (bestmodel->states < maxstates)
     list[modelcount++] = bestmodel->index + maxmixture;
   if (searchdirection == FORWARD)
     qsort(list, modelcount, sizeof(int), sort_function_int_ascending);
   else
     qsort(list, modelcount, sizeof(int), sort_function_int_descending);
   improved = BOOLEAN_FALSE;
   for (i = 0; i < modelcount; i++)
     if (list[i] != bestmodel->index)
      {
       models[list[i]].tried = BOOLEAN_TRUE;
       bestoftwo = compare_two_hmm_models(two_file, simulationdirectory, *bestmodel, models[list[i]]);
       if ((bestmodel->index < list[i] && bestoftwo == 1) || (bestmodel->index > list[i] && bestoftwo == 0))
        {
         bestmodel = &(models[list[i]]);
         improved = BOOLEAN_TRUE;
         break;
        }
      }
   if (bestmodel->selected)
     improved = BOOLEAN_FALSE;
   else
     bestmodel->selected = BOOLEAN_TRUE;
  }
 safe_free(list);
 *tries = 0;
 for (i = 0; i < maxstates * maxmixture; i++)
   if (models[i].tried)
     (*tries)++;
 result = *bestmodel;
 safe_free(models);
 free_2d((void**)two_file, 2);
 return result;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xd0, %rsp
movq %rdi, -0x98(%rbp)
movq %rdi, -0x90(%rbp)
movq %rsi, -0x8(%rbp)
movl %edx, -0xc(%rbp)
movl %ecx, -0x10(%rbp)
movq %r8, -0x18(%rbp)
movl %r9d, -0x1c(%rbp)
movl $0x1, -0x48(%rbp)
movl $0x1c, %edi
leaq 0x7e3cf(%rip), %rsi     # 0xe6ffd
movl $0x4, %edx
callq 0x52d70
movq %rax, -0x30(%rbp)
movslq -0xc(%rbp), %rax
imulq $0x14, %rax, %rdi
movslq -0x10(%rbp), %rax
imulq %rax, %rdi
leaq 0x7e3aa(%rip), %rsi     # 0xe6ffd
movl $0x5, %edx
callq 0x52d70
movq %rax, -0x58(%rbp)
movl $0x0, -0x40(%rbp)
movl $0x1, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0xc(%rbp), %eax
jg 0x68d1f
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x10(%rbp), %eax
jg 0x68d0f
movl -0x38(%rbp), %ecx
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, (%rax)
movl -0x3c(%rbp), %ecx
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x4(%rax)
movl -0x40(%rbp), %ecx
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movl %ecx, 0x8(%rax)
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0xc(%rax)
movq -0x58(%rbp), %rax
movslq -0x40(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x0, 0x10(%rax)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x68c82
jmp 0x68d11
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x68c6f
cmpl $0x0, -0x1c(%rbp)
jne 0x68d2f
movq -0x58(%rbp), %rax
movq %rax, -0x50(%rbp)
jmp 0x68d47
movq -0x58(%rbp), %rax
movl -0x40(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movl $0x1, 0x10(%rax)
movq -0x50(%rbp), %rax
movl $0x1, 0xc(%rax)
movl $0x8, %edi
movl $0x1, %esi
movl $0x2, %edx
movl $0x1f4, %ecx            # imm = 0x1F4
leaq 0x7e285(%rip), %r8      # 0xe6ffd
movl $0x14, %r9d
callq 0x53120
movq %rax, -0x28(%rbp)
cmpl $0x0, -0x48(%rbp)
je 0x69003
movl $0x0, -0x34(%rbp)
movq -0x50(%rbp), %rax
cmpl $0x1, (%rax)
jle 0x68dc0
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
subl -0x10(%rbp), %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
cmpl $0x1, 0x4(%rax)
jle 0x68de9
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
subl $0x1, %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl 0x4(%rax), %eax
cmpl -0x10(%rbp), %eax
jge 0x68e30
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
addl $0x1, %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
movq -0x50(%rbp), %rax
movl (%rax), %eax
cmpl -0xc(%rbp), %eax
jge 0x68e5a
movq -0x50(%rbp), %rax
movl 0x8(%rax), %edx
addl -0x10(%rbp), %edx
movq -0x30(%rbp), %rax
movl -0x34(%rbp), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, -0x34(%rbp)
movslq %ecx, %rcx
movl %edx, (%rax,%rcx,4)
cmpl $0x0, -0x1c(%rbp)
jne 0x68e7b
movq -0x30(%rbp), %rdi
movslq -0x34(%rbp), %rsi
movl $0x4, %edx
leaq -0x15a34(%rip), %rcx    # 0x53440
callq 0x41f0
jmp 0x68e94
movq -0x30(%rbp), %rdi
movslq -0x34(%rbp), %rsi
movl $0x4, %edx
leaq -0x159ff(%rip), %rcx    # 0x53490
callq 0x41f0
movl $0x0, -0x48(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jge 0x68fe0
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movq -0x50(%rbp), %rcx
cmpl 0x8(%rcx), %eax
je 0x68fd0
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movl $0x1, 0x10(%rax)
movq -0x28(%rbp), %rdi
movq -0x8(%rbp), %rsi
movq -0x50(%rbp), %rcx
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rdx
movslq -0x38(%rbp), %r8
movslq (%rdx,%r8,4), %rdx
imulq $0x14, %rdx, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, -0x70(%rbp)
movq 0x8(%rcx), %rdx
movq %rdx, -0x68(%rbp)
movl 0x10(%rcx), %ecx
movl %ecx, -0x60(%rbp)
movq (%rax), %rcx
movq %rcx, -0x88(%rbp)
movq 0x8(%rax), %rcx
movq %rcx, -0x80(%rbp)
movl 0x10(%rax), %eax
movl %eax, -0x78(%rbp)
leaq -0x70(%rbp), %rcx
leaq -0x88(%rbp), %rax
movq (%rcx), %rdx
movq %rdx, (%rsp)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rsp)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rsp)
movq (%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x20(%rsp)
movl 0x10(%rax), %eax
movl %eax, 0x28(%rsp)
callq 0x690a0
movl %eax, -0x44(%rbp)
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jge 0x68f90
cmpl $0x1, -0x44(%rbp)
je 0x68faa
movq -0x50(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
cmpl (%rcx,%rdx,4), %eax
jle 0x68fce
cmpl $0x0, -0x44(%rbp)
jne 0x68fce
movq -0x58(%rbp), %rax
movq -0x30(%rbp), %rcx
movslq -0x38(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x50(%rbp)
movl $0x1, -0x48(%rbp)
jmp 0x68fe0
jmp 0x68fd0
jmp 0x68fd2
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x68ea2
movq -0x50(%rbp), %rax
cmpl $0x0, 0xc(%rax)
je 0x68ff3
movl $0x0, -0x48(%rbp)
jmp 0x68ffe
movq -0x50(%rbp), %rax
movl $0x1, 0xc(%rax)
jmp 0x68d87
movq -0x30(%rbp), %rdi
callq 0x52e80
movq -0x18(%rbp), %rax
movl $0x0, (%rax)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl -0xc(%rbp), %ecx
imull -0x10(%rbp), %ecx
cmpl %ecx, %eax
jge 0x69058
movq -0x58(%rbp), %rax
movslq -0x38(%rbp), %rcx
imulq $0x14, %rcx, %rcx
addq %rcx, %rax
cmpl $0x0, 0x10(%rax)
je 0x6904b
movq -0x18(%rbp), %rax
movl (%rax), %ecx
addl $0x1, %ecx
movl %ecx, (%rax)
jmp 0x6904d
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x6901d
movq -0x98(%rbp), %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rdx
movq %rdx, 0x8(%rax)
movl 0x10(%rcx), %ecx
movl %ecx, 0x10(%rax)
movq -0x58(%rbp), %rdi
callq 0x52e80
movq -0x28(%rbp), %rdi
movl $0x2, %esi
callq 0x52e20
movq -0x90(%rbp), %rax
addq $0xd0, %rsp
popq %rbp
retq
nop