// File: /workspace/github_c_makefile_star2_O1/olcaytaner[P]Isell/hmm.c
// Function: check_hmm
int check_hmm(char* name, Hmmptr hmm)
{
 /*!Last Changed 11.04.2007*/
 int i, j;
 double sum;
 Gaussianptr g;
 Gaussianmixtureptr gm;
 int numrealfeatures = current_dataset->multifeaturecount - 1;
 printf("Checking %s. ", name);
 if (!between(hmm->hmmtype, 0, 2))
  {
   printf("Hmm type %d wrong\n", hmm->hmmtype);
   return 0;
  }
 if (!between(hmm->statetype, 0, 4))
  {
   printf("Hmm state type %d wrong\n", hmm->statetype);
   return 0;
  }
 if (hmm->statecount <= 1)
  {
   printf("Hmm state count %d must be larger than 1\n", hmm->statecount);
   return 0;
  }
 if (!(hmm->states))
  {
   printf("Hmm states not allocated\n");
   return 0;
  }
 sum = 0.0;
 for (i = 0; i < hmm->statecount; i++)
   sum += hmm->states[i].pi;
 if (!dequal(sum - 1, 0))
  {
   printf("Sum of pi %.6f is not equal to 1\n", sum);
   return 0;
  }
 for (i = 0; i < hmm->statecount; i++)
  {
   for (j = 0; j < hmm->statecount; j++)
     if (hmm->states[i].a_i_dot[j] != hmm->states[j].a_dot_j[i])
      {
       printf("Outgoing probability %.6f and incoming probability %.6f from state %d to state %d do not match\n", hmm->states[i].a_i_dot[j], hmm->states[j].a_dot_j[i], i, j);
       return 0;
      }
   sum = sum_of_list_double(hmm->states[i].a_i_dot, hmm->statecount);
   if (!dequal(sum - 1, 0))
    {
     printf("Sum of a_i_dot %.6f of state %d is not equal to 1\n", sum, i);
     return 0;
    }
   switch (hmm->statetype)
    {
     case         STATE_GAUSSIAN:g = (Gaussianptr) hmm->states[i].b;
                                 if (!(g->mean))
                                  {
                                   printf("Gaussian mean of state %d not allocated\n", i);
                                   return 0;
                                  }
                                 if (g->covariance.row != numrealfeatures || g->covariance.col != numrealfeatures)
                                  {
                                   printf("Covariance matrix dimensions %d %d of state %d is not true\n", g->covariance.row, g->covariance.col, i);
                                   return 0;
                                  }
                                 break;
     case STATE_GAUSSIAN_MIXTURE:gm = (Gaussianmixtureptr) hmm->states[i].b;
                                 if (gm->componentcount <= 0)
                                  {
                                   printf("Number of components %d must be larger than 0\n", gm->componentcount);
                                   return 0;
                                  }
                                 sum = sum_of_list_double(gm->weights, gm->componentcount);
                                 if (!dequal(sum - 1, 0))
                                  {
                                   printf("Sum of component weights %.6f must be equal to 1.0", sum);
                                   return 0;
                                  }
                                 if (!(gm->components))
                                  {
                                   printf("Gaussian components not allocated\n");
                                   return 0;
                                  }
                                 for (j = 0; i < gm->componentcount; i++)
                                  {
                                   if (!(gm->components[i].mean))
                                    {
                                     printf("Gaussian mean of mixture component %d of state %d not allocated\n", j, i);
                                     return 0;
                                    }
                                   if (gm->components[i].covariance.row != numrealfeatures || gm->components[i].covariance.col != numrealfeatures)
                                    {
                                     printf("Covariance matrix dimensions %d %d of mixture component %d of state %d is not true\n", g->covariance.row, g->covariance.col, j, i);
                                     return 0;
                                    }
                                  }
                                 break;
     default                    :break;
    }
  }
 printf("Ok...\n");
 return 1;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, %rbx
movq %rdi, %rsi
leaq 0xa9ec8(%rip), %rax     # 0xd2870
movq (%rax), %rax
movl 0x1c0(%rax), %r15d
leaq 0x7c941(%rip), %rdi     # 0xa52fa
xorl %ebp, %ebp
xorl %eax, %eax
callq 0x4030
movl 0x10(%rbx), %edi
xorl %esi, %esi
movl $0x2, %edx
callq 0x38d18
testl %eax, %eax
je 0x289ff
movl 0xc(%rbx), %edi
xorl %ebp, %ebp
xorl %esi, %esi
movl $0x4, %edx
callq 0x38d18
testl %eax, %eax
je 0x28a0b
movslq 0x8(%rbx), %rsi
cmpq $0x1, %rsi
jg 0x28a2d
leaq 0x7c939(%rip), %rdi     # 0xa5334
xorl %ebp, %ebp
jmp 0x28a15
movl 0x10(%rbx), %esi
leaq 0x7c8ff(%rip), %rdi     # 0xa5308
jmp 0x28a15
movl 0xc(%rbx), %esi
leaq 0x7c906(%rip), %rdi     # 0xa531b
xorl %eax, %eax
callq 0x4030
movl %ebp, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq (%rbx), %rax
testq %rax, %rax
je 0x28bef
decl %r15d
shlq $0x5, %rsi
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
addsd 0x10(%rax,%rcx), %xmm1
addq $0x20, %rcx
cmpq %rcx, %rsi
jne 0x28a46
movsd 0x7a34b(%rip), %xmm0    # 0xa2da8
movsd %xmm1, (%rsp)
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
callq 0x38d52
testl %eax, %eax
je 0x28bfd
movl 0x8(%rbx), %esi
testl %esi, %esi
jle 0x28bd9
xorl %r14d, %r14d
movslq %r14d, %r13
testl %esi, %esi
jle 0x28ac9
movq (%rbx), %rax
movq %r13, %rcx
shlq $0x5, %rcx
movq 0x8(%rax,%rcx), %rcx
movl %esi, %edi
xorl %edx, %edx
movsd (%rcx,%rdx,8), %xmm0
movq (%rax), %r8
movsd (%r8,%r13,8), %xmm1
ucomisd %xmm1, %xmm0
jne 0x28c12
jp 0x28c12
incq %rdx
addq $0x20, %rax
cmpq %rdx, %rdi
jne 0x28a9f
movq (%rbx), %rax
movq %r13, %rbp
shlq $0x5, %rbp
movq 0x8(%rax,%rbp), %rdi
callq 0x37ae1
movsd %xmm0, (%rsp)
addsd 0x7a2be(%rip), %xmm0    # 0xa2da8
xorpd %xmm1, %xmm1
callq 0x38d52
testl %eax, %eax
je 0x28c6e
movl 0xc(%rbx), %eax
cmpl $0x2, %eax
je 0x28b3d
cmpl $0x1, %eax
jne 0x28bca
movq (%rbx), %rax
movq 0x18(%rax,%rbp), %r12
cmpq $0x0, (%r12)
je 0x28cb1
movl 0x8(%r12), %esi
cmpl %r15d, %esi
jne 0x28c86
cmpl %r15d, 0xc(%r12)
je 0x28bca
jmp 0x28c86
movq (%rbx), %rax
movq 0x18(%rax,%rbp), %rbp
movl 0x8(%rbp), %esi
testl %esi, %esi
jle 0x28ca3
movq 0x10(%rbp), %rdi
callq 0x37ae1
movsd %xmm0, (%rsp)
addsd 0x7a242(%rip), %xmm0    # 0xa2da8
xorpd %xmm1, %xmm1
callq 0x38d52
testl %eax, %eax
je 0x28cc2
movq (%rbp), %rax
testq %rax, %rax
je 0x28cce
movslq 0x8(%rbp), %rdx
cmpl %edx, %r14d
jge 0x28bca
leaq (,%r13,2), %rcx
addq %r13, %rcx
leaq (%rax,%rcx,8), %rcx
addq $0xc, %rcx
subq %rdx, %r13
xorl %eax, %eax
cmpq $0x0, -0xc(%rcx)
je 0x28c51
cmpl %r15d, -0x4(%rcx)
jne 0x28c2a
cmpl %r15d, (%rcx)
jne 0x28c2a
decq %rax
addq $0x18, %rcx
cmpq %rax, %r13
jne 0x28ba5
subl %eax, %r14d
incl %r14d
movl 0x8(%rbx), %esi
cmpl %esi, %r14d
jl 0x28a85
leaq 0x7cbe6(%rip), %rdi     # 0xa57c6
callq 0x4090
movl $0x1, %ebp
jmp 0x28a1c
leaq 0x7cbb7(%rip), %rdi     # 0xa57ad
callq 0x4090
jmp 0x28c23
leaq 0x7c75a(%rip), %rdi     # 0xa535e
movsd (%rsp), %xmm0
movb $0x1, %al
callq 0x4030
jmp 0x28c23
leaq 0x7c767(%rip), %rdi     # 0xa5380
movl %r14d, %esi
movb $0x2, %al
callq 0x4030
xorl %ebp, %ebp
jmp 0x28a1c
subl %eax, %r14d
movl 0x8(%r12), %esi
movl 0xc(%r12), %edx
leaq 0x7c8dd(%rip), %rdi     # 0xa551b
xorl %ebp, %ebp
xorl %ecx, %ecx
movl %r14d, %r8d
xorl %eax, %eax
callq 0x4030
jmp 0x28a1c
subl %eax, %r14d
leaq 0x7c87f(%rip), %rdi     # 0xa54da
xorl %ebp, %ebp
xorl %esi, %esi
movl %r14d, %edx
xorl %eax, %eax
callq 0x4030
jmp 0x28a1c
leaq 0x7c76b(%rip), %rdi     # 0xa53e0
movsd (%rsp), %xmm0
movl %r14d, %esi
movb $0x1, %al
callq 0x4030
jmp 0x28c23
movl 0xc(%r12), %edx
leaq 0x7c7aa(%rip), %rdi     # 0xa543c
xorl %ebp, %ebp
movl %r14d, %ecx
xorl %eax, %eax
callq 0x4030
jmp 0x28a1c
leaq 0x7c7ce(%rip), %rdi     # 0xa5478
xorl %ebp, %ebp
jmp 0x28a15
leaq 0x7c75b(%rip), %rdi     # 0xa5413
xorl %ebp, %ebp
movl %r14d, %esi
jmp 0x28a15
leaq 0x7c7de(%rip), %rdi     # 0xa54a7
jmp 0x28c04
leaq 0x7caf7(%rip), %rdi     # 0xa57cc
jmp 0x28bf6