// File: /workspace/github_cpp_makefile_star2_O2/js850[P]lbfgs_cpp/lbfgs.cpp
// Function: LBFGS_ns::LBFGS::backtracking_linesearch()
double LBFGS::backtracking_linesearch()
{
  vector<double> xnew(x_.size());
  vector<double> gnew(x_.size());
  double fnew;

  // if the step is pointing uphill, invert it
  if (vecdot(step_, g_) > 0.){
    cout << "warning: step direction was uphill.  inverting\n";
    for (size_t j2 = 0; j2 < step_.size(); ++j2){
      step_[j2] *= -1;
    }
  }

  double factor = 1.;
  double stepsize = vecnorm(step_);

  // make sure the step is no larger than maxstep_
  if (factor * stepsize > maxstep_){
    factor = maxstep_ / stepsize;
  }

  int nred;
  int nred_max = 10;
  for (nred = 0; nred < nred_max; ++nred){
    for (size_t j2 = 0; j2 < xnew.size(); ++j2){
      xnew[j2] = x_[j2] + factor * step_[j2];
    }
    compute_func_gradient(xnew, fnew, gnew);

    double df = fnew - f_;
    if (df < max_f_rise_){
      break;
    } else {
      factor /= 10.;
      cout 
        << "function increased: " << df 
        << " reducing step size to " << factor * stepsize 
        << " H0 " << H0_ << "\n";
    }
  }

  if (nred >= nred_max){
    // possibly raise an error here
    cout << "warning: the line search backtracked too many times\n";
  }

  x_ = xnew;
  g_ = gnew;
  f_ = fnew;
  rms_ = vecnorm(gnew) / sqrt(gnew.size());
  return stepsize * factor;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rsi
subq 0x38(%rdi), %rsi
sarq $0x3, %rsi
leaq -0x98(%rbp), %rdi
leaq -0x68(%rbp), %rdx
callq 0x151e
movq 0x40(%rbx), %rsi
subq 0x38(%rbx), %rsi
sarq $0x3, %rsi
leaq -0x68(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x151e
leaq 0xd0(%rbx), %r15
leaq -0xe0(%rbp), %rdi
movq %r15, %rsi
callq 0x269c
leaq 0x58(%rbx), %r13
leaq -0xf8(%rbp), %rdi
movq %r13, %rsi
callq 0x269c
leaq -0xe0(%rbp), %r14
leaq -0xf8(%rbp), %r12
movq %r14, %rdi
movq %r12, %rsi
callq 0x17a0
movsd %xmm0, -0x50(%rbp)
movq %r12, %rdi
callq 0x1666
movq %r14, %rdi
callq 0x1666
xorpd %xmm0, %xmm0
movsd -0x50(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x21bc
movq 0x2e5f(%rip), %rdi      # 0x4fd8
leaq 0xfeb(%rip), %rsi       # 0x316b
callq 0x10b0
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
sarq $0x3, %rcx
xorl %edx, %edx
movapd 0xeec(%rip), %xmm0      # 0x3090
cmpq %rdx, %rcx
je 0x21bc
movsd (%rax,%rdx,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, (%rax,%rdx,8)
incq %rdx
jmp 0x21a4
leaq -0xc8(%rbp), %rdi
movq %r15, %rsi
callq 0x269c
movq %r13, -0x70(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x17fe
movsd %xmm0, -0x38(%rbp)
leaq 0x38(%rbx), %r12
leaq -0xc8(%rbp), %rdi
callq 0x1666
movsd 0x18(%rbx), %xmm2
movapd %xmm2, %xmm0
movsd -0x38(%rbp), %xmm1
divsd %xmm1, %xmm0
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0xe8d(%rip), %xmm1      # 0x30a0
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movapd %xmm2, -0x50(%rbp)
xorl %r14d, %r14d
leaq 0xf22(%rip), %r13       # 0x314c
cmpl $0xa, %r14d
je 0x2320
movq -0x98(%rbp), %rdi
movq -0x90(%rbp), %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
movq (%r12), %rax
movq (%r15), %rcx
xorl %esi, %esi
cmpq %rsi, %rdx
je 0x2270
movsd (%rcx,%rsi,8), %xmm0
mulsd -0x50(%rbp), %xmm0
addsd (%rax,%rsi,8), %xmm0
movsd %xmm0, (%rdi,%rsi,8)
incq %rsi
jmp 0x2252
incl 0x34(%rbx)
movq -0x68(%rbp), %rsi
callq *(%rbx)
movsd %xmm0, -0x78(%rbp)
movapd %xmm0, %xmm1
subsd 0x50(%rbx), %xmm1
movsd 0x20(%rbx), %xmm0
ucomisd %xmm1, %xmm0
ja 0x2333
movsd %xmm1, -0x80(%rbp)
movapd -0x50(%rbp), %xmm0
divsd 0xe00(%rip), %xmm0      # 0x30a8
movapd %xmm0, -0x50(%rbp)
movq 0x2d24(%rip), %rdi      # 0x4fd8
leaq 0xee0(%rip), %rsi       # 0x319b
callq 0x10b0
movq %rax, %rdi
movsd -0x80(%rbp), %xmm0
callq 0x1100
movq %rax, %rdi
leaq 0xed9(%rip), %rsi       # 0x31b0
callq 0x10b0
movsd -0x38(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movq %rax, %rdi
callq 0x1100
movq %rax, %rdi
leaq 0xed0(%rip), %rsi       # 0x31c8
callq 0x10b0
movsd 0xc0(%rbx), %xmm0
movq %rax, %rdi
callq 0x1100
movq %rax, %rdi
movq %r13, %rsi
callq 0x10b0
incl %r14d
jmp 0x222a
movq 0x2cb1(%rip), %rdi      # 0x4fd8
leaq 0xe9f(%rip), %rsi       # 0x31cd
callq 0x10b0
leaq -0x98(%rbp), %rsi
movq %r12, %rdi
callq 0x2754
leaq -0x68(%rbp), %rsi
movq -0x70(%rbp), %rdi
callq 0x2754
movsd -0x78(%rbp), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq -0xb0(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x269c
leaq -0xb0(%rbp), %rdi
callq 0x17fe
leaq -0x68(%rbp), %r14
movq 0x8(%r14), %rax
subq (%r14), %rax
sarq $0x3, %rax
movq %rax, %xmm1
punpckldq 0xcdf(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xce7(%rip), %xmm1      # 0x3080
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
sqrtsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rbx)
leaq -0xb0(%rbp), %rdi
callq 0x1666
movsd -0x38(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x38(%rbp)
movq %r14, %rdi
callq 0x1666
leaq -0x98(%rbp), %rdi
callq 0x1666
movsd -0x38(%rbp), %xmm0
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq -0xb0(%rbp), %rdi
jmp 0x241c
movq %rax, %rbx
leaq -0xc8(%rbp), %rdi
jmp 0x241c
jmp 0x242e
movq %rax, %rbx
leaq -0xe0(%rbp), %rdi
callq 0x1666
jmp 0x2431
movq %rax, %rbx
jmp 0x243a
jmp 0x242e
jmp 0x242e
jmp 0x242e
movq %rax, %rbx
leaq -0x68(%rbp), %rdi
callq 0x1666
leaq -0x98(%rbp), %rdi
callq 0x1666
movq %rbx, %rdi
callq 0x1150