// File: /workspace/github_c_makefile_star2_O1/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, 0x14(%rsp)
movl %esi, %r14d
movl %edi, %r12d
movl %ecx, %edx
callq 0x273c5
movq %rax, %rbx
movl %r12d, %edi
callq 0x3a1d2
movq %rax, 0x20(%rsp)
movl %r12d, %r15d
movq %r12, 0x8(%rsp)
testl %r12d, %r12d
jle 0x275de
leaq (,%r15,8), %r12
movq 0x8(%rsp), %rax
decl %eax
movslq %eax, %rcx
movq %rcx, 0x28(%rsp)
shlq $0x3, %rax
movq %rax, 0x18(%rsp)
xorl %r13d, %r13d
movq 0x20(%rsp), %rax
movsd (%rax,%r13), %xmm0
movq (%rbx), %rax
movsd %xmm0, 0x10(%rax,%r13,4)
movq %r12, %rdi
leaq 0x7de37(%rip), %rsi     # 0xa52e6
movl $0x9, %edx
callq 0x390f5
movq (%rbx), %rcx
movq %rax, (%rcx,%r13,4)
cmpl $0x2, %ebp
je 0x2753a
cmpl $0x1, %ebp
je 0x274e9
testl %ebp, %ebp
jne 0x275b8
movq 0x8(%rsp), %rdi
callq 0x3a1d2
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
jmp 0x275b8
movl $0x8, %esi
movq %r15, %rdi
leaq 0x7ddee(%rip), %rdx     # 0xa52e6
movl $0xe, %ecx
callq 0x39210
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
xorpd %xmm0, %xmm0
movsd 0x7b00a(%rip), %xmm1    # 0xa2520
callq 0x39f62
movq (%rbx), %rax
movq 0x8(%rax,%r13,4), %rax
cmpq %r13, 0x18(%rsp)
jne 0x27597
movabsq $0x3ff0000000000000, %rcx # imm = 0x3FF0000000000000
movq %rcx, (%rax,%r13)
jmp 0x275b8
movl $0x8, %esi
movq %r15, %rdi
leaq 0x7dd9d(%rip), %rdx     # 0xa52e6
movl $0x18, %ecx
callq 0x39210
movq (%rbx), %rcx
movq %rax, 0x8(%rcx,%r13,4)
xorpd %xmm0, %xmm0
movsd 0x7afb9(%rip), %xmm1    # 0xa2520
callq 0x39f62
movq (%rbx), %rax
movq 0x8(%rax,%r13,4), %rax
movsd 0x7afa4(%rip), %xmm1    # 0xa2520
subsd %xmm0, %xmm1
cmpq %r13, 0x18(%rsp)
jne 0x275ab
movq 0x28(%rsp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movsd %xmm1, (%rax)
jmp 0x275b8
movsd %xmm0, (%rax,%r13)
movsd 0x7af7b(%rip), %xmm1    # 0xa2520
subsd %xmm0, %xmm1
jmp 0x275b1
movsd %xmm0, (%rax,%r13)
movsd %xmm1, 0x8(%rax,%r13)
movl %r14d, %edi
movl 0x14(%rsp), %esi
movq 0x30(%rsp), %rdx
callq 0x2763c
movq (%rbx), %rcx
movq %rax, 0x18(%rcx,%r13,4)
addq $0x8, %r13
cmpq %r13, %r12
jne 0x27490
cmpl $0x0, 0x8(%rsp)
jle 0x27620
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 0x27600
incq %rdx
cmpq %r15, %rdx
jne 0x275f2
movq 0x20(%rsp), %rdi
callq 0x39194
movq %rbx, %rax
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq