// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/HMMProblemSlicedA.cpp
// Function: HMMProblemSlicedA::setGradB(FitBitSlicedA*)
void HMMProblemSlicedA::setGradB (FitBitSlicedA *fb){
    if(this->p->block_fitting[2]>0) return;
    NDAT t, ndat = 0;
	NPAR o, o0, i;//, j;//, z;
    struct data* dt;
    for(NCAT x=0; x<fb->xndat; x++) {
        dt = fb->x_data[x];
        if( dt->cnt!=0 ) continue;
        ndat += dt->n;
//        for(t=0; t<dt->n; t++) { // old
        for(t=0; t<dt->n; t++) { // Levinson MMFST
//            z = this->p->dat_slice[ dt->ix[t] ];
//            if(z == fb->tag) { // tag contains the current slice
                o  = this->p->dat_obs[ dt->ix[t] ];//->get( dt->ix[t] );
                dt->t = dt->ix[t]; // global state pointer
                o0 = this->p->dat_obs[ dt->ix[0] ];//->get( dt->ix[t] );
                if(o<0) // if no observation -- skip
                    continue;
                for(i=0; i<this->p->nS; i++)
                    fb->gradB[i][o] -= dt->alpha[t][i] * dt->beta[t][i] / safe0num(dt->p_O_param * fb->B[i][o]); // old
//                for(j=0; j<this->p->nS; j++)
//                    if(t==0) {
//                        fb->gradB[j][o] -= (o0==o) * getPI(dt,j) * dt->beta[0][j];
//                    } else {
//                        for(i=0; i<this->p->nS; i++)
//                            fb->gradB[j][o] -= ( dt->alpha[t-1][i] * getA(dt,i,j) * dt->beta[t][j] /*+ (o0==o) * getPI(dt,j) * dt->beta[0][j]*/ ) / safe0num(dt->p_O_param); // Levinson MMFST
//                    }
//            }
        }
    }
    // penalty
    if( this->p->Cslices>0 ) {
        fb->addL2Penalty(FBV_B, this->p, (NUMBER)ndat);
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x88(%rdi), %rdx
cmpb $0x0, 0x983(%rdx)
jle 0x2c6ff
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rbx
movl 0xd0(%rsi), %eax
testl %eax, %eax
jle 0x2c825
movq %rdi, %r14
xorl %esi, %esi
xorl %edi, %edi
movq 0xd8(%rbx), %rcx
movq (%rcx,%rsi,8), %r12
cmpl $0x0, 0x4(%r12)
jne 0x2c80d
movl (%r12), %ecx
addl %ecx, %edi
testl %ecx, %ecx
jle 0x2c80d
movl %edi, 0x4(%rsp)
movq %rsi, 0x8(%rsp)
xorl %r13d, %r13d
movq 0x870(%rdx), %rax
movq 0x10(%r12), %rsi
movslq (%rsi,%r13,4), %rsi
movsbq (%rax,%rsi), %rbp
movl %esi, 0x8(%r12)
testq %rbp, %rbp
js 0x2c7ef
cmpb $0x0, 0x8b8(%rdx)
jle 0x2c7ef
xorl %r15d, %r15d
movq 0x28(%r12), %rax
movq 0x30(%r12), %rcx
movq (%rax,%r13,8), %rax
movsd (%rax,%r15,8), %xmm0
movq (%rcx,%r13,8), %rax
mulsd (%rax,%r15,8), %xmm0
movsd %xmm0, 0x10(%rsp)
movsd 0x48(%r12), %xmm0
movq 0x20(%rbx), %rax
movq (%rax,%r15,8), %rax
mulsd (%rax,%rbp,8), %xmm0
callq 0x8df8
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x68(%rbx), %rax
movq (%rax,%r15,8), %rax
movsd (%rax,%rbp,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rbp,8)
incq %r15
movq 0x88(%r14), %rdx
movsbq 0x8b8(%rdx), %rax
cmpq %rax, %r15
jl 0x2c777
movl (%r12), %ecx
incq %r13
movslq %ecx, %rax
cmpq %rax, %r13
jl 0x2c748
movl 0xd0(%rbx), %eax
movq 0x8(%rsp), %rsi
movl 0x4(%rsp), %edi
incq %rsi
movslq %eax, %rcx
cmpq %rcx, %rsi
jl 0x2c717
xorps %xmm0, %xmm0
cvtsi2sd %edi, %xmm0
jmp 0x2c829
xorpd %xmm0, %xmm0
cmpb $0x0, 0x42(%rdx)
jle 0x2c6f0
movq %rbx, %rdi
movl $0x3, %esi
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc7e8