// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/classification.c
// Function: train_hmm
void* train_hmm(Instanceptr* trdata, Instanceptr *cvdata, void* parameters)
{
 /*!Last Changed 16.08.2007*/
 /*!Last Changed 02.04.2007*/
 Hmm_parameterptr p;
 Hmmptr* model;
 Instanceptr *trclasses, *cvclasses = NULL;
 int i;
 p = (Hmm_parameterptr) parameters;
 trclasses = divide_instancelist_into_classes(trdata);
 if (p->learningtype == LEARNING_SEPARATE)
   cvclasses = divide_instancelist_into_classes(cvdata);
 model = safemalloc(current_dataset->classno * sizeof(Hmmptr), "train_hmm", 9);
 switch (p->learningtype)
  {
   case LEARNING_SEPARATE:for (i = 0; i < current_dataset->classno; i++)
                           {
                            switch (p->statetype)
                             {
                              case          STATE_DISCRETE:
                              case          STATE_GAUSSIAN:
                              case         STATE_DIRICHLET:model[i] = best_hmm_for_single(trclasses[i], cvclasses[i], p);
                                                           break;
                              case  STATE_GAUSSIAN_MIXTURE:
                              case STATE_DIRICHLET_MIXTURE:model[i] = best_hmm_for_mixture(trclasses[i], cvclasses[i], p);
                                                           break;
                             }
                            printf("Class %d is finished\n", i + 1);
                           }
                          break;
   case LEARNING_TOGETHER:best_hmm_for_together(model, trclasses, *cvdata, p);
                          break;
   case    LEARNING_FIXED:for (i = 0; i < current_dataset->classno; i++)
                           {
                            model[i] = random_hmm(p->statecounts[i], p->statetype, p->componentcounts[i], p->hmmtype, trclasses[i]);
                            baumwelch(model[i], trclasses[i], p->iteration);
                           }
                          break;
  }
 merge_instancelist_groups(trdata, trclasses, current_dataset->classno);
 safe_free(trclasses);
 if (p->learningtype == LEARNING_SEPARATE)
  {
   merge_instancelist_groups(cvdata, cvclasses, current_dataset->classno);
   safe_free(cvclasses);
  }
 return model;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
callq 0x2cf1c
movq %rax, %r12
cmpl $0x0, 0x10(%r14)
movq %r15, 0x10(%rsp)
je 0x889a
movq $0x0, (%rsp)
jmp 0x88a6
movq %rbx, %rdi
callq 0x2cf1c
movq %rax, (%rsp)
leaq 0xc4fc3(%rip), %r15     # 0xcd870
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x8d5a5(%rip), %rsi     # 0x95e64
pushq $0x9
popq %rdx
callq 0x34f59
movq %rax, %rbp
movl 0x10(%r14), %eax
testl %eax, %eax
movq %rbx, 0x8(%rsp)
je 0x898f
cmpl $0x1, %eax
je 0x892b
cmpl $0x2, %eax
jne 0x893c
xorl %ebx, %ebx
movq (%r15), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %rbx
jge 0x893c
movq 0x18(%r14), %rax
movl (%rax,%rbx,4), %edi
movl (%r14), %ecx
movl 0x4(%r14), %esi
movq 0x20(%r14), %rax
movl (%rax,%rbx,4), %edx
movq (%r12,%rbx,8), %r8
callq 0x2460f
movq %rax, (%rbp,%rbx,8)
movq (%r12,%rbx,8), %rsi
movl 0x8(%r14), %edx
movq %rax, %rdi
callq 0x27f37
incq %rbx
jmp 0x88e7
movq (%rbx), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x28bb2
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2c705
movq %r12, %rdi
callq 0x34ff7
cmpl $0x0, 0x10(%r14)
jne 0x897d
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x8(%rsp), %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x2c705
movq %rbx, %rdi
callq 0x34ff7
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x8d4d8(%rip), %rbx     # 0x95e6e
xorl %r13d, %r13d
movq (%r15), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r13
jge 0x893c
movl 0x4(%r14), %eax
cmpl $0x4, %eax
ja 0x89e5
pushq $0xb
popq %rcx
btl %eax, %ecx
jae 0x89cc
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x2882b
jmp 0x89e0
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x28a9f
movq %rax, (%rbp,%r13,8)
incq %r13
movq %rbx, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x4030
jmp 0x8999