// File: /workspace/github_c_makefile_star2_O3/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 0x6ccd9(%rip), %rsi     # 0xa9ea7
movl $0xa, %edx
callq 0x3a0e1
movq %rax, 0x18(%rsp)
cmpl $0x0, 0x10(%rbx)
jle 0x3d5b0
leaq 0x30f20(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x6ccad(%rip), %r12     # 0xa9ea7
leaq 0x6ca2b(%rip), %r15     # 0xa9c2c
xorl %ecx, %ecx
movl $0x18, %edi
movq %r12, %rsi
movl $0xb, %edx
movq %rcx, %r13
callq 0x3a0e1
movq %rax, %rbp
movq 0x18(%rsp), %rax
movq %r13, 0x28(%rsp)
movq %rbp, (%rax,%r13,8)
leaq 0x8(%rbp), %rdx
movq %rdx, 0x38(%rsp)
movq %r14, %rdi
leaq 0x6cba5(%rip), %rsi     # 0xa9de1
leaq 0x14(%rsp), %rcx
xorl %eax, %eax
callq 0x4070
movl 0x14(%rsp), %eax
movl %eax, 0xc(%rbp)
movslq 0x8(%rbp), %rdi
shlq $0x5, %rdi
movq %r12, %rsi
movl $0x4, %edx
callq 0x3a0e1
movq %rax, (%rbp)
movq %rbp, 0x20(%rsp)
movl 0x8(%rbp), %esi
leaq 0x6ca09(%rip), %rbp     # 0xa9c80
testl %esi, %esi
jle 0x3d594
xorl %r12d, %r12d
movq %r14, %rdi
callq 0x3b5a4
movq 0x20(%rsp), %r13
movq (%r13), %rcx
movq %r12, 0x40(%rsp)
shlq $0x5, %r12
movq %rax, (%rcx,%r12)
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3b5a4
movq (%r13), %rcx
leaq (%rcx,%r12), %rdx
addq $0x10, %rdx
movq %rax, -0x8(%rdx)
movq %r14, %rdi
movq %rbp, %rsi
xorl %eax, %eax
callq 0x4070
movl 0xc(%r13), %eax
cmpq $0x4, %rax
ja 0x3d57b
movslq (%r15,%rax,4), %rax
addq %r15, %rax
jmpq *%rax
movq %r12, 0x8(%rsp)
movl $0x8, %edi
leaq 0x6cbb6(%rip), %r12     # 0xa9ea7
movq %r12, %rsi
movl $0xb, %edx
callq 0x3a0e1
movq %rax, %r13
movslq 0x1bc(%rbx), %rax
leaq -0x8(,%rax,8), %rdi
movq %r12, %rsi
movl $0xc, %edx
callq 0x3a0e1
movq %rax, (%r13)
movl 0x1bc(%rbx), %eax
testl %eax, %eax
jle 0x3d4e2
movq 0x30(%rsp), %r15
xorl %ebp, %ebp
movq 0x8(%rsp), %r12
cmpl $0x1, -0x18(%r15)
jne 0x3d35b
movl (%r15), %esi
movq %r14, %rdi
callq 0x3b5a4
movq (%r13), %rcx
movq %rax, (%rcx,%rbp,8)
movl 0x1bc(%rbx), %eax
incq %rbp
movslq %eax, %rcx
addq $0x340, %r15            # imm = 0x340
cmpq %rcx, %rbp
jl 0x3d33b
leaq 0x6c90c(%rip), %rbp     # 0xa9c80
leaq 0x6c8b1(%rip), %r15     # 0xa9c2c
jmp 0x3d56e
movq %r12, %rbp
movl $0x18, %edi
leaq 0x6cb18(%rip), %r12     # 0xa9ea7
movq %r12, %rsi
movl $0x26, %edx
callq 0x3a0e1
movq %rax, %r13
leaq 0x8(%rax), %rdx
movq %r14, %rdi
leaq 0x73848(%rip), %rsi     # 0xb0bf5
xorl %eax, %eax
callq 0x4070
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3b5a4
movq %rax, 0x10(%r13)
movslq 0x8(%r13), %rdi
shlq $0x3, %rdi
movq %r12, %rsi
movl $0x29, %edx
callq 0x3a0e1
movq %rax, (%r13)
cmpl $0x0, 0x8(%r13)
jle 0x3d564
xorl %r15d, %r15d
movq %rbp, %r12
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3b5a4
movq (%r13), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
movslq 0x8(%r13), %rax
cmpq %rax, %r15
jl 0x3d3ee
leaq 0x6c813(%rip), %r15     # 0xa9c2c
jmp 0x3d567
movq %r12, 0x8(%rsp)
movl $0x18, %edi
leaq 0x6ca78(%rip), %r12     # 0xa9ea7
movq %r12, %rsi
movl $0x17, %edx
callq 0x3a0e1
movq %rax, %r13
leaq 0x8(%rax), %rdx
movq %r14, %rdi
leaq 0x737a8(%rip), %rsi     # 0xb0bf5
xorl %eax, %eax
callq 0x4070
movl 0x8(%r13), %esi
movq %r14, %rdi
callq 0x3b5a4
movq %rax, 0x10(%r13)
movslq 0x8(%r13), %rax
shlq $0x3, %rax
leaq (%rax,%rax,2), %rdi
movq %r12, %rsi
movl $0x1a, %edx
callq 0x3a0e1
movq %rax, (%r13)
cmpl $0x0, 0x8(%r13)
jle 0x3d4e2
movl $0x10, %r15d
xorl %ebp, %ebp
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3b5a4
movq (%r13), %r12
movq %rax, -0x10(%r12,%r15)
movl 0x1c0(%rbx), %edx
decl %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x3b518
movq %rax, -0x8(%r12,%r15)
movq %rdx, (%r12,%r15)
incq %rbp
movslq 0x8(%r13), %rax
addq $0x18, %r15
cmpq %rax, %rbp
jl 0x3d490
leaq 0x6c7a5(%rip), %rbp     # 0xa9c80
leaq 0x6c74a(%rip), %r15     # 0xa9c2c
movq 0x8(%rsp), %r12
jmp 0x3d56e
movl $0x8, %edi
leaq 0x6c9af(%rip), %rsi     # 0xa9ea7
movl $0x22, %edx
callq 0x3a0e1
movq %rax, %r13
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3b5a4
movq %rax, (%r13)
jmp 0x3d56e
movl $0x18, %edi
leaq 0x6c980(%rip), %rsi     # 0xa9ea7
movl $0x12, %edx
callq 0x3a0e1
movq %rax, %r13
movl 0x1c0(%rbx), %esi
decl %esi
movq %r14, %rdi
callq 0x3b5a4
movq %rax, (%r13)
movl 0x1c0(%rbx), %edx
decl %edx
movq %r14, %rdi
movl %edx, %esi
callq 0x3b518
movq %rax, 0x8(%r13)
movq %rdx, 0x10(%r13)
jmp 0x3d56e
movq %rbp, %r12
leaq 0x6c712(%rip), %rbp     # 0xa9c80
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %r13, 0x18(%rax,%r12)
movq 0x40(%rsp), %r12
incq %r12
movq 0x38(%rsp), %rcx
movslq (%rcx), %rsi
cmpq %rsi, %r12
jl 0x3d282
movq 0x28(%rsp), %rcx
incq %rcx
movslq 0x10(%rbx), %rax
cmpq %rax, %rcx
leaq 0x6c8fd(%rip), %r12     # 0xa9ea7
jl 0x3d203
movq 0x18(%rsp), %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq