// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/geno/lbfgsb.cpp
// Function: LBFGSB::lineSearchMT(Eigen::Matrix<double, -1, 1, 0, -1, 1> const&, unsigned long)
Scalar LBFGSB::lineSearchMT(const Vector& deltaX, size_t iter) {
  Scalar const INF = std::numeric_limits<Scalar>::infinity();
  double stp;
  double a1, a2;
  double big  = 1.0e10;
  double ftol = 1.0e-3,
         gtol = 0.9,
         xtol = 0.1;
  Scalar dnorm = deltaX.norm();
  // Determine the maximum step length.
  Scalar stpmx = big;
  if (_constrained) {
    if (iter == 1) {
      stpmx = 1.0;
    } else {
      for (Index i = 0; i < _x.size(); ++i) {
        a1 = deltaX[i];
	//        if (_nbd[i] != 0) {     
	if (_lb[i] != -INF || _ub[i] != INF) {
	  //      if (a1 < zero && _nbd[i] <= 2) {
	  if (a1 < 0.0 && _lb[i] != -INF) {
	    a2 = _lb(i) - _x(i);
            if (a2 >= 0.0) {
              stpmx = 0.0;
            } else if (a1*stpmx < a2) {
              stpmx = a2/a1;
            }
	    //          } else if (a1 > zero && _nbd[i] >= 2) {
          } else if (a1 > 0.0 && _ub[i] != INF) {
            a2 = _ub(i) - _x(i);
            if (a2 <= 0.0) {
              stpmx = 0.0;
            } else if (a1*stpmx > a2) {
              stpmx = a2/a1;
            }
          }
        }
      }
    }
  }
  if (iter == 1 && !_boxed)
    stp = std::min(1.0/dnorm, stpmx);
  else
    stp = 1.0;
  _gNew = _g;
  _fNew = _f;
  TaskType csave = TaskType::START;
  Scalar gd = _gNew.dot(deltaX);
  if (gd >= 0.0) {
    std::cerr << "ascent direction in projection gd = " << gd << std::endl;
    stp = -1;
    return stp;
    //    std::exit(EXIT_FAILURE);
  }
  int funIter = 0;
  TMPContainer TCON;
  do {
    dcsrch(_fNew, gd, stp, ftol, gtol, xtol, 0.0, stpmx, csave, TCON);
    if (TaskType::ERROR == csave)
      std::exit(EXIT_FAILURE);
    if (csave == TaskType::CONVERGENCE || csave == TaskType::WARNING)
      break;
    _xNew = stp * deltaX + _x;
    _genoNLP.functionValueAndGradient(_xNew.data(), _fNew, _gNew.data());
    ++_funEval;
    gd = _gNew.dot(deltaX);
    ++funIter;
    if (funIter >= 19) {
      stp = -1;  // something went wrong
      break;
    }
  } while(true);
  return stp;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, %rdi
callq 0x13b08
movsd %xmm0, 0x28(%rsp)
cmpb $0x1, 0x258(%r14)
jne 0x1200e
cmpq $0x1, %r15
jne 0x12020
movsd 0x4181c(%rip), %xmm0    # 0x53820
movsd %xmm0, (%rsp)
jmp 0x121b1
movsd 0x41812(%rip), %xmm0    # 0x53828
movsd %xmm0, (%rsp)
jmp 0x121ab
movq %r15, 0x20(%rsp)
leaq 0x10(%r14), %r12
leaq 0x20(%r14), %r13
leaq 0x30(%r14), %rbp
movsd 0x417ef(%rip), %xmm0    # 0x53828
movsd %xmm0, (%rsp)
xorl %r15d, %r15d
cmpq 0x18(%r14), %r15
jge 0x121a6
movq %rbx, %rdi
movq %r15, %rsi
callq 0x13ce6
movsd (%rax), %xmm0
movsd %xmm0, 0x8(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0x13224
movsd 0x3f39d(%rip), %xmm0    # 0x51410
ucomisd (%rax), %xmm0
jb 0x12096
movq %rbp, %rdi
movq %r15, %rsi
callq 0x13224
movsd (%rax), %xmm0
ucomisd 0x3f358(%rip), %xmm0    # 0x513e8
jae 0x12194
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x12116
movq %r13, %rdi
movq %r15, %rsi
callq 0x13224
movsd 0x8(%rsp), %xmm1
movsd 0x3f351(%rip), %xmm0    # 0x51410
ucomisd (%rax), %xmm0
jae 0x12116
movq %r13, %rdi
movq %r15, %rsi
callq 0xd27a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xd27a
movsd 0x10(%rsp), %xmm3
movsd 0x8(%rsp), %xmm2
subsd (%rax), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm0, %xmm3
jae 0x12199
movsd (%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm2, %xmm0
ucomisd %xmm0, %xmm3
jmp 0x12184
ucomisd 0x3f2ea(%rip), %xmm1    # 0x51408
jbe 0x12194
movq %rbp, %rdi
movq %r15, %rsi
callq 0x13224
movsd (%rax), %xmm0
ucomisd 0x3f2b1(%rip), %xmm0    # 0x513e8
jae 0x12194
movq %rbp, %rdi
movq %r15, %rsi
callq 0xd27a
movsd (%rax), %xmm0
movsd %xmm0, 0x10(%rsp)
movq %r12, %rdi
movq %r15, %rsi
callq 0xd27a
movsd 0x10(%rsp), %xmm3
subsd (%rax), %xmm3
xorpd %xmm0, %xmm0
ucomisd %xmm3, %xmm0
movsd 0x8(%rsp), %xmm2
jae 0x12199
movsd (%rsp), %xmm1
movapd %xmm1, %xmm0
mulsd %xmm2, %xmm0
ucomisd %xmm3, %xmm0
movapd %xmm1, %xmm0
jbe 0x12199
divsd %xmm2, %xmm3
movapd %xmm3, %xmm0
jmp 0x12199
movsd (%rsp), %xmm0
incq %r15
movsd %xmm0, (%rsp)
jmp 0x12041
movq 0x20(%rsp), %r15
cmpq $0x1, %r15
jne 0x121bb
cmpb $0x0, 0x259(%r14)
je 0x121c5
movsd 0x4165d(%rip), %xmm0    # 0x53820
jmp 0x121dc
movsd 0x41653(%rip), %xmm1    # 0x53820
divsd 0x28(%rsp), %xmm1
movsd (%rsp), %xmm0
minsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rsp)
leaq 0x40(%r14), %rsi
leaq 0x248(%r14), %r15
movq %r15, %rdi
callq 0xe787
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x230(%r14)
andl $0x0, 0x1c(%rsp)
movq %r15, 0x8(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
callq 0x1325a
movsd %xmm0, 0x38(%rsp)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jae 0x12333
movq %rbx, 0x10(%rsp)
leaq 0x230(%r14), %r12
leaq 0x10(%r14), %rax
movq %rax, 0x28(%rsp)
leaq 0x238(%r14), %rax
movq %rax, 0x20(%rsp)
pushq $0x13
popq %rbx
leaq 0x30(%rsp), %r15
movq 0x10(%rsp), %rbp
xorpd %xmm3, %xmm3
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
movq %r15, %rdx
movsd 0x415be(%rip), %xmm0    # 0x53830
movsd 0x415be(%rip), %xmm1    # 0x53838
movsd 0x415be(%rip), %xmm2    # 0x53840
movsd (%rsp), %xmm4
leaq 0x1c(%rsp), %rcx
leaq 0xb8(%rsp), %r8
callq 0x2c44c
movl 0x1c(%rsp), %eax
cmpl $0x1, %eax
je 0x12382
addl $-0x3, %eax
cmpl $0x2, %eax
jb 0x1236a
leaq 0x40(%rsp), %r13
movq %r13, %rdi
movq %r15, %rsi
movq %rbp, %rdx
callq 0xdbac
movq %r12, %r15
movq %r14, %r12
leaq 0x70(%rsp), %r14
movq %r14, %rdi
movq %r13, %rsi
movq 0x28(%rsp), %rdx
callq 0x13d1c
movq 0x20(%rsp), %rdi
movq %r14, %rsi
movq %r12, %r14
movq %r15, %r12
callq 0x2b61b
movq (%r14), %rdi
movq 0x238(%r14), %rsi
movq 0x248(%r14), %rcx
movq (%rdi), %rax
movq %r15, %rdx
callq *0x48(%rax)
incq 0x50(%r14)
movq 0x8(%rsp), %rdi
movq %rbp, %rsi
leaq 0x30(%rsp), %r15
callq 0x1325a
movsd %xmm0, 0x38(%rsp)
decl %ebx
jne 0x1225b
jmp 0x12360
movq 0x84cb6(%rip), %rdi     # 0x96ff0
leaq 0x417ce(%rip), %rsi     # 0x53b0f
movsd %xmm0, (%rsp)
callq 0x9330
movq %rax, %rdi
movsd (%rsp), %xmm0
callq 0x9540
movq %rax, %rdi
callq 0x9170
movsd 0x3f078(%rip), %xmm0    # 0x513e0
jmp 0x12370
movsd 0x30(%rsp), %xmm0
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rdi
callq 0x93d0