// File: /workspace/github_cpp_makefile_star2_O3/louisabraham[P]cage/./cage.hpp
// Function: std::pair<float, std::vector<float, std::allocator<float>>> genetic_algorithm<std::vector<float, std::allocator<float>>, float>(std::function<std::vector<float, std::allocator<float>> ()>, std::function<float (std::vector<float, std::allocator<float>> const&)>, bool, std::function<void (std::vector<float, std::allocator<float>>&)>, int, int, int)
pair<S, T> genetic_algorithm(
    function<T()> init,           // generate a new item
    function<S(const T &)> score, // score function
    bool minimize,                // minimize or maximize
    function<void(T &)> mutate,   // in-place mutation function
    int pop_size,                 // population size
    int steps,                    // number of optimization steps
    int luby_basis = -1           // if not -1, use optimal Las Vegas restarts
                                  // heuristic: diameter of the search space in number of mutations
)
{
    srand(time(NULL));

    // restarts

    int cur_luby = 1;
    int luby_count = 0;
    int cur_count = 0;
    auto restart = [&]() {
        if (luby_basis == -1)
            return false;
        if (cur_count++ < cur_luby)
            return false;
        cur_count = 0;
        cur_luby = luby_basis * luby(luby_count++);
        return true;
    };

    using pair_t = pair<double, T>;

    auto comp = minimize ? mini<pair_t> : maxi<pair_t>;

    auto rank = [&](pair_t &e) {
        e.first = score(e.second);
    };

    pair_t global_best, best;

    auto reset = [&]() {
        if (comp(best, global_best))
            global_best = best;
        best.second = init();
        rank(best);
        //        cerr << best.first << endl;
    };

    reset();
    global_best = best;

    while (true)
    {
        auto cand = best;
        for (int i = 0; i < pop_size; i++)
        {
            mutate(cand.second);
            rank(cand);
            if (comp(cand, best))
                best = cand;
            steps--;
            if (!steps)
            {
                reset();
                return global_best;
            }
            if (restart())
                reset();
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x128, %rsp            # imm = 0x128
movl %r9d, %r13d
movq %r8, 0x68(%rsp)
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x8(%rsp)
xorl %edi, %edi
callq 0x10e0
movl %eax, %edi
callq 0x10f0
leaq 0x7d1(%rip), %rax       # 0x2797
leaq 0x837(%rip), %rcx       # 0x2804
testl %r15d, %r15d
cmovneq %rax, %rcx
leaq 0xb8(%rsp), %rax
movq %rcx, (%rax)
leaq 0xb0(%rsp), %rcx
movq %r12, (%rcx)
xorps %xmm0, %xmm0
leaq 0x90(%rsp), %rdx
movaps %xmm0, 0x10(%rdx)
movaps %xmm0, (%rdx)
leaq 0x40(%rsp), %rsi
movaps %xmm0, 0x10(%rsi)
movaps %xmm0, (%rsi)
leaq 0x100(%rsp), %rdi
movq %rax, (%rdi)
movq %rsi, 0x8(%rdi)
movq %rdx, 0x10(%rdi)
movq %rbx, 0x18(%rdi)
movq %rcx, 0x20(%rdi)
callq 0x2872
leaq 0x48(%rsp), %rsi
movsd -0x8(%rsi), %xmm0
leaq 0x98(%rsp), %rdi
movsd %xmm0, -0x8(%rdi)
callq 0x29ec
movl 0x160(%rsp), %r15d
movq 0x8(%rsp), %rax
movss (%rax), %xmm0
movss %xmm0, 0x4(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x10(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x20(%rsp)
movl $0x1, %eax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
xorl %r12d, %r12d
movl %r13d, 0x2c(%rsp)
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1f0a
xorl %r13d, %r13d
movl 0x2c(%rsp), %eax
testl %eax, %eax
jle 0x2255
movl %r15d, %ecx
subl %eax, %ecx
movl %ecx, 0x3c(%rsp)
movb $0x1, %r14b
movq 0x68(%rsp), %rax
cmpq $0x0, 0x10(%rax)
je 0x2352
movq 0x68(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq *0x18(%rdi)
movq 0xb0(%rsp), %rdi
cmpq $0x0, 0x10(%rdi)
je 0x2352
leaq 0x78(%rsp), %rsi
callq *0x18(%rdi)
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x70(%rsp)
movq 0xb8(%rsp), %rbx
movsd %xmm0, 0xe0(%rsp)
leaq 0xe8(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x1f0a
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1f0a
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq *%rbx
movl %eax, %ebx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x2177
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x2194
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
testb %bl, %bl
je 0x21b3
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x29ec
decl %r15d
je 0x225a
cmpl $-0x1, 0x168(%rsp)
je 0x223c
cmpl 0x30(%rsp), %ebp
jge 0x21d0
incl %ebp
jmp 0x223c
testl %r12d, %r12d
jle 0x21f0
movl $0x1, %eax
xorl %ecx, %ecx
incl %ecx
movl %eax, %esi
addl %eax, %esi
leal 0x1(,%rax,2), %eax
cmpl %r12d, %esi
jl 0x21dc
jmp 0x21f4
xorl %esi, %esi
xorl %ecx, %ecx
movl %r12d, %edx
cmpl %r12d, %esi
je 0x220b
sarl %esi
decl %ecx
movl %edx, %eax
cltd
idivl %esi
decl %esi
cmpl %edx, %esi
jne 0x21fc
movl $0x1, %eax
shlq %cl, %rax
movq %rax, 0x30(%rsp)
leaq 0x100(%rsp), %rdi
callq 0x2872
incl %r12d
movq 0x30(%rsp), %rax
imull 0x168(%rsp), %eax
movq %rax, 0x30(%rsp)
xorl %ebp, %ebp
incl %r13d
cmpl 0x2c(%rsp), %r13d
setl %r14b
jne 0x20c0
movl 0x3c(%rsp), %r15d
jmp 0x22b9
xorl %r14d, %r14d
jmp 0x22b9
leaq 0x100(%rsp), %rdi
callq 0x2872
xorps %xmm0, %xmm0
cvtsd2ss 0x90(%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x20(%rsp)
leaq 0x98(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
xorl %r15d, %r15d
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x22d3
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
testb $0x1, %r14b
je 0x208a
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x231e
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x233b
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x8(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
callq 0x1070
movq %rax, %rbx
jmp 0x24a4
jmp 0x245d
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
jmp 0x24a4
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
jmp 0x2439
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x2439
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x248a
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
jmp 0x248a
movq %rax, %rbx
jmp 0x248a
movq %rax, %rbx
movq 0x8(%rsp), %rax
movq 0x10(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x18(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0x4(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x24a4
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x24bb
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x24d8
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq %rbx, %rdi
callq 0x1170