// File: myudelson[P]hmm-scalable/HMMProblemComp.cpp
// Function: HMMProblemComp::getB(data*, signed char, signed char)
NUMBER HMMProblemComp::getB(struct data* dt, NPAR i, NPAR m) {
	NUMBER r = 0;
	// dt->cnt==0 means, get dt->k'th skill only
	// if param->tag1==1, try and see whether there are other "neighbours"
	// dt->t should be set to the global index of the row in question

	// special attention for "unknonw" observations, i.e. the observation was there but we do not know what it is
	// in this case we simply return 1, effectively resulting in no change in \alpha or \beta vatiables
	if(m<0) {
		r = 1;
	} else if( this->p->tag1==0 || this->is_multi[dt->k] == 0) { // we ask for single skill specifically or this skill is never multiskill
		r = this->B[dt->k][i][m];
	} else {
		NCAT n_skills = this->p->dat_skill_rcount[ dt->t ];
		if( n_skills==1 ) { // this skill is alone on row dt->t
			r = this->B[dt->k][i][m];
		} else { // collect multiple \pi[i]
			NUMBER* q = Calloc(NUMBER, (size_t)n_skills );
			NCAT k=0;
			for(NCAT l=0; l<n_skills; l++) {
				k = this->p->dat_skill_stacked[ this->p->dat_skill_rix[ dt->t ]+l ];
				q[l] = this->B[k][i][m];
			}
			r = this->pu->unite(q, n_skills, NULL, 0); //r = squishing(q, n_skills);
			free(q);
		} // definitely multiskill
	} // end sometimes multiskill
	return r;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movb %cl, %al
movb %dl, %cl
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movb %cl, -0x11(%rbp)
movb %al, -0x12(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x40(%rbp)
xorps %xmm0, %xmm0
movsd %xmm0, -0x20(%rbp)
movsbl -0x12(%rbp), %eax
cmpl $0x0, %eax
jge 0x4c4d5
movsd 0x353d(%rip), %xmm0     # 0x4fa08
movsd %xmm0, -0x20(%rbp)
jmp 0x4c652
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rax
cmpl $0x0, 0x9a0(%rax)
je 0x4c505
movq -0x40(%rbp), %rax
movq 0x90(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x58(%rcx), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jne 0x4c536
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x58(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x11(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x12(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x4c650
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x890(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x8(%rcx), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
cmpl $0x1, -0x24(%rbp)
jne 0x4c58d
movq -0x40(%rbp), %rax
movq 0x48(%rax), %rax
movq -0x10(%rbp), %rcx
movslq 0x58(%rcx), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x11(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x12(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x20(%rbp)
jmp 0x4c64e
movslq -0x24(%rbp), %rdi
movl $0x8, %esi
callq 0x5180
movq %rax, -0x30(%rbp)
movl $0x0, -0x34(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4c623
movq -0x40(%rbp), %rax
movq 0x88(%rax), %rcx
movq 0x888(%rcx), %rcx
movq 0x88(%rax), %rdx
movq 0x898(%rdx), %rdx
movq -0x10(%rbp), %rsi
movslq 0x8(%rsi), %rsi
movl (%rdx,%rsi,4), %edx
addl -0x38(%rbp), %edx
movslq %edx, %rdx
movl (%rcx,%rdx,4), %ecx
movl %ecx, -0x34(%rbp)
movq 0x48(%rax), %rax
movslq -0x34(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x11(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x12(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x4c5ad
movq -0x40(%rbp), %rax
movq 0x98(%rax), %rdi
movq -0x30(%rbp), %rsi
movl -0x24(%rbp), %edx
movq (%rdi), %rax
xorl %ecx, %ecx
xorl %r8d, %r8d
callq *0x8(%rax)
movsd %xmm0, -0x20(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5380
jmp 0x4c650
jmp 0x4c652
movsd -0x20(%rbp), %xmm0
addq $0x40, %rsp
popq %rbp
retq
nopl (%rax)