// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemSlicedA.cpp
// Function: HMMProblemSlicedA::checkPIABConstraints(double*, double***, double**)
bool HMMProblemSlicedA::checkPIABConstraints(NUMBER* a_PI, NUMBER*** a_A, NUMBER** a_B) {
	NPAR i, j, z;
    NPAR nS = this->p->nS, nO = this->p->nO, nZ = this->p->nZ;
	// check values
	NUMBER sum_pi = 0.0;
	NUMBER sum_a_row[nZ][nS];
	NUMBER sum_b_row[nS];
    for(i=0; i<nS; i++) {
        for(z=0; z<nZ; z++) {
            sum_a_row[z][i] = 0.0;
        }
        sum_b_row[i] = 0.0;
    }
	for(i=0; i<nS; i++) {
		if( a_PI[i]>1.0 || a_PI[i]<0.0)
			return false;
		sum_pi += a_PI[i];
    }
    
    for(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            for(j=0; j<nS; j++) {
                if( a_A[z][i][j]>1.0 || a_A[z][i][j]<0.0)
                    return false;
                sum_a_row[z][i] += a_A[z][i][j];
            }// all states 2
        }// all states
    } // all slices

    for(i=0; i<nS; i++) {
        for(int m=0; m<nO; m++) {
            if( a_B[i][m]>1.0 || a_B[i][m]<0.0)
                return false;
            sum_b_row[i] += a_B[i][m];
        }// all observations
    }// all states
    
    if(sum_pi!=1.0)
		return false;
    for(i=0; i<nS; i++) {
        if( sum_b_row[i]!=1.0) return false;
        for(z=0; z<nZ; z++)
            if( sum_a_row[z][i]!=1.0 ) return false;
    }
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq 0x88(%rdi), %rax
movzbl 0x8b8(%rax), %r11d
movb 0x8b9(%rax), %bl
movzbl 0x8c8(%rax), %edi
movl %edi, %eax
imull %r11d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %r8
subq %rax, %r8
movq %r8, %rsp
leal 0xf(,%r11,8), %eax
andl $-0x10, %eax
movq %rsp, %r9
subq %rax, %r9
movq %r9, %rsp
xorl %eax, %eax
testb %dil, %dil
cmovlel %eax, %edi
testb %r11b, %r11b
movl $0x0, %r10d
cmovgl %r11d, %r10d
movl %r11d, %r14d
shll $0x3, %r14d
movq %r8, %r15
cmpq %r10, %rax
je 0x253bd
movq %r15, %r12
movq %rdi, %r13
subq $0x1, %r13
jb 0x253af
andq $0x0, (%r12)
addq %r14, %r12
jmp 0x2539f
andq $0x0, (%r9,%rax,8)
incq %rax
addq $0x8, %r15
jmp 0x25394
xorpd %xmm2, %xmm2
xorl %r14d, %r14d
movsd 0x7524(%rip), %xmm0     # 0x2c8f0
xorpd %xmm1, %xmm1
xorl %eax, %eax
cmpq %r14, %r10
je 0x253fa
movsd (%rsi,%r14,8), %xmm3
ucomisd %xmm0, %xmm3
ja 0x254af
ucomisd %xmm3, %xmm2
ja 0x254af
addsd %xmm3, %xmm1
incq %r14
jmp 0x253d2
xorl %esi, %esi
xorpd %xmm2, %xmm2
cmpq %rdi, %rsi
je 0x25457
movq %rsi, %rax
imulq %r11, %rax
leaq (%r8,%rax,8), %r14
xorl %r15d, %r15d
cmpq %r10, %r15
je 0x25452
xorl %r12d, %r12d
cmpq %r12, %r11
je 0x2544d
movq (%rdx,%rsi,8), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%r12,8), %xmm3
xorl %eax, %eax
ucomisd %xmm0, %xmm3
ja 0x254af
ucomisd %xmm3, %xmm2
ja 0x254af
addsd (%r14,%r15,8), %xmm3
movsd %xmm3, (%r14,%r15,8)
incq %r12
jmp 0x2541b
incq %r15
jmp 0x25413
incq %rsi
jmp 0x25400
movzbl %bl, %eax
xorl %edx, %edx
testb %al, %al
cmovlel %edx, %eax
movzbl %al, %esi
xorpd %xmm2, %xmm2
cmpq %r10, %rdx
je 0x254a1
xorl %ebx, %ebx
cmpq %rbx, %rsi
je 0x2549c
movq (%rcx,%rdx,8), %rax
movsd (%rax,%rbx,8), %xmm3
xorl %eax, %eax
ucomisd %xmm0, %xmm3
ja 0x254af
ucomisd %xmm3, %xmm2
ja 0x254af
addsd (%r9,%rdx,8), %xmm3
movsd %xmm3, (%r9,%rdx,8)
incq %rbx
jmp 0x2546f
incq %rdx
jmp 0x25468
ucomisd 0x7447(%rip), %xmm1     # 0x2c8f0
jne 0x254ad
jnp 0x254be
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incq %rdi
leal (,%r11,8), %ecx
xorl %edx, %edx
cmpq %r10, %rdx
sete %al
je 0x254af
movsd (%r9,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x254af
jp 0x254af
movq %r8, %rsi
movq %rdi, %r11
decq %r11
je 0x254ff
movsd (%rsi), %xmm1
addq %rcx, %rsi
xorl %eax, %eax
ucomisd %xmm0, %xmm1
jne 0x254af
jnp 0x254e7
jmp 0x254af
incq %rdx
addq $0x8, %r8
jmp 0x254cb