// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemAGK.cpp
// Function: HMMProblemAGK::setGradA(FitBit*)
void HMMProblemAGK::setGradA (FitBit *fb){
    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] ];//->get( dt->ix[t] );
            for(i=0; i<fb->nS /*&& fitparam[1]>0*/; 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:getB(dt,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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %edx, %edx
xorl %ecx, %ecx
movslq 0xe8(%rbx), %rax
cmpq %rax, %rdx
jge 0x19ba1
movq 0xf0(%rbx), %rax
movq (%rax,%rdx,8), %r15
cmpl $0x0, 0x4(%r15)
jne 0x19b99
movq %rdx, 0x20(%rsp)
movl %ecx, 0x14(%rsp)
movl (%r15), %eax
movl %eax, 0x10(%rsp)
pushq $0x1
popq %r13
cltq
cmpq %rax, %r13
jge 0x19b8c
movq 0x88(%r14), %rax
movq 0x870(%rax), %rax
movq 0x10(%r15), %rcx
movslq (%rcx,%r13,4), %rcx
movb (%rax,%rcx), %cl
movb 0x1(%rbx), %al
movb %cl, 0x7(%rsp)
movsbl %cl, %ecx
movl %ecx, 0x18(%rsp)
xorl %ebp, %ebp
movsbq %al, %rcx
cmpq %rcx, %rbp
jge 0x19b81
movsbl %bpl, %ecx
movl %ecx, 0x1c(%rsp)
xorl %r12d, %r12d
movsbq %al, %rcx
cmpq %rcx, %r12
jge 0x19b79
movq (%r14), %rax
movsbl %r12b, %ecx
movq %r14, %rdi
movq %r15, %rsi
movl 0x1c(%rsp), %edx
callq *0x18(%rax)
movsd %xmm0, 0x8(%rsp)
movq 0x18(%rbx), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm1
movsd 0x12e33(%rip), %xmm0    # 0x2c8f0
subsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x67cb
movsd 0x12e1e(%rip), %xmm2    # 0x2c8f0
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
movapd %xmm2, %xmm0
movsd 0x8(%rsp), %xmm3
subsd %xmm3, %xmm0
mulsd %xmm3, %xmm0
mulsd %xmm1, %xmm0
movq 0x30(%r15), %rax
movq (%rax,%r13,8), %rax
mulsd (%rax,%r12,8), %xmm0
movsd %xmm0, 0x8(%rsp)
movapd %xmm2, %xmm0
cmpb $0x0, 0x7(%rsp)
js 0x19b23
movq (%r14), %rax
movsbl %r12b, %edx
movq %r14, %rdi
movq %r15, %rsi
movl 0x18(%rsp), %ecx
callq *0x20(%rax)
movsd 0x8(%rsp), %xmm1
mulsd %xmm0, %xmm1
movq 0x28(%r15), %rax
movq -0x8(%rax,%r13,8), %rax
mulsd (%rax,%rbp,8), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd 0x48(%r15), %xmm0
callq 0x67cb
movsd 0x8(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x60(%rbx), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%r12,8)
incq %r12
movb 0x1(%rbx), %al
jmp 0x19a80
incq %rbp
jmp 0x19a68
incq %r13
movl (%r15), %eax
jmp 0x19a34
movl 0x14(%rsp), %ecx
addl 0x10(%rsp), %ecx
movq 0x20(%rsp), %rdx
incq %rdx
jmp 0x199fa
movq 0x88(%r14), %rdx
cmpb $0x0, 0x42(%rdx)
jle 0x19bcb
cvtsi2sd %ecx, %xmm0
pushq $0x2
popq %rsi
movq %rbx, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x90fe
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq