// File: /workspace/github_cpp_makefile_star2_O1/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 $0xe8, %rsp
movq %rdi, %rbx
movq 0x40(%rdi), %rsi
subq 0x38(%rdi), %rsi
sarq $0x3, %rsi
leaq -0x90(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x2a7e
movq 0x40(%rbx), %rsi
subq 0x38(%rbx), %rsi
sarq $0x3, %rsi
leaq -0x70(%rbp), %rdi
leaq -0x29(%rbp), %rdx
callq 0x2a7e
leaq 0xd0(%rbx), %rsi
leaq -0xf0(%rbp), %rdi
movq %rsi, -0x78(%rbp)
callq 0x29fe
leaq 0x58(%rbx), %r15
leaq -0x108(%rbp), %rdi
movq %r15, %rsi
callq 0x29fe
leaq -0xf0(%rbp), %rdi
leaq -0x108(%rbp), %r14
movq %r14, %rsi
callq 0x16b0
movsd %xmm0, -0x50(%rbp)
movq (%r14), %rdi
testq %rdi, %rdi
je 0x2336
movq -0xf8(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x2351
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
xorpd %xmm0, %xmm0
movsd -0x50(%rbp), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x23b7
movq 0x2c71(%rip), %rdi      # 0x4fd8
leaq 0xdcd(%rip), %rsi       # 0x313b
movl $0x2f, %edx
callq 0x10e0
movq 0xd0(%rbx), %rax
movq 0xd8(%rbx), %rcx
subq %rax, %rcx
je 0x23b7
sarq $0x3, %rcx
cmpq $0x1, %rcx
adcq $0x0, %rcx
xorl %edx, %edx
movapd 0xcbf(%rip), %xmm0      # 0x3060
movsd (%rax,%rdx,8), %xmm1
xorpd %xmm0, %xmm1
movlpd %xmm1, (%rax,%rdx,8)
incq %rdx
cmpq %rdx, %rcx
jne 0x23a1
leaq -0xd8(%rbp), %rdi
movq -0x78(%rbp), %rsi
callq 0x29fe
leaq -0xd8(%rbp), %rdi
callq 0x1724
movsd %xmm0, -0x58(%rbp)
movq %r15, -0x98(%rbp)
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x23fa
movq -0xc8(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
leaq 0x38(%rbx), %r12
movsd 0x18(%rbx), %xmm2
movapd %xmm2, %xmm0
movsd -0x58(%rbp), %xmm1
divsd %xmm1, %xmm0
cmpltsd %xmm1, %xmm2
andpd %xmm2, %xmm0
movsd 0xc4f(%rip), %xmm1      # 0x3070
andnpd %xmm1, %xmm2
orpd %xmm0, %xmm2
movapd %xmm2, -0x50(%rbp)
xorl %r15d, %r15d
movq 0x2ba0(%rip), %r13      # 0x4fd8
movq -0x90(%rbp), %rdi
movq -0x88(%rbp), %rax
movq %rax, %rdx
subq %rdi, %rdx
sarq $0x3, %rdx
cmpq %rdi, %rax
movapd -0x50(%rbp), %xmm1
je 0x2491
movq (%r12), %rax
movq -0x78(%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 0x2473
incl 0x34(%rbx)
movq -0x70(%rbp), %rsi
callq *(%rbx)
movsd %xmm0, -0xa0(%rbp)
subsd 0x50(%rbx), %xmm0
movsd 0x20(%rbx), %xmm1
movsd %xmm0, -0x38(%rbp)
movsd %xmm1, -0xa8(%rbp)
ucomisd %xmm0, %xmm1
ja 0x255a
movapd -0x50(%rbp), %xmm0
divsd 0xba8(%rip), %xmm0      # 0x3078
movapd %xmm0, -0x50(%rbp)
movl $0x14, %edx
movq %r13, %rdi
leaq 0xc87(%rip), %rsi       # 0x316b
callq 0x10e0
movq %r13, %rdi
movsd -0x38(%rbp), %xmm0
callq 0x1110
movq %rax, %r14
movl $0x17, %edx
movq %rax, %rdi
leaq 0xc78(%rip), %rsi       # 0x3180
callq 0x10e0
movsd -0x58(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
movq %r14, %rdi
callq 0x1110
movq %rax, %r14
movl $0x4, %edx
movq %rax, %rdi
leaq 0xc67(%rip), %rsi       # 0x3198
callq 0x10e0
movsd 0xc0(%rbx), %xmm0
movq %r14, %rdi
callq 0x1110
movl $0x1, %edx
movq %rax, %rdi
leaq 0xbc7(%rip), %rsi       # 0x311c
callq 0x10e0
movsd -0xa8(%rbp), %xmm0
ucomisd -0x38(%rbp), %xmm0
ja 0x257c
incl %r15d
cmpl $0xa, %r15d
jne 0x2438
movl $0xa, %r15d
cmpl $0xa, %r15d
jb 0x259a
movq 0x2a4f(%rip), %rdi      # 0x4fd8
leaq 0xc0d(%rip), %rsi       # 0x319d
movl $0x34, %edx
callq 0x10e0
leaq -0x90(%rbp), %rsi
movq %r12, %rdi
callq 0x2bb4
leaq -0x70(%rbp), %rsi
movq -0x98(%rbp), %rdi
callq 0x2bb4
movsd -0xa0(%rbp), %xmm0
movsd %xmm0, 0x50(%rbx)
leaq -0xc0(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x29fe
leaq -0xc0(%rbp), %rdi
callq 0x1724
movapd %xmm0, %xmm2
movq -0x68(%rbp), %rax
subq -0x70(%rbp), %rax
sarq $0x3, %rax
movq %rax, %xmm1
punpckldq 0xa41(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0xa49(%rip), %xmm1      # 0x3050
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jb 0x2623
sqrtsd %xmm0, %xmm0
jmp 0x2632
movsd %xmm2, -0x38(%rbp)
callq 0x10a0
movsd -0x38(%rbp), %xmm2
divsd %xmm0, %xmm2
movsd %xmm2, 0x70(%rbx)
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x2656
movq -0xb0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x266b
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x2683
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movsd -0x58(%rbp), %xmm0
mulsd -0x50(%rbp), %xmm0
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq -0xc0(%rbp), %rdi
testq %rdi, %rdi
je 0x26ff
movq -0xb0(%rbp), %rsi
jmp 0x26e7
movq %rax, %rbx
movq -0xd8(%rbp), %rdi
testq %rdi, %rdi
je 0x26ff
movq -0xc8(%rbp), %rsi
jmp 0x26e7
jmp 0x26fc
movq %rax, %rbx
movq -0xf0(%rbp), %rdi
testq %rdi, %rdi
je 0x26ff
movq -0xe0(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
jmp 0x26ff
movq %rax, %rbx
jmp 0x2714
jmp 0x26fc
jmp 0x26fc
jmp 0x26fc
movq %rax, %rbx
movq -0x70(%rbp), %rdi
testq %rdi, %rdi
je 0x2714
movq -0x60(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq -0x90(%rbp), %rdi
testq %rdi, %rdi
je 0x272c
movq -0x80(%rbp), %rsi
subq %rdi, %rsi
callq 0x10d0
movq %rbx, %rdi
callq 0x1160