// File: /workspace/github_c_makefile_star2_O1/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, 0x8(%rsp)
movq %rsi, %r14
movq %rdi, %r15
leaq 0x1fc08(%rip), %rdx     # 0xa616b
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x39529
cmpl $0x0, 0x10(%r14)
jle 0x867d8
leaq 0x30f20(%r14), %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
movq 0x8(%rsp), %rax
movq %rcx, 0x10(%rsp)
movq (%rax,%rcx,8), %rbx
movl 0x8(%rbx), %edx
movl 0xc(%rbx), %ecx
movq %r15, %rdi
leaq 0x1c886(%rip), %rsi     # 0xa2e2c
xorl %eax, %eax
callq 0x42e0
movl 0x8(%rbx), %edx
testl %edx, %edx
jle 0x867c3
xorl %r12d, %r12d
movq %rbx, (%rsp)
movq (%rbx), %rax
movq %r12, %r13
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq %r15, %rdi
callq 0x84e7d
movq (%rbx), %rax
movq 0x8(%rax,%r13), %rsi
movl 0x8(%rbx), %edx
movq %r15, %rdi
callq 0x84e7d
movq (%rbx), %rax
movsd 0x10(%rax,%r13), %xmm0
movq %r15, %rdi
leaq 0x20(%rsp), %rsi
movb $0x1, %al
callq 0x42e0
movl 0xc(%rbx), %eax
cmpq $0x4, %rax
ja 0x867af
leaq 0x2774b(%rip), %rcx     # 0xadd60
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $0x0, 0x1bc(%r14)
jle 0x867af
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %rbx
movq 0x18(%rsp), %r13
xorl %ebp, %ebp
cmpl $0x1, -0x18(%r13)
jne 0x86659
movq (%rbx), %rax
movq (%rax,%rbp,8), %rsi
movl (%r13), %edx
movq %r15, %rdi
callq 0x84e7d
incq %rbp
movslq 0x1bc(%r14), %rax
addq $0x340, %r13            # imm = 0x340
cmpq %rax, %rbp
jl 0x8663f
jmp 0x867af
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %r13
movl 0x8(%r13), %edx
movq %r15, %rdi
leaq 0x26ebb(%rip), %rsi     # 0xad549
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r13), %rsi
movl 0x8(%r13), %edx
movq %r15, %rdi
callq 0x84e7d
cmpl $0x0, 0x8(%r13)
jle 0x867af
xorl %ebx, %ebx
movq (%r13), %rax
movq (%rax,%rbx,8), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x84e7d
incq %rbx
movslq 0x8(%r13), %rax
cmpq %rax, %rbx
jl 0x866b2
jmp 0x867af
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %r13
movl 0x8(%r13), %edx
movq %r15, %rdi
leaq 0x26e53(%rip), %rsi     # 0xad549
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r13), %rsi
movl 0x8(%r13), %edx
movq %r15, %rdi
callq 0x84e7d
cmpl $0x0, 0x8(%r13)
jle 0x867af
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r13), %rax
movq (%rax,%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x84e7d
movq (%r13), %rax
movq 0x8(%rax,%rbx), %rsi
movq 0x10(%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x84de0
incq %rbp
movslq 0x8(%r13), %rax
addq $0x18, %rbx
cmpq %rax, %rbp
jl 0x8671c
jmp 0x867af
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %rax
movq (%rax), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x84e7d
jmp 0x867af
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %rbx
movq (%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x84e7d
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %r15, %rdi
callq 0x84de0
incq %r12
movq (%rsp), %rbx
movslq 0x8(%rbx), %rdx
cmpq %rdx, %r12
jl 0x865bf
movq 0x10(%rsp), %rcx
incq %rcx
movslq 0x10(%r14), %rax
cmpq %rax, %rcx
jl 0x86588
addq $0x7a148, %rsp          # imm = 0x7A148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq