// File: myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::doLagrangeStep(FitBitSt*)
void HMMProblemSt::doLagrangeStep(FitBitSt *fb) {
    // goal: for PI, and every row of A, and B multiply by negative gradient and average over the sum
        
    NUMBER buf;
    //NCAT active = 0;
    for(NCAT l=0; l<fb->sclsmplx_n; l++) { // for all vectors (simplexes) that are supposed to sum to 1
        if(fb->sclsmplx_blocks[l]==0) continue; // if the simplex belongs to block that is not in active set, skip
        buf = 0;
        for(NCAT i=fb->sclsmplx_offsets[l]; i<(fb->sclsmplx_offsets[l]+fb->sclsmplx_sizes[l]); i++)
            //if( (this->active_set_param[i] + this->unblocked_param[i]) == 2 ) // in active set and unblocked
                buf -= fb->PARAM[i]*fb->GRAD[i];
        for(NCAT i=fb->sclsmplx_offsets[l]; i<(fb->sclsmplx_offsets[l]+fb->sclsmplx_sizes[l]); i++)
            //if( (this->active_set_param[i] + this->unblocked_param[i]) == 2 ) // in active set and unblocked
                fb->PARAM[i] = (buf>0)? (-fb->PARAM[i]*fb->GRAD[i])/buf : fb->PARAM[i];
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpl 0xc0(%rcx), %eax
jge 0x16cf8
movq -0x10(%rbp), %rax
movq 0xb0(%rax), %rax
movslq -0x1c(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
jne 0x16b70
jmp 0x16cea
xorps %xmm0, %xmm0
movsd %xmm0, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x20(%rbp)
movl -0x20(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq -0x10(%rbp), %rdx
movq 0xa8(%rdx), %rdx
movslq -0x1c(%rbp), %rsi
movsbl (%rdx,%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x16c14
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movsd -0x18(%rbp), %xmm1
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, -0x18(%rbp)
movl -0x20(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x20(%rbp)
jmp 0x16b8d
movq -0x10(%rbp), %rax
movq 0x98(%rax), %rax
movslq -0x1c(%rbp), %rcx
movl (%rax,%rcx,4), %eax
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
movq -0x10(%rbp), %rcx
movq 0x98(%rcx), %rcx
movslq -0x1c(%rbp), %rdx
movl (%rcx,%rdx,4), %ecx
movq -0x10(%rbp), %rdx
movq 0xa8(%rdx), %rdx
movslq -0x1c(%rbp), %rsi
movsbl (%rdx,%rsi), %edx
addl %edx, %ecx
cmpl %ecx, %eax
jge 0x16ce8
movsd -0x18(%rbp), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0x16cae
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x24(%rbp), %rcx
mulsd (%rax,%rcx,8), %xmm0
divsd -0x18(%rbp), %xmm0
movsd %xmm0, -0x30(%rbp)
jmp 0x16cc4
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x30(%rbp)
movsd -0x30(%rbp), %xmm0
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x24(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x16c29
jmp 0x16cea
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x16b43
popq %rbp
retq
nopw (%rax,%rax)