// File: /workspace/github_cpp_makefile_star2_O2/myudelson[P]hmm-scalable/HMMProblemSt.cpp
// Function: HMMProblemSt::doConjugateLinearStep(FitBitSt*)
void HMMProblemSt::doConjugateLinearStep(FitBitSt *fb) {
    NPAR i=0;
    NCAT nK = this->task->nK, k, l;
   
    // first scale down gradients -- MOVED TO Cycle Bit
    // fb->scaleGradients(false, this->active_set_block);
    
    // compute beta_gradient_direction
    NUMBER *beta_grad = init1D<NUMBER>(nK);
    NUMBER *beta_grad_den = init1D<NUMBER>(nK);

    for(k=0; k<nK; k++) {
        if(this->active_set_block[k]>0) {
            for(i=0; i<skill1_n; i++) {
                l = skill1_n*k + i;
                if(this->task->solver_setting == 1) { // Polak-Ribiere
                    beta_grad[k]     += fb->GRAD[l]*fb->GRAD[l];
                    beta_grad_den[k] += fb->GRADm1[l]*fb->GRADm1[l];
                } else if(this->task->solver_setting == 2) { // Fletcher-Reeves
                    beta_grad[k]     += -fb->GRAD[l]*(-fb->GRAD[l] + fb->GRADm1[l]);
                    beta_grad_den[k] +=  fb->GRADm1[l]*fb->GRADm1[l];
                } else if(this->task->solver_setting == 3) { // Hestenes-Stiefel
                    beta_grad[k]     += fb->GRAD[l]* (-fb->GRAD[l] + fb->GRADm1[l]); // no -, since neg gradient and - is +
                    beta_grad_den[k] += fb->DIRm1[l]*(-fb->GRAD[l] + fb->GRADm1[l]);
                } else if(this->task->solver_setting == 4) { // Dai-Yuan
                    beta_grad[k]     += -fb->GRAD[l]*fb->GRAD[l];
                    beta_grad_den[k] +=  fb->DIRm1[l]*(-fb->GRAD[l] + fb->GRADm1[l]);
                } else {
                    fprintf(stderr,"Wrong stepping algorithm (%d) specified for Conjugate Gradient Descent\n",this->task->solver_setting);
                    exit(1);
                }
            }
            beta_grad[k] = beta_grad[k] / safe0num(beta_grad_den[k]);
            beta_grad[k] = (beta_grad[k]>=0)?beta_grad[k]:0;
        } // if in the active set
    }// for all skills
    
    // compute new negative direction
    toZero1D(fb->DIR, fb->nPARAM);
    for(k=0; k<nK; k++) {
        if(this->active_set_block[k]>0) {
            for(i=0; i<skill1_n; i++) {
                l = skill1_n*k + i;
//              fb->DIR[l] = -fb->GRAD[l] + beta_grad[k] * fb->DIRm1[l];
                fb->DIR[l] =  fb->GRAD[l] - beta_grad[k] * fb->DIRm1[l]; // negative direction
            }
        }
    }
    fb->scaleGradients(true, this->active_set_block);

    // almost identical code from linear step, but using direction
    doLinearStep(fb, true /*direction*/);
     
    // recycle
    free(beta_grad);
    free(beta_grad_den);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rsi, %rbx
movq %rdi, %r14
movq 0x68(%rdi), %rax
movl 0x908(%rax), %r12d
movl %r12d, %edi
callq 0x6a57
movq %rax, %r15
movl %r12d, %edi
callq 0x6a57
movq %r12, %rcx
movq %rax, %r12
xorl %ebp, %ebp
testl %ecx, %ecx
cmovlel %ebp, %ecx
leaq 0x3098(%rip), %r13      # 0x11258
movq %rcx, 0x8(%rsp)
cmpq %rcx, %rbp
je 0xe331
movq 0x58(%r14), %rax
cmpb $0x0, (%rax,%rbp)
jle 0xe329
movl 0x38(%r14), %eax
movl %ebp, %ecx
imull %eax, %ecx
movq 0x68(%r14), %rdx
xorl %esi, %esi
movsbl %sil, %edi
cmpl %edi, %eax
jle 0xe2f1
movzbl 0x50(%rdx), %r9d
leal -0x1(%r9), %r8d
cmpl $0x3, %r8d
ja 0xe3de
addl %ecx, %edi
movslq (%r13,%r8,4), %r8
addq %r13, %r8
movslq %edi, %rdi
jmpq *%r8
movq 0x30(%rbx), %r8
movsd (%r8,%rdi,8), %xmm0
mulsd %xmm0, %xmm0
addsd (%r15,%rbp,8), %xmm0
movsd %xmm0, (%r15,%rbp,8)
movq 0x38(%rbx), %r8
movsd (%r8,%rdi,8), %xmm0
jmp 0xe2d9
movq 0x30(%rbx), %r8
movq 0x38(%rbx), %r9
movsd (%r8,%rdi,8), %xmm0
movsd (%r9,%rdi,8), %xmm1
subsd %xmm0, %xmm1
mulsd %xmm0, %xmm1
addsd (%r15,%rbp,8), %xmm1
movsd %xmm1, (%r15,%rbp,8)
jmp 0xe28f
movq 0x30(%rbx), %r8
movsd (%r8,%rdi,8), %xmm0
movsd (%r15,%rbp,8), %xmm1
mulsd %xmm0, %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, (%r15,%rbp,8)
movq 0x38(%rbx), %r9
movq 0x50(%rbx), %r10
movsd (%r9,%rdi,8), %xmm0
subsd (%r8,%rdi,8), %xmm0
mulsd (%r10,%rdi,8), %xmm0
jmp 0xe2dd
movq 0x30(%rbx), %r8
movq 0x38(%rbx), %r9
movsd (%r8,%rdi,8), %xmm0
movsd (%r9,%rdi,8), %xmm1
subsd %xmm0, %xmm1
movsd (%r15,%rbp,8), %xmm2
mulsd %xmm0, %xmm1
subsd %xmm1, %xmm2
movsd %xmm2, (%r15,%rbp,8)
movsd (%r9,%rdi,8), %xmm0
mulsd %xmm0, %xmm0
addsd (%r12,%rbp,8), %xmm0
movsd %xmm0, (%r12,%rbp,8)
incb %sil
jmp 0xe1eb
movsd (%r15,%rbp,8), %xmm0
movaps %xmm0, 0x10(%rsp)
movsd (%r12,%rbp,8), %xmm0
callq 0x55a1
movq 0x8(%rsp), %rcx
movapd 0x10(%rsp), %xmm1
divsd %xmm0, %xmm1
xorpd %xmm0, %xmm0
cmplesd %xmm1, %xmm0
andpd %xmm1, %xmm0
movlpd %xmm0, (%r15,%rbp,8)
incq %rbp
jmp 0xe1c5
movq 0x48(%rbx), %rdi
movl 0xc(%rbx), %esi
callq 0xedbf
movq 0x8(%rsp), %r11
movq 0x58(%r14), %rdx
movslq 0x38(%r14), %rax
xorl %ecx, %ecx
cmpq %r11, %rcx
je 0xe3a2
cmpb $0x0, (%rdx,%rcx)
jle 0xe39d
movq %rcx, %rsi
imulq %rax, %rsi
xorl %edi, %edi
movsbl %dil, %r8d
cmpl %r8d, %eax
jle 0xe39d
movsbq %dil, %r8
addq %rsi, %r8
movq 0x30(%rbx), %r9
movsd (%r15,%rcx,8), %xmm0
movq 0x50(%rbx), %r10
mulsd (%r10,%r8,8), %xmm0
movq 0x48(%rbx), %r10
movsd (%r9,%r8,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%r10,%r8,8)
incb %dil
jmp 0xe360
incq %rcx
jmp 0xe34c
pushq $0x1
popq %rbp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x7404
movq (%r14), %rax
movq %r14, %rdi
movq %rbx, %rsi
movl %ebp, %edx
callq *0xa0(%rax)
movq %r15, %rdi
callq 0x3230
movq %r12, %rdi
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x3230
movsbl %r9b, %edx
movq 0x7bef(%rip), %rax      # 0x15fd8
movq (%rax), %rdi
leaq 0x30b5(%rip), %rsi      # 0x114a8
xorl %eax, %eax
callq 0x32d0
pushq $0x1
popq %rdi
callq 0x3240