// File: /workspace/github_cpp_makefile_star2_O3/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 %rcx, -0x30(%rbp)
movq 0x88(%rdi), %rax
movzbl 0x8b8(%rax), %edi
movsbq 0x8b9(%rax), %r11
movzbl 0x8c8(%rax), %r8d
movl %r8d, %eax
imull %edi, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rbx
subq %rax, %rbx
movq %rbx, %rsp
leal 0xf(,%rdi,8), %eax
andl $-0x10, %eax
movq %rsp, %r10
subq %rax, %r10
movq %r10, %rsp
movb $0x1, %cl
testb %dil, %dil
jle 0x2b7b4
leal 0x1(%r8), %eax
andl $0xfe, %eax
leaq -0x1(%r8), %r9
movq %r9, %xmm0
pshufd $0x44, %xmm0, %xmm0     # xmm0 = xmm0[0,1,0,1]
movl %edi, %r14d
shll $0x4, %r14d
xorl %r15d, %r15d
movdqa 0x91ce(%rip), %xmm1     # 0x34890
movdqa 0x91d6(%rip), %xmm2     # 0x348a0
pxor %xmm2, %xmm0
pcmpeqd %xmm3, %xmm3
movdqa 0x91d6(%rip), %xmm4     # 0x348b0
movq %rbx, %r9
testb %r8b, %r8b
jle 0x2b74b
movq %rax, %r13
movq %r9, %r12
movdqa %xmm1, %xmm5
movdqa %xmm5, %xmm6
pxor %xmm2, %xmm6
movdqa %xmm6, %xmm7
pcmpgtd %xmm0, %xmm7
pcmpeqd %xmm0, %xmm6
pshufd $0xf5, %xmm6, %xmm8     # xmm8 = xmm6[1,1,3,3]
pand %xmm7, %xmm8
pshufd $0xf5, %xmm7, %xmm6     # xmm6 = xmm7[1,1,3,3]
por %xmm8, %xmm6
movd %xmm6, %ecx
notl %ecx
testb $0x1, %cl
je 0x2b728
movq $0x0, (%r12)
pxor %xmm3, %xmm6
pextrw $0x4, %xmm6, %ecx
testb $0x1, %cl
je 0x2b73e
movq $0x0, (%r12,%rdi,8)
paddq %xmm4, %xmm5
addq %r14, %r12
addq $-0x2, %r13
jne 0x2b6ec
movq $0x0, (%r10,%r15,8)
incq %r15
addq $0x8, %r9
cmpq %rdi, %r15
jne 0x2b6dd
testb %dil, %dil
movb $0x1, %cl
jle 0x2b7b4
pxor %xmm0, %xmm0
xorl %ecx, %ecx
movsd 0x8178(%rip), %xmm2     # 0x338f0
pxor %xmm1, %xmm1
movsd (%rsi,%rcx,8), %xmm3
xorl %eax, %eax
ucomisd %xmm2, %xmm3
ja 0x2b887
ucomisd %xmm3, %xmm0
ja 0x2b887
addsd %xmm3, %xmm1
incq %rcx
cmpq %rcx, %rdi
jne 0x2b77c
cmpneqsd 0x8144(%rip), %xmm1     # 0x338f0
movq %xmm1, %rcx
andl $0x1, %ecx
testb %r8b, %r8b
jle 0x2b825
xorl %esi, %esi
movsd 0x812d(%rip), %xmm0     # 0x338f0
pxor %xmm1, %xmm1
testb %dil, %dil
jle 0x2b81d
movq %rsi, %rax
imulq %rdi, %rax
leaq (%rbx,%rax,8), %r9
movq (%rdx,%rsi,8), %r14
xorl %r15d, %r15d
movq (%r14,%r15,8), %r12
xorl %r13d, %r13d
movsd (%r12,%r13,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x2b887
ucomisd %xmm2, %xmm1
ja 0x2b887
addsd (%r9,%r15,8), %xmm2
movsd %xmm2, (%r9,%r15,8)
incq %r13
cmpq %r13, %rdi
jne 0x2b7e5
incq %r15
cmpq %rdi, %r15
jne 0x2b7de
incq %rsi
cmpq %r8, %rsi
jne 0x2b7c7
testb %dil, %dil
jle 0x2b882
xorl %edx, %edx
movsd 0x80bc(%rip), %xmm0     # 0x338f0
pxor %xmm1, %xmm1
testb %r11b, %r11b
jle 0x2b870
movq -0x30(%rbp), %rax
movq (%rax,%rdx,8), %rsi
xorl %r9d, %r9d
movsd (%rsi,%r9,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x2b887
ucomisd %xmm2, %xmm1
ja 0x2b887
addsd (%r10,%rdx,8), %xmm2
movsd %xmm2, (%r10,%rdx,8)
incq %r9
cmpq %r9, %r11
jne 0x2b848
incq %rdx
cmpq %rdi, %rdx
jne 0x2b838
testb %dil, %dil
setle %al
orb %cl, %al
je 0x2b896
xorb $0x1, %cl
movl %ecx, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leal (,%rdi,8), %ecx
xorl %edx, %edx
movsd (%r10,%rdx,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x2b8e7
jp 0x2b8e7
movq %r8, %rax
movq %rbx, %rsi
testb %r8b, %r8b
jle 0x2b8cc
movsd (%rsi), %xmm2
ucomisd %xmm0, %xmm2
jne 0x2b8e7
jp 0x2b8e7
addq %rcx, %rsi
decq %rax
jne 0x2b8b8
cmpeqsd %xmm0, %xmm1
movq %xmm1, %rax
andl $0x1, %eax
incq %rdx
addq $0x8, %rbx
cmpq %rdi, %rdx
jne 0x2b89f
jmp 0x2b887
xorl %eax, %eax
jmp 0x2b887
nop