// File: /workspace/github_cpp_makefile_star2_O2/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
movq %rdx, %rbx
movl %esi, %r12d
movq %rdi, %r15
callq 0xe54a
movq 0x88(%r15), %rax
movzbl 0x8b8(%rax), %eax
xorl %r14d, %r14d
testb %al, %al
movl $0x0, %ecx
movq %rax, 0x40(%rsp)
cmovgl %eax, %ecx
movq %rcx, 0x38(%rsp)
testl %r12d, %r12d
cmovlel %r14d, %r12d
movq %r12, 0x48(%rsp)
cmpq 0x48(%rsp), %r14
je 0xeefb
movq (%rbx,%r14,8), %rax
cmpl $0x0, 0x4(%rax)
je 0xecf3
incq %r14
jmp 0xecd9
xorl %ebp, %ebp
movslq (%rax), %rcx
decq %rcx
cmpq %rcx, %rbp
jge 0xecee
movq 0x88(%r15), %rcx
movq 0x870(%rcx), %rcx
movq 0x10(%rax), %rax
leaq 0x1(%rbp), %rdx
movq %rdx, 0x18(%rsp)
movslq 0x4(%rax,%rbp,4), %rax
movb (%rcx,%rax), %al
movb %al, 0x7(%rsp)
xorpd %xmm2, %xmm2
xorl %r12d, %r12d
movsbl 0x7(%rsp), %eax
movl %eax, 0x14(%rsp)
cmpq 0x38(%rsp), %r12
je 0xedea
xorl %r13d, %r13d
cmpq %r13, 0x40(%rsp)
je 0xede2
movapd %xmm2, 0x20(%rsp)
movq (%rbx,%r14,8), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movq (%r15), %rax
movsbl %r12b, %edx
movsbl %r13b, %ecx
movq %r15, %rdi
callq *0x18(%rax)
movapd %xmm0, %xmm1
mulsd 0x8(%rsp), %xmm1
movq (%rbx,%r14,8), %rsi
movq 0x30(%rsi), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r13,8), %xmm1
movsd 0x1db48(%rip), %xmm0    # 0x2c8f0
cmpb $0x0, 0x7(%rsp)
js 0xedcc
movq (%r15), %rax
movsbl %r13b, %edx
movq %r15, %rdi
movl 0x14(%rsp), %ecx
movsd %xmm1, 0x8(%rsp)
callq *0x20(%rax)
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movapd 0x20(%rsp), %xmm2
addsd %xmm1, %xmm2
incq %r13
jmp 0xed45
incq %r12
jmp 0xed2e
xorpd %xmm1, %xmm1
cmpltsd %xmm2, %xmm1
andpd %xmm1, %xmm2
movsd 0x1daf1(%rip), %xmm0    # 0x2c8f0
andnpd %xmm0, %xmm1
orpd %xmm2, %xmm1
movapd %xmm1, 0x50(%rsp)
xorl %r13d, %r13d
cmpq 0x38(%rsp), %r13
je 0xeeed
movsbl %r13b, %eax
movl %eax, 0x8(%rsp)
xorl %r12d, %r12d
cmpq %r12, 0x40(%rsp)
je 0xeee5
movq (%rbx,%r14,8), %rsi
movq 0x28(%rsi), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r13,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movq (%r15), %rax
movsbl %r12b, %ecx
movq %r15, %rdi
movl 0x8(%rsp), %edx
callq *0x18(%rax)
movapd %xmm0, %xmm1
mulsd 0x20(%rsp), %xmm1
movq (%rbx,%r14,8), %rsi
movq 0x30(%rsi), %rax
movq 0x18(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r12,8), %xmm1
cmpb $0x0, 0x7(%rsp)
js 0xeea5
movq (%r15), %rax
movsbl %r12b, %edx
movq %r15, %rdi
movl 0x14(%rsp), %ecx
movsd %xmm1, 0x20(%rsp)
callq *0x20(%rax)
movsd 0x20(%rsp), %xmm1
movq (%rbx,%r14,8), %rsi
jmp 0xeead
movsd 0x1da43(%rip), %xmm0    # 0x2c8f0
mulsd %xmm0, %xmm1
divsd 0x50(%rsp), %xmm1
movq 0x40(%rsi), %rax
movq (%rax,%rbp,8), %rax
movq (%rax,%r13,8), %rax
movsd %xmm1, (%rax,%r12,8)
movq 0x38(%rsi), %rax
movq (%rax,%rbp,8), %rax
addsd (%rax,%r13,8), %xmm1
movsd %xmm1, (%rax,%r13,8)
incq %r12
jmp 0xee26
incq %r13
jmp 0xee10
movq (%rbx,%r14,8), %rax
movq 0x18(%rsp), %rbp
jmp 0xecf5
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq