// File: /workspace/github_c_makefile_star2_O0/olcaytaner[P]Isell/hmm.c
// Function: best_hmm_for_together
void best_hmm_for_together(Hmmptr* model, Instanceptr* traindata, Instanceptr cvdata, Hmm_parameterptr p)
{
 /*!Last Changed 14.04.2007*/
 Hmmptr candidate, besthmm, tmp;
 int i, j, bestone = 0, operatorcount;
 double besterror, error;
 if (in_list(p->statetype, 3, STATE_DISCRETE, STATE_GAUSSIAN, STATE_DIRICHLET))
   operatorcount = 1;
 else
   operatorcount = 3;
 for (i = 0; i < current_dataset->classno; i++)
  {
   model[i] = random_hmm(2, p->statetype, 1, p->hmmtype, traindata[i]);
   baumwelch(model[i], traindata[i], p->iteration);
  }
 besterror = hmm_error_rate(model, cvdata);
 printf("Start error:%.6f\n", besterror);
 while (bestone != NO_CHANGE)
  {
   bestone = NO_CHANGE;
   besthmm = NULL;
   for (i = 0; i < current_dataset->classno; i++)
     for (j = 0; j < operatorcount; j++)
      {
       candidate = apply_operator(model[i], j, p, traindata[i]);
       tmp = model[i];
       model[i] = candidate;
       error = hmm_error_rate(model, cvdata);
       printf("Candidate error:%.6f\n", error);
       if (error < besterror)
        {
         if (besthmm)
           free_hmm(besthmm);
         besthmm = candidate;
         besterror = error;
         bestone = i;
         printf("Best error:%.6f\n", besterror);
        }
       else
         free_hmm(candidate);
       model[i] = tmp;
      }
   if (bestone != NO_CHANGE)
    {
     free_hmm(model[bestone]);
     model[bestone] = besthmm;
    }
  }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl $0x0, -0x44(%rbp)
movq -0x20(%rbp), %rax
movl 0x4(%rax), %edi
movl $0x3, %r8d
xorl %edx, %edx
movl $0x1, %ecx
movl %r8d, %esi
movb $0x0, %al
callq 0x53e40
cmpl $0x0, %eax
je 0x3ebeb
movl $0x1, -0x48(%rbp)
jmp 0x3ebf2
movl $0x3, -0x48(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
leaq 0xc6c3d(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x3ec71
movq -0x20(%rbp), %rax
movl 0x4(%rax), %esi
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rdx
movq (%rax,%rdx,8), %r8
movl $0x2, %edi
movl $0x1, %edx
callq 0x38060
movq %rax, %rdx
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rsi
movq -0x20(%rbp), %rax
movl 0x8(%rax), %edx
callq 0x3dbd0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3ebf9
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3ee10
movsd %xmm0, -0x50(%rbp)
movsd -0x50(%rbp), %xmm0
leaq 0xa66b6(%rip), %rdi     # 0xe5345
movb $0x1, %al
callq 0x4030
cmpl $-0x1, -0x44(%rbp)
je 0x3edfc
movl $0xffffffff, -0x44(%rbp) # imm = 0xFFFFFFFF
movq $0x0, -0x30(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
leaq 0xc6b80(%rip), %rcx     # 0x105840
movq (%rcx), %rcx
cmpl 0x10(%rcx), %eax
jge 0x3edd0
movl $0x0, -0x40(%rbp)
movl -0x40(%rbp), %eax
cmpl -0x48(%rbp), %eax
jge 0x3edc0
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
movl -0x40(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x10(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rcx
callq 0x3e8d0
movq %rax, -0x28(%rbp)
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x28(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movq -0x8(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0x3ee10
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
leaq 0xa6612(%rip), %rdi     # 0xe5357
movb $0x1, %al
callq 0x4030
movsd -0x58(%rbp), %xmm1
movsd -0x50(%rbp), %xmm0
ucomisd %xmm1, %xmm0
jbe 0x3ed99
cmpq $0x0, -0x30(%rbp)
je 0x3ed6c
movq -0x30(%rbp), %rdi
callq 0x386d0
movq -0x28(%rbp), %rax
movq %rax, -0x30(%rbp)
movsd -0x58(%rbp), %xmm0
movsd %xmm0, -0x50(%rbp)
movl -0x3c(%rbp), %eax
movl %eax, -0x44(%rbp)
movsd -0x50(%rbp), %xmm0
leaq 0xa65dd(%rip), %rdi     # 0xe536d
movb $0x1, %al
callq 0x4030
jmp 0x3eda2
movq -0x28(%rbp), %rdi
callq 0x386d0
movq -0x38(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x3c(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x3ecd3
jmp 0x3edc2
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x3ecb6
cmpl $-0x1, -0x44(%rbp)
je 0x3edf7
movq -0x8(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq (%rax,%rcx,8), %rdi
callq 0x386d0
movq -0x30(%rbp), %rdx
movq -0x8(%rbp), %rax
movslq -0x44(%rbp), %rcx
movq %rdx, (%rax,%rcx,8)
jmp 0x3ec96
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)