// File: /workspace/github_cpp_makefile_star2_O1/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 $0x98, %rsp
movq %rdi, %rbx
callq 0x185c8
testb %al, %al
je 0x186d3
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 0x186f8
movsd %xmm1, 0x10(%rsp)
jle 0x18d32
movq (%r14), %rax
leaq 0x40(%rsp), %rdi
movq %rax, (%rdi)
movq %r14, 0x10(%rdi)
leaq 0x18(%rsp), %rsi
callq 0x2d744
movsd 0x10(%rsp), %xmm1
jmp 0x186fc
movq 0x6f8e6(%rip), %rbx     # 0x87fc0
leaq 0x45513(%rip), %rsi     # 0x5dbf4
movl $0x17, %edx
movq %rbx, %rdi
callq 0x93a0
movl $0x3, %ebp
jmp 0x187af
xorpd %xmm0, %xmm0
addsd %xmm0, %xmm1
movq %xmm1, %rax
btrq $0x3f, %rax
movabsq $0x7ff0000000000000, %rcx # imm = 0x7FF0000000000000
cmpq %rcx, %rax
jl 0x1873b
movq 0x6f8a0(%rip), %rbx     # 0x87fc0
leaq 0x454e5(%rip), %rsi     # 0x5dc0c
movl $0x34, %edx
movq %rbx, %rdi
callq 0x93a0
movl $0x4, %ebp
jmp 0x187af
movq %rbx, %rdi
callq 0x17d5a
leaq 0x220(%rbx), %r14
cmpq $0x0, 0x228(%rbx)
je 0x18783
movq %r14, 0x18(%rsp)
jle 0x18d13
movq (%r14), %rax
leaq 0x40(%rsp), %rdi
movq %rax, 0x8(%rdi)
leaq 0x18(%rsp), %rax
movq %rax, 0x18(%rdi)
leaq 0x88(%rsp), %rsi
callq 0x102e6
jmp 0x18787
xorpd %xmm0, %xmm0
movsd 0x68(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x187ea
movq 0x6f7df(%rip), %rbx     # 0x87f78
leaq 0x454a1(%rip), %rsi     # 0x5dc41
movl $0xf, %edx
movq %rbx, %rdi
callq 0x93a0
xorl %ebp, %ebp
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x9320
movsbl %al, %esi
movq %rbx, %rdi
callq 0x9040
movq %rax, %rdi
callq 0x9220
movl %ebp, %eax
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpb $0x1, 0x58(%rbx)
jne 0x18821
leaq 0x4545a(%rip), %rdi     # 0x5dc51
leaq 0x4546c(%rip), %rsi     # 0x5dc6a
leaq 0x4546f(%rip), %rdx     # 0x5dc74
leaq 0x45470(%rip), %rcx     # 0x5dc7c
leaq 0x45475(%rip), %r8      # 0x5dc88
leaq 0x45477(%rip), %r9      # 0x5dc91
xorl %eax, %eax
callq 0x9070
leaq 0x10(%rbx), %r13
leaq 0x1f0(%rbx), %rax
movq %rax, 0x38(%rsp)
leaq 0x1d0(%rbx), %rax
movq %rax, 0x30(%rsp)
leaq 0x200(%rbx), %rax
movq %rax, 0x28(%rsp)
leaq 0x210(%rbx), %rax
movq %rax, 0x80(%rsp)
movl $0x1, %r15d
movq %r13, 0x68(%rsp)
movq 0x1e0(%rbx), %rbp
movq 0x1e8(%rbx), %r12
cmpq %r12, 0x1f8(%rbx)
je 0x18898
testq %r12, %r12
js 0x18cb6
movl $0x1, %ecx
movq 0x38(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x10056
movq 0x1f8(%rbx), %rax
cmpq %r12, %rax
jne 0x18c80
movq 0x38(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x188da
xorl %esi, %esi
movapd (%rbp,%rsi,8), %xmm0
movapd %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x188c6
cmpq %rax, %rdx
jge 0x188f2
movsd (%rbp,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x188df
cmpq $0x1, %r15
sete %al
orb 0x258(%rbx), %al
cmpb $0x1, %al
movq %r15, 0x10(%rsp)
jne 0x18915
movq %rbx, %rdi
callq 0x14510
jmp 0x18a53
movq 0x10(%rbx), %rbp
movq 0x18(%rbx), %r12
cmpq %r12, 0x1d8(%rbx)
je 0x18944
testq %r12, %r12
js 0x18cb6
movl $0x1, %ecx
movq 0x30(%rsp), %rdi
movq %r12, %rsi
movq %r12, %rdx
callq 0x10056
movq 0x1d8(%rbx), %rax
cmpq %r12, %rax
jne 0x18c80
movq 0x30(%rsp), %rcx
movq (%rcx), %rcx
movq %rax, %rdx
shrq $0x3f, %rdx
addq %rax, %rdx
andq $-0x2, %rdx
cmpq $0x2, %rax
jl 0x18986
xorl %esi, %esi
movapd (%rbp,%rsi,8), %xmm0
movapd %xmm0, (%rcx,%rsi,8)
addq $0x2, %rsi
cmpq %rdx, %rsi
jl 0x18972
cmpq %rax, %rdx
jge 0x1899e
movsd (%rbp,%rdx,8), %xmm0
movsd %xmm0, (%rcx,%rdx,8)
incq %rdx
cmpq %rdx, %rax
jne 0x1898b
movq 0xb8(%rbx), %rbp
testq %rbp, %rbp
js 0x18cf4
addq %rbp, %rbp
cmpq %rbp, 0x208(%rbx)
je 0x189cf
movl $0x1, %ecx
movq 0x28(%rsp), %rdi
movq %rbp, %rsi
movq %rbp, %rdx
callq 0x10056
movq 0x208(%rbx), %r12
cmpq %rbp, %r12
jne 0x18cd5
movq %r14, %r13
movq 0x28(%rsp), %rax
movq (%rax), %rbp
movq %r12, %r15
shrq $0x3f, %r15
addq %r12, %r15
movq %r15, %r14
andq $-0x2, %r14
cmpq $0x2, %r12
jl 0x18a28
cmpq $0x3, %r14
movl $0x2, %eax
cmovgeq %r14, %rax
leaq -0x8(,%rax,8), %rdx
andq $-0x10, %rdx
addq $0x10, %rdx
movq %rbp, %rdi
xorl %esi, %esi
callq 0x91c0
cmpq %r12, %r14
movq %r13, %r14
movq 0x68(%rsp), %r13
jge 0x18a53
sarq %r15
shlq $0x4, %r15
addq %r15, %rbp
shlq $0x3, %r12
subq %r15, %r12
movq %rbp, %rdi
xorl %esi, %esi
movq %r12, %rdx
callq 0x91c0
movq %rbx, %rdi
callq 0x13504
movq %rbx, %rdi
callq 0x15ba4
movq 0x80(%rsp), %rax
movq %rax, 0x40(%rsp)
movq %r13, 0x48(%rsp)
movq 0x218(%rbx), %rax
cmpq 0x18(%rbx), %rax
jne 0x18c97
leaq 0x88(%rsp), %r15
movq %r15, %rdi
leaq 0x40(%rsp), %rsi
callq 0x2a530
movq %rbx, %rdi
movq %r15, %rsi
movq 0x10(%rsp), %r15
movq %r15, %rdx
callq 0x17692
ucomisd 0x438ea(%rip), %xmm0    # 0x5c3a0
jne 0x18af9
jp 0x18af9
cmpq $0x0, 0xb8(%rbx)
je 0x18b6b
movq %rbx, %rdi
callq 0x181de
movl $0x11, %edx
movq 0x6f49c(%rip), %rdi     # 0x87f78
leaq 0x451b9(%rip), %rsi     # 0x5dc9c
callq 0x93a0
decq %r15
decq 0x50(%rbx)
movl $0x4, %ebp
jmp 0x18c3c
movsd %xmm0, 0x78(%rsp)
movq %rbx, %rdi
callq 0x17f7a
movsd %xmm0, 0x70(%rsp)
cmpb $0x1, 0x58(%rbx)
jne 0x18b9b
movq 0x50(%rbx), %r12
movsd 0x230(%rbx), %xmm1
cmpq $0x0, 0x228(%rbx)
je 0x18b7d
movsd %xmm1, 0x60(%rsp)
movq %r14, 0x18(%rsp)
jle 0x18d13
movq (%r14), %rax
movq %rax, 0x48(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0xb(%rsp), %rsi
callq 0x102e6
movapd %xmm0, %xmm2
movsd 0x60(%rsp), %xmm1
jmp 0x18b81
movl $0x1, %ebp
movl $0x1, 0xc(%rsp)
jmp 0x18c3c
xorpd %xmm2, %xmm2
leaq 0x45126(%rip), %rdi     # 0x5dcae
movq %r15, %rsi
movq %r12, %rdx
movsd 0x78(%rsp), %xmm0
movb $0x3, %al
callq 0x9070
cmpq $0x0, 0x228(%rbx)
je 0x18bd3
movq %r14, 0x18(%rsp)
jle 0x18d13
movq (%r14), %rax
movq %rax, 0x48(%rsp)
leaq 0x18(%rsp), %rax
movq %rax, 0x58(%rsp)
leaq 0x40(%rsp), %rdi
leaq 0xb(%rsp), %rsi
callq 0x102e6
jmp 0x18bd7
xorpd %xmm0, %xmm0
movsd 0x68(%rbx), %xmm1
ucomisd %xmm0, %xmm1
jbe 0x18bfe
movl $0x0, 0xc(%rsp)
movl $0x1, %ebp
cmpb $0x1, 0x58(%rbx)
jne 0x18c3c
leaq 0x564a3(%rip), %rdi     # 0x6f09f
jmp 0x18c25
movsd 0x70(%rbx), %xmm0
ucomisd 0x70(%rsp), %xmm0
jbe 0x18c2c
movl $0x0, 0xc(%rsp)
movl $0x1, %ebp
cmpb $0x1, 0x58(%rbx)
jne 0x18c3c
leaq 0x56454(%rip), %rdi     # 0x6f079
callq 0x9540
jmp 0x18c3c
cmpq 0x60(%rbx), %r15
jae 0x18c57
xorl %ebp, %ebp
movq %rbx, %rdi
callq 0x10638
movq 0x88(%rsp), %rdi
callq 0x93c0
testb $0x3, %bpl
jne 0x18c77
incq %r15
jmp 0x18863
movl $0x1, %ebp
cmpb $0x1, 0x58(%rbx)
jne 0x18b70
leaq 0x563ec(%rip), %rdi     # 0x6f059
callq 0x9540
jmp 0x18b70
movl 0xc(%rsp), %ebp
jmp 0x187d6
leaq 0x443d9(%rip), %rdi     # 0x5d060
leaq 0x4388b(%rip), %rsi     # 0x5c519
leaq 0x44657(%rip), %rcx     # 0x5d2ec
jmp 0x18cea
leaq 0x45250(%rip), %rdi     # 0x5deee
leaq 0x45282(%rip), %rsi     # 0x5df27
leaq 0x4e907(%rip), %rcx     # 0x675b3
movl $0x6e, %edx
callq 0x9200
leaq 0x4419b(%rip), %rdi     # 0x5ce58
leaq 0x43ff3(%rip), %rsi     # 0x5ccb7
leaq 0x4431c(%rip), %rcx     # 0x5cfe7
movl $0x11d, %edx            # imm = 0x11D
callq 0x9200
leaq 0x44384(%rip), %rdi     # 0x5d060
leaq 0x43836(%rip), %rsi     # 0x5c519
leaq 0x447d9(%rip), %rcx     # 0x5d4c3
movl $0x2d1, %edx            # imm = 0x2D1
callq 0x9200
leaq 0x43841(%rip), %rdi     # 0x5c53c
leaq 0x438cf(%rip), %rsi     # 0x5c5d1
leaq 0x446c3(%rip), %rcx     # 0x5d3cc
movl $0x4a, %edx
callq 0x9200
leaq 0x43cb7(%rip), %rdi     # 0x5c9d1
leaq 0x43cf4(%rip), %rsi     # 0x5ca15
leaq 0x448bf(%rip), %rcx     # 0x5d5e7
movl $0x19d, %edx            # imm = 0x19D
callq 0x9200
leaq 0x43c98(%rip), %rdi     # 0x5c9d1
leaq 0x43cd5(%rip), %rsi     # 0x5ca15
leaq 0x56200(%rip), %rcx     # 0x6ef47
jmp 0x18d28
jmp 0x18d4b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
callq 0x93c0
movq %rbx, %rdi
callq 0x9670
nop