// File: /workspace/github_cpp_makefile_star2_O3/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq 0x88(%rdi), %rdx
cmpb $0x0, 0x982(%rdx)
jle 0x22c69
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rsi, %rbx
movl 0xe8(%rsi), %eax
testl %eax, %eax
jle 0x22e34
xorl %edx, %edx
movl $0x0, 0x4(%rsp)
movq 0xf0(%rbx), %rcx
movq (%rcx,%rdx,8), %r15
cmpl $0x0, 0x4(%r15)
jne 0x22e13
movl (%r15), %ecx
addl %ecx, 0x4(%rsp)
cmpl $0x2, %ecx
jl 0x22e13
movq %rdx, 0x20(%rsp)
movb 0x1(%rbx), %al
movl $0x1, %edx
movq %rdx, 0x8(%rsp)
testb %al, %al
jle 0x22def
movq 0x88(%rdi), %rcx
movq 0x870(%rcx), %rcx
movq 0x10(%r15), %rdx
movq 0x8(%rsp), %rsi
movslq (%rdx,%rsi,4), %rdx
movzbl (%rcx,%rdx), %r12d
xorl %r14d, %r14d
testb %al, %al
jle 0x22ddc
movsbl %r14b, %eax
movl %eax, 0x1c(%rsp)
xorl %ebp, %ebp
movq (%rdi), %rax
movsbl %bpl, %ecx
movq %rdi, %r13
movq %r15, %rsi
movl 0x1c(%rsp), %edx
callq *0x18(%rax)
movsd %xmm0, 0x10(%rsp)
movq 0x18(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd (%rax,%rbp,8), %xmm1
movsd 0x10bc8(%rip), %xmm0    # 0x338f0
subsd %xmm1, %xmm0
mulsd %xmm1, %xmm0
callq 0x8df8
movsd 0x10bb3(%rip), %xmm3    # 0x338f0
movapd %xmm3, %xmm1
testb %r12b, %r12b
js 0x22d54
movq 0x20(%rbx), %rax
movq (%rax,%rbp,8), %rax
movsd (%rax,%r12,8), %xmm1
movapd %xmm3, %xmm2
divsd %xmm0, %xmm2
movsd 0x10(%rsp), %xmm0
subsd %xmm0, %xmm3
mulsd %xmm0, %xmm3
mulsd %xmm2, %xmm3
movq 0x30(%r15), %rax
movq 0x8(%rsp), %rcx
movq (%rax,%rcx,8), %rax
mulsd (%rax,%rbp,8), %xmm3
mulsd %xmm1, %xmm3
movq 0x28(%r15), %rax
movq -0x8(%rax,%rcx,8), %rax
mulsd (%rax,%r14,8), %xmm3
movsd %xmm3, 0x10(%rsp)
movsd 0x48(%r15), %xmm0
callq 0x8df8
movsd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
movq 0x60(%rbx), %rax
movq (%rax,%r14,8), %rax
movsd (%rax,%rbp,8), %xmm0
subsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rbp,8)
incq %rbp
movb 0x1(%rbx), %al
movsbq %al, %rcx
cmpq %rcx, %rbp
movq %r13, %rdi
jl 0x22cf9
jmp 0x22de0
movsbq %al, %rcx
incq %r14
cmpq %rcx, %r14
jl 0x22ce7
movl (%r15), %ecx
movq 0x8(%rsp), %r8
incq %r8
movslq %ecx, %rdx
movq %r8, 0x8(%rsp)
cmpq %rdx, %r8
jl 0x22cbc
movl 0xe8(%rbx), %eax
movq 0x20(%rsp), %rdx
incq %rdx
movslq %eax, %rcx
cmpq %rcx, %rdx
jl 0x22c84
movq 0x88(%rdi), %rdx
xorps %xmm0, %xmm0
cvtsi2sdl 0x4(%rsp), %xmm0
jmp 0x22e38
xorpd %xmm0, %xmm0
cmpb $0x0, 0x42(%rdx)
jle 0x22c5a
movq %rbx, %rdi
movl $0x2, %esi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb90a
nop