// File: /workspace/github_cpp_makefile_star2_O3/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 $0x118, %rsp            # imm = 0x118
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r14
movq %rsi, 0x60(%rsp)
cmpq $0x0, 0x8(%rsi)
je 0x16efc
jle 0x174e0
movq (%rbx), %rax
leaq 0xa8(%rsp), %rdi
movq %rax, 0x8(%rdi)
leaq 0x60(%rsp), %rax
movq %rax, 0x18(%rdi)
leaq 0x48(%rsp), %rsi
callq 0xfe82
jmp 0x16f00
xorpd %xmm0, %xmm0
cmpb $0x1, 0x258(%r14)
jne 0x16f1d
cmpq $0x1, %r15
jne 0x16f2a
movsd 0x454e0(%rip), %xmm7    # 0x5c3f8
jmp 0x1703d
movsd 0x46903(%rip), %xmm7    # 0x5d828
jmp 0x17037
movq 0x18(%r14), %rax
testq %rax, %rax
jle 0x17061
movq (%rbx), %rcx
movq 0x8(%rbx), %rdx
movq 0x28(%r14), %rsi
movq 0x10(%r14), %rdi
movq 0x20(%r14), %r8
movq 0x38(%r14), %r9
xorl %r10d, %r10d
testq %rdx, %rdx
cmovleq %r10, %rdx
movq 0x30(%r14), %r11
testq %rsi, %rsi
cmovleq %r10, %rsi
movsd 0x468bd(%rip), %xmm4    # 0x5d828
movsd 0x454b5(%rip), %xmm1    # 0x5c428
xorpd %xmm2, %xmm2
movsd 0x45481(%rip), %xmm3    # 0x5c400
cmpq %r10, %rdx
je 0x17445
cmpq %r10, %rsi
je 0x173fd
movsd (%rcx,%r10,8), %xmm5
movsd (%r8,%r10,8), %xmm6
ucomisd %xmm6, %xmm1
jae 0x16fc7
ucomisd %xmm5, %xmm2
jbe 0x16fdc
subsd (%rdi,%r10,8), %xmm6
xorpd %xmm7, %xmm7
ucomisd %xmm7, %xmm6
jae 0x17027
movapd %xmm4, %xmm7
mulsd %xmm5, %xmm7
ucomisd %xmm7, %xmm6
jmp 0x17013
cmpq %r10, %r9
jle 0x173fd
movsd (%r11,%r10,8), %xmm6
ucomisd %xmm3, %xmm6
jae 0x17023
ucomisd %xmm2, %xmm5
jbe 0x17023
cmpq %r10, %r9
jle 0x173fd
movsd (%r11,%r10,8), %xmm6
ucomisd %xmm3, %xmm6
jae 0x17023
subsd (%rdi,%r10,8), %xmm6
xorpd %xmm7, %xmm7
ucomisd %xmm6, %xmm7
jae 0x17027
movapd %xmm4, %xmm7
mulsd %xmm5, %xmm7
ucomisd %xmm6, %xmm7
movapd %xmm4, %xmm7
jbe 0x17027
divsd %xmm5, %xmm6
movapd %xmm6, %xmm7
jmp 0x17027
movapd %xmm4, %xmm7
incq %r10
movapd %xmm7, %xmm4
cmpq %r10, %rax
jne 0x16f7f
cmpq $0x1, %r15
jne 0x17069
cmpb $0x0, 0x259(%r14)
jne 0x17069
sqrtsd %xmm0, %xmm0
movsd 0x453a5(%rip), %xmm1    # 0x5c3f8
divsd %xmm0, %xmm1
movapd %xmm7, %xmm0
minsd %xmm1, %xmm0
jmp 0x17071
movsd 0x467bf(%rip), %xmm7    # 0x5d828
movsd 0x45387(%rip), %xmm0    # 0x5c3f8
movsd %xmm7, 0x20(%rsp)
movsd %xmm0, 0x28(%rsp)
leaq 0x248(%r14), %r13
movq 0x40(%r14), %r15
movq 0x48(%r14), %r12
cmpq %r12, 0x250(%r14)
je 0x170be
testq %r12, %r12
js 0x174f7
movl $0x1, %ecx
movq %r13, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xff4c
cmpq %r12, 0x250(%r14)
jne 0x17516
movq (%r13), %rax
movq %r12, %rcx
shrq $0x3f, %rcx
addq %r12, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r12
jl 0x170ec
xorl %edx, %edx
movapd (%r15,%rdx,8), %xmm0
movapd %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x170d8
cmpq %r12, %rcx
jge 0x17104
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x170f1
movsd 0x8(%r14), %xmm0
movsd %xmm0, 0x230(%r14)
movl $0x0, 0x1c(%rsp)
movq 0x250(%r14), %rax
cmpq 0x8(%rbx), %rax
jne 0x1741c
movq %rbx, %r15
leaq 0x230(%r14), %r12
movq %r13, 0x60(%rsp)
movq %rbx, 0x68(%rsp)
testq %rax, %rax
je 0x1737e
jle 0x174a2
movq (%r13), %rax
leaq 0xa8(%rsp), %rdi
movq %rax, 0x8(%rdi)
movq (%r15), %rax
movq %rax, 0x18(%rdi)
leaq 0x60(%rsp), %rax
movq %rax, 0x28(%rdi)
leaq 0x48(%rsp), %rsi
callq 0x193da
movsd %xmm0, 0x38(%rsp)
xorpd %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jae 0x17382
movq %r14, 0x10(%rsp)
leaq 0x238(%r14), %rax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
movsd 0x20(%rsp), %xmm4
movq %r15, 0x40(%rsp)
xorpd %xmm3, %xmm3
movq %r12, %rdi
leaq 0x38(%rsp), %rsi
leaq 0x28(%rsp), %rdx
movsd 0x4666c(%rip), %xmm0    # 0x5d830
movsd 0x4666c(%rip), %xmm1    # 0x5d838
movsd 0x4666c(%rip), %xmm2    # 0x5d840
leaq 0x1c(%rsp), %rcx
leaq 0xa8(%rsp), %r8
callq 0x2d5ac
movl 0x1c(%rsp), %eax
cmpl $0x1, %eax
je 0x1743b
addl $-0x3, %eax
cmpl $0x2, %eax
jb 0x173f5
movq %r13, %rbx
movq 0x8(%r15), %r13
testq %r13, %r13
js 0x17483
movq 0x10(%rsp), %rax
cmpq 0x18(%rax), %r13
jne 0x17464
movq %r12, %r14
movsd 0x28(%rsp), %xmm2
movq (%r15), %r15
movq 0x10(%rax), %r12
cmpq %r13, 0x240(%rax)
je 0x17270
movl $0x1, %ecx
movq 0x30(%rsp), %rdi
movq %r13, %rsi
movq %r13, %rdx
movapd %xmm2, 0x90(%rsp)
callq 0xff4c
movapd 0x90(%rsp), %xmm2
movq 0x10(%rsp), %rax
cmpq %r13, 0x240(%rax)
jne 0x174c1
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %r13, %rcx
movabsq $0x7ffffffffffffffe, %rdx # imm = 0x7FFFFFFFFFFFFFFE
andq %rdx, %rcx
cmpq $0x2, %r13
jb 0x172b6
movapd %xmm2, %xmm0
unpcklpd %xmm2, %xmm0            # xmm0 = xmm0[0],xmm2[0]
xorl %edx, %edx
movapd (%r15,%rdx,8), %xmm1
mulpd %xmm0, %xmm1
addpd (%r12,%rdx,8), %xmm1
movapd %xmm1, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jb 0x17298
cmpq %r13, %rcx
je 0x172d8
movsd (%r15,%rcx,8), %xmm0
mulsd %xmm2, %xmm0
addsd (%r12,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r13
jne 0x172bb
movq 0x10(%rsp), %r15
movq (%r15), %rdi
movq 0x238(%r15), %rsi
movq 0x248(%r15), %rcx
movq (%rdi), %rax
movq %r14, %r12
movq %r14, %rdx
callq *0x48(%rax)
incq 0x50(%r15)
movq 0x250(%r15), %rax
movq 0x40(%rsp), %r15
cmpq 0x8(%r15), %rax
jne 0x1741c
movq %rbx, %r13
movq %rbx, 0x48(%rsp)
movq %r15, 0x50(%rsp)
testq %rax, %rax
movsd 0x20(%rsp), %xmm4
je 0x17367
jle 0x174a2
movq (%r13), %rax
movq %rax, 0x68(%rsp)
movq (%r15), %rax
movq %rax, 0x78(%rsp)
leaq 0x48(%rsp), %rax
movq %rax, 0x88(%rsp)
leaq 0x60(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x193da
movsd 0x20(%rsp), %xmm4
jmp 0x1736b
xorpd %xmm0, %xmm0
movsd %xmm0, 0x38(%rsp)
incl %ebp
cmpl $0x13, %ebp
jne 0x171ab
jmp 0x173db
xorpd %xmm0, %xmm0
movsd %xmm0, 0x10(%rsp)
movq 0x6ec61(%rip), %rbx     # 0x85ff0
leaq 0x467a9(%rip), %rsi     # 0x5db3f
movl $0x24, %edx
movq %rbx, %rdi
callq 0x93b0
movq %rbx, %rdi
movsd 0x10(%rsp), %xmm0
callq 0x9570
movq %rax, %rbx
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x9330
movsbl %al, %esi
movq %rbx, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9230
movsd 0x4500d(%rip), %xmm0    # 0x5c3f0
addq $0x118, %rsp            # imm = 0x118
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsd 0x28(%rsp), %xmm0
jmp 0x173e3
leaq 0x45e41(%rip), %rdi     # 0x5d245
leaq 0x45e57(%rip), %rsi     # 0x5d262
leaq 0x4682d(%rip), %rcx     # 0x5dc3f
movl $0x198, %edx            # imm = 0x198
callq 0x9200
leaq 0x468d3(%rip), %rdi     # 0x5dcf6
leaq 0x468e3(%rip), %rsi     # 0x5dd0d
leaq 0x468f3(%rip), %rcx     # 0x5dd24
movl $0x52, %edx
callq 0x9200
movl $0x1, %edi
callq 0x93e0
leaq 0x45df9(%rip), %rdi     # 0x5d245
leaq 0x45e0f(%rip), %rsi     # 0x5d262
leaq 0x559d9(%rip), %rcx     # 0x6ce33
movl $0xa2, %edx
callq 0x9200
leaq 0x469f3(%rip), %rdi     # 0x5de5e
leaq 0x46a25(%rip), %rsi     # 0x5de97
leaq 0x55a4f(%rip), %rcx     # 0x6cec8
movl $0x6e, %edx
callq 0x9200
leaq 0x450d2(%rip), %rdi     # 0x5c55c
leaq 0x45160(%rip), %rsi     # 0x5c5f1
leaq 0x4517b(%rip), %rcx     # 0x5c613
movl $0x4a, %edx
callq 0x9200
leaq 0x45548(%rip), %rdi     # 0x5c9f1
leaq 0x45585(%rip), %rsi     # 0x5ca35
leaq 0x46a01(%rip), %rcx     # 0x5deb8
movl $0x19d, %edx            # imm = 0x19D
callq 0x9200
leaq 0x45bb8(%rip), %rdi     # 0x5d080
leaq 0x4506a(%rip), %rsi     # 0x5c539
leaq 0x55ca6(%rip), %rcx     # 0x6d17c
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x4550a(%rip), %rdi     # 0x5c9f1
leaq 0x45547(%rip), %rsi     # 0x5ca35
leaq 0x45559(%rip), %rcx     # 0x5ca4e
jmp 0x174b7
leaq 0x4597a(%rip), %rdi     # 0x5ce78
leaq 0x457d2(%rip), %rsi     # 0x5ccd7
leaq 0x45afb(%rip), %rcx     # 0x5d007
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x45b63(%rip), %rdi     # 0x5d080
leaq 0x45015(%rip), %rsi     # 0x5c539
leaq 0x45de1(%rip), %rcx     # 0x5d30c
jmp 0x174d6
nop