// File: /workspace/github_cpp_makefile_star2_O3/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, -0x48(%rbp)
movq 0x88(%rdi), %rax
movzbl 0x8b8(%rax), %ebx
movsbq 0x8b9(%rax), %rcx
movq %rcx, -0x40(%rbp)
movzbl 0x8c8(%rax), %r15d
movl %ebx, %eax
imull %r15d, %eax
leal 0xf(,%rax,8), %eax
andl $-0x10, %eax
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x38(%rbp)
movq %rcx, %rsp
movq %rsp, %rcx
subq %rax, %rcx
movq %rcx, -0x30(%rbp)
movq %rcx, %rsp
testb %r15b, %r15b
jle 0x25436
movq %rsi, -0x50(%rbp)
movq %rdx, -0x58(%rbp)
leal (,%rbx,8), %r12d
xorl %r14d, %r14d
movq %r15, -0x60(%rbp)
testb %bl, %bl
jle 0x2540a
movq -0x38(%rbp), %rax
leaq (%rax,%r14), %rdi
movq -0x30(%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 0x253df
testb %bl, %bl
movq -0x60(%rbp), %r15
movq -0x58(%rbp), %rdx
movq -0x50(%rbp), %rsi
jg 0x2543e
movb $0x1, %r12b
xorl %ecx, %ecx
movl $0x0, %eax
testb %r15b, %r15b
jg 0x25494
jmp 0x25573
testb %bl, %bl
jle 0x25571
xorpd %xmm1, %xmm1
xorl %ecx, %ecx
movsd 0xe4a4(%rip), %xmm2     # 0x338f0
xorpd %xmm0, %xmm0
xorl %eax, %eax
movsd (%rsi,%rcx,8), %xmm3
ucomisd %xmm2, %xmm3
ja 0x25573
ucomisd %xmm3, %xmm1
ja 0x25573
addsd %xmm3, %xmm0
incq %rcx
cmpq %rcx, %rbx
jne 0x25452
testb %r15b, %r15b
jle 0x25565
cmpneqsd 0xe467(%rip), %xmm0     # 0x338f0
movq %xmm0, %r12
andl $0x1, %r12d
movb $0x1, %cl
xorl %esi, %esi
movsd 0xe452(%rip), %xmm0     # 0x338f0
xorpd %xmm1, %xmm1
testb %cl, %cl
je 0x25545
movq %rsi, %rax
imulq %rbx, %rax
movq -0x38(%rbp), %rdi
leaq (%rdi,%rax,8), %rdi
movq -0x30(%rbp), %r8
leaq (%r8,%rax,8), %r8
movq (%rdx,%rsi,8), %r9
xorl %r10d, %r10d
movq (%r9,%r10,8), %r11
xorl %r14d, %r14d
movsd (%r11,%r14,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x25573
ucomisd %xmm2, %xmm1
ja 0x25573
addsd (%rdi,%r10,8), %xmm2
movsd %xmm2, (%rdi,%r10,8)
incq %r14
cmpq %r14, %rbx
jne 0x254cf
cmpb $0x0, -0x40(%rbp)
jle 0x2553d
movq -0x48(%rbp), %rax
movq (%rax,%rsi,8), %rax
movq (%rax,%r10,8), %r11
xorl %r14d, %r14d
movsd (%r11,%r14,8), %xmm2
xorl %eax, %eax
ucomisd %xmm0, %xmm2
ja 0x25573
ucomisd %xmm2, %xmm1
ja 0x25573
addsd (%r8,%r10,8), %xmm2
movsd %xmm2, (%r8,%r10,8)
incq %r14
cmpq %r14, -0x40(%rbp)
jne 0x25514
incq %r10
cmpq %rbx, %r10
jne 0x254c8
incq %rsi
cmpq %r15, %rsi
jne 0x254a2
testb %r15b, %r15b
setle %al
orb %r12b, %al
je 0x25586
xorb $0x1, %r12b
movl %r12d, %eax
jmp 0x25573
ucomisd 0xe383(%rip), %xmm0     # 0x338f0
jne 0x25571
jnp 0x25582
xorl %eax, %eax
leaq -0x28(%rbp), %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
jmp 0x25573
leal (,%rbx,8), %edx
xorl %esi, %esi
testb %cl, %cl
je 0x255bf
xorl %eax, %eax
movq -0x38(%rbp), %rdi
movsd (%rdi,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x25571
jp 0x25571
movq -0x30(%rbp), %rdi
movsd (%rdi,%rax,8), %xmm1
ucomisd %xmm0, %xmm1
jne 0x25571
jp 0x25571
incq %rax
cmpq %rax, %rbx
jne 0x25595
incq %rsi
addq %rdx, -0x30(%rbp)
addq %rdx, -0x38(%rbp)
movb $0x1, %al
cmpq %r15, %rsi
jne 0x2558f
jmp 0x25573
nop