// File: /workspace/github_cpp_makefile_star2_O2/js850[P]lbfgs_cpp/lbfgs.cpp
// Function: LBFGS_ns::LBFGS::LBFGS(double (*)(double*, double*, unsigned long), double const*, unsigned long, int)
LBFGS::LBFGS(
    double (*func)(double *, double *, size_t), 
    double const * x0, 
    size_t N, 
    int M
    //double tol,
    //double maxstep,
    //double max_f_rise,
    //double H0,
    //int maxiter
    )
  :
    func_f_grad_(func),
    M_(M),
    tol_(1e-4),
    maxstep_(0.2),
    max_f_rise_(1e-4),
    maxiter_(1000),
    iprint_(-1),
    iter_number_(0),
    nfev_(0),
    H0_(0.1),
    k_(0)
{
  // set the precision of the printing
  cout << std::setprecision(12);

  // allocate arrays
  x_ = std::vector<double>(N);
  g_ = std::vector<double>(N);

  y_ = std::vector<vector<double> >(M_, vector<double>(N));
  s_ = std::vector<vector<double> >(M_, vector<double>(N));
  rho_ = std::vector<double>(M_);
  step_ = std::vector<double>(N);

  for (size_t j2 = 0; j2 < N; ++j2){
    x_[j2] = x0[j2];
  }
  compute_func_gradient(x_, f_, g_);
  rms_ = vecnorm(g_) / sqrt(N);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x88, %rsp
movq %rcx, %r13
movq %rdx, %r15
movq %rdi, %r12
movq %rsi, (%rdi)
movl %r8d, 0x8(%rdi)
movabsq $0x3f1a36e2eb1c432d, %rax # imm = 0x3F1A36E2EB1C432D
movq %rax, 0x10(%rdi)
movabsq $0x3fc999999999999a, %rcx # imm = 0x3FC999999999999A
movq %rcx, 0x18(%rdi)
movq %rax, 0x20(%rdi)
movl $0x3e8, 0x28(%rdi)      # imm = 0x3E8
orl $-0x1, 0x2c(%rdi)
leaq 0x38(%rdi), %r14
leaq 0x58(%rdi), %rax
movq %rax, -0x90(%rbp)
andq $0x0, 0x68(%rdi)
xorpd %xmm0, %xmm0
movupd %xmm0, 0x58(%rdi)
leaq 0x78(%rdi), %rax
movq %rax, -0x80(%rbp)
leaq 0x90(%rdi), %rax
movq %rax, -0x88(%rbp)
leaq 0xa8(%rdi), %rax
movq %rax, -0x78(%rbp)
movupd %xmm0, 0x30(%rdi)
movupd %xmm0, 0x40(%rdi)
movupd %xmm0, 0x78(%rdi)
movupd %xmm0, 0x88(%rdi)
andq $0x0, 0xb8(%rdi)
movupd %xmm0, 0x98(%rdi)
movupd %xmm0, 0xa8(%rdi)
movabsq $0x3fb999999999999a, %rax # imm = 0x3FB999999999999A
movq %rax, 0xc0(%rdi)
andl $0x0, 0xc8(%rdi)
leaq 0xd0(%rdi), %rax
movq %rax, -0x68(%rbp)
movupd %xmm0, 0xd0(%rdi)
andq $0x0, 0xe0(%rdi)
movq 0x3666(%rip), %rax      # 0x4fd8
movq (%rax), %rcx
movq -0x18(%rcx), %rcx
movq $0xc, 0x8(%rax,%rcx)
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r13, %rsi
movq %r14, -0x70(%rbp)
callq 0x151e
leaq -0x60(%rbp), %rbx
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2828
movq %rbx, %rdi
callq 0x1666
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r13, %rsi
callq 0x151e
movq -0x90(%rbp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0x2828
movq %rbx, %rdi
callq 0x1666
movslq 0x8(%r12), %rbx
leaq -0x48(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
movq %r13, %rsi
callq 0x151e
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
leaq -0x29(%rbp), %rcx
movq %rbx, %rsi
callq 0x26f4
leaq -0x60(%rbp), %rbx
movq -0x88(%rbp), %rdi
movq %rbx, %rsi
callq 0x29be
movq %rbx, %rdi
callq 0x15c2
leaq -0x48(%rbp), %rdi
callq 0x1666
movslq 0x8(%r12), %rbx
leaq -0x48(%rbp), %rdi
leaq -0x2a(%rbp), %rdx
movq %r13, %rsi
callq 0x151e
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
leaq -0x29(%rbp), %rcx
movq %rbx, %rsi
callq 0x26f4
leaq -0x60(%rbp), %rbx
movq -0x80(%rbp), %rdi
movq %rbx, %rsi
callq 0x29be
movq %rbx, %rdi
callq 0x15c2
leaq -0x48(%rbp), %rdi
callq 0x1666
movslq 0x8(%r12), %rsi
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
callq 0x151e
movq -0x78(%rbp), %rdi
movq %rbx, %rsi
callq 0x2828
movq %rbx, %rdi
callq 0x1666
leaq -0x60(%rbp), %rdi
leaq -0x48(%rbp), %rdx
movq %r13, %rsi
callq 0x151e
movq -0x68(%rbp), %rdi
movq %rbx, %rsi
callq 0x2828
movq %rbx, %rdi
callq 0x1666
movq -0x70(%rbp), %rsi
movq (%rsi), %rax
xorl %ecx, %ecx
cmpq %rcx, %r13
je 0x1ad6
movsd (%r15,%rcx,8), %xmm0
movsd %xmm0, (%rax,%rcx,8)
incq %rcx
jmp 0x1ac1
leaq 0x50(%r12), %rdx
movq %r12, %rdi
movq %r14, %rcx
callq 0x1bbe
leaq -0xa8(%rbp), %rdi
movq %r14, %rsi
callq 0x269c
leaq -0xa8(%rbp), %rdi
callq 0x17fe
movq %r13, %xmm1
punpckldq 0x1562(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x156a(%rip), %xmm1     # 0x3080
movapd %xmm1, %xmm2
unpckhpd %xmm1, %xmm2            # xmm2 = xmm2[1],xmm1[1]
addsd %xmm1, %xmm2
sqrtsd %xmm2, %xmm1
divsd %xmm1, %xmm0
movsd %xmm0, 0x70(%r12)
leaq -0xa8(%rbp), %rdi
callq 0x1666
addq $0x88, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %r15
leaq -0xa8(%rbp), %rdi
jmp 0x1b6a
jmp 0x1b77
jmp 0x1b77
jmp 0x1b63
jmp 0x1b77
movq %rax, %r15
leaq -0x48(%rbp), %rdi
callq 0x1666
jmp 0x1b7a
jmp 0x1b77
jmp 0x1b77
jmp 0x1b77
movq %rax, %r15
movq -0x68(%rbp), %rdi
callq 0x1666
movq -0x78(%rbp), %rdi
callq 0x1666
movq -0x88(%rbp), %rdi
callq 0x15c2
movq -0x80(%rbp), %rdi
callq 0x15c2
movq -0x90(%rbp), %rdi
callq 0x1666
movq -0x70(%rbp), %rdi
callq 0x1666
movq %r15, %rdi
callq 0x1150