// File: /workspace/github_cpp_makefile_star2_O3/canzarlab[P]Trajan/geno/lbfgsb.cpp
// Function: LBFGSB::solve()
SolverStatus LBFGSB::solve() {
  Scalar const INF = std::numeric_limits<Scalar>::infinity();
  if (!initFeasible()) {
    std::cout << "Prolem is not feasible." << std::endl;
    return INFEASIBLE;
  }

  _funEval = 1;
  _genoNLP.functionValueAndGradient(_x.data(), _f, _g.data());
  //    std::cout << "x " << _x.transpose() << std::endl;
  //    std::cout << "g " << _g.transpose() << std::endl;
  // check for NANs and INFs
  double sum = _f + _g.sum();
  if ((-INF < sum) && (sum < INF)) {
  } else {
    std::cout << "encountered INF or NAN in function value or gradient" << std::endl;
    return NUM_ERROR;      
  }
  projectedGradient();
  if (_projectedGradient.lpNorm<Eigen::Infinity>() < _tol) {
    std::clog << "already optimal" << std::endl;
    return SOLVED;
  }

  if (_verbose)
    printf("\n%8s %8s %14s %14s %14s\n",
        "Iteration", "FunEval", "Step Length", "FunValue", "Proj.Grad.");
  size_t k = 1;
  for (;; ++k) {
    // Backup the old state
    _workingSetOld = _workingSet;
    if (_constrained || 1 == k) {
      cauchyPoint();
    } else {
      _xCP = _x;
      _c = Vector::Zero(_S.cols() * 2);
    }

    formK();
    subsm();
    Vector deltaX = _xSubspace - _x;
    Scalar t = lineSearchMT(deltaX, k);
    if (-1 == t) {
      if (0 != _S.cols()) {
        refresh();
        std::clog << "refresh() called\n";
        --k;
        --_funEval;  // TODO remove
        continue;
      }
      //        std::cerr << "error in line search - abnormal termination" << std::endl;
      //        std::exit(EXIT_FAILURE);
      return SUBOPTIMAL;
    }
    Scalar deltaF = helper();

    if (_verbose) {
      printf(" %8lu %8lu %14.5g %14.5E %14.5E\n",
          k, _funEval, t, _fNew, _projectedGradient.lpNorm<Eigen::Infinity>());
    }

    if (_projectedGradient.lpNorm<Eigen::Infinity>() < _tol) {
      if (_verbose) printf("Directional derivative below tol\n");
      return SOLVED;
    }

    if (deltaF < _tolFun) {
      if (_verbose) printf("Change in function value below tolFun\n");
      return SOLVED;
    }

    if (k >= _maxIter) {
      if (_verbose) printf("Maximum iteration count reached\n");
      return SUBOPTIMAL;
    }

    updateB();
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rdi, %rbx
callq 0x17e1a
testb %al, %al
je 0x17f67
movq $0x1, 0x50(%rbx)
movq (%rbx), %rdi
movq 0x10(%rbx), %rsi
leaq 0x8(%rbx), %rdx
leaq 0x40(%rbx), %r14
movq 0x40(%rbx), %rcx
movq (%rdi), %rax
callq *0x48(%rax)
movsd 0x8(%rbx), %xmm1
cmpq $0x0, 0x48(%rbx)
je 0x17fb3
movsd %xmm1, 0x10(%rsp)
jle 0x18579
movq (%r14), %rax
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq %r14, 0x10(%rdi)
leaq 0x18(%rsp), %rsi
callq 0x2cda2
movsd 0x10(%rsp), %xmm1
jmp 0x17fb7
movq 0x6e052(%rip), %rbx     # 0x85fc0
leaq 0x45bef(%rip), %rsi     # 0x5db64
movl $0x17, %edx
movq %rbx, %rdi
callq 0x93b0
movq (%rbx), %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
movl $0x3, %ebp
jmp 0x184bb
xorpd %xmm0, %xmm0
addsd %xmm0, %xmm1
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jl 0x18020
movq 0x6dfe5(%rip), %rbx     # 0x85fc0
leaq 0x45b9a(%rip), %rsi     # 0x5db7c
movl $0x34, %edx
movq %rbx, %rdi
callq 0x93b0
movq (%rbx), %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
movl $0x4, %ebp
jmp 0x184bb
movq %rbx, %rdi
callq 0x1752e
leaq 0x220(%rbx), %r14
cmpq $0x0, 0x228(%rbx)
je 0x18065
movq %r14, 0x18(%rsp)
jle 0x18543
movq (%r14), %rax
leaq 0x40(%rsp), %rdi
movq %rax, 0x8(%rdi)
leaq 0x18(%rsp), %rax
movq %rax, 0x18(%rdi)
leaq 0x60(%rsp), %rsi
callq 0x101d8
jmp 0x18069
xorpd %xmm0, %xmm0
movsd 0x68(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x180bd
movq 0x6defd(%rip), %rbx     # 0x85f78
leaq 0x45b2f(%rip), %rsi     # 0x5dbb1
movl $0xf, %edx
movq %rbx, %rdi
callq 0x93b0
movq (%rbx), %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
xorl %ebp, %ebp
jmp 0x184bb
movq %r14, 0x28(%rsp)
cmpb $0x1, 0x58(%rbx)
jne 0x180f9
leaq 0x45af2(%rip), %rdi     # 0x5dbc1
leaq 0x45b04(%rip), %rsi     # 0x5dbda
leaq 0x45b07(%rip), %rdx     # 0x5dbe4
leaq 0x45b08(%rip), %rcx     # 0x5dbec
leaq 0x45b0d(%rip), %r8      # 0x5dbf8
leaq 0x45b0f(%rip), %r9      # 0x5dc01
xorl %eax, %eax
callq 0x9070
leaq 0x10(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x1f0(%rbx), %r14
leaq 0x1d0(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x200(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x210(%rbx), %r15
movl $0x1, %r13d
movq 0x1e0(%rbx), %rbp
movq 0x1e8(%rbx), %r12
cmpq %r12, 0x1f8(%rbx)
je 0x1816e
testq %r12, %r12
js 0x184ee
movl $0x1, %ecx
movq %r14, %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xff4c
cmpq %r12, 0x1f8(%rbx)
jne 0x1850d
movq (%r14), %rax
movq %r12, %rcx
shrq $0x3f, %rcx
addq %r12, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r12
jl 0x1819b
xorl %edx, %edx
movapd (%rbp,%rdx,8), %xmm0
movapd %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x18187
cmpq %r12, %rcx
jge 0x181b3
movsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x181a0
cmpq $0x1, %r13
sete %al
orb 0x258(%rbx), %al
cmpb $0x1, %al
jne 0x181d1
movq %rbx, %rdi
callq 0x1421c
jmp 0x182cb
movq 0x10(%rbx), %rbp
movq 0x18(%rbx), %r12
cmpq %r12, 0x1d8(%rbx)
je 0x1820d
testq %r12, %r12
js 0x184ee
movl $0x1, %ecx
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xff4c
cmpq %r12, 0x1d8(%rbx)
jne 0x1850d
movq 0x38(%rsp), %rax
movq (%rax), %rax
movq %r12, %rcx
shrq $0x3f, %rcx
addq %r12, %rcx
andq $-0x2, %rcx
cmpq $0x2, %r12
jl 0x1823f
xorl %edx, %edx
movapd (%rbp,%rdx,8), %xmm0
movapd %xmm0, (%rax,%rdx,8)
addq $0x2, %rdx
cmpq %rcx, %rdx
jl 0x1822b
cmpq %r12, %rcx
jge 0x18257
movsd (%rbp,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
cmpq %rcx, %r12
jne 0x18244
movq 0xb8(%rbx), %rbp
testq %rbp, %rbp
js 0x18524
leaq (,%rbp,2), %r12
cmpq %r12, 0x208(%rbx)
je 0x1829a
movl $0x1, %ecx
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0xff4c
cmpq %r12, 0x208(%rbx)
jne 0x1855a
testq %rbp, %rbp
je 0x182cb
cmpq $0x3, %r12
movl $0x2, %eax
cmovbq %rax, %r12
movq 0x30(%rsp), %rax
movq (%rax), %rdi
leaq -0x8(,%r12,8), %rdx
andq $-0x10, %rdx
addq $0x10, %rdx
xorl %esi, %esi
callq 0x91c0
movq %rbx, %rdi
callq 0x13276
movq %rbx, %rdi
callq 0x156ae
movq %r15, 0x40(%rsp)
movq 0x10(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0x218(%rbx), %rax
cmpq 0x18(%rbx), %rax
jne 0x184cf
leaq 0x60(%rsp), %r12
movq %r12, %rdi
leaq 0x40(%rsp), %rsi
callq 0x29bde
movq %rbx, %rdi
movq %r12, %rsi
movq %r13, %rdx
callq 0x16eac
ucomisd 0x440cd(%rip), %xmm0    # 0x5c3f0
jne 0x18361
jp 0x18361
cmpq $0x0, 0xb8(%rbx)
je 0x18471
movq %rbx, %rdi
callq 0x1797c
movl $0x11, %edx
movq 0x6dc2f(%rip), %rdi     # 0x85f78
leaq 0x458bc(%rip), %rsi     # 0x5dc0c
callq 0x93b0
decq %r13
decq 0x50(%rbx)
jmp 0x1845f
movsd %xmm0, 0x78(%rsp)
movq %rbx, %rdi
callq 0x1771e
movsd %xmm0, 0x80(%rsp)
cmpb $0x1, 0x58(%rbx)
jne 0x183f5
movq 0x50(%rbx), %r12
movsd 0x230(%rbx), %xmm1
cmpq $0x0, 0x228(%rbx)
je 0x183d7
movsd %xmm1, 0x70(%rsp)
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
jle 0x18543
movq (%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x101d8
movapd %xmm0, %xmm2
movsd 0x70(%rsp), %xmm1
jmp 0x183db
xorpd %xmm2, %xmm2
leaq 0x4583c(%rip), %rdi     # 0x5dc1e
movq %r13, %rsi
movq %r12, %rdx
movsd 0x78(%rsp), %xmm0
movb $0x3, %al
callq 0x9070
cmpq $0x0, 0x228(%rbx)
je 0x18432
movq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
jle 0x18543
movq (%rax), %rax
movq %rax, 0x48(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0xf(%rsp), %rsi
callq 0x101d8
jmp 0x18436
xorpd %xmm0, %xmm0
movsd 0x68(%rbx), %xmm1
ucomisd %xmm0, %xmm1
ja 0x18478
movsd 0x70(%rbx), %xmm0
ucomisd 0x80(%rsp), %xmm0
ja 0x18489
cmpq 0x60(%rbx), %r13
jae 0x1849a
movq %rbx, %rdi
callq 0x104bc
movq 0x60(%rsp), %rdi
callq 0x93d0
incq %r13
jmp 0x1812e
movl $0x1, %ebp
jmp 0x184b1
xorl %ebp, %ebp
cmpb $0x0, 0x58(%rbx)
je 0x184b1
leaq 0x557b9(%rip), %rdi     # 0x6dc40
jmp 0x184ac
xorl %ebp, %ebp
cmpb $0x0, 0x58(%rbx)
je 0x184b1
leaq 0x55782(%rip), %rdi     # 0x6dc1a
jmp 0x184ac
movl $0x1, %ebp
cmpb $0x0, 0x58(%rbx)
je 0x184b1
leaq 0x5574e(%rip), %rdi     # 0x6dbfa
callq 0x9550
movq 0x60(%rsp), %rdi
callq 0x93d0
movl %ebp, %eax
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x45988(%rip), %rdi     # 0x5de5e
leaq 0x459ba(%rip), %rsi     # 0x5de97
leaq 0x4edf7(%rip), %rcx     # 0x672db
movl $0x6e, %edx
callq 0x9200
leaq 0x44983(%rip), %rdi     # 0x5ce78
leaq 0x447db(%rip), %rsi     # 0x5ccd7
leaq 0x44b04(%rip), %rcx     # 0x5d007
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x44b6c(%rip), %rdi     # 0x5d080
leaq 0x4401e(%rip), %rsi     # 0x5c539
leaq 0x44dea(%rip), %rcx     # 0x5d30c
jmp 0x1856f
leaq 0x44031(%rip), %rdi     # 0x5c55c
leaq 0x440bf(%rip), %rsi     # 0x5c5f1
leaq 0x44eb3(%rip), %rcx     # 0x5d3ec
movl $0x4a, %edx
callq 0x9200
leaq 0x444a7(%rip), %rdi     # 0x5c9f1
leaq 0x444e4(%rip), %rsi     # 0x5ca35
leaq 0x450af(%rip), %rcx     # 0x5d607
jmp 0x1858e
leaq 0x44b1f(%rip), %rdi     # 0x5d080
leaq 0x43fd1(%rip), %rsi     # 0x5c539
leaq 0x44f74(%rip), %rcx     # 0x5d4e3
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x44471(%rip), %rdi     # 0x5c9f1
leaq 0x444ae(%rip), %rsi     # 0x5ca35
leaq 0x5555a(%rip), %rcx     # 0x6dae8
movl $0x19d, %edx            # imm = 0x19D
callq 0x9200
jmp 0x1859a
movq %rax, %rbx
movq 0x60(%rsp), %rdi
callq 0x93d0
movq %rbx, %rdi
callq 0x9680
nop