// File: /workspace/github_cpp_makefile_star2_O2/canzarlab[P]Trajan/geno/lbfgsb.cpp
// Function: LBFGSB::formK()
void LBFGSB::formK() {
  Vector diffWS = _workingSet - _workingSetOld;
  for (Index i = 0; i < _workingSet.size(); ++i) {
    if (diffWS[i]) {
      _SSws += diffWS[i] * _S.row(i).transpose() * _S.row(i);
      _SYws += diffWS[i] * _S.row(i).transpose() * _Y.row(i);
      _YYws += diffWS[i] * _Y.row(i).transpose() * _Y.row(i);
    }
  }

  Matrix SY2 = _Q * _SY * _Q.transpose();
  Matrix D = Matrix(_SY.rows(), _SY.cols());
  D.setZero();
  D.diagonal() = SY2.diagonal();

  Matrix M1 = SY2.triangularView<Eigen::StrictlyLower>();
  Matrix SYws2 = _Q * _SYws * _Q.transpose();
  M1 = M1 - SYws2;
  Matrix YYws2 = _Q * _YYws * _Q.transpose();

  Matrix SS2 = _Q * _SS * _Q.transpose();
  Matrix SSws2 = _Q * _SSws * _Q.transpose();

  _K = Matrix::Zero(D.rows() * 2, 2 * D.cols());

  _K.topLeftCorner(D.rows(), D.cols()) = -D-YYws2/_theta;
  _K.topRightCorner(D.rows(), D.cols()) = M1.transpose();
  _K.bottomLeftCorner(D.rows(), D.cols()) = M1;
  _K.bottomRightCorner(D.rows(), D.cols()) = _theta*(SS2-SSws2);

  choleskyFactorK();
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x258, %rsp            # imm = 0x258
movq %rdi, %rbx
leaq 0x1e0(%rdi), %rsi
leaq 0x1f0(%rdi), %rdx
leaq 0xf0(%rsp), %r14
movq %r14, %rdi
callq 0x1367c
movq %rsp, %rdi
movq %r14, %rsi
callq 0x25a0a
leaq 0xa8(%rbx), %r14
leaq 0x1a0(%rbx), %rax
movq %rax, 0x20(%rsp)
leaq 0xc0(%rbx), %r15
leaq 0x188(%rbx), %rax
movq %rax, 0x18(%rsp)
movq %rbx, 0x28(%rsp)
leaq 0x1b8(%rbx), %rax
movq %rax, 0x10(%rsp)
xorl %r12d, %r12d
leaq 0x1e8(%rsp), %rbx
leaq 0x68(%rsp), %rbp
movq 0x28(%rsp), %rax
cmpq 0x1e8(%rax), %r12
jge 0x1044a
movq %rsp, %rdi
movq %r12, %rsi
callq 0x13224
movsd (%rax), %xmm0
ucomisd 0x4119f(%rip), %xmm0    # 0x51408
jne 0x10271
jnp 0x10442
movq %rsp, %rdi
movq %r12, %rsi
callq 0x13224
movq %rax, %r13
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x154fe
movq 0xa0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0xb8(%rsp), %rax
movupd (%rax), %xmm0
movups 0x10(%rax), %xmm1
leaq 0x48(%rsp), %rax
movups %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x30(%rsp), %rdx
callq 0x13697
movq %rbp, %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x154fe
leaq 0xf0(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x25c36
movq 0x20(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x136ea
movq %rsp, %rdi
movq %r12, %rsi
callq 0x13224
movq %rax, %r13
leaq 0xa0(%rsp), %rdi
movq %r14, %rsi
movq %r12, %rdx
callq 0x154fe
movq 0xa0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0xb8(%rsp), %rax
movupd (%rax), %xmm0
movups 0x10(%rax), %xmm1
leaq 0x48(%rsp), %rax
movups %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x30(%rsp), %rdx
callq 0x13697
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x154fe
leaq 0xf0(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x25c36
movq 0x18(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x136ea
movq %rsp, %rdi
movq %r12, %rsi
callq 0x13224
movq %rax, %r13
leaq 0xa0(%rsp), %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x154fe
movq 0xa0(%rsp), %rax
movq 0xb0(%rsp), %rcx
movq %rax, 0x30(%rsp)
movq %rcx, 0x40(%rsp)
leaq 0xb8(%rsp), %rax
movupd (%rax), %xmm0
movups 0x10(%rax), %xmm1
leaq 0x48(%rsp), %rax
movups %xmm1, 0x10(%rax)
movupd %xmm0, (%rax)
movq %rbx, %rdi
movq %r13, %rsi
leaq 0x30(%rsp), %rdx
callq 0x13697
movq %rbp, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x154fe
leaq 0xf0(%rsp), %rdi
movq %rbx, %rsi
movq %rbp, %rdx
callq 0x25c36
movq 0x10(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x136ea
incq %r12
jmp 0x10240
movq 0x28(%rsp), %r12
leaq 0x128(%r12), %r13
leaq 0xe0(%r12), %rsi
movq %r13, %rdi
callq 0x132e2
leaq 0x1e8(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x30(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xf0(%rsp), %rdi
callq 0x15c84
leaq 0xa0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15cbe
movq 0xe8(%r12), %rax
leaq 0xf0(%rsp), %rsi
movq %rax, (%rsi)
movq 0xf0(%r12), %rax
leaq 0x1e8(%rsp), %rdx
movq %rax, (%rdx)
leaq 0x68(%rsp), %rdi
callq 0x13306
leaq 0x68(%rsp), %rdi
callq 0x1333e
leaq 0xf0(%rsp), %rdi
leaq 0xa0(%rsp), %rbx
movq %rbx, %rsi
callq 0x1334e
leaq 0x1e8(%rsp), %rdi
leaq 0x68(%rsp), %r14
movq %r14, %rsi
callq 0x1334e
leaq 0x1e8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x198d6
leaq 0xf0(%rsp), %rsi
movq %rbx, (%rsi)
leaq 0xd8(%rsp), %rdi
callq 0x19a74
movq %r13, %rdi
movq 0x18(%rsp), %rsi
callq 0x132e2
leaq 0x1e8(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x30(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xf0(%rsp), %rdi
callq 0x15c84
leaq 0x1d0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15cbe
leaq 0xf0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
leaq 0x1d0(%rsp), %rdx
callq 0x13708
leaq 0xd8(%rsp), %rbx
leaq 0xf0(%rsp), %rsi
movq %rbx, %rdi
callq 0x262da
movq %r13, %rdi
movq 0x10(%rsp), %rsi
callq 0x132e2
leaq 0x1e8(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x30(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xf0(%rsp), %rdi
callq 0x15c84
leaq 0x1b8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15cbe
leaq 0xf8(%r12), %rsi
movq %r13, %rdi
callq 0x132e2
leaq 0x1e8(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x30(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xf0(%rsp), %rdi
callq 0x15c84
leaq 0x1a0(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15cbe
movq %r13, %rdi
movq 0x20(%rsp), %rsi
callq 0x132e2
leaq 0x1e8(%rsp), %rsi
movq %rax, (%rsi)
movq %rdx, 0x8(%rsi)
leaq 0x30(%rsp), %rdx
movq %r13, (%rdx)
leaq 0xf0(%rsp), %rdi
callq 0x15c84
leaq 0x188(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x15cbe
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rsi
addq %rdx, %rdx
leaq 0xf0(%rsp), %rdi
callq 0x1365c
leaq 0x140(%r12), %r15
leaq 0xf0(%rsp), %rsi
movq %r15, %rdi
callq 0x25651
movq %r14, 0x248(%rsp)
leaq 0xd8(%r12), %r14
leaq 0x30(%rsp), %rdi
leaq 0x1b8(%rsp), %rsi
movq %r14, %rdx
callq 0x13740
leaq 0xf0(%rsp), %rdi
leaq 0x248(%rsp), %rsi
leaq 0x30(%rsp), %rdx
callq 0x13724
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0x1e8(%rsp), %rdi
movq %r15, %rsi
callq 0x133b2
leaq 0x1e8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x26552
movq %rbx, 0x1e8(%rsp)
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0xf0(%rsp), %rdi
movq %r15, %rsi
callq 0x133ca
leaq 0xf0(%rsp), %rdi
leaq 0x1e8(%rsp), %rsi
callq 0x1a221
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0xf0(%rsp), %rdi
movq %r15, %rsi
callq 0x133e8
leaq 0xf0(%rsp), %rdi
leaq 0xd8(%rsp), %rsi
callq 0x19fa7
leaq 0x30(%rsp), %rdi
leaq 0x1a0(%rsp), %rsi
leaq 0x188(%rsp), %rdx
callq 0x13708
leaq 0xf0(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r14, %rsi
callq 0x13794
movq 0x70(%rsp), %rdx
movq 0x78(%rsp), %rcx
leaq 0x1e8(%rsp), %rdi
movq %r15, %rsi
callq 0x13406
leaq 0x1e8(%rsp), %rdi
leaq 0xf0(%rsp), %rsi
callq 0x268be
movq %r12, %rdi
callq 0xfd9e
movq 0x188(%rsp), %rdi
callq 0x93c0
movq 0x1a0(%rsp), %rdi
callq 0x93c0
movq 0x1b8(%rsp), %rdi
callq 0x93c0
movq 0x1d0(%rsp), %rdi
callq 0x93c0
movq 0xd8(%rsp), %rdi
callq 0x93c0
movq 0x68(%rsp), %rdi
callq 0x93c0
movq 0xa0(%rsp), %rdi
callq 0x93c0
movq (%rsp), %rdi
callq 0x93c0
addq $0x258, %rsp            # imm = 0x258
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x108a1
jmp 0x108fe
jmp 0x10903
jmp 0x1090a
jmp 0x1090f
jmp 0x10914
jmp 0x10914
jmp 0x10914
movq %rax, %rbx
jmp 0x108ef
jmp 0x1092d
jmp 0x108a1
jmp 0x108a1
jmp 0x108a1
jmp 0x108a1
jmp 0x108a1
jmp 0x108a1
movq %rax, %rbx
movq 0x188(%rsp), %rdi
callq 0x93c0
movq 0x1a0(%rsp), %rdi
callq 0x93c0
movq 0x1b8(%rsp), %rdi
callq 0x93c0
movq 0x1d0(%rsp), %rdi
callq 0x93c0
movq 0xd8(%rsp), %rdi
callq 0x93c0
movq 0x68(%rsp), %rdi
callq 0x93c0
movq 0xa0(%rsp), %rdi
callq 0x93c0
jmp 0x10930
movq %rax, %rbx
jmp 0x108b1
movq %rax, %rbx
jmp 0x108be
jmp 0x1090a
movq %rax, %rbx
jmp 0x108cb
movq %rax, %rbx
jmp 0x108d8
movq %rax, %rbx
jmp 0x108e5
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
jmp 0x1092d
movq %rax, %rbx
movq (%rsp), %rdi
callq 0x93c0
movq %rbx, %rdi
callq 0x9640
nop