// File: /workspace/github_c_makefile_star2_O2/olcaytaner[P]Isell/hmm.c
// Function: random_hmm
Hmmptr random_hmm(int statecount, HMM_STATE_TYPE statetype, int componentcount, HMM_MODEL_TYPE hmmtype, Instanceptr traindata)
{
 /*!Last Changed 27.03.2007*/
 int i, j;
 Hmmptr result;
 double* myarray, randvalue;
 result = empty_hmm(statecount, statetype, hmmtype);
 myarray = random_normalized_array(statecount);
 for (i = 0; i < statecount; i++)
  {
   result->states[i].pi = myarray[i];
   result->states[i].a_dot_j = safemalloc(sizeof(double) * statecount, "random_hmm", 9);
   switch (hmmtype)
    {
     case    FULL_MODEL:result->states[i].a_i_dot = random_normalized_array(statecount);
                        break;
     case      LR_MODEL:result->states[i].a_i_dot = safecalloc(statecount, sizeof(double), "random_hmm", 14);
                        randvalue = produce_random_value(0.0, 1.0);
                        if (i != statecount - 1)
                         {
                          result->states[i].a_i_dot[i] = randvalue;
                          result->states[i].a_i_dot[i + 1] = 1 - randvalue;
                         } 
                        else
                          result->states[i].a_i_dot[i] = 1.0;
                        break;
     case LR_LOOP_MODEL:result->states[i].a_i_dot = safecalloc(statecount, sizeof(double), "random_hmm", 24);
                        randvalue = produce_random_value(0.0, 1.0);
                        if (i != statecount - 1)
                         {
                          result->states[i].a_i_dot[i] = randvalue;
                          result->states[i].a_i_dot[i + 1] = 1 - randvalue;
                         } 
                        else
                         {
                          result->states[i].a_i_dot[statecount - 1] = randvalue;
                          result->states[i].a_i_dot[0] = 1 - randvalue;
                         }
                        break;
    }
   result->states[i].b = random_state_model(statetype, componentcount, traindata);
  } 
 for (i = 0; i < statecount; i++)
   for (j = 0; j < statecount; j++)
     result->states[j].a_dot_j[i] = result->states[i].a_i_dot[j];
 safe_free(myarray);
 return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %r8, 0x40(%rsp)
movl %ecx, %ebp
movl %edx, 0xc(%rsp)
movl %edi, %r13d
movl %esi, 0x8(%rsp)
movl %ecx, %edx
callq 0x245b4
movq %rax, %rbx
movl %r13d, %edi
callq 0x35e36
movq %rax, 0x28(%rsp)
movslq %r13d, %rax
leaq (,%rax,8), %r14
leal -0x1(%rax), %ecx
xorl %r12d, %r12d
movq %rax, 0x20(%rsp)
testl %eax, %eax
movl $0x0, %r15d
movl %r13d, 0x4(%rsp)
cmovgl %r13d, %r15d
movslq %ecx, %rax
movq %rax, 0x30(%rsp)
leaq (,%r15,8), %r13
leaq (,%rcx,8), %rax
movq %rax, 0x18(%rsp)
movq %rcx, 0x38(%rsp)
shlq $0x5, %rcx
movq %rcx, 0x10(%rsp)
cmpq %r12, %r13
je 0x24809
movq 0x28(%rsp), %rax
movsd (%rax,%r12), %xmm0
movq (%rbx), %rax
movsd %xmm0, 0x10(%rax,%r12,4)
movq %r14, %rdi
leaq 0x73bfe(%rip), %rsi     # 0x982be
pushq $0x9
popq %rdx
callq 0x34f59
movq (%rbx), %rcx
movq %rax, (%rcx,%r12,4)
cmpl $0x2, %ebp
je 0x2475b
cmpl $0x1, %ebp
je 0x246fb
testl %ebp, %ebp
jne 0x247e6
movl 0x4(%rsp), %edi
callq 0x35e36
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r12,4)
jmp 0x247e6
movq 0x20(%rsp), %rdi
pushq $0x8
popq %rsi
leaq 0x73bb4(%rip), %rdx     # 0x982be
pushq $0xe
popq %rcx
callq 0x35067
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r12,4)
xorpd %xmm0, %xmm0
movsd 0x70dfa(%rip), %xmm1    # 0x95520
callq 0x35cae
movq (%rbx), %rax
cmpq %r12, 0x18(%rsp)
jne 0x247bb
movq 0x10(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq 0x38(%rsp), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
jmp 0x247e6
movq 0x20(%rsp), %rdi
pushq $0x8
popq %rsi
leaq 0x73b54(%rip), %rdx     # 0x982be
pushq $0x18
popq %rcx
callq 0x35067
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r12,4)
xorpd %xmm0, %xmm0
movsd 0x70d9a(%rip), %xmm1    # 0x95520
callq 0x35cae
movq (%rbx), %rax
movsd 0x70d8a(%rip), %xmm1    # 0x95520
subsd %xmm0, %xmm1
cmpq %r12, 0x18(%rsp)
jne 0x247d4
movq 0x10(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd %xmm1, (%rax)
jmp 0x247e6
movq 0x8(%rax,%r12,4), %rax
movsd %xmm0, (%rax,%r12)
movsd 0x70d52(%rip), %xmm1    # 0x95520
subsd %xmm0, %xmm1
jmp 0x247df
movq 0x8(%rax,%r12,4), %rax
movsd %xmm0, (%rax,%r12)
movsd %xmm1, 0x8(%rax,%r12)
movl 0x8(%rsp), %edi
movl 0xc(%rsp), %esi
movq 0x40(%rsp), %rdx
callq 0x24864
movq (%rbx), %rcx
movq %rax, 0x18(%rcx,%r12,4)
addq $0x8, %r12
jmp 0x24698
movl 0x4(%rsp), %eax
shlq $0x3, %rax
xorl %ecx, %ecx
cmpq %r15, %rcx
je 0x24848
movq %rcx, %rdx
shlq $0x5, %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x24843
movq (%rbx), %rdi
movq 0x8(%rdi,%rdx), %r8
movsd (%r8,%rsi), %xmm0
movq (%rdi,%rsi,4), %rdi
movsd %xmm0, (%rdi,%rcx,8)
addq $0x8, %rsi
jmp 0x24821
incq %rcx
jmp 0x24813
movq 0x28(%rsp), %rdi
callq 0x34ff7
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq