// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/hmm.c
// Function: clone_state_model
void* clone_state_model(void* model, HMM_STATE_TYPE statetype)
{
 /*!Last Changed 15.03.2007*/
 Gaussianptr g, g1;
 Gaussianmixtureptr gm, gm1;
 Multinomialptr m, m1;
 Dirichletptr d, d1;
 Dirichletmixtureptr dm, dm1;
 int i, j;
 int numrealfeatures = current_dataset->multifeaturecount - 1;
 switch (statetype)
  {
   case          STATE_DISCRETE:m = (Multinomialptr) model;
                                m1 = safemalloc(sizeof(Multinomial), "clone_state_model", 11);
                                m1->prob = safemalloc(sizeof(double*) * (current_dataset->featurecount - 1), "clone_state_model", 11);
                                j = 0;
                                for (i = 0; i < current_dataset->featurecount; i++)
                                  if (current_dataset->features[i].type == STRING)
                                   {
                                    m1->prob[j] = clone_array(m->prob[j],  current_dataset->features[i].valuecount);
                                    j++;
                                   }
                                return m1;
                                break;
   case          STATE_GAUSSIAN:g = (Gaussianptr) model;
                                g1 = safemalloc(sizeof(Gaussian), "clone_state_model", 23);
                                g1->mean = clone_array(g->mean, numrealfeatures);
                                g1->covariance = matrix_copy(g->covariance);
                                return g1;
                                break;
   case  STATE_GAUSSIAN_MIXTURE:gm = (Gaussianmixtureptr) model;
                                gm1 = safemalloc(sizeof(Gaussianmixture), "clone_state_model", 29);
                                gm1->componentcount = gm->componentcount;
                                gm1->weights = clone_array(gm->weights, gm->componentcount);
                                gm1->components = safemalloc(gm->componentcount * sizeof(Gaussian), "clone_state_model", 32);
                                for (i = 0; i < gm->componentcount; i++)
                                 {
                                  gm1->components[i].mean = clone_array(gm->components[i].mean, numrealfeatures);
                                  gm1->components[i].covariance = matrix_copy(gm->components[i].covariance);
                                 }
                                return gm1;
                                break;
   case         STATE_DIRICHLET:d = (Dirichletptr) model;
                                d1 = safemalloc(sizeof(Dirichlet), "clone_state_model", 40);
                                d1->alpha = clone_array(d->alpha, numrealfeatures);
                                return d1;
                                break;
   case STATE_DIRICHLET_MIXTURE:dm = (Dirichletmixtureptr) model;
                                dm1 = safemalloc(sizeof(Dirichletmixture), "clone_state_model", 45);
                                dm1->componentcount = dm->componentcount;
                                dm1->weights = clone_array(dm->weights, dm->componentcount);
                                dm1->components = safemalloc(dm->componentcount * sizeof(Dirichlet), "clone_state_model", 48);
                                for (i = 0; i < dm->componentcount; i++)
                                  dm1->components[i].alpha = clone_array(dm->components[i].alpha, numrealfeatures);
                                return dm1;
                                break;
      default                  :return NULL;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
cmpl $0x4, %esi
ja 0x2536c
movq %rdi, %rbx
leaq 0xa8706(%rip), %r12     # 0xcd870
movq (%r12), %rax
movl 0x1c0(%rax), %ebp
decl %ebp
movl %esi, %eax
leaq 0x730a9(%rip), %rcx     # 0x98228
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
leaq 0x733e8(%rip), %r15     # 0x98577
pushq $0x8
popq %rdi
pushq $0xb
popq %rbp
movq %r15, %rsi
movl %ebp, %edx
callq 0x34f59
movq %rax, %r14
movq (%r12), %rax
movslq 0x1bc(%rax), %rax
leaq -0x8(,%rax,8), %rdi
movq %r15, %rsi
movl %ebp, %edx
callq 0x34f59
movq %rax, (%r14)
movq (%r12), %rax
xorl %r15d, %r15d
movl $0x30f20, %r13d         # imm = 0x30F20
xorl %ebp, %ebp
movslq 0x1bc(%rax), %rcx
cmpq %rcx, %r15
jge 0x2536f
cmpl $0x1, -0x18(%rax,%r13)
jne 0x25209
movq (%rbx), %rcx
movslq %ebp, %rbp
movq (%rcx,%rbp,8), %rdi
movl (%rax,%r13), %esi
callq 0x3325d
movq (%r14), %rcx
movq %rax, (%rcx,%rbp,8)
incl %ebp
movq (%r12), %rax
incq %r15
addq $0x340, %r13            # imm = 0x340
jmp 0x251d1
leaq 0x7335b(%rip), %r15     # 0x98577
pushq $0x18
popq %rdi
pushq $0x2d
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r14
movl 0x8(%rbx), %esi
movl %esi, 0x8(%rax)
movq 0x10(%rbx), %rdi
callq 0x3325d
movq %rax, 0x10(%r14)
movslq 0x8(%rbx), %rdi
shlq $0x3, %rdi
pushq $0x30
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, (%r14)
xorl %r15d, %r15d
movslq 0x8(%rbx), %rax
cmpq %rax, %r15
jge 0x2536f
movq (%rbx), %rax
movq (%rax,%r15,8), %rdi
movl %ebp, %esi
callq 0x3325d
movq (%r14), %rcx
movq %rax, (%rcx,%r15,8)
incq %r15
jmp 0x25259
leaq 0x732f0(%rip), %r15     # 0x98577
pushq $0x18
popq %rdi
pushq $0x1d
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, %r14
movl 0x8(%rbx), %esi
movl %esi, 0x8(%rax)
movq 0x10(%rbx), %rdi
callq 0x3325d
movq %rax, 0x10(%r14)
movslq 0x8(%rbx), %rax
imulq $0x18, %rax, %rdi
pushq $0x20
popq %rdx
movq %r15, %rsi
callq 0x34f59
movq %rax, (%r14)
xorl %r15d, %r15d
xorl %r12d, %r12d
movslq 0x8(%rbx), %rax
cmpq %rax, %r12
jge 0x2536f
movq (%rbx), %rax
movq (%rax,%r15), %rdi
movl %ebp, %esi
callq 0x3325d
movq (%r14), %r13
movq %rax, (%r13,%r15)
movq (%rbx), %rax
movq 0x8(%rax,%r15), %rdi
movq 0x10(%rax,%r15), %rsi
callq 0x383f4
movq %rax, 0x8(%r13,%r15)
movq %rdx, 0x10(%r13,%r15)
incq %r12
addq $0x18, %r15
jmp 0x252c7
leaq 0x73261(%rip), %rsi     # 0x98577
pushq $0x8
popq %rdi
pushq $0x28
popq %rdx
callq 0x34f59
movq %rax, %r14
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x3325d
movq %rax, (%r14)
jmp 0x2536f
leaq 0x7323d(%rip), %rsi     # 0x98577
pushq $0x18
popq %rdi
pushq $0x17
popq %rdx
callq 0x34f59
movq %rax, %r14
movq (%rbx), %rdi
movl %ebp, %esi
callq 0x3325d
movq %rax, (%r14)
movq 0x8(%rbx), %rdi
movq 0x10(%rbx), %rsi
callq 0x383f4
movq %rax, 0x8(%r14)
movq %rdx, 0x10(%r14)
jmp 0x2536f
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq