// File: myudelson[P]hmm-scalable/HMMProblemPiABGK.cpp
// Function: HMMProblemPiABGK::setGradA(FitBit*)
void HMMProblemPiABGK::setGradA (FitBit *fb){
    if(this->p->block_fitting[1]>0) return;
    NDAT t, ndat = 0;
    NPAR o, i, j;
    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=1; t<dt->n; t++) {
            o = this->p->dat_obs[ dt->ix[t] ];
            for(i=0; i<fb->nS; i++)
                for(j=0; j<fb->nS; j++) {
                    combined = getA(dt,i,j);
                    deriv_logit = 1 / safe0num( fb->A[i][j] * (1-fb->A[i][j]) );
                    fb->gradA[i][j] -= combined * (1-combined) * deriv_logit * dt->beta[t][j] * ((o<0)?1:fb->B[j][o]) * dt->alpha[t-1][i] / safe0num(dt->p_O_param) ;
                }
        }
    }
    if( this->p->Cslices>0 ) // penalty
        fb->addL2Penalty(FBV_A, 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 0x982(%rax), %eax
cmpl $0x0, %eax
jle 0x35a30
jmp 0x35cb8
movl $0x0, -0x18(%rbp)
movl $0x0, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xe8(%rcx), %eax
jge 0x35c86
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 0x35a77
jmp 0x35c78
movq -0x38(%rbp), %rax
movl (%rax), %eax
addl -0x18(%rbp), %eax
movl %eax, -0x18(%rbp)
movl $0x1, -0x14(%rbp)
movl -0x14(%rbp), %eax
movq -0x38(%rbp), %rcx
cmpl (%rcx), %eax
jge 0x35c76
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)
movb $0x0, -0x1a(%rbp)
movsbl -0x1a(%rbp), %eax
movq -0x10(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x35c66
movb $0x0, -0x1b(%rbp)
movsbl -0x1b(%rbp), %eax
movq -0x10(%rbp), %rcx
movsbl 0x1(%rcx), %ecx
cmpl %ecx, %eax
jge 0x35c57
movq -0x48(%rbp), %rdi
movq -0x38(%rbp), %rsi
movb -0x1a(%rbp), %dl
movb -0x1b(%rbp), %cl
movq (%rdi), %rax
movsbl %dl, %edx
movsbl %cl, %ecx
callq *0x18(%rax)
movsd %xmm0, -0x28(%rbp)
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1b(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x18(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1b(%rbp), %rcx
movsd 0x19ebf(%rip), %xmm1    # 0x4fa08
subsd (%rax,%rcx,8), %xmm1
mulsd %xmm1, %xmm0
callq 0x9a40
movaps %xmm0, %xmm1
movsd 0x19ea6(%rip), %xmm0    # 0x4fa08
divsd %xmm1, %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x28(%rbp), %xmm0
movsd 0x19e90(%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 -0x1b(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x50(%rbp)
movsbl -0x19(%rbp), %eax
cmpl $0x0, %eax
jge 0x35bbd
movsd 0x19e52(%rip), %xmm0    # 0x4fa08
movsd %xmm0, -0x58(%rbp)
jmp 0x35bdd
movq -0x10(%rbp), %rax
movq 0x20(%rax), %rax
movsbq -0x1b(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x19(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x50(%rbp), %xmm0
movsd -0x58(%rbp), %xmm1
mulsd %xmm1, %xmm0
movq -0x38(%rbp), %rax
movq 0x28(%rax), %rax
movl -0x14(%rbp), %ecx
subl $0x1, %ecx
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1a(%rbp), %rcx
mulsd (%rax,%rcx,8), %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 0x60(%rax), %rax
movsbq -0x1a(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movsbq -0x1b(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movb -0x1b(%rbp), %al
addb $0x1, %al
movb %al, -0x1b(%rbp)
jmp 0x35add
jmp 0x35c59
movb -0x1a(%rbp), %al
addb $0x1, %al
movb %al, -0x1a(%rbp)
jmp 0x35ac5
jmp 0x35c68
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x14(%rbp)
jmp 0x35a8a
jmp 0x35c78
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x35a3e
movq -0x48(%rbp), %rax
movq 0x88(%rax), %rax
movsbl 0x42(%rax), %eax
cmpl $0x0, %eax
jle 0x35cb8
movq -0x48(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x88(%rax), %rdx
cvtsi2sdl -0x18(%rbp), %xmm0
movl $0x2, %esi
callq 0xf200
addq $0x60, %rsp
popq %rbp
retq
nop