// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/loadmodel.c
// Function: load_model_hmm
void* load_model_hmm(FILE* infile, Datasetptr d)
{
 /*!Last Changed 26.02.2007*/
 int i, j, k, statetype;
 Hmmptr h;
 Hmmptr* hmmarray;
 Multinomialptr m;
 Gaussianptr g;
 Gaussianmixtureptr gm;
 Dirichletptr di;
 Dirichletmixtureptr dm;
 hmmarray = safemalloc(d->classno * sizeof(Hmmptr), "load_model_hmm", 10);
 for (k = 0; k < d->classno; k++)
  {
   h = safemalloc(sizeof(Hmm), "load_model_hmm", 11);
   hmmarray[k] = h;
   fscanf(infile, "%d%d", &(h->statecount), &statetype);
   h->statetype = statetype;
   h->states = safemalloc(h->statecount * sizeof(State), "load_model_hmm", 4);
   for (i = 0; i < h->statecount; i++)
    {
     h->states[i].a_dot_j = load_array(infile, h->statecount);
     h->states[i].a_i_dot = load_array(infile, h->statecount);
     fscanf(infile, "%lf", &(h->states[i].pi));
     switch (h->statetype)
      {
       case          STATE_DISCRETE:m = safemalloc(sizeof(Multinomial), "load_model_hmm", 11);
                                    m->prob = safemalloc((d->featurecount - 1) * sizeof(double*), "load_model_hmm", 12);
                                    for (j = 0; j < d->featurecount; j++)
                                      if (d->features[j].type == STRING)
                                        m->prob[j] = load_array(infile, d->features[j].valuecount);
                                    h->states[i].b = m;
                                    break;
       case          STATE_GAUSSIAN:g = safemalloc(sizeof(Gaussian), "load_model_hmm", 18);
                                    g->mean = load_array(infile, d->multifeaturecount - 1);
                                    g->covariance = load_matrix(infile, d->multifeaturecount - 1, d->multifeaturecount - 1);
                                    h->states[i].b = g;
                                    break;
       case  STATE_GAUSSIAN_MIXTURE:gm = safemalloc(sizeof(Gaussianmixture), "load_model_hmm", 23);
                                    fscanf(infile, "%d", &(gm->componentcount));
                                    gm->weights = load_array(infile, gm->componentcount);
                                    gm->components = safemalloc(gm->componentcount * sizeof(Gaussian), "load_model_hmm", 26);
                                    for (j = 0; j < gm->componentcount; j++)
                                     {
                                      gm->components[j].mean = load_array(infile, d->multifeaturecount - 1);
                                      gm->components[j].covariance = load_matrix(infile, d->multifeaturecount - 1, d->multifeaturecount - 1);
                                     }
                                    h->states[i].b = gm;
                                    break;
       case         STATE_DIRICHLET:di = safemalloc(sizeof(Dirichlet), "load_model_hmm", 34);
                                    di->alpha = load_array(infile, d->multifeaturecount - 1);
                                    h->states[i].b = di;
                                    break;
       case STATE_DIRICHLET_MIXTURE:dm = safemalloc(sizeof(Dirichletmixture), "load_model_hmm", 38);
                                    fscanf(infile, "%d", &(dm->componentcount));
                                    dm->weights = load_array(infile, dm->componentcount);
                                    dm->components = safemalloc(dm->componentcount * sizeof(Dirichlet), "load_model_hmm", 41);
                                    for (j = 0; j < dm->componentcount; j++)
                                      dm->components[j].alpha = load_array(infile, d->multifeaturecount - 1);
                                    h->states[i].b = dm;
                                    break;
      }
    }
  }
 return hmmarray;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x10(%rsi), %rdi
shlq $0x3, %rdi
leaq 0x62232(%rip), %rsi     # 0x99dcf
pushq $0xa
popq %rdx
callq 0x34f59
movq %rax, 0x10(%rsp)
leaq 0x30f20(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x61feb(%rip), %r15     # 0x99ba8
xorl %ecx, %ecx
movq %rbx, 0x20(%rsp)
movq %r14, 0x18(%rsp)
movslq 0x10(%rbx), %rax
cmpq %rax, %rcx
jge 0x37f1d
pushq $0x18
popq %rdi
leaq 0x621ef(%rip), %rbp     # 0x99dcf
movq %rbp, %rsi
pushq $0xb
popq %rdx
movq %rcx, %r12
callq 0x34f59
movq %rax, %r13
movq 0x10(%rsp), %rax
movq %r12, 0x28(%rsp)
movq %r13, (%rax,%r12,8)
leaq 0x8(%r13), %rdx
movq %r14, %rdi
leaq 0x620fc(%rip), %rsi     # 0x99d09
movq %rdx, 0x38(%rsp)
leaq 0xc(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
movl 0xc(%rsp), %eax
movl %eax, 0xc(%r13)
movslq 0x8(%r13), %rdi
shlq $0x5, %rdi
movq %rbp, %rsi
pushq $0x4
popq %rdx
callq 0x34f59
movq %rax, (%r13)
xorl %ebp, %ebp
movq %r13, (%rsp)
movq 0x38(%rsp), %rax
movslq (%rax), %rsi
cmpq %rsi, %rbp
jge 0x37f10
movq %r14, %rdi
callq 0x3615a
movq (%r13), %rcx
movq %rbp, %r12
shlq $0x5, %r12
movq %rax, (%rcx,%r12)
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3615a
movq (%r13), %rcx
movq %r12, 0x48(%rsp)
leaq (%rcx,%r12), %rdx
addq $0x10, %rdx
movq %rax, -0x8(%rdx)
movq %r14, %rdi
movq %r15, %rsi
xorl %eax, %eax
callq 0x4070
movl 0xc(%r13), %eax
cmpq $0x4, %rax
ja 0x37f08
movq %rbp, 0x40(%rsp)
leaq 0x61ea1(%rip), %rcx     # 0x99b54
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
pushq $0x8
popq %rdi
leaq 0x62109(%rip), %r15     # 0x99dcf
movq %r15, %rsi
pushq $0xb
popq %rdx
callq 0x34f59
movq %rax, %r12
movslq 0x1bc(%rbx), %rax
leaq -0x8(,%rax,8), %rdi
movq %r15, %rsi
pushq $0xc
popq %rdx
callq 0x34f59
movq %rax, (%r12)
movq 0x30(%rsp), %r15
xorl %r13d, %r13d
movslq 0x1bc(%rbx), %rax
cmpq %rax, %r13
jge 0x37e78
cmpl $0x1, -0x18(%r15)
jne 0x37d24
movl (%r15), %esi
movq %r14, %rdi
callq 0x3615a
movq (%r12), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
addq $0x340, %r15            # imm = 0x340
jmp 0x37cfa
pushq $0x18
popq %rdi
leaq 0x62095(%rip), %r13     # 0x99dcf
movq %r13, %rsi
pushq $0x26
popq %rdx
callq 0x34f59
movq %rax, %r12
leaq 0x8(%rax), %r15
movq %r14, %rdi
leaq 0x68e03(%rip), %rsi     # 0xa0b59
movq %r15, %rdx
xorl %eax, %eax
callq 0x4070
movl 0x8(%r12), %esi
movq %r14, %rdi
callq 0x3615a
movq %rax, 0x10(%r12)
movslq 0x8(%r12), %rdi
shlq $0x3, %rdi
movq %r13, %rsi
pushq $0x29
popq %rdx
callq 0x34f59
movq %rax, (%r12)
xorl %r13d, %r13d
movslq (%r15), %rax
cmpq %rax, %r13
jge 0x37e78
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3615a
movq (%r12), %rcx
movq %rax, (%rcx,%r13,8)
incq %r13
jmp 0x37d8d
pushq $0x18
popq %rdi
leaq 0x6200f(%rip), %rbx     # 0x99dcf
movq %rbx, %rsi
pushq $0x17
popq %rdx
callq 0x34f59
movq %rax, %r12
leaq 0x8(%rax), %rdx
movq %r14, %rdi
leaq 0x68d7d(%rip), %rsi     # 0xa0b59
movq %rdx, 0x50(%rsp)
xorl %eax, %eax
callq 0x4070
movl 0x8(%r12), %esi
movq %r14, %rdi
callq 0x3615a
movq %rax, 0x10(%r12)
movslq 0x8(%r12), %rax
imulq $0x18, %rax, %rdi
movq %rbx, %rsi
pushq $0x1a
popq %rdx
callq 0x34f59
movq %rax, (%r12)
pushq $0x10
popq %rbp
xorl %r13d, %r13d
movq 0x50(%rsp), %rax
movslq (%rax), %rax
cmpq %rax, %r13
jge 0x37e6e
movq 0x20(%rsp), %r14
movl 0x1c0(%r14), %esi
decl %esi
movq 0x18(%rsp), %r15
movq %r15, %rdi
callq 0x3615a
movq (%r12), %rbx
movq %rax, -0x10(%rbx,%rbp)
movl 0x1c0(%r14), %edx
decl %edx
movq %r15, %rdi
movl %edx, %esi
callq 0x360cc
movq %rax, -0x8(%rbx,%rbp)
movq %rdx, (%rbx,%rbp)
incq %r13
addq $0x18, %rbp
jmp 0x37e18
movq 0x20(%rsp), %rbx
movq 0x18(%rsp), %r14
leaq 0x61d29(%rip), %r15     # 0x99ba8
movq (%rsp), %r13
jmp 0x37ef5
pushq $0x8
popq %rdi
leaq 0x61f40(%rip), %rsi     # 0x99dcf
pushq $0x22
popq %rdx
callq 0x34f59
movq %rax, %r12
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3615a
movq %rax, (%r12)
jmp 0x37ef5
pushq $0x18
popq %rdi
leaq 0x61f15(%rip), %rsi     # 0x99dcf
pushq $0x12
popq %rdx
callq 0x34f59
movq %rax, %r12
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3615a
movq %rax, (%r12)
movl 0x1c0(%rbx), %edx
decl %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x360cc
movq %rax, 0x8(%r12)
movq %rdx, 0x10(%r12)
movq (%r13), %rax
movq 0x48(%rsp), %rcx
movq %r12, 0x18(%rax,%rcx)
movq 0x40(%rsp), %rbp
incq %rbp
jmp 0x37c43
movq 0x28(%rsp), %rcx
incq %rcx
jmp 0x37bc9
movq 0x10(%rsp), %rax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq