// File: /workspace/github_cpp_makefile_star2_O1/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, 0x34(%rsp)
movq %r8, %r14
movl %ecx, %r15d
movq %rdx, %r12
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
xorl %edi, %edi
callq 0x10e0
movl %eax, %edi
callq 0x10f0
leaq 0x7e9(%rip), %rax       # 0x27e5
leaq 0x84f(%rip), %rcx       # 0x2852
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 0x28c0
leaq 0x48(%rsp), %rsi
movsd -0x8(%rsi), %xmm0
leaq 0x98(%rsp), %rdi
movsd %xmm0, -0x8(%rdi)
callq 0x2a46
movl 0x160(%rsp), %r15d
movq 0x10(%rsp), %rax
movss (%rax), %xmm0
movss %xmm0, 0xc(%rsp)
movl 0x34(%rsp), %ebx
testl %ebx, %ebx
setg 0xb(%rsp)
movq 0x8(%rax), %rcx
movq %rcx, 0x18(%rsp)
movq 0x10(%rax), %rcx
movq %rcx, 0x20(%rsp)
movq 0x18(%rax), %rax
movq %rax, 0x28(%rsp)
movl $0x1, %eax
movq %rax, 0x68(%rsp)
movl $0x0, 0x38(%rsp)
xorl %r12d, %r12d
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0x70(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1f40
testl %ebx, %ebx
jle 0x22a2
movl %r15d, %eax
subl %ebx, %eax
movl %eax, 0x3c(%rsp)
xorl %r13d, %r13d
movb 0xb(%rsp), %bpl
cmpq $0x0, 0x10(%r14)
je 0x23a5
movq %r14, %rdi
leaq 0x78(%rsp), %rsi
callq *0x18(%r14)
movq 0xb0(%rsp), %rdi
cmpq $0x0, 0x10(%rdi)
je 0x23a5
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 0x1f40
movsd 0x40(%rsp), %xmm0
movsd %xmm0, 0xc0(%rsp)
leaq 0xc8(%rsp), %rdi
leaq 0x48(%rsp), %rsi
callq 0x1f40
leaq 0xe0(%rsp), %rdi
leaq 0xc0(%rsp), %rsi
callq *%rbx
movl %eax, %ebx
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x21b1
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x21ce
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
testb %bl, %bl
je 0x21ed
movsd 0x70(%rsp), %xmm0
movsd %xmm0, 0x40(%rsp)
leaq 0x48(%rsp), %rdi
leaq 0x78(%rsp), %rsi
callq 0x2a46
decl %r15d
je 0x22a9
cmpl $-0x1, 0x168(%rsp)
movl 0x38(%rsp), %eax
je 0x2214
xorl %esi, %esi
cmpl 0x68(%rsp), %eax
jge 0x2218
incl %eax
movl %eax, 0x38(%rsp)
jmp 0x2275
xorl %esi, %esi
jmp 0x2275
movl $0x0, %ecx
testl %r12d, %r12d
jle 0x223b
movl $0x1, %eax
xorl %ecx, %ecx
incl %ecx
movl %eax, %esi
addl %eax, %esi
leal 0x1(,%rax,2), %eax
cmpl %r12d, %esi
jl 0x2229
movl %r12d, %edx
cmpl %r12d, %esi
je 0x2252
sarl %esi
decl %ecx
movl %edx, %eax
cltd
idivl %esi
decl %esi
cmpl %edx, %esi
jne 0x2243
movl $0x1, %eax
shlq %cl, %rax
incl %r12d
imull 0x168(%rsp), %eax
movq %rax, 0x68(%rsp)
movb $0x1, %sil
movl $0x0, 0x38(%rsp)
testb %sil, %sil
je 0x2287
leaq 0x100(%rsp), %rdi
callq 0x28c0
incl %r13d
movl 0x34(%rsp), %ebx
cmpl %ebx, %r13d
setl %bpl
jne 0x2100
movl 0x3c(%rsp), %r15d
jmp 0x230c
movb 0xb(%rsp), %bpl
jmp 0x230c
leaq 0x100(%rsp), %rdi
callq 0x28c0
xorps %xmm0, %xmm0
cvtsd2ss 0x90(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movq 0x98(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xa0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xa8(%rsp), %rax
movq %rax, 0x28(%rsp)
leaq 0x98(%rsp), %rax
xorps %xmm0, %xmm0
movups %xmm0, (%rax)
movq $0x0, 0x10(%rax)
xorl %r15d, %r15d
movl 0x34(%rsp), %ebx
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x2326
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
testb $0x1, %bpl
je 0x20cc
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x2371
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x238e
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x10(%rsp), %rax
addq $0x128, %rsp            # imm = 0x128
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
callq 0x1070
movq %rax, %rbx
jmp 0x24f7
jmp 0x24b0
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
jmp 0x24f7
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
jmp 0x248c
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0xc8(%rsp), %rdi
testq %rdi, %rdi
je 0x248c
movq 0xd8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0xe8(%rsp), %rdi
testq %rdi, %rdi
je 0x24dd
movq 0xf8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
jmp 0x24dd
movq %rax, %rbx
jmp 0x24dd
movq %rax, %rbx
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rcx
movq %rcx, 0x8(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x10(%rax)
movq 0x28(%rsp), %rcx
movq %rcx, 0x18(%rax)
movss 0xc(%rsp), %xmm0
movss %xmm0, (%rax)
movq 0x78(%rsp), %rdi
testq %rdi, %rdi
je 0x24f7
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x250e
movq 0x58(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x252b
movq 0xa8(%rsp), %rsi
subq %rdi, %rsi
callq 0x1120
movq %rbx, %rdi
callq 0x1170
nop