// File: /workspace/github_c_makefile_star2_O1/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 $0x48, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movslq 0x10(%rsi), %rdi
shlq $0x3, %rdi
leaq 0x6ad09(%rip), %rsi     # 0xa6e37
movl $0xa, %edx
callq 0x390f5
movq %rax, 0x20(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x3c4fa
leaq 0x30f20(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x6acdd(%rip), %r12     # 0xa6e37
leaq 0x6aa5b(%rip), %r15     # 0xa6bbc
xorl %ecx, %ecx
movl $0x18, %edi
movq %r12, %rsi
movl $0xb, %edx
movq %rcx, %r13
callq 0x390f5
movq %rax, %rbp
movq 0x20(%rsp), %rax
movq %r13, 0x30(%rsp)
movq %rbp, (%rax,%r13,8)
leaq 0x8(%rbp), %r13
movq %r14, %rdi
leaq 0x6abda(%rip), %rsi     # 0xa6d71
movq %r13, %rdx
leaq 0x1c(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
movl 0x1c(%rsp), %eax
movl %eax, 0xc(%rbp)
movslq 0x8(%rbp), %rdi
shlq $0x5, %rdi
movq %r12, %rsi
movl $0x4, %edx
callq 0x390f5
movq %rax, (%rbp)
movq %rbp, 0x28(%rsp)
movl 0x8(%rbp), %esi
testl %esi, %esi
jle 0x3c4de
movq %r13, %rbp
xorl %r12d, %r12d
movq %r13, 0x10(%rsp)
movq %r14, %rdi
callq 0x3a514
movq 0x28(%rsp), %r13
movq (%r13), %rcx
movq %r12, 0x40(%rsp)
shlq $0x5, %r12
movq %rax, (%rcx,%r12)
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3a514
movq (%r13), %rcx
leaq (%rcx,%r12), %rdx
addq $0x10, %rdx
movq %rax, -0x8(%rdx)
movq %r14, %rdi
leaq 0x6a9eb(%rip), %rsi     # 0xa6c10
xorl %eax, %eax
callq 0x4070
movl 0xc(%r13), %eax
cmpq $0x4, %rax
ja 0x3c4c9
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq %r12, 0x8(%rsp)
movl $0x8, %edi
leaq 0x6abe3(%rip), %r12     # 0xa6e37
movq %r12, %rsi
movl $0xb, %edx
callq 0x390f5
movq %rax, %r13
movslq 0x1bc(%rbx), %rax
leaq -0x8(,%rax,8), %rdi
movq %r12, %rsi
movl $0xc, %edx
callq 0x390f5
movq %rax, (%r13)
cmpl $0x0, 0x1bc(%rbx)
jle 0x3c432
movq 0x38(%rsp), %r15
xorl %ebp, %ebp
movq 0x8(%rsp), %r12
cmpl $0x1, -0x18(%r15)
jne 0x3c2b7
movl (%r15), %esi
movq %r14, %rdi
callq 0x3a514
movq (%r13), %rcx
movq %rax, (%rcx,%rbp,8)
incq %rbp
movslq 0x1bc(%rbx), %rax
addq $0x340, %r15            # imm = 0x340
cmpq %rax, %rbp
jl 0x3c29d
jmp 0x3c364
movq %r12, %rbp
movl $0x18, %edi
leaq 0x6ab56(%rip), %r12     # 0xa6e37
movq %r12, %rsi
movl $0x26, %edx
callq 0x390f5
movq %rax, %r13
leaq 0x8(%rax), %rdx
movq %r14, %rdi
leaq 0x7185e(%rip), %rsi     # 0xadb5d
xorl %eax, %eax
callq 0x4070
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3a514
movq %rax, 0x10(%r13)
movslq 0x8(%r13), %rdi
shlq $0x3, %rdi
movq %r12, %rsi
movl $0x29, %edx
callq 0x390f5
movq %rax, (%r13)
cmpl $0x0, 0x8(%r13)
jle 0x3c4b4
xorl %r15d, %r15d
movq %rbp, %r12
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3a514
movq (%r13), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movslq 0x8(%r13), %rax
cmpq %rax, %r15
jl 0x3c340
leaq 0x6a851(%rip), %r15     # 0xa6bbc
jmp 0x3c4b7
movq %r12, 0x8(%rsp)
movl $0x18, %edi
leaq 0x6aab6(%rip), %r12     # 0xa6e37
movq %r12, %rsi
movl $0x17, %edx
callq 0x390f5
movq %rax, %r13
leaq 0x8(%rax), %rdx
movq %r14, %rdi
leaq 0x717be(%rip), %rsi     # 0xadb5d
xorl %eax, %eax
callq 0x4070
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3a514
movq %rax, 0x10(%r13)
movslq 0x8(%r13), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
movq %r12, %rsi
movl $0x1a, %edx
callq 0x390f5
movq %rax, (%r13)
cmpl $0x0, 0x8(%r13)
jle 0x3c432
movl $0x10, %r15d
xorl %ebp, %ebp
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3a514
movq (%r13), %r12
movq %rax, -0x10(%r12,%r15)
movl 0x1c0(%rbx), %edx
decl %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x3a488
movq %rax, -0x8(%r12,%r15)
movq %rdx, (%r12,%r15)
incq %rbp
movslq 0x8(%r13), %rax
addq $0x18, %r15
cmpq %rax, %rbp
jl 0x3c3e2
leaq 0x6a78f(%rip), %r15     # 0xa6bbc
movq 0x10(%rsp), %rbp
movq 0x8(%rsp), %r12
jmp 0x3c4bc
movl $0x8, %edi
leaq 0x6a9ef(%rip), %rsi     # 0xa6e37
movl $0x22, %edx
callq 0x390f5
movq %rax, %r13
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3a514
movq %rax, (%r13)
jmp 0x3c4bc
movl $0x18, %edi
leaq 0x6a9c0(%rip), %rsi     # 0xa6e37
movl $0x12, %edx
callq 0x390f5
movq %rax, %r13
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3a514
movq %rax, (%r13)
movl 0x1c0(%rbx), %edx
decl %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x3a488
movq %rax, 0x8(%r13)
movq %rdx, 0x10(%r13)
jmp 0x3c4bc
movq %rbp, %r12
movq 0x10(%rsp), %rbp
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %r13, 0x18(%rax,%r12)
movq 0x40(%rsp), %r12
incq %r12
movslq (%rbp), %rsi
cmpq %rsi, %r12
jl 0x3c1e1
movq 0x30(%rsp), %rcx
incq %rcx
movslq 0x10(%rbx), %rax
cmpq %rax, %rcx
leaq 0x6a943(%rip), %r12     # 0xa6e37
jl 0x3c163
movq 0x20(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq