// File: /workspace/github_cpp_makefile_star2_O2/kmyk[P]codevs-for-student-2016/Main.cpp
// Function: void beam_search<AI::think(primitive::input_t const&)::'lambda1'(std::shared_ptr<photon_t> const&)>(std::shared_ptr<photon_t> const&, primitive::config_t const&, int, int, AI::think(primitive::input_t const&)::'lambda1'(std::shared_ptr<photon_t> const&))
void beam_search(shared_ptr<photon_t> const & initial, config_t const & config, int beam_width, int beam_depth, F cont) {
    vector<shared_ptr<photon_t> > beam, nbeam;
    beam.push_back(initial);
    repeat (i, beam_depth) {
        if (initial->turn + i >= config.packs.size()) break;
        for (shared_ptr<photon_t> const & pho : beam) {
            step_photon_all(pho, config.packs[initial->turn + i]);
            repeat_from (x, - pack_size + 1, width) repeat (r, 4) {
                shared_ptr<photon_t> npho = pho->next[x+pack_size-1][r];
                if (not npho) continue;
                npho = cont(npho);
                if (not npho) continue;
                if (i+1 < beam_depth) {
                    nbeam.push_back(npho);
                }
            }
        }
        beam.resize(min<int>(beam_width, nbeam.size()));
        partial_sort_copy(nbeam.begin(), nbeam.end(), beam.begin(), beam.end(), compare_photon_reversed);
        nbeam.clear();
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xa8, %rsp
movl %ecx, %ebp
movl %edx, 0x8(%rsp)
movq %rsi, 0x30(%rsp)
movq %rdi, %rsi
movq %r8, 0x88(%rsp)
movq %r9, 0x90(%rsp)
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rdi
movaps %xmm0, (%rdi)
andq $0x0, 0x10(%rdi)
movaps %xmm0, 0x10(%rsp)
andq $0x0, 0x20(%rsp)
movq %rsi, 0x28(%rsp)
callq 0x6d50
xorl %r14d, %r14d
testl %ebp, %ebp
movl $0x0, %eax
cmovgl %ebp, %eax
movl %eax, 0xc(%rsp)
leaq 0x58(%rsp), %r15
leaq 0x98(%rsp), %r13
cmpl 0xc(%rsp), %r14d
je 0x7175
movq 0x28(%rsp), %rax
movq (%rax), %rax
movslq (%rax), %rcx
movslq %r14d, %rax
movq %rax, 0x68(%rsp)
addq %rax, %rcx
movq 0x30(%rsp), %rdx
movq 0x8(%rdx), %rax
subq (%rdx), %rax
cqto
pushq $0x9
popq %rsi
idivq %rsi
cmpq %rcx, %rax
jbe 0x7175
movq 0x40(%rsp), %r12
movq 0x48(%rsp), %rax
movq %rax, 0x70(%rsp)
incl %r14d
movq %r14, 0x80(%rsp)
cmpq 0x70(%rsp), %r12
je 0x7122
movq 0x28(%rsp), %rax
movq (%rax), %rax
movslq (%rax), %rax
addq 0x68(%rsp), %rax
leaq (%rax,%rax,8), %rsi
movq 0x30(%rsp), %rax
addq (%rax), %rsi
movq %r12, %rdi
callq 0x3676
movl $0x138, %eax            # imm = 0x138
movq %rax, 0x38(%rsp)
pushq $-0x2
popq %rax
cmpq $0xa, %rax
je 0x7119
movq %rax, 0x78(%rsp)
xorl %ebx, %ebx
cmpq $0x40, %rbx
je 0x7106
movq (%r12), %rsi
addq 0x38(%rsp), %rsi
addq %rbx, %rsi
movq %r15, %rdi
callq 0x605a
cmpq $0x0, 0x58(%rsp)
je 0x70f3
movq %r13, %rdi
leaq 0x88(%rsp), %rsi
movq %r15, %rdx
callq 0x9126
cmpl %ebp, %r14d
movl %ebp, %r14d
setl %bpl
movq %r15, %rdi
movq %r13, %rsi
callq 0xc96a
leaq 0xa0(%rsp), %rdi
callq 0x5f78
cmpq $0x0, 0x58(%rsp)
setne %al
testb %bpl, %al
movl %r14d, %ebp
movq 0x80(%rsp), %r14
je 0x70f3
leaq 0x10(%rsp), %rdi
movq %r15, %rsi
callq 0x6d50
leaq 0x60(%rsp), %rdi
callq 0x5f78
addq $0x10, %rbx
jmp 0x7072
movq 0x78(%rsp), %rax
incq %rax
addq $0x40, 0x38(%rsp)
jmp 0x7061
addq $0x10, %r12
jmp 0x7025
movq 0x18(%rsp), %rax
subq 0x10(%rsp), %rax
shrq $0x4, %rax
movl 0x8(%rsp), %ecx
cmpl %ecx, %eax
cmovgel %ecx, %eax
movslq %eax, %rsi
leaq 0x40(%rsp), %rdi
callq 0x9182
movq 0x10(%rsp), %rdi
movq 0x18(%rsp), %rsi
movq 0x40(%rsp), %rdx
movq 0x48(%rsp), %rcx
leaq -0x36a5(%rip), %r8      # 0x3abc
callq 0x92f0
leaq 0x10(%rsp), %rdi
callq 0x91b2
jmp 0x6fcd
leaq 0x10(%rsp), %rdi
callq 0x60fc
leaq 0x40(%rsp), %rdi
callq 0x60fc
addq $0xa8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0x71a1
jmp 0x71a1
jmp 0x71a1
movq %rax, %rbx
jmp 0x71b5
jmp 0x71a8
movq %rax, %rbx
leaq 0x60(%rsp), %rdi
callq 0x5f78
leaq 0x10(%rsp), %rdi
callq 0x60fc
leaq 0x40(%rsp), %rdi
callq 0x60fc
movq %rbx, %rdi
callq 0x2250
nop