// File: /workspace/github_cpp_makefile_star2_O3/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 0x97da(%rip), %rdi      # 0xcff0
leaq 0x58ed(%rip), %rsi      # 0x910a
movl $0x1e, %edx
callq 0x31f0
movl $0x18, %edi
callq 0x31c0
movq %rax, %r12
movq %rax, 0x10(%rsp)
addq $0x18, %rax
movq %rax, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%r12)
movq $0x0, 0x10(%r12)
movq %rax, 0x18(%rsp)
movl $0x18, %edi
callq 0x31c0
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, %rdx
addq $0x18, %rdx
movq %rdx, 0x10(%rsi)
xorl %ecx, %ecx
movq %rcx, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rdx, 0x8(%rsi)
movaps 0x5780(%rip), %xmm0     # 0x9010
movups %xmm0, (%r12)
movabsq $0x4020000000000000, %rdx # imm = 0x4020000000000000
movq %rdx, 0x10(%r12)
leaq 0x8(%rsp), %rdx
movq %rcx, (%rdx)
leaq 0x58(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq %rcx, -0x8(%rdx)
movb $0x0, (%rdx)
movsd 0x579c(%rip), %xmm0     # 0x9060
leaq 0x88(%rsp), %r15
leaq 0x68(%rsp), %rbp
movq 0x9718(%rip), %r13      # 0xcff0
leaq 0x5a0b(%rip), %r14      # 0x92ea
movapd %xmm0, %xmm1
mulsd 0x5775(%rip), %xmm0     # 0x9060
addsd %xmm1, %xmm0
movsd %xmm0, (%rax)
movsd 0x8(%r12), %xmm0
addsd %xmm0, %xmm0
addsd (%r12), %xmm0
movsd %xmm0, 0x8(%rax)
movsd 0x10(%r12), %xmm0
addsd %xmm0, %xmm0
movsd 0x574c(%rip), %xmm3     # 0x9068
addsd %xmm3, %xmm0
movsd %xmm0, 0x10(%rax)
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movapd %xmm0, %xmm2
mulsd 0x5732(%rip), %xmm2     # 0x9070
mulsd %xmm0, %xmm2
mulsd %xmm1, %xmm0
addsd %xmm2, %xmm0
mulsd %xmm1, %xmm1
addsd %xmm0, %xmm1
movsd 0x10(%r12), %xmm0
movapd %xmm0, %xmm2
mulsd %xmm0, %xmm2
addsd %xmm1, %xmm2
mulsd %xmm3, %xmm0
addsd %xmm2, %xmm0
addsd 0x5703(%rip), %xmm0     # 0x9078
movsd %xmm0, 0x8(%rsp)
testq %rcx, %rcx
je 0x39b9
movq %r15, %rdi
leaq 0x48(%rsp), %rsi
movl $0x4, %edx
callq 0x32d0
movq %rbx, %rdi
movq %r15, %rsi
callq 0x5026
movq %r15, %rdi
movq 0x9621(%rip), %rsi      # 0xcfc8
callq 0x3250
leaq 0x100(%rsp), %rdi
callq 0x3070
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x3daa
movq %r15, %rdi
movl $0x4, %esi
callq 0x3190
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4fce
movq %rbp, %rdi
leaq 0x90(%rsp), %rsi
callq 0x3280
leaq 0x48(%rsp), %rdi
movq %rbp, %rsi
callq 0x3210
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rax
cmpq %rax, %rdi
je 0x3a21
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %r15, %rdi
movq 0x95a5(%rip), %rsi      # 0xcfd0
callq 0x30f0
leaq 0xf8(%rsp), %rdi
callq 0x3070
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq %r13, %rdi
callq 0x3290
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x31f0
movq 0x10(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %r12, %rdi
callq 0x3290
movq %rax, %r12
movl $0x1, %edx
movq %rax, %rdi
movq %r14, %rsi
callq 0x31f0
movq 0x10(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq %r12, %rdi
callq 0x3290
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movl $0x7, %edx
movq %r13, %rdi
leaq 0x5619(%rip), %rsi      # 0x90ea
callq 0x31f0
movsd 0x8(%rsp), %xmm0
movq %r13, %rdi
callq 0x3290
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x55fc(%rip), %rsi      # 0x90f2
callq 0x31f0
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movq %r12, %rdi
callq 0x3290
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x55dc(%rip), %rsi      # 0x90fa
callq 0x31f0
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %r12, %rdi
callq 0x3290
movq %rax, %r12
movl $0x7, %edx
movq %rax, %rdi
leaq 0x55bb(%rip), %rsi      # 0x9102
callq 0x31f0
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq %r12, %rdi
callq 0x3290
movq %rax, %r12
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r12, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r12, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0xc(%rbx)
jne 0x3c2c
addsd 0x54e8(%rip), %xmm0     # 0x9088
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
xorpd 0x5478(%rip), %xmm0     # 0x9030
movlpd %xmm0, 0x8(%rax)
movq %r15, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e36
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %r15, %rcx
callq 0x3daa
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3bfc
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movq 0x10(%rsp), %r12
movsd (%r12), %xmm0
movsd 0x8(%r12), %xmm1
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rcx
jmp 0x38e3
movq %rax, %rdi
callq 0x3090
callq 0x32b0
jmp 0x3bdf
movq 0x48(%rsp), %rdi
leaq 0x58(%rsp), %rax
cmpq %rax, %rdi
movsd %xmm0, 0x28(%rsp)
je 0x3c54
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31d0
movsd 0x28(%rsp), %xmm0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3c71
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movsd 0x28(%rsp), %xmm0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3c8e
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movsd 0x28(%rsp), %xmm0
addq $0x208, %rsp            # imm = 0x208
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x3d1c
movq 0x98(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
jmp 0x3d1c
movq %rax, %rbx
jmp 0x3d4f
jmp 0x3d19
movq %rax, %rbx
movq 0x92f2(%rip), %rsi      # 0xcfc8
leaq 0x88(%rsp), %rdi
callq 0x3250
leaq 0x100(%rsp), %rdi
jmp 0x3d12
jmp 0x3d19
jmp 0x3d19
jmp 0x3cf3
movq %rax, %rbx
movq 0x92d3(%rip), %rsi      # 0xcfd0
leaq 0x88(%rsp), %rdi
callq 0x30f0
leaq 0xf8(%rsp), %rdi
callq 0x3070
jmp 0x3d1c
movq %rax, %rbx
leaq 0x58(%rsp), %rax
movq 0x48(%rsp), %rdi
cmpq %rax, %rdi
je 0x3d38
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3d4f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3d66
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movq %rbx, %rdi
callq 0x3300