// File: /workspace/github_cpp_makefile_star2_O3/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 $0x68, %rsp
movl %esi, %ebp
movq %rdi, %r14
movq %rdx, 0x20(%rsp)
callq 0x11620
testl %ebp, %ebp
jle 0x120f7
movq 0x88(%r14), %rax
movzbl 0x8b8(%rax), %eax
movq %rax, 0x10(%rsp)
movl %ebp, %eax
movq %rax, 0x60(%rsp)
xorl %eax, %eax
movq 0x20(%rsp), %rcx
movq %rax, 0x18(%rsp)
movq (%rcx,%rax,8), %rsi
cmpl $0x0, 0x4(%rsi)
jne 0x120e4
cmpl $0x2, (%rsi)
jl 0x120e4
xorl %r12d, %r12d
leaq 0x1(%r12), %rax
movq %rax, 0x30(%rsp)
cmpb $0x0, 0x10(%rsp)
jle 0x120c2
movq 0x88(%r14), %rax
movq 0x870(%rax), %rax
movq 0x10(%rsi), %rcx
movslq 0x4(%rcx,%r12,4), %rcx
movb (%rax,%rcx), %al
movb %al, 0xf(%rsp)
xorps %xmm2, %xmm2
xorl %ecx, %ecx
movsbl %cl, %eax
movl %eax, 0x50(%rsp)
xorl %ebp, %ebp
movaps %xmm2, 0x40(%rsp)
movq 0x20(%rsp), %r15
movq 0x18(%rsp), %r13
movq (%r15,%r13,8), %rsi
movq 0x28(%rsi), %rax
movq %r12, %rbx
movq (%rax,%r12,8), %rax
movq %rcx, %r12
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, 0x28(%rsp)
movq (%r14), %rax
movsbl %bpl, %ecx
movq %r14, %rdi
movl 0x50(%rsp), %edx
callq *0x18(%rax)
movapd %xmm0, %xmm1
mulsd 0x28(%rsp), %xmm1
movq (%r15,%r13,8), %rsi
movq 0x30(%rsi), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%rbp,8), %xmm1
movb 0xf(%rsp), %al
movsbl %al, %r15d
movsd 0x2199d(%rip), %xmm0    # 0x338f0
testb %al, %al
js 0x11f73
movq (%r14), %rax
movsbl %bpl, %edx
movq %r14, %rdi
movl %r15d, %ecx
movsd %xmm1, 0x28(%rsp)
callq *0x20(%rax)
movsd 0x28(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd 0x40(%rsp), %xmm2
addsd %xmm1, %xmm2
incq %rbp
cmpq %rbp, 0x10(%rsp)
movq %r12, %rcx
movq %rbx, %r12
jne 0x11ee6
incq %rcx
cmpq 0x10(%rsp), %rcx
jne 0x11edd
cmpb $0x0, 0x10(%rsp)
movq 0x20(%rsp), %rcx
jle 0x120c2
movl %r15d, 0x3c(%rsp)
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm2
movsd 0x21923(%rip), %xmm0    # 0x338f0
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movapd %xmm1, 0x50(%rsp)
movq 0x18(%rsp), %rax
movq (%rcx,%rax,8), %rsi
xorl %r15d, %r15d
movsbl %r15b, %eax
movl %eax, 0x28(%rsp)
xorl %r13d, %r13d
movq 0x28(%rsi), %rax
movq (%rax,%r12,8), %rax
movsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x40(%rsp)
movq (%r14), %rax
movsbl %r13b, %ecx
movq %r14, %rdi
movl 0x28(%rsp), %edx
callq *0x18(%rax)
movapd %xmm0, %xmm1
mulsd 0x40(%rsp), %xmm1
movq 0x18(%rsp), %rbp
movq 0x20(%rsp), %rbx
movq (%rbx,%rbp,8), %rsi
movq 0x30(%rsi), %rax
movq 0x30(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r13,8), %xmm1
cmpb $0x0, 0xf(%rsp)
js 0x1206c
movq (%r14), %rax
movsbl %r13b, %edx
movq %r14, %rdi
movl 0x3c(%rsp), %ecx
movsd %xmm1, 0x40(%rsp)
callq *0x20(%rax)
movsd 0x40(%rsp), %xmm1
movq (%rbx,%rbp,8), %rsi
jmp 0x12074
movsd 0x2187c(%rip), %xmm0    # 0x338f0
mulsd %xmm0, %xmm1
divsd 0x50(%rsp), %xmm1
movq 0x40(%rsi), %rax
movq (%rax,%r12,8), %rax
movq (%rax,%r15,8), %rax
movsd %xmm1, (%rax,%r13,8)
movq 0x38(%rsi), %rax
movq (%rax,%r12,8), %rax
addsd (%rax,%r15,8), %xmm1
movsd %xmm1, (%rax,%r15,8)
incq %r13
cmpq %r13, 0x10(%rsp)
jne 0x11ff2
incq %r15
cmpq 0x10(%rsp), %r15
jne 0x11fe7
jmp 0x120cb
movq 0x18(%rsp), %rax
movq (%rcx,%rax,8), %rsi
movslq (%rsi), %rax
decq %rax
movq 0x30(%rsp), %r12
cmpq %rax, %r12
movq 0x20(%rsp), %rcx
jl 0x11ea5
movq 0x18(%rsp), %rax
incq %rax
cmpq 0x60(%rsp), %rax
jne 0x11e81
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq