// File: 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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x38(%rbp)
movb $0x0, -0x11(%rbp)
movq 0x68(%rax), %rax
movl 0x908(%rax), %eax
movl %eax, -0x18(%rbp)
movl -0x18(%rbp), %edi
callq 0x9da0
movq %rax, -0x28(%rbp)
movl -0x18(%rbp), %edi
callq 0x9da0
movq %rax, -0x30(%rbp)
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x18387
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jle 0x18377
movb $0x0, -0x11(%rbp)
movq -0x38(%rbp), %rcx
movsbl -0x11(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x182f4
movq -0x38(%rbp), %rax
movl 0x38(%rax), %ecx
imull -0x1c(%rbp), %ecx
movsbl -0x11(%rbp), %edx
addl %edx, %ecx
movl %ecx, -0x20(%rbp)
movq 0x68(%rax), %rax
movsbl 0x50(%rax), %eax
cmpl $0x1, %eax
jne 0x18030
movq -0x10(%rbp), %rax
movq 0x30(%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
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x182e5
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movsbl 0x50(%rax), %eax
cmpl $0x2, %eax
jne 0x18101
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%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 -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x182e3
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movsbl 0x50(%rax), %eax
cmpl $0x3, %eax
jne 0x181e3
movq -0x10(%rbp), %rax
movq 0x30(%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), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x50(%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), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm2
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x182e1
movq -0x38(%rbp), %rax
movq 0x68(%rax), %rax
movsbl 0x50(%rax), %eax
cmpl $0x4, %eax
jne 0x182b1
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%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 -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
movq -0x10(%rbp), %rax
movq 0x50(%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), %xmm1
movq %xmm1, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm2
movq -0x10(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x20(%rbp), %rcx
addsd (%rax,%rcx,8), %xmm2
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, (%rax,%rcx,8)
jmp 0x182df
movq -0x38(%rbp), %rax
movq 0x9d1c(%rip), %rcx      # 0x21fd8
movq (%rcx), %rdi
movq 0x68(%rax), %rax
movsbl 0x50(%rax), %edx
leaq 0x422e(%rip), %rsi      # 0x1c4fc
movb $0x0, %al
callq 0x33c0
movl $0x1, %edi
callq 0x3330
jmp 0x182e1
jmp 0x182e3
jmp 0x182e5
jmp 0x182e7
movb -0x11(%rbp), %al
addb $0x1, %al
movb %al, -0x11(%rbp)
jmp 0x17f81
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x40(%rbp)
movq -0x30(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
callq 0x75f0
movaps %xmm0, %xmm1
movsd -0x40(%rbp), %xmm0
divsd %xmm1, %xmm0
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x1835b
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x18365
xorps %xmm0, %xmm0
movsd %xmm0, -0x48(%rbp)
jmp 0x18365
movsd -0x48(%rbp), %xmm0
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
jmp 0x18379
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x17f58
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rdi
movq -0x10(%rbp), %rax
movl 0xc(%rax), %esi
callq 0x19350
movl $0x0, -0x1c(%rbp)
movl -0x1c(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x1846e
movq -0x38(%rbp), %rax
movq 0x58(%rax), %rax
movslq -0x1c(%rbp), %rcx
movsbl (%rax,%rcx), %eax
cmpl $0x0, %eax
jle 0x1845e
movb $0x0, -0x11(%rbp)
movq -0x38(%rbp), %rcx
movsbl -0x11(%rbp), %eax
cmpl 0x38(%rcx), %eax
jge 0x1845c
movq -0x38(%rbp), %rax
movl 0x38(%rax), %eax
imull -0x1c(%rbp), %eax
movsbl -0x11(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm1
movq -0x28(%rbp), %rax
movslq -0x1c(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm0
movq -0x10(%rbp), %rax
movq 0x50(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd (%rax,%rcx,8), %xmm2
movq %xmm0, %rax
movabsq $-0x8000000000000000, %rcx # imm = 0x8000000000000000
xorq %rcx, %rax
movq %rax, %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movq -0x10(%rbp), %rax
movq 0x48(%rax), %rax
movslq -0x20(%rbp), %rcx
movsd %xmm0, (%rax,%rcx,8)
movb -0x11(%rbp), %al
addb $0x1, %al
movb %al, -0x11(%rbp)
jmp 0x183cb
jmp 0x1845e
jmp 0x18460
movl -0x1c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x1c(%rbp)
jmp 0x183a2
movq -0x38(%rbp), %rax
movq -0x10(%rbp), %rdi
movq 0x58(%rax), %rdx
movl $0x1, %esi
callq 0xb570
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rsi
movq (%rdi), %rax
movl $0x1, %edx
callq *0xa0(%rax)
movq -0x28(%rbp), %rdi
callq 0x3320
movq -0x30(%rbp), %rdi
callq 0x3320
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)