// File: /workspace/github_c_makefile_star2_O3/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 $0x38, %rsp
movq %r8, 0x30(%rsp)
movl %ecx, %ebp
movl %edx, 0x4(%rsp)
movl %esi, %r14d
movl %edi, %r13d
movl %ecx, %edx
callq 0x27aa9
movq %rax, %rbx
movl %r13d, %edi
callq 0x3b25f
movq %rax, 0x28(%rsp)
testl %r13d, %r13d
jle 0x27d2f
movl %r13d, %r15d
leaq (,%r15,8), %r12
movq %r13, 0x18(%rsp)
leal -0x1(%r13), %eax
movq (%rbx), %rcx
leaq (,%rax,8), %rdx
movq %rdx, 0x20(%rsp)
xorl %r13d, %r13d
movq %rax, 0x10(%rsp)
shlq $0x5, %rax
movq %rax, 0x8(%rsp)
movq 0x28(%rsp), %rax
movsd (%rax,%r13), %xmm0
movsd %xmm0, 0x10(%rcx,%r13,4)
movq %r12, %rdi
leaq 0x807a4(%rip), %rsi     # 0xa833e
movl $0x9, %edx
callq 0x3a0e1
movq (%rbx), %rcx
movq %rax, (%rcx,%r13,4)
cmpl $0x2, %ebp
je 0x27c3a
cmpl $0x1, %ebp
je 0x27bd8
testl %ebp, %ebp
jne 0x27cc7
movq 0x18(%rsp), %rdi
callq 0x3b25f
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
jmp 0x27cc7
movl $0x8, %esi
movq %r15, %rdi
leaq 0x80757(%rip), %rdx     # 0xa833e
movl $0xe, %ecx
callq 0x3a1fc
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
xorpd %xmm0, %xmm0
movsd 0x7d91b(%rip), %xmm1    # 0xa5520
callq 0x3af6a
movq (%rbx), %rax
cmpq %r13, 0x20(%rsp)
jne 0x27c9c
movq 0x8(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq 0x10(%rsp), %rcx
movabsq $0x3ff0000000000000, %rdx # imm = 0x3FF0000000000000
movq %rdx, (%rax,%rcx,8)
jmp 0x27cc7
movl $0x8, %esi
movq %r15, %rdi
leaq 0x806f5(%rip), %rdx     # 0xa833e
movl $0x18, %ecx
callq 0x3a1fc
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
xorpd %xmm0, %xmm0
movsd 0x7d8b9(%rip), %xmm1    # 0xa5520
callq 0x3af6a
movq (%rbx), %rax
movsd 0x7d8a9(%rip), %xmm1    # 0xa5520
subsd %xmm0, %xmm1
cmpq %r13, 0x20(%rsp)
jne 0x27cb5
movq 0x8(%rsp), %rcx
movq 0x8(%rax,%rcx), %rax
movq 0x10(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd %xmm1, (%rax)
jmp 0x27cc7
movq 0x8(%rax,%r13,4), %rax
movsd %xmm0, (%rax,%r13)
movsd 0x7d871(%rip), %xmm1    # 0xa5520
subsd %xmm0, %xmm1
jmp 0x27cc0
movq 0x8(%rax,%r13,4), %rax
movsd %xmm0, (%rax,%r13)
movsd %xmm1, 0x8(%rax,%r13)
movl %r14d, %edi
movl 0x4(%rsp), %esi
movq 0x30(%rsp), %rdx
callq 0x27d4b
movq (%rbx), %rcx
movq %rax, 0x18(%rcx,%r13,4)
addq $0x8, %r13
cmpq %r13, %r12
jne 0x27b7e
cmpl $0x0, 0x18(%rsp)
jle 0x27d2f
movq (%rbx), %rax
leaq (,%r15,8), %rcx
xorl %edx, %edx
movq %rdx, %rsi
shlq $0x5, %rsi
movq 0x8(%rax,%rsi), %rsi
xorl %edi, %edi
movsd (%rsi,%rdi), %xmm0
movq (%rax,%rdi,4), %r8
movsd %xmm0, (%r8,%rdx,8)
addq $0x8, %rdi
cmpq %rdi, %rcx
jne 0x27d0f
incq %rdx
cmpq %r15, %rdx
jne 0x27d01
movq 0x28(%rsp), %rdi
callq 0x3a180
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq