// File: myudelson[P]hmm-scalable/HMMProblemPiABGK.cpp
// Function: HMMProblemPiABGK::setGradB(FitBit*)
void HMMProblemPiABGK::setGradB (FitBit *fb){
    if(this->p->block_fitting[2]>0) return;
    NDAT t, ndat = 0;
    NPAR o=0, i;
    NUMBER combined, deriv_logit;
    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++) {
            o = this->p->dat_obs[ dt->ix[t] ];
            if(o<0)
                continue;
            for(i=0; i<fb->nS; i++) {
                combined = getB(dt,i,o);
                deriv_logit = 1 / safe0num( fb->B[i][o] * (1-fb->B[i][o]) );
                fb->gradB[i][o] -= combined * (1-combined) * deriv_logit * dt->alpha[t][i] * dt->beta[t][i] / safe0num(dt->p_O_param * ((o<0)?1:fb->B[i][o]));
            }
        }
    }
    if( this->p->Cslices>0 ) // penalty
        fb->addL2Penalty(FBV_B, this->p, (NUMBER)ndat);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x48(%rbp)
movq 0x88(%rax), %rax
movsbl 0x983(%rax), %eax
cmpl $0x0, %eax
jle 0x35cf0
jmp 0x35f5e
movl $0x0, -0x18(%rbp)
movb $0x0, -0x19(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
jge 0x35f2c
movq -0x10(%rbp), %rax
movq 0xf0(%rax), %rax
movslq -0x3c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rax
cmpl $0x0, 0x4(%rax)
je 0x35d3b
jmp 0x35f1e
movq -0x38(%rbp), %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl $0x0, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35f1c
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movq 0x870(%rax), %rax
movq -0x38(%rbp), %rcx
movq 0x10(%rcx), %rcx
movslq -0x14(%rbp), %rdx
movslq (%rcx,%rdx,4), %rcx
movb (%rax,%rcx), %al
movb %al, -0x19(%rbp)
movsbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jge 0x35d93
jmp 0x35f0e
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movq -0x10(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x35f0c
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movb -0x1a(%rbp), %dl
movb -0x19(%rbp), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x20(%rax)
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
movsd 0x19c05(%rip), %xmm1    # 0x4fa08
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
callq 0x9a40
movaps %xmm0, %xmm1
movsd 0x19bec(%rip), %xmm0    # 0x4fa08
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x19bd6(%rip), %xmm1    # 0x4fa08
subsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd -0x30(%rbp), %xmm0
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1a(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1a(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movq -0x38(%rbp), %rax
movsd 0x48(%rax), %xmm0
movsd %xmm0, -0x50(%rbp)
movsbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jge 0x35e9f
movsd 0x19b70(%rip), %xmm0    # 0x4fa08
movsd %xmm0, -0x60(%rbp)
jmp 0x35ebf
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x60(%rbp), %xmm1
mulsd %xmm1, %xmm0
callq 0x9a40
movsd -0x58(%rbp), %xmm1
divsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movq 0x68(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x35d97
jmp 0x35f0e
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x35d4e
jmp 0x35f1e
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x35d02
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x42(%rax), %eax
cmpl $0x0, %eax
jle 0x35f5e
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x88(%rax), %rdx
cvtsi2sdl -0x18(%rbp), %xmm0
movl $0x3, %esi
callq 0xf200
addq $0x60, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)