// File: /workspace/github_c_makefile_star2_O3/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 0x203ce(%rip), %rdx     # 0xa919b
leaq 0x20(%rsp), %rdi
xorl %esi, %esi
callq 0x3a535
cmpl $0x0, 0x10(%r14)
jle 0x89044
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 0x1d01c(%rip), %rsi     # 0xa5e2c
xorl %eax, %eax
callq 0x42e0
movl 0x8(%rbx), %edx
testl %edx, %edx
jle 0x8902f
xorl %r12d, %r12d
movq %rbx, (%rsp)
movq (%rbx), %rax
movq %r12, %r13
shlq $0x5, %r13
movq (%rax,%r13), %rsi
movq %r15, %rdi
callq 0x876d1
movq (%rbx), %rax
movq 0x8(%rax,%r13), %rsi
movl 0x8(%rbx), %edx
movq %r15, %rdi
callq 0x876d1
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 0x8901b
leaq 0x27f79(%rip), %rcx     # 0xb0df8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0x1bc(%r14), %eax
testl %eax, %eax
jle 0x8901b
movq (%rsp), %rcx
movq (%rcx), %rcx
movq 0x18(%rcx,%r13), %r13
movq 0x18(%rsp), %rbx
xorl %ebp, %ebp
cmpl $0x1, -0x18(%rbx)
jne 0x88ec9
movq (%r13), %rax
movq (%rax,%rbp,8), %rsi
movl (%rbx), %edx
movq %r15, %rdi
callq 0x876d1
movl 0x1bc(%r14), %eax
incq %rbp
movslq %eax, %rcx
addq $0x340, %rbx            # imm = 0x340
cmpq %rcx, %rbp
jl 0x88eaa
jmp 0x8901b
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %r13
movl 0x8(%r13), %edx
movq %r15, %rdi
leaq 0x276e7(%rip), %rsi     # 0xb05e1
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r13), %rsi
movl 0x8(%r13), %edx
movq %r15, %rdi
callq 0x876d1
cmpl $0x0, 0x8(%r13)
jle 0x8901b
xorl %ebx, %ebx
movq (%r13), %rax
movq (%rax,%rbx,8), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x876d1
incq %rbx
movslq 0x8(%r13), %rax
cmpq %rax, %rbx
jl 0x88f1e
jmp 0x8901b
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %r13
movl 0x8(%r13), %edx
movq %r15, %rdi
leaq 0x2767f(%rip), %rsi     # 0xb05e1
xorl %eax, %eax
callq 0x42e0
movq 0x10(%r13), %rsi
movl 0x8(%r13), %edx
movq %r15, %rdi
callq 0x876d1
cmpl $0x0, 0x8(%r13)
jle 0x8901b
xorl %ebx, %ebx
xorl %ebp, %ebp
movq (%r13), %rax
movq (%rax,%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x876d1
movq (%r13), %rax
movq 0x8(%rax,%rbx), %rsi
movq 0x10(%rax,%rbx), %rdx
movq %r15, %rdi
callq 0x87634
incq %rbp
movslq 0x8(%r13), %rax
addq $0x18, %rbx
cmpq %rax, %rbp
jl 0x88f88
jmp 0x8901b
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %rax
movq (%rax), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x876d1
jmp 0x8901b
movq (%rsp), %rax
movq (%rax), %rax
movq 0x18(%rax,%r13), %rbx
movq (%rbx), %rsi
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
callq 0x876d1
movq 0x8(%rbx), %rsi
movq 0x10(%rbx), %rdx
movq %r15, %rdi
callq 0x87634
incq %r12
movq (%rsp), %rbx
movslq 0x8(%rbx), %rdx
cmpq %rdx, %r12
jl 0x88e29
movq 0x10(%rsp), %rcx
incq %rcx
movslq 0x10(%r14), %rax
cmpq %rax, %rcx
jl 0x88df2
addq $0x7a148, %rsp          # imm = 0x7A148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq