// File: /workspace/github_cpp_makefile_star2_O3/myudelson[P]hmm-scalable/HMMProblemSlicedAB.cpp
// Function: HMMProblemSlicedAB::setGradB(FitBitSlicedAB*)
void HMMProblemSlicedAB::setGradB (FitBitSlicedAB *fb){
    if(this->p->block_fitting[2]>0) return;
    NDAT t, ndat = 0;
    NPAR o, o0, i, 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] ];
            o  = this->p->dat_obs[ dt->ix[t] ];//->get( dt->ix[t] );
            o0 = this->p->dat_obs[ dt->ix[0] ];//->get( dt->ix[t] );
            dt->t = dt->ix[t]; // global state pointer
            if(o<0) // if no observation -- skip
                continue;
            for(i=0; i<this->p->nS; i++)
                fb->gradB[z][i][o] -= dt->alpha[t][i] * dt->beta[t][i] / safe0num(dt->p_O_param * fb->B[z][i][o]); // old
//            for(j=0; j<this->p->nS; j++)
//                if(t==0) {
//                    fb->gradB[z][j][o] -= (o0==o) * getPI(dt,j) * dt->beta[0][j];
//                } else {
//                    for(i=0; i<this->p->nS; i++)
//                        fb->gradB[z][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 $0x28, %rsp
movq 0x88(%rdi), %rdx
cmpb $0x0, 0x983(%rdx)
jle 0x26461
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %r13
movl 0xd0(%rsi), %eax
testl %eax, %eax
jle 0x265ad
xorl %r8d, %r8d
xorl %r9d, %r9d
movq 0xd8(%r13), %rcx
movq (%rcx,%r8,8), %rbp
cmpl $0x0, 0x4(%rbp)
jne 0x26594
movl (%rbp), %ecx
addl %ecx, %r9d
testl %ecx, %ecx
jle 0x26594
movl %r9d, 0xc(%rsp)
movq %r8, 0x10(%rsp)
xorl %r12d, %r12d
movq 0x870(%rdx), %rax
movq 0x8a8(%rdx), %r9
movq 0x10(%rbp), %r8
movslq (%r8,%r12,4), %r8
movsbq (%r9,%r8), %r15
movsbq (%rax,%r8), %rbx
movl %r8d, 0x8(%rbp)
testq %rbx, %rbx
js 0x26574
cmpb $0x0, 0x8b8(%rdx)
jle 0x26574
xorl %r14d, %r14d
movq %rbx, 0x18(%rsp)
movq 0x28(%rbp), %rax
movq 0x30(%rbp), %rcx
movq (%rax,%r12,8), %rax
movsd (%rax,%r14,8), %xmm0
movq (%rcx,%r12,8), %rax
mulsd (%rax,%r14,8), %xmm0
movsd %xmm0, 0x20(%rsp)
movsd 0x48(%rbp), %xmm0
movq 0x20(%r13), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r14,8), %rax
mulsd (%rax,%rbx,8), %xmm0
movq %rdi, %rbx
callq 0x8df8
movq %rbx, %rdi
movq 0x18(%rsp), %rbx
movsd 0x20(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x68(%r13), %rax
movq (%rax,%r15,8), %rax
movq (%rax,%r14,8), %rax
movsd (%rax,%rbx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rbx,8)
incq %r14
movq 0x88(%rdi), %rdx
movsbq 0x8b8(%rdx), %rax
cmpq %rax, %r14
jl 0x264ea
movl (%rbp), %ecx
incq %r12
movslq %ecx, %rax
cmpq %rax, %r12
jl 0x264a8
movl 0xd0(%r13), %eax
movq 0x10(%rsp), %r8
movl 0xc(%rsp), %r9d
incq %r8
movslq %eax, %rcx
cmpq %rcx, %r8
jl 0x26478
xorps %xmm0, %xmm0
cvtsi2sd %r9d, %xmm0
jmp 0x265b1
xorpd %xmm0, %xmm0
cmpb $0x0, 0x42(%rdx)
jle 0x26452
movq %r13, %rdi
movl $0x3, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xd890