// File: /workspace/github_cpp_makefile_star2_O2/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 $0xc8, %rsp
leaq 0x58(%rdi), %rsi
cmpl $0x0, 0xc8(%rdi)
movq %rdi, -0x40(%rbp)
je 0x1fe5
movq %rdi, %rax
addq $0xd0, %rdi
movq %rdi, -0x58(%rbp)
movq %rax, %rbx
callq 0x2754
movl 0xc8(%rbx), %r14d
movslq 0x8(%rbx), %rsi
movl %r14d, %eax
subl %esi, %eax
xorl %r15d, %r15d
testl %eax, %eax
cmovgl %eax, %r15d
leaq -0x70(%rbp), %rdi
leaq -0x2d(%rbp), %rdx
callq 0x151e
movl %r14d, -0x34(%rbp)
movq -0x40(%rbp), %r8
movl %r15d, -0x2c(%rbp)
cmpl %r15d, %r14d
jle 0x1e77
decl %r14d
movl %r14d, %eax
cltd
idivl 0x8(%r8)
movslq %edx, %r12
movq 0xa8(%r8), %rax
movsd (%rax,%r12,8), %xmm0
movsd %xmm0, -0x50(%rbp)
imulq $0x18, %r12, %r13
movq 0x78(%r8), %rsi
addq %r13, %rsi
leaq -0xa0(%rbp), %rdi
callq 0x269c
leaq -0xe8(%rbp), %rbx
movq %rbx, %rdi
movq -0x58(%rbp), %rsi
callq 0x269c
leaq -0xa0(%rbp), %r15
movq %r15, %rdi
movq %rbx, %rsi
callq 0x17a0
movsd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movq -0x70(%rbp), %rax
movsd %xmm1, (%rax,%r12,8)
movq %rbx, %rdi
callq 0x1666
movq %r15, %rdi
callq 0x1666
movq -0x40(%rbp), %r8
movq 0xd0(%r8), %rax
movq 0xd8(%r8), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
movq -0x70(%rbp), %rdx
addq 0x90(%r8), %r13
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x1e6e
movsd (%rdx,%r12,8), %xmm0
movq (%r13), %rdi
mulsd (%rdi,%rsi,8), %xmm0
movsd (%rax,%rsi,8), %xmm1
subsd %xmm0, %xmm1
movsd %xmm1, (%rax,%rsi,8)
incq %rsi
jmp 0x1e47
movl -0x2c(%rbp), %r15d
jmp 0x1d99
movq 0xd0(%r8), %rax
movq 0xd8(%r8), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
movl -0x34(%rbp), %esi
cmpq %rdx, %rcx
je 0x1f85
movsd 0xc0(%r8), %xmm0
mulsd (%rax,%rdx,8), %xmm0
movsd %xmm0, (%rax,%rdx,8)
incq %rdx
jmp 0x1e91
movl %r15d, -0x2c(%rbp)
movl %r15d, %eax
cltd
idivl 0x8(%r8)
movl %edx, %r14d
movq 0xa8(%r8), %rax
movsd (%rax,%r14,8), %xmm0
movsd %xmm0, -0x50(%rbp)
imulq $0x18, %r14, %r12
movq 0x90(%r8), %rsi
addq %r12, %rsi
leaq -0x88(%rbp), %rdi
callq 0x269c
movq %r13, %rdi
movq -0x58(%rbp), %rsi
callq 0x269c
movq %r13, %r15
leaq -0x88(%rbp), %r13
movq %r13, %rdi
movq %r15, %rsi
callq 0x17a0
movsd -0x50(%rbp), %xmm1
mulsd %xmm0, %xmm1
movsd %xmm1, -0x50(%rbp)
movq %r15, %rdi
callq 0x1666
movq %r13, %rdi
callq 0x1666
movsd -0x50(%rbp), %xmm1
movq -0x40(%rbp), %r8
movq 0xd0(%r8), %rax
movq 0xd8(%r8), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
addq 0x78(%r8), %r12
movq -0x70(%rbp), %rdx
xorl %esi, %esi
cmpq %rsi, %rcx
je 0x1f7b
movq (%r12), %rdi
movsd (%rdx,%r14,8), %xmm0
subsd %xmm1, %xmm0
mulsd (%rdi,%rsi,8), %xmm0
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rax,%rsi,8)
incq %rsi
jmp 0x1f54
movl -0x2c(%rbp), %r15d
incl %r15d
movl -0x34(%rbp), %esi
leaq -0xd0(%rbp), %r13
cmpl %esi, %r15d
jl 0x1eb2
movq 0x40(%r8), %rax
subq 0x38(%r8), %rax
movq 0xd0(%r8), %rcx
sarq $0x3, %rax
xorl %edx, %edx
movapd 0x10de(%rip), %xmm0     # 0x3090
cmpq %rdx, %rax
je 0x1fca
movsd (%rcx,%rdx,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, (%rcx,%rdx,8)
incq %rdx
jmp 0x1fb2
leaq -0x70(%rbp), %rdi
callq 0x1666
addq $0xc8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq -0xb8(%rbp), %r14
movq %r14, %rdi
callq 0x269c
movq %r14, %rdi
callq 0x17fe
movapd %xmm0, -0x50(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x1666
movsd 0x108b(%rip), %xmm0     # 0x30a0
movapd %xmm0, %xmm1
movapd -0x50(%rbp), %xmm2
divsd %xmm2, %xmm1
cmpltsd %xmm2, %xmm0
andpd %xmm0, %xmm1
andnpd %xmm2, %xmm0
orpd %xmm1, %xmm0
movq -0x40(%rbp), %rdi
movq 0x40(%rdi), %rax
movq 0x58(%rdi), %rcx
subq 0x38(%rdi), %rax
sarq $0x3, %rax
xorpd 0x1041(%rip), %xmm0     # 0x3090
movq 0xd0(%rdi), %rdx
xorl %esi, %esi
cmpq %rsi, %rax
je 0x1fd3
movsd 0xc0(%rdi), %xmm1
mulsd %xmm0, %xmm1
mulsd (%rcx,%rsi,8), %xmm1
movsd %xmm1, (%rdx,%rsi,8)
incq %rsi
jmp 0x2058
movq %rax, %rbx
leaq -0xb8(%rbp), %rdi
jmp 0x20b3
movq %rax, %rbx
jmp 0x20b8
movq %rax, %rbx
leaq -0x88(%rbp), %rdi
jmp 0x20a5
jmp 0x20ac
movq %rax, %rbx
leaq -0xa0(%rbp), %rdi
callq 0x1666
jmp 0x20af
movq %rax, %rbx
leaq -0x70(%rbp), %rdi
callq 0x1666
movq %rbx, %rdi
callq 0x1150