// File: myudelson[P]hmm-scalable/HMMProblemPiGK.cpp
// Function: HMMProblemPiGK::setGradPI(FitBit*)
void HMMProblemPiGK::setGradPI(FitBit *fb){
    if(this->p->block_fitting[0]>0) return;
    NDAT t = 0, ndat = 0;
    NPAR i, o;
    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;
//    o = dt->obs[t];
        o = this->p->dat_obs[ dt->ix[t] ];//->get( dt->ix[t] );
        for(i=0; i<fb->nS; i++) {
            combined = getPI(dt,i);//sigmoid( logit(this->PI[k][i]) + logit(this->PIg[g][i]) );
            deriv_logit = 1 / safe0num( fb->pi[i] * (1-fb->pi[i]) );
            fb->gradPI[i] -= combined * (1-combined) * deriv_logit * dt->beta[t][i] * ((o<0)?1:getB(dt,i,o)) / safe0num(dt->p_O_param);
        }
    }
    if( this->p->Cslices>0 ) // penalty
        fb->addL2Penalty(FBV_PI, 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 0x981(%rax), %eax
cmpl $0x0, %eax
jle 0x28a80
jmp 0x28c81
movl $0x0, -0x14(%rbp)
movl $0x0, -0x18(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
jge 0x28c4f
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 0x28ace
jmp 0x28c41
movq -0x48(%rbp), %rax
movq -0x38(%rbp), %rcx
movl (%rcx), %ecx
addl -0x18(%rbp), %ecx
movl %ecx, -0x18(%rbp)
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, -0x1a(%rbp)
movb $0x0, -0x19(%rbp)
movsbl -0x19(%rbp), %eax
movq -0x10(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x28c3f
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movb -0x19(%rbp), %cl
movq (%rdi), %rax
movsbl %cl, %edx
callq *0x10(%rax)
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movsbq -0x19(%rbp), %rcx
movsd 0x26eae(%rip), %xmm1    # 0x4fa08
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
callq 0x9a40
movaps %xmm0, %xmm1
movsd 0x26e95(%rip), %xmm0    # 0x4fa08
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x26e7f(%rip), %xmm1    # 0x4fa08
subsd -0x28(%rbp), %xmm1
mulsd %xmm1, %xmm0
mulsd -0x30(%rbp), %xmm0
movq -0x38(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x50(%rbp)
movsbl -0x1a(%rbp), %eax
cmpl $0x0, %eax
jge 0x28bce
movsd 0x26e41(%rip), %xmm0    # 0x4fa08
movsd %xmm0, -0x58(%rbp)
jmp 0x28bed
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movb -0x19(%rbp), %dl
movb -0x1a(%rbp), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x20(%rax)
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm0
movsd %xmm0, -0x60(%rbp)
movq -0x38(%rbp), %rax
movsd 0x48(%rax), %xmm0
callq 0x9a40
movsd -0x60(%rbp), %xmm1
divsd %xmm0, %xmm1
movq -0x10(%rbp), %rax
movq 0x58(%rax), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x19(%rbp), %al
addb $0x1, %al
movb %al, -0x19(%rbp)
jmp 0x28b06
jmp 0x28c41
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x28a95
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x42(%rax), %eax
cmpl $0x0, %eax
jle 0x28c81
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x88(%rax), %rdx
cvtsi2sdl -0x18(%rbp), %xmm0
movl $0x1, %esi
callq 0xf200
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)