// File: 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
movq %rsp, %rbp
subq $0xa40, %rsp            # imm = 0xA40
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rdx
movq %rdx, -0x8f0(%rbp)
movq %rdx, %rsi
addq $0x1e0, %rsi            # imm = 0x1E0
addq $0x1f0, %rdx            # imm = 0x1F0
leaq -0x30(%rbp), %rdi
callq 0x27be0
leaq -0x18(%rbp), %rdi
leaq -0x30(%rbp), %rsi
callq 0x27c50
movq $0x0, -0x38(%rbp)
movq -0x8f0(%rbp), %rdi
movq -0x38(%rbp), %rax
movq %rax, -0x900(%rbp)
addq $0x1e0, %rdi            # imm = 0x1E0
callq 0x14700
movq %rax, -0x8f8(%rbp)
jmp 0x20de0
movq -0x900(%rbp), %rax
movq -0x8f8(%rbp), %rcx
cmpq %rcx, %rax
jge 0x2108b
movq -0x38(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x26650
movq %rax, -0x908(%rbp)
jmp 0x20e0d
movq -0x908(%rbp), %rax
movsd (%rax), %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jne 0x20e28
jp 0x20e28
jmp 0x21078
movq -0x38(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x26650
movq %rax, -0x910(%rbp)
jmp 0x20e3e
movq -0x8f0(%rbp), %rsi
addq $0xa8, %rsi
movq -0x38(%rbp), %rdx
leaq -0x1b0(%rbp), %rdi
callq 0x269c0
jmp 0x20e5e
leaq -0x178(%rbp), %rdi
leaq -0x1b0(%rbp), %rsi
callq 0x27d30
jmp 0x20e73
movq -0x910(%rbp), %rsi
leaq -0x140(%rbp), %rdi
leaq -0x178(%rbp), %rdx
callq 0x27c90
jmp 0x20e8f
movq -0x8f0(%rbp), %rsi
addq $0xa8, %rsi
movq -0x38(%rbp), %rdx
leaq -0x1e8(%rbp), %rdi
callq 0x269c0
jmp 0x20eaf
leaq -0xe0(%rbp), %rdi
leaq -0x140(%rbp), %rsi
leaq -0x1e8(%rbp), %rdx
callq 0x27d70
jmp 0x20ecb
movq -0x8f0(%rbp), %rdi
addq $0x1a0, %rdi            # imm = 0x1A0
leaq -0xe0(%rbp), %rsi
callq 0x27dc0
jmp 0x20ee7
movq -0x38(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x26650
movq %rax, -0x918(%rbp)
jmp 0x20efd
movq -0x8f0(%rbp), %rsi
addq $0xa8, %rsi
movq -0x38(%rbp), %rdx
leaq -0x350(%rbp), %rdi
callq 0x269c0
jmp 0x20f1d
leaq -0x318(%rbp), %rdi
leaq -0x350(%rbp), %rsi
callq 0x27d30
jmp 0x20f32
movq -0x918(%rbp), %rsi
leaq -0x2e0(%rbp), %rdi
leaq -0x318(%rbp), %rdx
callq 0x27c90
jmp 0x20f4e
movq -0x8f0(%rbp), %rsi
addq $0xc0, %rsi
movq -0x38(%rbp), %rdx
leaq -0x388(%rbp), %rdi
callq 0x269c0
jmp 0x20f6e
leaq -0x280(%rbp), %rdi
leaq -0x2e0(%rbp), %rsi
leaq -0x388(%rbp), %rdx
callq 0x27d70
jmp 0x20f8a
movq -0x8f0(%rbp), %rdi
addq $0x188, %rdi            # imm = 0x188
leaq -0x280(%rbp), %rsi
callq 0x27dc0
jmp 0x20fa6
movq -0x38(%rbp), %rsi
leaq -0x18(%rbp), %rdi
callq 0x26650
movq %rax, -0x920(%rbp)
jmp 0x20fbc
movq -0x8f0(%rbp), %rsi
addq $0xc0, %rsi
movq -0x38(%rbp), %rdx
leaq -0x4f0(%rbp), %rdi
callq 0x269c0
jmp 0x20fdc
leaq -0x4b8(%rbp), %rdi
leaq -0x4f0(%rbp), %rsi
callq 0x27d30
jmp 0x20ff1
movq -0x920(%rbp), %rsi
leaq -0x480(%rbp), %rdi
leaq -0x4b8(%rbp), %rdx
callq 0x27c90
jmp 0x2100d
movq -0x8f0(%rbp), %rsi
addq $0xc0, %rsi
movq -0x38(%rbp), %rdx
leaq -0x528(%rbp), %rdi
callq 0x269c0
jmp 0x2102d
leaq -0x420(%rbp), %rdi
leaq -0x480(%rbp), %rsi
leaq -0x528(%rbp), %rdx
callq 0x27d70
jmp 0x21049
movq -0x8f0(%rbp), %rdi
addq $0x1b8, %rdi            # imm = 0x1B8
leaq -0x420(%rbp), %rsi
callq 0x27dc0
jmp 0x21065
jmp 0x21078
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x21924
jmp 0x2107a
movq -0x38(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x38(%rbp)
jmp 0x20db9
movq -0x8f0(%rbp), %rsi
movq %rsi, %rdi
addq $0x128, %rdi            # imm = 0x128
addq $0xe0, %rsi
callq 0x26bd0
movq %rdx, -0x930(%rbp)
movq %rax, -0x928(%rbp)
jmp 0x210b8
movq -0x8f0(%rbp), %rdi
movq -0x930(%rbp), %rax
movq -0x928(%rbp), %rcx
movq %rcx, -0x568(%rbp)
movq %rax, -0x560(%rbp)
addq $0x128, %rdi            # imm = 0x128
callq 0x26900
movq %rax, -0x938(%rbp)
jmp 0x210f0
movq -0x938(%rbp), %rax
movq %rax, -0x570(%rbp)
leaq -0x558(%rbp), %rdi
leaq -0x568(%rbp), %rsi
leaq -0x570(%rbp), %rdx
callq 0x26c20
jmp 0x2111a
leaq -0x540(%rbp), %rdi
leaq -0x558(%rbp), %rsi
callq 0x26c70
jmp 0x2112f
movq -0x8f0(%rbp), %rdi
addq $0xe0, %rdi
callq 0x26850
movq %rax, -0x940(%rbp)
jmp 0x2114b
movq -0x8f0(%rbp), %rdi
movq -0x940(%rbp), %rax
movq %rax, -0x590(%rbp)
addq $0xe0, %rdi
callq 0x26800
movq %rax, -0x948(%rbp)
jmp 0x21175
movq -0x948(%rbp), %rax
movq %rax, -0x598(%rbp)
leaq -0x588(%rbp), %rdi
leaq -0x590(%rbp), %rsi
leaq -0x598(%rbp), %rdx
callq 0x26cb0
jmp 0x2119f
leaq -0x588(%rbp), %rdi
callq 0x26d20
jmp 0x211ad
leaq -0x5a8(%rbp), %rdi
leaq -0x540(%rbp), %rsi
callq 0x26d50
jmp 0x211c2
leaq -0x5b8(%rbp), %rdi
leaq -0x588(%rbp), %rsi
callq 0x26d50
jmp 0x211d7
leaq -0x5b8(%rbp), %rdi
leaq -0x5a8(%rbp), %rsi
callq 0x26d90
jmp 0x211ec
leaq -0x540(%rbp), %rdi
callq 0x26dc0
movq %rax, -0x950(%rbp)
jmp 0x21201
movq -0x950(%rbp), %rax
movq %rax, -0x5d8(%rbp)
leaq -0x5d0(%rbp), %rdi
leaq -0x5d8(%rbp), %rsi
callq 0x26df0
jmp 0x21224
movq -0x8f0(%rbp), %rsi
movq %rsi, %rdi
addq $0x128, %rdi            # imm = 0x128
addq $0x188, %rsi            # imm = 0x188
callq 0x26bd0
movq %rdx, -0x960(%rbp)
movq %rax, -0x958(%rbp)
jmp 0x21251
movq -0x8f0(%rbp), %rdi
movq -0x960(%rbp), %rax
movq -0x958(%rbp), %rcx
movq %rcx, -0x618(%rbp)
movq %rax, -0x610(%rbp)
addq $0x128, %rdi            # imm = 0x128
callq 0x26900
movq %rax, -0x968(%rbp)
jmp 0x21289
movq -0x968(%rbp), %rax
movq %rax, -0x620(%rbp)
leaq -0x608(%rbp), %rdi
leaq -0x618(%rbp), %rsi
leaq -0x620(%rbp), %rdx
callq 0x26c20
jmp 0x212b3
leaq -0x5f0(%rbp), %rdi
leaq -0x608(%rbp), %rsi
callq 0x26c70
jmp 0x212c8
leaq -0x638(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
leaq -0x5f0(%rbp), %rdx
callq 0x27e20
jmp 0x212e4
leaq -0x5d0(%rbp), %rdi
leaq -0x638(%rbp), %rsi
callq 0x27e90
jmp 0x212f9
movq -0x8f0(%rbp), %rsi
movq %rsi, %rdi
addq $0x128, %rdi            # imm = 0x128
addq $0x1b8, %rsi            # imm = 0x1B8
callq 0x26bd0
movq %rdx, -0x978(%rbp)
movq %rax, -0x970(%rbp)
jmp 0x21326
movq -0x8f0(%rbp), %rdi
movq -0x978(%rbp), %rax
movq -0x970(%rbp), %rcx
movq %rcx, -0x678(%rbp)
movq %rax, -0x670(%rbp)
addq $0x128, %rdi            # imm = 0x128
callq 0x26900
movq %rax, -0x980(%rbp)
jmp 0x2135e
movq -0x980(%rbp), %rax
movq %rax, -0x680(%rbp)
leaq -0x668(%rbp), %rdi
leaq -0x678(%rbp), %rsi
leaq -0x680(%rbp), %rdx
callq 0x26c20
jmp 0x21388
leaq -0x650(%rbp), %rdi
leaq -0x668(%rbp), %rsi
callq 0x26c70
jmp 0x2139d
movq -0x8f0(%rbp), %rsi
movq %rsi, %rdi
addq $0x128, %rdi            # imm = 0x128
addq $0xf8, %rsi
callq 0x26bd0
movq %rdx, -0x990(%rbp)
movq %rax, -0x988(%rbp)
jmp 0x213ca
movq -0x8f0(%rbp), %rdi
movq -0x990(%rbp), %rax
movq -0x988(%rbp), %rcx
movq %rcx, -0x6c0(%rbp)
movq %rax, -0x6b8(%rbp)
addq $0x128, %rdi            # imm = 0x128
callq 0x26900
movq %rax, -0x998(%rbp)
jmp 0x21402
movq -0x998(%rbp), %rax
movq %rax, -0x6c8(%rbp)
leaq -0x6b0(%rbp), %rdi
leaq -0x6c0(%rbp), %rsi
leaq -0x6c8(%rbp), %rdx
callq 0x26c20
jmp 0x2142c
leaq -0x698(%rbp), %rdi
leaq -0x6b0(%rbp), %rsi
callq 0x26c70
jmp 0x21441
movq -0x8f0(%rbp), %rsi
movq %rsi, %rdi
addq $0x128, %rdi            # imm = 0x128
addq $0x1a0, %rsi            # imm = 0x1A0
callq 0x26bd0
movq %rdx, -0x9a8(%rbp)
movq %rax, -0x9a0(%rbp)
jmp 0x2146e
movq -0x8f0(%rbp), %rdi
movq -0x9a8(%rbp), %rax
movq -0x9a0(%rbp), %rcx
movq %rcx, -0x708(%rbp)
movq %rax, -0x700(%rbp)
addq $0x128, %rdi            # imm = 0x128
callq 0x26900
movq %rax, -0x9b0(%rbp)
jmp 0x214a6
movq -0x9b0(%rbp), %rax
movq %rax, -0x710(%rbp)
leaq -0x6f8(%rbp), %rdi
leaq -0x708(%rbp), %rsi
leaq -0x710(%rbp), %rdx
callq 0x26c20
jmp 0x214d0
leaq -0x6e0(%rbp), %rdi
leaq -0x6f8(%rbp), %rsi
callq 0x26c70
jmp 0x214e5
leaq -0x588(%rbp), %rdi
callq 0x26850
movq %rax, -0x9b8(%rbp)
jmp 0x214fa
movq -0x9b8(%rbp), %rax
addq %rax, %rax
movq %rax, -0x9c8(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x26800
movq %rax, -0x9c0(%rbp)
jmp 0x21520
movq -0x9c8(%rbp), %rsi
movq -0x9c0(%rbp), %rdx
addq %rdx, %rdx
leaq -0x728(%rbp), %rdi
callq 0x27aa0
jmp 0x2153f
movq -0x8f0(%rbp), %rdi
addq $0x140, %rdi            # imm = 0x140
leaq -0x728(%rbp), %rsi
callq 0x27ae0
jmp 0x2155b
leaq -0x780(%rbp), %rdi
leaq -0x588(%rbp), %rsi
callq 0x270a0
jmp 0x21570
movq -0x8f0(%rbp), %rdx
addq $0xd8, %rdx
leaq -0x7a8(%rbp), %rdi
leaq -0x650(%rbp), %rsi
callq 0x27f30
jmp 0x21593
leaq -0x770(%rbp), %rdi
leaq -0x780(%rbp), %rsi
leaq -0x7a8(%rbp), %rdx
callq 0x27ec0
jmp 0x215af
movq -0x8f0(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x9d8(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x26850
movq %rax, -0x9d0(%rbp)
jmp 0x215d8
leaq -0x588(%rbp), %rdi
callq 0x26800
movq %rax, -0x9e0(%rbp)
jmp 0x215ed
movq -0x9e0(%rbp), %rcx
movq -0x9d0(%rbp), %rdx
movq -0x9d8(%rbp), %rsi
leaq -0x7e0(%rbp), %rdi
callq 0x26ed0
jmp 0x21610
leaq -0x7e0(%rbp), %rdi
leaq -0x770(%rbp), %rsi
callq 0x27fe0
jmp 0x21625
leaq -0x5d0(%rbp), %rdi
callq 0x26900
movq %rax, -0x9e8(%rbp)
jmp 0x2163a
movq -0x8f0(%rbp), %rax
movq -0x9e8(%rbp), %rcx
movq %rcx, -0x7e8(%rbp)
addq $0x140, %rax            # imm = 0x140
movq %rax, -0x9f8(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x26850
movq %rax, -0x9f0(%rbp)
jmp 0x21671
leaq -0x588(%rbp), %rdi
callq 0x26800
movq %rax, -0xa00(%rbp)
jmp 0x21686
movq -0xa00(%rbp), %rcx
movq -0x9f0(%rbp), %rdx
movq -0x9f8(%rbp), %rsi
leaq -0x820(%rbp), %rdi
callq 0x26f60
jmp 0x216a9
leaq -0x820(%rbp), %rdi
leaq -0x7e8(%rbp), %rsi
callq 0x27060
jmp 0x216be
movq -0x8f0(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0xa10(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x26850
movq %rax, -0xa08(%rbp)
jmp 0x216e7
leaq -0x588(%rbp), %rdi
callq 0x26800
movq %rax, -0xa18(%rbp)
jmp 0x216fc
movq -0xa18(%rbp), %rcx
movq -0xa08(%rbp), %rdx
movq -0xa10(%rbp), %rsi
leaq -0x858(%rbp), %rdi
callq 0x27000
jmp 0x2171f
leaq -0x858(%rbp), %rdi
leaq -0x5d0(%rbp), %rsi
callq 0x26fc0
jmp 0x21734
movq -0x8f0(%rbp), %rax
addq $0xd8, %rax
movq %rax, -0xa20(%rbp)
leaq -0x8b0(%rbp), %rdi
leaq -0x698(%rbp), %rsi
leaq -0x6e0(%rbp), %rdx
callq 0x27e20
jmp 0x21764
movq -0xa20(%rbp), %rsi
leaq -0x898(%rbp), %rdi
leaq -0x8b0(%rbp), %rdx
callq 0x28020
jmp 0x21780
movq -0x8f0(%rbp), %rax
addq $0x140, %rax            # imm = 0x140
movq %rax, -0xa30(%rbp)
leaq -0x588(%rbp), %rdi
callq 0x26850
movq %rax, -0xa28(%rbp)
jmp 0x217a9
leaq -0x588(%rbp), %rdi
callq 0x26800
movq %rax, -0xa38(%rbp)
jmp 0x217be
movq -0xa38(%rbp), %rcx
movq -0xa28(%rbp), %rdx
movq -0xa30(%rbp), %rsi
leaq -0x8e8(%rbp), %rdi
callq 0x270f0
jmp 0x217e1
leaq -0x8e8(%rbp), %rdi
leaq -0x898(%rbp), %rsi
callq 0x280c0
jmp 0x217f6
movq -0x8f0(%rbp), %rdi
callq 0x20720
jmp 0x21804
leaq -0x6e0(%rbp), %rdi
callq 0x1ae20
leaq -0x698(%rbp), %rdi
callq 0x1ae20
leaq -0x650(%rbp), %rdi
callq 0x1ae20
leaq -0x5f0(%rbp), %rdi
callq 0x1ae20
leaq -0x5d0(%rbp), %rdi
callq 0x1ae20
leaq -0x588(%rbp), %rdi
callq 0x1ae20
leaq -0x540(%rbp), %rdi
callq 0x1ae20
leaq -0x18(%rbp), %rdi
callq 0xff40
addq $0xa40, %rsp            # imm = 0xA40
popq %rbp
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x21918
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x2190c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x21900
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x218f4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x218e8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
jmp 0x218dc
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x40(%rbp)
movl %eax, -0x44(%rbp)
leaq -0x6e0(%rbp), %rdi
callq 0x1ae20
leaq -0x698(%rbp), %rdi
callq 0x1ae20
leaq -0x650(%rbp), %rdi
callq 0x1ae20
leaq -0x5f0(%rbp), %rdi
callq 0x1ae20
leaq -0x5d0(%rbp), %rdi
callq 0x1ae20
leaq -0x588(%rbp), %rdi
callq 0x1ae20
leaq -0x540(%rbp), %rdi
callq 0x1ae20
leaq -0x18(%rbp), %rdi
callq 0xff40
movq -0x40(%rbp), %rdi
callq 0xa7c0
nopw %cs:(%rax,%rax)