// File: /workspace/github_cpp_makefile_star2_O2/redpony[P]libpopt/optimize_test.cc
// Function: TestPersistentOptimizer(Optimizer*)
double TestPersistentOptimizer(Optimizer* opt) {
  cerr << "\nTESTING PERSISTENT OPTIMIZER\n";
  // f(x,y) = 4x1^2 + x1*x2 + x2^2 + x3^2 + 6x3 + 5
  // df/dx1 = 8*x1 + x2
  // df/dx2 = 2*x2 + x1
  // df/dx3 = 2*x3 + 6
  vector<double> x(3);
  vector<double> g(3);
  x[0] = 8;
  x[1] = 8;
  x[2] = 8;
  double obj = 0;
  string state;
  bool converged = false;
  while (!converged) {
    g[0] = 8 * x[0] + x[1];
    g[1] = 2 * x[1] + x[0];
    g[2] = 2 * x[2] + 6;
    obj = 4 * x[0]*x[0] + x[0] * x[1] + x[1]*x[1] + x[2]*x[2] + 6 * x[2] + 5;

    {
      if (state.size() > 0) {
        istringstream is(state, ios::binary);
        opt->Load(&is);
      }
      opt->Optimize(obj, g, &x);
      ostringstream os(ios::binary); opt->Save(&os); state = os.str();

    }

    cerr << x[0] << " " << x[1] << " " << x[2] << endl;
    cerr << "   obj=" << obj << "\td/dx1=" << g[0] << " d/dx2=" << g[1] << " d/dx3=" << g[2] << endl;
    converged = opt->HasConverged();
    if (!converged) {
      // now screw up the state (should be undone by Load)
      obj += 2.0;
      g[1] = -g[2];
      vector<double> x2 = x;
      try {
        opt->Optimize(obj, g, &x2);
      } catch (...) { }
    }
  }
  return obj;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x208, %rsp            # imm = 0x208
movq %rdi, %rbx
movq 0x88dc(%rip), %rdi      # 0xbff0
leaq 0x49bf(%rip), %rsi      # 0x80da
callq 0x3190
leaq 0x10(%rsp), %rdi
pushq $0x3
popq %r14
leaq 0x88(%rsp), %rdx
movq %r14, %rsi
callq 0x3aec
leaq 0x28(%rsp), %rdi
leaq 0x88(%rsp), %rdx
movq %r14, %rsi
callq 0x3aec
leaq 0x10(%rsp), %rax
movq (%rax), %rax
movapd 0x48b2(%rip), %xmm0     # 0x8010
movupd %xmm0, (%rax)
movabsq $0x4020000000000000, %rcx # imm = 0x4020000000000000
movq %rcx, 0x10(%rax)
leaq 0x8(%rsp), %rcx
andq $0x0, (%rcx)
leaq 0x58(%rsp), %rcx
movq %rcx, -0x10(%rcx)
andq $0x0, -0x8(%rcx)
movb $0x0, (%rcx)
xorl %ecx, %ecx
leaq 0x28(%rsp), %r13
leaq 0x88(%rsp), %rbp
leaq 0x68(%rsp), %r12
movq 0x884b(%rip), %r14      # 0xbff0
leaq 0x4b0e(%rip), %r15      # 0x82ba
movsd (%rax), %xmm0
mulsd 0x4878(%rip), %xmm0     # 0x8030
addsd 0x8(%rax), %xmm0
movq 0x28(%rsp), %rdx
movsd %xmm0, (%rdx)
movsd 0x8(%rax), %xmm0
addsd %xmm0, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x8(%rdx)
movsd 0x10(%rax), %xmm0
addsd %xmm0, %xmm0
movsd 0x484f(%rip), %xmm3     # 0x8038
addsd %xmm3, %xmm0
movsd %xmm0, 0x10(%rdx)
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movapd %xmm0, %xmm2
mulsd 0x4839(%rip), %xmm2     # 0x8040
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%rax), %xmm0
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
addsd 0x480c(%rip), %xmm0     # 0x8048
movsd %xmm0, 0x8(%rsp)
testq %rcx, %rcx
je 0x386a
movq %rbp, %rdi
leaq 0x48(%rsp), %rsi
pushq $0x4
popq %rdx
callq 0x32b0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4a30
movq %rbp, %rdi
callq 0x30b0
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
leaq 0x10(%rsp), %rcx
callq 0x3b3e
movq %rbp, %rdi
pushq $0x4
popq %rsi
callq 0x3160
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x49d2
movq %r12, %rdi
leaq 0x90(%rsp), %rsi
callq 0x3250
leaq 0x48(%rsp), %rdi
movq %r12, %rsi
callq 0x31d0
movq %r12, %rdi
callq 0x30a0
movq %rbp, %rdi
callq 0x3040
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq %r14, %rdi
callq 0x3270
movq %rax, %rdi
movq %r15, %rsi
callq 0x3190
movq 0x10(%rsp), %rcx
movsd 0x8(%rcx), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
movq %r15, %rsi
callq 0x3190
movq 0x10(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
callq 0x30c0
movq %r14, %rdi
leaq 0x479b(%rip), %rsi      # 0x80ba
callq 0x3190
movsd 0x8(%rsp), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
leaq 0x4786(%rip), %rsi      # 0x80c2
callq 0x3190
movq 0x28(%rsp), %rcx
movsd (%rcx), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
leaq 0x476e(%rip), %rsi      # 0x80ca
callq 0x3190
movq 0x28(%rsp), %rcx
movsd 0x8(%rcx), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
leaq 0x4755(%rip), %rsi      # 0x80d2
callq 0x3190
movq 0x28(%rsp), %rcx
movsd 0x10(%rcx), %xmm0
movq %rax, %rdi
callq 0x3270
movq %rax, %rdi
callq 0x30c0
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0xc(%rbx)
jne 0x3a13
addsd 0x46a8(%rip), %xmm0     # 0x8058
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rax
movsd 0x10(%rax), %xmm0
xorpd 0x4658(%rip), %xmm0     # 0x8020
movlpd %xmm0, 0x8(%rax)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3bc8
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
movq %r13, %rdx
movq %rbp, %rcx
callq 0x3b3e
movq %rbp, %rdi
callq 0x4682
movq 0x10(%rsp), %rax
movq 0x50(%rsp), %rcx
jmp 0x37ac
movq %rax, %rdi
callq 0x3080
callq 0x3290
jmp 0x39ed
leaq 0x48(%rsp), %rdi
movsd %xmm0, 0x40(%rsp)
callq 0x30a0
leaq 0x28(%rsp), %rdi
callq 0x4682
leaq 0x10(%rsp), %rdi
callq 0x4682
movsd 0x40(%rsp), %xmm0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x4682
jmp 0x3a95
movq %rax, %rbx
jmp 0x3aa9
jmp 0x3a92
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x30b0
jmp 0x3a95
jmp 0x3a92
jmp 0x3a92
jmp 0x3a80
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
callq 0x3040
jmp 0x3a95
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x30a0
leaq 0x28(%rsp), %rdi
callq 0x4682
leaq 0x10(%rsp), %rdi
callq 0x4682
movq %rbx, %rdi
callq 0x32e0