// File: /workspace/github_cpp_makefile_star2_O1/js850[P]lbfgs_cpp/lbfgs.cpp
// Function: LBFGS_ns::LBFGS::compute_lbfgs_step()
void LBFGS::compute_lbfgs_step()
{
  if (k_ == 0){ 
    double gnorm = vecnorm(g_);
    if (gnorm > 1.) gnorm = 1. / gnorm;
    for (size_t j2 = 0; j2 < x_.size(); ++j2){
      step_[j2] = - gnorm * H0_ * g_[j2];
    }
    return;
  } 

  step_ = g_;

  int jmin = std::max(0, k_ - M_);
  int jmax = k_;
  int i;
  double beta;
  vector<double> alpha(M_);

  // loop backwards through the memory
  for (int j = jmax - 1; j >= jmin; --j){
    i = j % M_;
    //cout << "    i " << i << " j " << j << "\n";
    alpha[i] = rho_[i] * vecdot(s_[i], step_);
    for (size_t j2 = 0; j2 < step_.size(); ++j2){
      step_[j2] -= alpha[i] * y_[i][j2];
    }
  }

  // scale the step size by H0
  for (size_t j2 = 0; j2 < step_.size(); ++j2){
    step_[j2] *= H0_;
  }

  // loop forwards through the memory
  for (int j = jmin; j < jmax; ++j){
    i = j % M_;
    //cout << "    i " << i << " j " << j << "\n";
    beta = rho_[i] * vecdot(y_[i], step_);
    for (size_t j2 = 0; j2 < step_.size(); ++j2){
      step_[j2] += s_[i][j2] * (alpha[i] - beta);
    }
  }

  // invert the step to point downhill
  for (size_t j2 = 0; j2 < x_.size(); ++j2){
    step_[j2] *= -1;
  }

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xb8, %rsp
movq %rdi, %rbx
leaq 0x58(%rdi), %rsi
cmpl $0x0, 0xc8(%rdi)
je 0x2166
leaq 0xd0(%rbx), %rdi
movq %rdi, -0x50(%rbp)
callq 0x2bb4
movl 0xc8(%rbx), %r14d
movslq 0x8(%rbx), %rsi
movl %r14d, %eax
subl %esi, %eax
xorl %r15d, %r15d
testl %eax, %eax
cmovgl %eax, %r15d
leaq -0x68(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
callq 0x2a7e
movl %r14d, -0x2c(%rbp)
cmpl %r15d, %r14d
jle 0x1fcf
movl -0x2c(%rbp), %r14d
movl %r15d, -0x38(%rbp)
decl %r14d
movl %r14d, %eax
cltd
idivl 0x8(%rbx)
movslq %edx, %r12
movq 0xa8(%rbx), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r12,%r12,2), %r13
leaq (,%r13,8), %rsi
addq 0x78(%rbx), %rsi
leaq -0x98(%rbp), %rdi
callq 0x29fe
leaq -0xe0(%rbp), %r15
movq %r15, %rdi
movq -0x50(%rbp), %rsi
callq 0x29fe
leaq -0x98(%rbp), %rdi
movq %r15, %rsi
callq 0x16b0
movsd -0x40(%rbp), %xmm1
mulsd %xmm0, %xmm1
movq -0x68(%rbp), %rax
movsd %xmm1, (%rax,%r12,8)
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x1f56
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x1f71
movq -0x88(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
je 0x1fc2
sarq $0x3, %rcx
movq -0x68(%rbp), %rdx
movq 0x90(%rbx), %rsi
movq (%rsi,%r13,8), %rsi
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edi, %edi
movsd (%rdx,%r12,8), %xmm0
movsd (%rax,%rdi,8), %xmm1
mulsd (%rsi,%rdi,8), %xmm0
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x1fa1
movl -0x38(%rbp), %r15d
cmpl %r15d, %r14d
jg 0x1ecb
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
je 0x200a
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movsd 0xc0(%rbx), %xmm0
mulsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x1ff0
cmpl -0x2c(%rbp), %r15d
jge 0x210b
movl %r15d, %r13d
movl %r15d, %eax
cltd
idivl 0x8(%rbx)
movl %edx, %r14d
movq 0xa8(%rbx), %rax
movsd (%rax,%r14,8), %xmm0
movsd %xmm0, -0x40(%rbp)
leaq (%r14,%r14,2), %r12
leaq (,%r12,8), %rsi
addq 0x90(%rbx), %rsi
leaq -0x80(%rbp), %rdi
callq 0x29fe
leaq -0xc8(%rbp), %r15
movq %r15, %rdi
movq -0x50(%rbp), %rsi
callq 0x29fe
leaq -0x80(%rbp), %rdi
movq %r15, %rsi
callq 0x16b0
movsd %xmm0, -0x38(%rbp)
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x208e
movq -0xb8(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x20a3
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
movsd -0x40(%rbp), %xmm1
je 0x20fb
mulsd -0x38(%rbp), %xmm1
sarq $0x3, %rcx
movq 0x78(%rbx), %rdx
movq (%rdx,%r12,8), %rdx
movq -0x68(%rbp), %rsi
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edi, %edi
movsd (%rsi,%r14,8), %xmm0
subsd %xmm1, %xmm0
mulsd (%rdx,%rdi,8), %xmm0
addsd (%rax,%rdi,8), %xmm0
movsd %xmm0, (%rax,%rdi,8)
incq %rdi
cmpq %rdi, %rcx
jne 0x20da
movl %r13d, %r15d
incl %r15d
cmpl -0x2c(%rbp), %r15d
jne 0x2014
movq 0x40(%rbx), %rax
subq 0x38(%rbx), %rax
je 0x2148
sarq $0x3, %rax
movq -0x50(%rbp), %rcx
movq (%rcx), %rcx
cmpq $0x1, %rax
adcq $0x0, %rax
xorl %edx, %edx
movapd 0xf2e(%rip), %xmm0      # 0x3060
movsd (%rcx,%rdx,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x2132
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x220b
movq -0x58(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x220b
leaq -0xb0(%rbp), %r14
movq %r14, %rdi
callq 0x29fe
movq %r14, %rdi
callq 0x1724
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x21a1
movq -0xa0(%rbp), %rsi
subq %rdi, %rsi
movaps %xmm0, -0x50(%rbp)
callq 0x10d0
movapd -0x50(%rbp), %xmm0
movq 0x40(%rbx), %rax
subq 0x38(%rbx), %rax
je 0x220b
sarq $0x3, %rax
movsd 0xeb9(%rip), %xmm2      # 0x3070
movapd %xmm2, %xmm1
divsd %xmm0, %xmm1
cmpltsd %xmm0, %xmm2
andpd %xmm2, %xmm1
andnpd %xmm0, %xmm2
orpd %xmm1, %xmm2
xorpd 0xe88(%rip), %xmm2      # 0x3060
movq 0x58(%rbx), %rcx
movq 0xd0(%rbx), %rdx
cmpq $0x1, %rax
adcq $0x0, %rax
xorl %esi, %esi
movsd 0xc0(%rbx), %xmm1
mulsd %xmm2, %xmm1
mulsd (%rcx,%rsi,8), %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
cmpq %rsi, %rax
jne 0x21ed
addq $0xb8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xb0(%rbp), %rdi
testq %rdi, %rdi
je 0x2286
movq -0xa0(%rbp), %rsi
jmp 0x227e
movq %rax, %rbx
jmp 0x2286
jmp 0x224e
movq %rax, %rbx
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x2271
movq -0x70(%rbp), %rsi
jmp 0x2269
movq %rax, %rbx
jmp 0x2271
movq %rax, %rbx
movq -0x98(%rbp), %rdi
testq %rdi, %rdi
je 0x2271
movq -0x88(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x2286
movq -0x58(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1160