// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemSlicedAB.cpp
// Function: HMMProblemSlicedAB::checkPIABConstraints(double*, double***, double***)
bool HMMProblemSlicedAB::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[nZ][nS];
    for(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            sum_a_row[z][i] = 0.0;
            sum_b_row[z][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
            for(int m=0; m<nO; m++) {
                if( a_B[z][i][m]>1.0 || a_B[z][i][m]<0.0)
                    return false;
                sum_b_row[z][i] += a_B[z][i][m];
            }// all observations
        }// all states
    } // all slices
	if(sum_pi!=1.0)
		return false;
    for(z=0; z<nZ; z++) {
        for(i=0; i<nS; i++) {
            if( sum_a_row[z][i]!=1.0 || sum_b_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
subq $0x38, %rsp
movq %rcx, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
movq %rsi, -0x60(%rbp)
movq 0x88(%rdi), %rax
movzbl 0x8b8(%rax), %ebx
movsbq 0x8b9(%rax), %rcx
movq %rcx, -0x48(%rbp)
movzbl 0x8c8(%rax), %ecx
movl %ebx, %eax
imull %ecx, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x40(%rbp)
movq %rdx, %rsp
movq %rsp, %rdx
subq %rax, %rdx
movq %rdx, -0x38(%rbp)
movq %rdx, %rsp
movq %rcx, -0x30(%rbp)
testb %cl, %cl
jle 0x258c5
leal (,%rbx,8), %r12d
xorl %r14d, %r14d
movq -0x30(%rbp), %r15
testb %bl, %bl
jle 0x258bd
movq -0x40(%rbp), %rax
leaq (%rax,%r14), %rdi
movq -0x38(%rbp), %rax
leaq (%rax,%r14), %r13
xorl %esi, %esi
movq %r12, %rdx
callq 0x4120
movq %r13, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x4120
addq %r12, %r14
decq %r15
jne 0x25892
testb %bl, %bl
jle 0x2591d
xorpd %xmm0, %xmm0
xorl %ecx, %ecx
movsd 0xf019(%rip), %xmm2     # 0x348f0
xorpd %xmm1, %xmm1
movq -0x48(%rbp), %r14
movq -0x60(%rbp), %rdx
xorl %eax, %eax
movsd (%rdx,%rcx,8), %xmm3
ucomisd %xmm2, %xmm3
ja 0x259eb
ucomisd %xmm3, %xmm0
ja 0x259eb
addsd %xmm3, %xmm1
incq %rcx
cmpq %rcx, %rbx
jne 0x258e5
cmpneqsd 0xefdd(%rip), %xmm1     # 0x348f0
movq %xmm1, %rcx
andl $0x1, %ecx
jmp 0x25923
movb $0x1, %cl
movq -0x48(%rbp), %r14
cmpb $0x0, -0x30(%rbp)
jle 0x259e5
xorl %edx, %edx
movsd 0xefb9(%rip), %xmm0     # 0x348f0
xorpd %xmm1, %xmm1
testb %bl, %bl
jle 0x259d8
movq %rdx, %rax
imulq %rbx, %rax
movq -0x40(%rbp), %rsi
leaq (%rsi,%rax,8), %rsi
movq -0x38(%rbp), %rdi
leaq (%rdi,%rax,8), %rdi
movq -0x58(%rbp), %rax
movq (%rax,%rdx,8), %r8
xorl %r9d, %r9d
movq (%r8,%r9,8), %r10
xorl %r11d, %r11d
movsd (%r10,%r11,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x259eb
ucomisd %xmm2, %xmm1
ja 0x259eb
addsd (%rsi,%r9,8), %xmm2
movsd %xmm2, (%rsi,%r9,8)
incq %r11
cmpq %r11, %rbx
jne 0x2596c
testb %r14b, %r14b
jle 0x259d0
movq -0x50(%rbp), %rax
movq (%rax,%rdx,8), %rax
movq (%rax,%r9,8), %r10
xorl %r11d, %r11d
movsd (%r10,%r11,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x259eb
ucomisd %xmm2, %xmm1
ja 0x259eb
addsd (%rdi,%r9,8), %xmm2
movsd %xmm2, (%rdi,%r9,8)
incq %r11
cmpq %r11, %r14
jne 0x259a8
incq %r9
cmpq %rbx, %r9
jne 0x25965
incq %rdx
cmpq -0x30(%rbp), %rdx
jne 0x2593b
testb %cl, %cl
je 0x259fa
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
cmpb $0x0, -0x30(%rbp)
jle 0x259eb
leal (,%rbx,8), %ecx
xorl %edx, %edx
movsd 0xeedd(%rip), %xmm0     # 0x348f0
testb %bl, %bl
jle 0x25a43
xorl %esi, %esi
movq -0x40(%rbp), %rdi
movsd (%rdi,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x259e9
jp 0x259e9
movq -0x38(%rbp), %rdi
movsd (%rdi,%rsi,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x259e9
jp 0x259e9
incq %rsi
cmpq %rsi, %rbx
jne 0x25a19
incq %rdx
addq %rcx, -0x40(%rbp)
addq %rcx, -0x38(%rbp)
cmpq -0x30(%rbp), %rdx
jne 0x25a13
jmp 0x259eb