// File: redpony[P]libpopt/optimize_test.cc
// Function: TestOptimizer(Optimizer*)
double TestOptimizer(Optimizer* opt) {
  cerr << "TESTING NON-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;
  do {
    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;
    opt->Optimize(obj, g, &x);

    cerr << x[0] << " " << x[1] << " " << x[2] << endl;
    cerr << "   obj=" << obj << "\td/dx1=" << g[0] << " d/dx2=" << g[1] << " d/dx3=" << g[2] << endl;
  } while (!opt->HasConverged());
  return obj;
}

// Assembly:
subq $0x188, %rsp            # imm = 0x188
movq %rdi, 0x180(%rsp)
movq 0xea1a(%rip), %rdi      # 0x11ff0
leaq 0xaaa3(%rip), %rsi      # 0xe080
callq 0x3210
leaq 0x167(%rsp), %rdi
movq %rdi, 0x120(%rsp)
callq 0x4610
movq 0x120(%rsp), %rdx
leaq 0x168(%rsp), %rdi
movl $0x3, %esi
callq 0x4620
jmp 0x3613
leaq 0x167(%rsp), %rdi
callq 0x46a0
leaq 0x137(%rsp), %rdi
movq %rdi, 0x118(%rsp)
callq 0x4610
movq 0x118(%rsp), %rdx
leaq 0x138(%rsp), %rdi
movl $0x3, %esi
callq 0x4620
jmp 0x3651
leaq 0x137(%rsp), %rdi
callq 0x46a0
leaq 0x168(%rsp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x46b0
movsd 0xa991(%rip), %xmm0     # 0xe008
movsd %xmm0, (%rax)
leaq 0x168(%rsp), %rdi
movl $0x1, %esi
callq 0x46b0
movsd 0xa973(%rip), %xmm0     # 0xe008
movsd %xmm0, (%rax)
leaq 0x168(%rsp), %rdi
movl $0x2, %esi
callq 0x46b0
movsd 0xa955(%rip), %xmm0     # 0xe008
movsd %xmm0, (%rax)
xorps %xmm0, %xmm0
movsd %xmm0, 0x128(%rsp)
xorl %eax, %eax
movl %eax, %esi
movq %rsi, 0xa8(%rsp)
leaq 0x168(%rsp), %rdi
movq %rdi, 0x110(%rsp)
callq 0x46b0
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x80(%rsp)
movl $0x1, %esi
movq %rsi, 0xc8(%rsp)
callq 0x46b0
movsd 0x80(%rsp), %xmm0
movq 0xa8(%rsp), %rsi
movsd (%rax), %xmm1
movsd 0xa8e0(%rip), %xmm2     # 0xe008
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x88(%rsp)
leaq 0x138(%rsp), %rdi
movq %rdi, 0x108(%rsp)
callq 0x46b0
movsd 0x88(%rsp), %xmm0
movq 0xc8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd %xmm0, (%rax)
callq 0x46b0
movq 0xa8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0x90(%rsp)
callq 0x46b0
movsd 0x90(%rsp), %xmm0
movq 0xc8(%rsp), %rsi
movq 0x108(%rsp), %rdi
movsd (%rax), %xmm1
addsd %xmm0, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x98(%rsp)
callq 0x46b0
movsd 0x98(%rsp), %xmm0
movq 0x110(%rsp), %rdi
movsd %xmm0, (%rax)
movl $0x2, %esi
movq %rsi, 0xf0(%rsp)
callq 0x46b0
movq 0xf0(%rsp), %rsi
movq 0x108(%rsp), %rdi
movsd (%rax), %xmm0
addsd %xmm0, %xmm0
movsd 0xa804(%rip), %xmm1     # 0xe010
movsd %xmm1, 0xf8(%rsp)
addsd %xmm1, %xmm0
movsd %xmm0, 0xa0(%rsp)
callq 0x46b0
movsd 0xa0(%rsp), %xmm0
movq 0xa8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd %xmm0, (%rax)
callq 0x46b0
movq 0xa8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd 0xa7b3(%rip), %xmm1     # 0xe018
mulsd %xmm1, %xmm0
movsd %xmm0, 0xb8(%rsp)
callq 0x46b0
movq 0xa8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0xc0(%rsp)
callq 0x46b0
movq 0xc8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0xb0(%rsp)
callq 0x46b0
movsd 0xb0(%rsp), %xmm1
movsd 0xb8(%rsp), %xmm0
movsd 0xc0(%rsp), %xmm2
movq 0xc8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm3
mulsd %xmm3, %xmm1
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xd8(%rsp)
callq 0x46b0
movq 0xc8(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0xd0(%rsp)
callq 0x46b0
movsd 0xd0(%rsp), %xmm0
movsd 0xd8(%rsp), %xmm1
movq 0xf0(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0xe8(%rsp)
callq 0x46b0
movq 0xf0(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm0
movsd %xmm0, 0xe0(%rsp)
callq 0x46b0
movsd 0xe0(%rsp), %xmm0
movsd 0xe8(%rsp), %xmm1
movq 0xf0(%rsp), %rsi
movq 0x110(%rsp), %rdi
movsd (%rax), %xmm2
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd %xmm0, 0x100(%rsp)
callq 0x46b0
movsd 0xf8(%rsp), %xmm2
movsd 0x100(%rsp), %xmm1
movq 0x108(%rsp), %rdx
movq 0x110(%rsp), %rcx
movsd (%rax), %xmm0
mulsd %xmm2, %xmm0
addsd %xmm1, %xmm0
movsd 0xa62a(%rip), %xmm1     # 0xe020
addsd %xmm1, %xmm0
movsd %xmm0, 0x128(%rsp)
movq 0x180(%rsp), %rdi
leaq 0x128(%rsp), %rsi
callq 0x46d0
jmp 0x3a1a
xorl %eax, %eax
movl %eax, %esi
leaq 0x168(%rsp), %rdi
callq 0x46b0
movsd (%rax), %xmm0
movq 0xe5ba(%rip), %rdi      # 0x11ff0
callq 0x3400
movq %rax, 0x78(%rsp)
jmp 0x3a42
movq 0x78(%rsp), %rdi
leaq 0xa854(%rip), %rsi      # 0xe2a2
callq 0x3210
movq %rax, 0x70(%rsp)
jmp 0x3a5a
leaq 0x168(%rsp), %rdi
movl $0x1, %esi
callq 0x46b0
movq 0x70(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3400
movq %rax, 0x68(%rsp)
jmp 0x3a81
movq 0x68(%rsp), %rdi
leaq 0xa815(%rip), %rsi      # 0xe2a2
callq 0x3210
movq %rax, 0x60(%rsp)
jmp 0x3a99
leaq 0x168(%rsp), %rdi
movl $0x2, %esi
callq 0x46b0
movq 0x60(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3400
movq %rax, 0x58(%rsp)
jmp 0x3ac0
movq 0x58(%rsp), %rdi
movq 0xe4f4(%rip), %rsi      # 0x11fc0
callq 0x3250
jmp 0x3ad3
movq 0xe516(%rip), %rdi      # 0x11ff0
leaq 0xa5c1(%rip), %rsi      # 0xe0a2
callq 0x3210
movq %rax, 0x50(%rsp)
jmp 0x3aed
movq 0x50(%rsp), %rdi
movsd 0x128(%rsp), %xmm0
callq 0x3400
movq %rax, 0x48(%rsp)
jmp 0x3b07
movq 0x48(%rsp), %rdi
leaq 0xa597(%rip), %rsi      # 0xe0aa
callq 0x3210
movq %rax, 0x40(%rsp)
jmp 0x3b1f
xorl %eax, %eax
movl %eax, %esi
leaq 0x138(%rsp), %rdi
callq 0x46b0
movq 0x40(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3400
movq %rax, 0x38(%rsp)
jmp 0x3b45
movq 0x38(%rsp), %rdi
leaq 0xa561(%rip), %rsi      # 0xe0b2
callq 0x3210
movq %rax, 0x30(%rsp)
jmp 0x3b5d
leaq 0x138(%rsp), %rdi
movl $0x1, %esi
callq 0x46b0
movq 0x30(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3400
movq %rax, 0x28(%rsp)
jmp 0x3b84
movq 0x28(%rsp), %rdi
leaq 0xa52a(%rip), %rsi      # 0xe0ba
callq 0x3210
movq %rax, 0x20(%rsp)
jmp 0x3b9c
leaq 0x138(%rsp), %rdi
movl $0x2, %esi
callq 0x46b0
movq 0x20(%rsp), %rdi
movsd (%rax), %xmm0
callq 0x3400
movq %rax, 0x18(%rsp)
jmp 0x3bc3
movq 0x18(%rsp), %rdi
movq 0xe3f1(%rip), %rsi      # 0x11fc0
callq 0x3250
jmp 0x3bd6
jmp 0x3bd8
movq 0x180(%rsp), %rdi
callq 0x47c0
movb %al, 0x17(%rsp)
jmp 0x3beb
movb 0x17(%rsp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x36c3
movsd 0x128(%rsp), %xmm0
movsd %xmm0, 0x8(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x47d0
leaq 0x168(%rsp), %rdi
callq 0x47d0
movsd 0x8(%rsp), %xmm0
addq $0x188, %rsp            # imm = 0x188
retq
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x167(%rsp), %rdi
callq 0x46a0
jmp 0x3ca4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x137(%rsp), %rdi
callq 0x46a0
jmp 0x3c97
movq %rax, %rcx
movl %edx, %eax
movq %rcx, 0x158(%rsp)
movl %eax, 0x154(%rsp)
leaq 0x138(%rsp), %rdi
callq 0x47d0
leaq 0x168(%rsp), %rdi
callq 0x47d0
movq 0x158(%rsp), %rdi
callq 0x33b0
nopw %cs:(%rax,%rax)