// File: /workspace/github_c_makefile_star2_O3/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, 0x10(%rsp)
callq 0x30f42
movq %rax, %r12
cmpl $0x0, 0x10(%r14)
je 0x8c14
movq $0x0, (%rsp)
jmp 0x8c20
movq %rbx, %rdi
callq 0x30f42
movq %rax, (%rsp)
leaq 0xccc49(%rip), %r15     # 0xd5870
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9d223(%rip), %rsi     # 0xa5e5c
movl $0x9, %edx
callq 0x3a0e1
movq %rax, %rbp
movl 0x10(%r14), %eax
testl %eax, %eax
movq %rbx, 0x8(%rsp)
je 0x8cca
cmpl $0x1, %eax
je 0x8cb7
cmpl $0x2, %eax
jne 0x8d3b
movq (%r15), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8d3b
xorl %ebx, %ebx
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 0x27b0a
movq %rax, (%rbp,%rbx,8)
movq (%r12,%rbx,8), %rsi
movl 0x8(%r14), %edx
movq %rax, %rdi
callq 0x2bab3
incq %rbx
movq (%r15), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %rbx
jl 0x8c70
jmp 0x8d3b
movq (%rbx), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x2c85f
jmp 0x8d3b
movq (%r15), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8d3b
leaq 0x9d18c(%rip), %rbx     # 0xa5e66
xorl %r13d, %r13d
movl 0x4(%r14), %eax
cmpl $0x4, %eax
ja 0x8d1f
movl $0xb, %ecx
btl %eax, %ecx
jae 0x8d06
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x2c4b9
jmp 0x8d1a
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x2c744
movq %rax, (%rbp,%r13,8)
incq %r13
movq %rbx, %rdi
movl %r13d, %esi
xorl %eax, %eax
callq 0x4030
movq (%r15), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %r13
jl 0x8cdd
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x30669
movq %r12, %rdi
callq 0x3a180
cmpl $0x0, 0x10(%r14)
jne 0x8d7c
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x8(%rsp), %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x30669
movq %rbx, %rdi
callq 0x3a180
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq