// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblem.cpp
// Function: HMMProblem::computeXiGamma(int, data**)
void HMMProblem::computeXiGamma(NCAT xndat, struct data** x_data){
	HMMProblem::initXiGamma(xndat, x_data);
    NPAR nS = this->p->nS;
//    int parallel_now = this->p->parallel==2; //PAR
//    #pragma omp parallel for schedule(dynamic) if(parallel_now) //PAR
	for(NCAT x=0; x<xndat; x++) {
        NDAT t;
        NPAR i, j, o_tp1;
        NUMBER denom;
		if( x_data[x]->cnt!=0 ) continue; // ... and the thing has not been computed yet (e.g. from group to skill)
        
		for(t=0; t<(x_data[x]->n-1); t++) { // -1 is important
            //			o_tp1 = x_data[x]->obs[t+1];
            o_tp1 = this->p->dat_obs[ x_data[x]->ix[t+1] ];//->get( x_data[x]->ix[t+1] );
            
            denom = 0.0;
			for(i=0; i<nS; i++) {
				for(j=0; j<nS; j++) {
                    denom += x_data[x]->alpha[t][i] * getA(x_data[x],i,j) * x_data[x]->beta[t+1][j] * ((o_tp1<0)?1:getB(x_data[x],j,o_tp1));
                }
            }
			for(i=0; i<nS; i++) {
				for(j=0; j<nS; j++) {
                    x_data[x]->xi[t][i][j] = x_data[x]->alpha[t][i] * getA(x_data[x],i,j) * x_data[x]->beta[t+1][j] * ((o_tp1<0)?1:getB(x_data[x],j,o_tp1)) / ((denom>0)?denom:1); //
                    x_data[x]->gamma[t][i] += x_data[x]->xi[t][i][j];
                }
            }
        
		} // for all observations within skill-group
	} // for all groups in skill
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, %r14
callq 0x1177e
testl %ebp, %ebp
jle 0x12230
movq 0x88(%r14), %rax
movzbl 0x8b8(%rax), %eax
movq %rax, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x50(%rsp)
xorl %r13d, %r13d
movq (%rbx,%r13,8), %rax
cmpl $0x0, 0x4(%rax)
jne 0x12222
movq (%rbx,%r13,8), %rax
cmpl $0x2, (%rax)
jl 0x12222
xorl %ebp, %ebp
leaq 0x1(%rbp), %rcx
movq %rcx, 0x28(%rsp)
movq 0x88(%r14), %rcx
movq 0x870(%rcx), %rcx
movq 0x10(%rax), %rax
movslq 0x4(%rax,%rbp,4), %rax
movb (%rcx,%rax), %al
movb %al, 0xf(%rsp)
movsbl %al, %eax
movl %eax, 0x24(%rsp)
cmpb $0x0, 0x10(%rsp)
jle 0x12104
xorps %xmm1, %xmm1
xorl %r12d, %r12d
movsbl %r12b, %eax
movl %eax, 0x40(%rsp)
xorl %r15d, %r15d
movaps %xmm1, 0x30(%rsp)
movq (%rbx,%r13,8), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x18(%rsp)
movq (%r14), %rax
movsbl %r15b, %ecx
movq %r14, %rdi
movl 0x40(%rsp), %edx
callq *0x18(%rax)
movapd %xmm0, %xmm2
mulsd 0x18(%rsp), %xmm2
movq (%rbx,%r13,8), %rsi
movq 0x30(%rsi), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r15,8), %xmm2
movsd 0x2283c(%rip), %xmm0    # 0x348f0
cmpb $0x0, 0xf(%rsp)
js 0x120d8
movq (%r14), %rax
movsbl %r15b, %edx
movq %r14, %rdi
movl 0x24(%rsp), %ecx
movsd %xmm2, 0x18(%rsp)
callq *0x20(%rax)
movsd 0x18(%rsp), %xmm2
mulsd %xmm0, %xmm2
movapd 0x30(%rsp), %xmm1
addsd %xmm2, %xmm1
incq %r15
cmpq %r15, 0x10(%rsp)
jne 0x1205d
incq %r12
cmpq 0x10(%rsp), %r12
jne 0x12052
jmp 0x12108
xorpd %xmm1, %xmm1
cmpb $0x0, 0x10(%rsp)
jle 0x1220a
xorpd %xmm2, %xmm2
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm1
movsd 0x227c8(%rip), %xmm0    # 0x348f0
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, 0x40(%rsp)
xorl %r12d, %r12d
movsbl %r12b, %eax
movl %eax, 0x18(%rsp)
xorl %r15d, %r15d
movq (%rbx,%r13,8), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movq (%r14), %rax
movsbl %r15b, %ecx
movq %r14, %rdi
movl 0x18(%rsp), %edx
callq *0x18(%rax)
movapd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm1
movq (%rbx,%r13,8), %rsi
movq 0x30(%rsi), %rax
movq 0x28(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r15,8), %xmm1
movsd 0x2275a(%rip), %xmm0    # 0x348f0
cmpb $0x0, 0xf(%rsp)
js 0x121ba
movq (%r14), %rax
movsbl %r15b, %edx
movq %r14, %rdi
movl 0x24(%rsp), %ecx
movsd %xmm1, 0x30(%rsp)
callq *0x20(%rax)
movsd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
divsd 0x40(%rsp), %xmm1
movq (%rbx,%r13,8), %rax
movq 0x40(%rax), %rcx
movq (%rcx,%rbp,8), %rcx
movq (%rcx,%r12,8), %rcx
movsd %xmm1, (%rcx,%r15,8)
movq 0x38(%rax), %rax
movq (%rax,%rbp,8), %rax
addsd (%rax,%r12,8), %xmm1
movsd %xmm1, (%rax,%r12,8)
incq %r15
cmpq %r15, 0x10(%rsp)
jne 0x12144
incq %r12
cmpq 0x10(%rsp), %r12
jne 0x12139
movq (%rbx,%r13,8), %rax
movslq (%rax), %rcx
decq %rcx
movq 0x28(%rsp), %rbp
cmpq %rcx, %rbp
jl 0x12013
incq %r13
cmpq 0x50(%rsp), %r13
jne 0x11ff6
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop