// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/savemodel.c
// Function: save_model_hmm
void save_model_hmm(FILE* modelfile, Datasetptr d, Hmmptr* hmmarray)
{
 /*Last Changed 02.04.2007*/
 /*Last Changed 26.02.2007*/
 int i, j, k;
 char pst[READLINELENGTH];
 Multinomialptr m;
 Hmmptr h;
 Gaussianptr g;
 Gaussianmixtureptr gm;
 Dirichletptr di;
 Dirichletmixtureptr dm;
 set_precision(pst, NULL, "\n");
 for (k = 0; k < d->classno; k++)
  {
   h = hmmarray[k];
   fprintf(modelfile, "%d %d\n", h->statecount, h->statetype);
   for (i = 0; i < h->statecount; i++)
    {
     save_array(modelfile, h->states[i].a_dot_j, h->statecount);
     save_array(modelfile, h->states[i].a_i_dot, h->statecount);
     fprintf(modelfile, pst, h->states[i].pi);
     switch (h->statetype)
      {
       case          STATE_DISCRETE:m = (Multinomialptr) (h->states[i].b);
                                    for (j = 0; j < d->featurecount; j++)
                                      if (d->features[j].type == STRING)
                                        save_array(modelfile, m->prob[j], d->features[j].valuecount);
                                    break;
       case          STATE_GAUSSIAN:g = (Gaussianptr) (h->states[i].b);
                                    save_array(modelfile, g->mean, d->multifeaturecount - 1);
                                    save_matrix(modelfile, g->covariance);
                                    break;
       case  STATE_GAUSSIAN_MIXTURE:gm = (Gaussianmixtureptr) (h->states[i].b);
                                    fprintf(modelfile, "%d\n", gm->componentcount);
                                    save_array(modelfile, gm->weights, gm->componentcount);
                                    for (j = 0; j < gm->componentcount; j++)
                                     {
                                      save_array(modelfile, gm->components[j].mean, d->multifeaturecount - 1);
                                      save_matrix(modelfile, gm->components[j].covariance); 
                                     }
                                    break;
       case         STATE_DIRICHLET:di = (Dirichletptr) (h->states[i].b);
                                    save_array(modelfile, di->alpha, d->multifeaturecount - 1);
                                    break;
       case STATE_DIRICHLET_MIXTURE:dm = (Dirichletmixtureptr) (h->states[i].b);
                                    fprintf(modelfile, "%d\n", dm->componentcount);
                                    save_array(modelfile, dm->weights, dm->componentcount);
                                    for (j = 0; j < dm->componentcount; j++)
                                      save_array(modelfile, dm->components[j].alpha, d->multifeaturecount - 1);
                                    break;
      }
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x7a148, %rsp          # imm = 0x7A148
movq %rdx, (%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1d5c9(%rip), %rdx     # 0x9910b
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x35305
leaq 0x30f20(%r14), %rax
movq %rax, 0x10(%rsp)
xorl %ecx, %ecx
movslq 0x10(%r14), %rax
cmpq %rax, %rcx
jge 0x7bd8c
movq (%rsp), %rax
movq %rcx, 0x8(%rsp)
movq (%rax,%rcx,8), %r13
movl 0x8(%r13), %edx
movl 0xc(%r13), %ecx
movq %r15, %rdi
leaq 0x1a2ac(%rip), %rsi     # 0x95e34
xorl %eax, %eax
callq 0x42e0
xorl %r12d, %r12d
movslq 0x8(%r13), %rdx
cmpq %rdx, %r12
jge 0x7bd7f
movq (%r13), %rax
movq %r12, 0x18(%rsp)
shlq $0x5, %r12
movq (%rax,%r12), %rsi
movq %r15, %rdi
callq 0x7a51f
movq (%r13), %rax
movq 0x8(%rax,%r12), %rsi
movl 0x8(%r13), %edx
movq %r15, %rdi
callq 0x7a51f
movq (%r13), %rax
movsd 0x10(%rax,%r12), %xmm0
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
movb $0x1, %al
callq 0x42e0
movl 0xc(%r13), %eax
cmpq $0x4, %rax
ja 0x7bd72
leaq 0x25160(%rip), %rcx     # 0xa0d5c
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq (%r13), %rax
movq 0x18(%rax,%r12), %rbx
movq 0x10(%rsp), %r12
xorl %ebp, %ebp
movslq 0x1bc(%r14), %rax
cmpq %rax, %rbp
jge 0x7bd72
cmpl $0x1, -0x18(%r12)
jne 0x7bc40
movq (%rbx), %rax
movq (%rax,%rbp,8), %rsi
movl (%r12), %edx
movq %r15, %rdi
callq 0x7a51f
incq %rbp
addq $0x340, %r12            # imm = 0x340
jmp 0x7bc15
movq (%r13), %rax
movq 0x18(%rax,%r12), %r12
movl 0x8(%r12), %edx
movq %r15, %rdi
leaq 0x248e1(%rip), %rsi     # 0xa0545
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r12), %rsi
movl 0x8(%r12), %edx
movq %r15, %rdi
callq 0x7a51f
xorl %ebx, %ebx
movslq 0x8(%r12), %rax
cmpq %rax, %rbx
jge 0x7bd72
movq (%r12), %rax
movq (%rax,%rbx,8), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x7a51f
incq %rbx
jmp 0x7bc7f
movq (%r13), %rax
movq 0x18(%rax,%r12), %r12
movl 0x8(%r12), %edx
movq %r15, %rdi
leaq 0x24882(%rip), %rsi     # 0xa0545
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r12), %rsi
movl 0x8(%r12), %edx
movq %r15, %rdi
callq 0x7a51f
xorl %ebx, %ebx
xorl %ebp, %ebp
movslq 0x8(%r12), %rax
cmpq %rax, %rbp
jge 0x7bd72
movq (%r12), %rax
movq (%rax,%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x7a51f
movq (%r12), %rax
movq 0x8(%rax,%rbx), %rsi
movq 0x10(%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x7a484
incq %rbp
addq $0x18, %rbx
jmp 0x7bce0
movq (%r13), %rax
movq 0x18(%rax,%r12), %rax
movq (%rax), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x7a51f
jmp 0x7bd72
movq (%r13), %rax
movq 0x18(%rax,%r12), %rbx
movq (%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x7a51f
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %r15, %rdi
callq 0x7a484
movq 0x18(%rsp), %r12
incq %r12
jmp 0x7bb92
movq 0x8(%rsp), %rcx
incq %rcx
jmp 0x7bb5c
addq $0x7a148, %rsp          # imm = 0x7A148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq