// File: /workspace/github_c_makefile_star2_O1/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 0x3066f
movq %rax, %r12
cmpl $0x0, 0x10(%r14)
je 0x8be4
movq $0x0, (%rsp)
jmp 0x8bf0
movq %rbx, %rdi
callq 0x3066f
movq %rax, (%rsp)
leaq 0xc9c79(%rip), %r15     # 0xd2870
movq (%r15), %rax
movslq 0x10(%rax), %rdi
shlq $0x3, %rdi
leaq 0x9a253(%rip), %rsi     # 0xa2e5c
movl $0x9, %edx
callq 0x390f5
movq %rax, %rbp
movl 0x10(%r14), %eax
testl %eax, %eax
movq %rbx, 0x8(%rsp)
je 0x8c9a
cmpl $0x1, %eax
je 0x8c87
cmpl $0x2, %eax
jne 0x8d0b
movq (%r15), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8d0b
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 0x27426
movq %rax, (%rbp,%rbx,8)
movq (%r12,%rbx,8), %rsi
movl 0x8(%r14), %edx
movq %rax, %rdi
callq 0x2b24a
incq %rbx
movq (%r15), %rax
movslq 0x10(%rax), %rax
cmpq %rax, %rbx
jl 0x8c40
jmp 0x8d0b
movq (%rbx), %rdx
movq %rbp, %rdi
movq %r12, %rsi
movq %r14, %rcx
callq 0x2bfad
jmp 0x8d0b
movq (%r15), %rax
cmpl $0x0, 0x10(%rax)
jle 0x8d0b
leaq 0x9a1bc(%rip), %rbx     # 0xa2e66
xorl %r13d, %r13d
movl 0x4(%r14), %eax
cmpl $0x4, %eax
ja 0x8cef
movl $0xb, %ecx
btl %eax, %ecx
jae 0x8cd6
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x2bc07
jmp 0x8cea
movq (%r12,%r13,8), %rdi
movq (%rsp), %rax
movq (%rax,%r13,8), %rsi
movq %r14, %rdx
callq 0x2be92
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 0x8cad
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x10(%rsp), %rdi
movq %r12, %rsi
callq 0x2fd7a
movq %r12, %rdi
callq 0x39194
cmpl $0x0, 0x10(%r14)
jne 0x8d4c
movq (%r15), %rax
movl 0x10(%rax), %edx
movq 0x8(%rsp), %rdi
movq (%rsp), %rbx
movq %rbx, %rsi
callq 0x2fd7a
movq %rbx, %rdi
callq 0x39194
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq