// File: /workspace/github_cpp_makefile_star2_O1/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 $0x218, %rsp            # imm = 0x218
movq %rdi, %rbx
movq 0x97c1(%rip), %rdi      # 0xcff0
leaq 0x58d4(%rip), %rsi      # 0x910a
movl $0x1e, %edx
callq 0x31f0
xorl %r14d, %r14d
movq %r14, 0x20(%rsp)
xorpd %xmm0, %xmm0
movapd %xmm0, 0x10(%rsp)
movl $0x18, %edi
callq 0x31c0
movq %rax, 0x10(%rsp)
movq %rax, 0x18(%rsp)
leaq 0x18(%rax), %rcx
movq %rcx, 0x20(%rsp)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %r14, 0x10(%rax)
movq %rcx, 0x18(%rsp)
movq %r14, 0x40(%rsp)
movapd %xmm0, 0x30(%rsp)
movl $0x18, %edi
callq 0x31c0
leaq 0x30(%rsp), %rsi
movq %rax, (%rsi)
movq %rax, 0x8(%rsi)
movq %rax, %rcx
addq $0x18, %rcx
movq %rcx, 0x10(%rsi)
xorl %edx, %edx
movq %rdx, 0x10(%rax)
xorpd %xmm0, %xmm0
movupd %xmm0, (%rax)
movq %rcx, 0x8(%rsi)
leaq 0x10(%rsp), %rax
movq (%rax), %rax
movapd 0x5742(%rip), %xmm0     # 0x9010
movupd %xmm0, (%rax)
movabsq $0x4020000000000000, %rcx # imm = 0x4020000000000000
movq %rcx, 0x10(%rax)
leaq 0x8(%rsp), %rax
movq %rdx, (%rax)
leaq 0x68(%rsp), %rax
movq %rax, -0x10(%rax)
movq %rdx, -0x8(%rax)
movb $0x0, (%rax)
leaq 0x98(%rsp), %rbp
leaq 0x78(%rsp), %r13
movq 0x96e4(%rip), %r15      # 0xcff0
leaq 0x59d7(%rip), %r12      # 0x92ea
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
mulsd 0x573c(%rip), %xmm0     # 0x9060
addsd 0x8(%rax), %xmm0
movq 0x30(%rsp), %rcx
movsd %xmm0, (%rcx)
movsd 0x8(%rax), %xmm0
addsd %xmm0, %xmm0
addsd (%rax), %xmm0
movsd %xmm0, 0x8(%rcx)
movsd 0x10(%rax), %xmm0
addsd %xmm0, %xmm0
movsd 0x5713(%rip), %xmm3     # 0x9068
addsd %xmm3, %xmm0
movsd %xmm0, 0x10(%rcx)
movsd (%rax), %xmm0
movsd 0x8(%rax), %xmm1
movapd %xmm0, %xmm2
mulsd 0x56fd(%rip), %xmm2     # 0x9070
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 0x56d0(%rip), %xmm0     # 0x9078
movsd %xmm0, 0x8(%rsp)
cmpq $0x0, 0x60(%rsp)
je 0x39ef
movq %rbp, %rdi
leaq 0x58(%rsp), %rsi
movl $0x4, %edx
callq 0x32d0
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x5042
movq %rbp, %rdi
movq 0x95eb(%rip), %rsi      # 0xcfc8
callq 0x3250
leaq 0x110(%rsp), %rdi
callq 0x3070
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x3dca
movq %rbp, %rdi
movl $0x4, %esi
callq 0x3190
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x4fea
movq %r13, %rdi
leaq 0xa0(%rsp), %rsi
callq 0x3280
leaq 0x58(%rsp), %rdi
movq %r13, %rsi
callq 0x3210
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x3a5d
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x31d0
movq %rbp, %rdi
movq 0x9569(%rip), %rsi      # 0xcfd0
callq 0x30f0
leaq 0x108(%rsp), %rdi
callq 0x3070
movq 0x10(%rsp), %rax
movsd (%rax), %xmm0
movq %r15, %rdi
callq 0x3290
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x31f0
movq 0x10(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %r14, %rdi
callq 0x3290
movq %rax, %r14
movl $0x1, %edx
movq %rax, %rdi
movq %r12, %rsi
callq 0x31f0
movq 0x10(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq %r14, %rdi
callq 0x3290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movl $0x7, %edx
movq %r15, %rdi
leaq 0x55dd(%rip), %rsi      # 0x90ea
callq 0x31f0
movsd 0x8(%rsp), %xmm0
movq %r15, %rdi
callq 0x3290
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x55c0(%rip), %rsi      # 0x90f2
callq 0x31f0
movq 0x30(%rsp), %rax
movsd (%rax), %xmm0
movq %r14, %rdi
callq 0x3290
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x55a0(%rip), %rsi      # 0x90fa
callq 0x31f0
movq 0x30(%rsp), %rax
movsd 0x8(%rax), %xmm0
movq %r14, %rdi
callq 0x3290
movq %rax, %r14
movl $0x7, %edx
movq %rax, %rdi
leaq 0x557f(%rip), %rsi      # 0x9102
callq 0x31f0
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
movq %r14, %rdi
callq 0x3290
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x31b0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3030
movq %rax, %rdi
callq 0x3130
movsd 0x8(%rsp), %xmm0
cmpb $0x0, 0xc(%rbx)
jne 0x3c4c
addsd 0x54b0(%rip), %xmm0     # 0x9088
movsd %xmm0, 0x8(%rsp)
movq 0x30(%rsp), %rax
movsd 0x10(%rax), %xmm0
xorpd 0x5440(%rip), %xmm0     # 0x9030
movlpd %xmm0, 0x8(%rax)
movq %rbp, %rdi
leaq 0x10(%rsp), %rsi
callq 0x3e56
movq %rbx, %rdi
leaq 0x8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
movq %rbp, %rcx
callq 0x3dca
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x3913
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
jmp 0x3913
movq %rax, %rdi
callq 0x3090
callq 0x32b0
jmp 0x3c17
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
movsd %xmm0, 0x50(%rsp)
je 0x3c74
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x31d0
movsd 0x50(%rsp), %xmm0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3c91
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movsd 0x50(%rsp), %xmm0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3cae
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movsd 0x50(%rsp), %xmm0
addq $0x218, %rsp            # imm = 0x218
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x3d3c
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
jmp 0x3d3c
movq %rax, %rbx
jmp 0x3d6f
jmp 0x3d39
movq %rax, %rbx
movq 0x92d2(%rip), %rsi      # 0xcfc8
leaq 0x98(%rsp), %rdi
callq 0x3250
leaq 0x110(%rsp), %rdi
jmp 0x3d32
jmp 0x3d39
jmp 0x3d39
jmp 0x3d13
movq %rax, %rbx
movq 0x92b3(%rip), %rsi      # 0xcfd0
leaq 0x98(%rsp), %rdi
callq 0x30f0
leaq 0x108(%rsp), %rdi
callq 0x3070
jmp 0x3d3c
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq 0x58(%rsp), %rdi
cmpq %rax, %rdi
je 0x3d58
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x31d0
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x3d6f
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x3d86
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x31d0
movq %rbx, %rdi
callq 0x3300