// File: /workspace/github_cpp_makefile_star2_O3/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 -0x80(%rbp), %rdi
leaq -0x60(%rbp), %rdx
callq 0x2ab8
movq 0x40(%rbx), %rsi
subq 0x38(%rbx), %rsi
sarq $0x3, %rsi
leaq -0x60(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2ab8
leaq 0xd0(%rbx), %rsi
leaq -0xe0(%rbp), %rdi
movq %rsi, -0x68(%rbp)
callq 0x2a38
leaq 0x58(%rbx), %r15
leaq -0xf8(%rbp), %rdi
movq %r15, %rsi
callq 0x2a38
leaq -0xe0(%rbp), %rdi
leaq -0xf8(%rbp), %r14
movq %r14, %rsi
callq 0x16b0
movsd %xmm0, -0x40(%rbp)
movq (%r14), %rdi
testq %rdi, %rdi
je 0x23a5
movq -0xe8(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x23c0
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
xorpd %xmm0, %xmm0
movsd -0x40(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x2426
movq 0x2c02(%rip), %rdi      # 0x4fd8
leaq 0xd6e(%rip), %rsi       # 0x314b
movl $0x2f, %edx
callq 0x10e0
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
je 0x2426
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movapd 0xc60(%rip), %xmm0      # 0x3070
movsd (%rax,%rdx,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x2410
leaq -0xc8(%rbp), %rdi
movq -0x68(%rbp), %rsi
callq 0x2a38
leaq -0xc8(%rbp), %rdi
callq 0x1724
movsd %xmm0, -0x48(%rbp)
movq %r15, -0x88(%rbp)
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x2469
movq -0xb8(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
leaq 0x38(%rbx), %r12
movsd 0x18(%rbx), %xmm2
movapd %xmm2, %xmm0
movsd -0x48(%rbp), %xmm1
divsd %xmm1, %xmm0
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0xbf0(%rip), %xmm1      # 0x3080
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movapd %xmm2, -0x40(%rbp)
xorl %r15d, %r15d
movq 0x2b31(%rip), %r13      # 0x4fd8
movq -0x80(%rbp), %rdi
movq -0x78(%rbp), %rax
movq %rax, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rdi, %rax
movapd -0x40(%rbp), %xmm1
je 0x24fa
movq (%r12), %rax
movq -0x68(%rbp), %rcx
movq (%rcx), %rcx
cmpq $0x1, %rdx
movq %rdx, %rsi
adcq $0x0, %rsi
xorl %r8d, %r8d
movsd (%rcx,%r8,8), %xmm0
mulsd %xmm1, %xmm0
addsd (%rax,%r8,8), %xmm0
movsd %xmm0, (%rdi,%r8,8)
incq %r8
cmpq %r8, %rsi
jne 0x24dc
incl 0x34(%rbx)
movq -0x60(%rbp), %rsi
callq *(%rbx)
movsd %xmm0, -0x90(%rbp)
movapd %xmm0, %xmm1
subsd 0x50(%rbx), %xmm1
movsd 0x20(%rbx), %xmm0
ucomisd %xmm1, %xmm0
ja 0x25ea
movsd %xmm1, -0x98(%rbp)
movapd -0x40(%rbp), %xmm0
divsd 0xb50(%rip), %xmm0      # 0x3088
movapd %xmm0, -0x40(%rbp)
movl $0x14, %edx
movq %r13, %rdi
leaq 0xc2f(%rip), %rsi       # 0x317b
callq 0x10e0
movq %r13, %rdi
movsd -0x98(%rbp), %xmm0
callq 0x1110
movq %rax, %r14
movl $0x17, %edx
movq %rax, %rdi
leaq 0xc1d(%rip), %rsi       # 0x3190
callq 0x10e0
movsd -0x48(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
movq %r14, %rdi
callq 0x1110
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0xc0c(%rip), %rsi       # 0x31a8
callq 0x10e0
movsd 0xc0(%rbx), %xmm0
movq %r14, %rdi
callq 0x1110
movl $0x1, %edx
movq %rax, %rdi
leaq 0xb6c(%rip), %rsi       # 0x312c
callq 0x10e0
incl %r15d
cmpl $0xa, %r15d
jne 0x24a7
movq 0x29ff(%rip), %rdi      # 0x4fd8
leaq 0xbcd(%rip), %rsi       # 0x31ad
movl $0x34, %edx
callq 0x10e0
leaq -0x80(%rbp), %rsi
movq %r12, %rdi
callq 0x2bf2
leaq -0x60(%rbp), %rsi
movq -0x88(%rbp), %rdi
callq 0x2bf2
movsd -0x90(%rbp), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq -0xb0(%rbp), %rdi
leaq -0x60(%rbp), %rsi
callq 0x2a38
leaq -0xb0(%rbp), %rdi
callq 0x1724
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rax
subq %rdi, %rax
sarq $0x3, %rax
movq %rax, %xmm1
punpckldq 0x9f5(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x9fd(%rip), %xmm1      # 0x3050
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
xorps %xmm1, %xmm1
sqrtsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x70(%rbx)
movq -0xb0(%rbp), %rax
testq %rax, %rax
je 0x2691
movq -0xa0(%rbp), %rsi
subq %rax, %rsi
movq %rax, %rdi
callq 0x10d0
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x26a2
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x26b7
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movsd -0x48(%rbp), %xmm0
mulsd -0x40(%rbp), %xmm0
addq $0xd8, %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 0x2733
movq -0xa0(%rbp), %rsi
jmp 0x271b
movq %rax, %rbx
movq -0xc8(%rbp), %rdi
testq %rdi, %rdi
je 0x2733
movq -0xb8(%rbp), %rsi
jmp 0x271b
jmp 0x2730
movq %rax, %rbx
movq -0xe0(%rbp), %rdi
testq %rdi, %rdi
je 0x2733
movq -0xd0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x2733
movq %rax, %rbx
jmp 0x2748
jmp 0x2730
jmp 0x2730
jmp 0x2730
movq %rax, %rbx
movq -0x60(%rbp), %rdi
testq %rdi, %rdi
je 0x2748
movq -0x50(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x80(%rbp), %rdi
testq %rdi, %rdi
je 0x275d
movq -0x70(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1160
nop