// File: /workspace/github_cpp_makefile_star2_O1/myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::computeXiGamma()
void HMMProblemSt::computeXiGamma(){
    NPAR nS = this->task->nS, o_tp1 = -1, i, j;
    NDAT Nst = this->task->Nst, N = this->task->N;
    NCAT g,k;
    // prepare values
    toZero2D(this->gamma, Nst, nS);
    toZero3D(this->xi, Nst, nS, nS);
    struct context* ctx = new context;
    NUMBER denom = 0.0;

    for(NDAT t=0; t<N; t++) {
        g = this->task->dat_group[t]; 
        ctx->g=g;
        ctx->t=t;
        // grab skill array (if exists)
        NCAT *ar;
        NPAR n;
        getSkillsAtRow(this->task, t, &ar, &n);
        // deal with null skill
        if(ar[0]<0) { // if no skill label
            // fprintf(stderr, "WARNING! We are not dealing with skill-less observation\n");
            continue;
        }
        
        NCAT n_active = 0;
        for(int l=0; l<n; l++) n_active+=(this->active_set_block[ar[l]]>0);

        for(int l=0; l<n && (n_active==n)/**/; l++) {
            k = ar[l];
            ctx->k=k;
            NDAT tt = l + this->task->dat_skill_rix[t]; // tt – index into stacked skill array
            NDAT next_tt = this->forward_ix[tt];
            if(next_tt==-1) continue;
            o_tp1 = this->task->dat_obs_stacked[next_tt];
            
            denom = 0.0;
            for(i=0; i<nS; i++) {
                for(j=0; j<nS; j++) {
                    denom += this->alpha[tt][i] * getA(ctx,i,j) * this->beta[next_tt][j] * ((o_tp1<0)?1:getB(ctx,j,o_tp1));
                }
            }
            for(i=0; i<nS; i++) {
                for(j=0; j<nS; j++) {
                    this->xi[tt][i][j] = this->alpha[tt][i] * getA(ctx,i,j) * this->beta[next_tt][j] * ((o_tp1<0)?1:getB(ctx,j,o_tp1)) / ((denom>0)?denom:1); //
                    this->gamma[tt][i] += this->xi[tt][i][j];
                }
            }
        } // all row's skills
    } // all N rows
    delete ctx;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x78, %rsp
movq %rdi, %rbx
movq 0x68(%rdi), %rax
movsbl 0x900(%rax), %edx
movzbl %dl, %ecx
movq %rcx, 0x8(%rsp)
movslq 0x8fc(%rax), %r15
movl 0x8f8(%rax), %eax
movq %rax, 0x50(%rsp)
movl %edx, 0x20(%rsp)
movl %edx, %r12d
testq %r15, %r15
jle 0xc787
movq 0x98(%rbx), %r13
leaq (,%r12,8), %r14
xorl %ebp, %ebp
cmpb $0x0, 0x8(%rsp)
jle 0xc77f
movq (%r13,%rbp,8), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x2100
incq %rbp
cmpq %rbp, %r15
jne 0xc769
testl %r15d, %r15d
jle 0xc7de
movq 0xa0(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq (,%r12,8), %r14
xorl %ebp, %ebp
movq %r15, 0x10(%rsp)
cmpb $0x0, 0x8(%rsp)
jle 0xc7d1
movq 0x30(%rsp), %rax
movq (%rax,%rbp,8), %r13
xorl %r15d, %r15d
movq (%r13,%r15,8), %rdi
xorl %esi, %esi
movq %r14, %rdx
callq 0x2100
incq %r15
cmpq %r15, %r12
jne 0xc7ba
incq %rbp
movq 0x10(%rsp), %r15
cmpq %r15, %rbp
jne 0xc7a7
movl $0x14, %edi
callq 0x21c0
movq %rax, %r14
cmpl $0x0, 0x50(%rsp)
jle 0xcacd
movslq 0x20(%rsp), %rax
movq %rax, 0x70(%rsp)
xorl %r15d, %r15d
movq 0x68(%rbx), %rdi
movq 0x890(%rdi), %rax
movl (%rax,%r15,4), %eax
movl %eax, 0x4(%r14)
movl %r15d, 0xc(%r14)
movl %r15d, %esi
leaq 0x58(%rsp), %rdx
leaq 0x7(%rsp), %rcx
callq 0x76ed
movq 0x58(%rsp), %rax
cmpl $0x0, (%rax)
js 0xcabf
movsbq 0x7(%rsp), %rcx
testq %rcx, %rcx
jle 0xc86a
movq 0x58(%rbx), %rdx
xorl %esi, %esi
xorl %r9d, %r9d
movslq (%rax,%rsi,4), %rdi
xorl %r8d, %r8d
cmpb $0x0, (%rdx,%rdi)
setg %r8b
addl %r8d, %r9d
incq %rsi
cmpq %rsi, %rcx
jne 0xc84e
jmp 0xc86d
xorl %r9d, %r9d
movsbl 0x7(%rsp), %eax
testl %eax, %eax
jle 0xcabf
cmpl %eax, %r9d
jne 0xcabf
xorl %esi, %esi
movq %r15, 0x60(%rsp)
movl %r9d, 0x4c(%rsp)
movq 0x58(%rsp), %rax
movl (%rax,%rsi,4), %eax
movl %eax, (%r14)
movq 0x68(%rbx), %rax
movq 0xb8(%rbx), %rcx
movq 0x8b0(%rax), %rdx
movslq (%rdx,%r15,4), %rdx
movq %rsi, 0x68(%rsp)
movslq %esi, %r15
addq %rdx, %r15
movslq (%rcx,%r15,4), %rdx
movq %rdx, 0x10(%rsp)
cmpq $-0x1, %rdx
je 0xca99
movq 0x888(%rax), %rax
movq 0x10(%rsp), %rcx
movb (%rax,%rcx), %r12b
movsbl %r12b, %eax
movl %eax, 0x1c(%rsp)
cmpb $0x0, 0x8(%rsp)
jle 0xc99e
xorps %xmm1, %xmm1
xorl %ebp, %ebp
xorl %r13d, %r13d
movaps %xmm1, 0x30(%rsp)
movq (%rbx), %rax
movq 0x70(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movsd (%rcx,%rbp,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsbl %bpl, %edx
movsbl %r13b, %ecx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x30(%rax)
movapd %xmm0, %xmm2
mulsd 0x20(%rsp), %xmm2
movq 0x90(%rbx), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r13,8), %xmm2
movsd 0x5003(%rip), %xmm0     # 0x11950
testb %r12b, %r12b
js 0xc972
movq (%rbx), %rax
movsbl %r13b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %ecx
movsd %xmm2, 0x20(%rsp)
callq *0x38(%rax)
movsd 0x20(%rsp), %xmm2
mulsd %xmm0, %xmm2
movapd 0x30(%rsp), %xmm1
addsd %xmm2, %xmm1
incq %r13
cmpq %r13, 0x8(%rsp)
jne 0xc8f9
incq %rbp
cmpq 0x8(%rsp), %rbp
jne 0xc8f6
jmp 0xc9a2
xorpd %xmm1, %xmm1
cmpb $0x0, 0x8(%rsp)
jle 0xca99
xorpd %xmm2, %xmm2
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm1
movsd 0x4f8e(%rip), %xmm0     # 0x11950
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
movapd %xmm2, 0x20(%rsp)
xorl %ebp, %ebp
xorl %r13d, %r13d
movq (%rbx), %rax
movq 0x70(%rbx), %rcx
movq (%rcx,%r15,8), %rcx
movsd (%rcx,%rbp,8), %xmm0
movsd %xmm0, 0x30(%rsp)
movsbl %bpl, %edx
movsbl %r13b, %ecx
movq %rbx, %rdi
movq %r14, %rsi
callq *0x30(%rax)
movapd %xmm0, %xmm1
mulsd 0x30(%rsp), %xmm1
movq 0x90(%rbx), %rax
movq 0x10(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%r13,8), %xmm1
movsd 0x4f2c(%rip), %xmm0     # 0x11950
testb %r12b, %r12b
js 0xca49
movq (%rbx), %rax
movsbl %r13b, %edx
movq %rbx, %rdi
movq %r14, %rsi
movl 0x1c(%rsp), %ecx
movsd %xmm1, 0x30(%rsp)
callq *0x38(%rax)
movsd 0x30(%rsp), %xmm1
mulsd %xmm0, %xmm1
divsd 0x20(%rsp), %xmm1
movq 0xa0(%rbx), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%rbp,8), %rax
movsd %xmm1, (%rax,%r13,8)
movq 0x98(%rbx), %rax
movq (%rax,%r15,8), %rax
addsd (%rax,%rbp,8), %xmm1
movsd %xmm1, (%rax,%rbp,8)
incq %r13
cmpq %r13, 0x8(%rsp)
jne 0xc9d5
incq %rbp
cmpq 0x70(%rsp), %rbp
jne 0xc9d2
movq 0x68(%rsp), %rsi
incq %rsi
movsbq 0x7(%rsp), %rax
cmpq %rax, %rsi
movq 0x60(%rsp), %r15
movl 0x4c(%rsp), %r9d
jge 0xcabf
cmpl %eax, %r9d
je 0xc88f
incq %r15
cmpq 0x50(%rsp), %r15
jne 0xc803
movl $0x14, %esi
movq %r14, %rdi
callq 0x21d0
addq $0x78, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop