// File: /workspace/github_cpp_makefile_star2_O1/kmyk[P]codevs-for-student-2016/Main.cpp
// Function: void chokudai_search<AI::think(primitive::input_t const&)::'lambda2'(std::shared_ptr<photon_t> const&)>(std::deque<std::priority_queue<std::pair<double, std::weak_ptr<photon_t>>, std::vector<std::pair<double, std::weak_ptr<photon_t>>, std::allocator<std::pair<double, std::weak_ptr<photon_t>>>>, std::function<bool (std::pair<double, std::weak_ptr<photon_t>> const&, std::pair<double, std::weak_ptr<photon_t>> const&)>>, std::allocator<std::priority_queue<std::pair<double, std::weak_ptr<photon_t>>, std::vector<std::pair<double, std::weak_ptr<photon_t>>, std::allocator<std::pair<double, std::weak_ptr<photon_t>>>>, std::function<bool (std::pair<double, std::weak_ptr<photon_t>> const&, std::pair<double, std::weak_ptr<photon_t>> const&)>>>>&, primitive::config_t const&, int, int, int, int, std::shared_ptr<photon_t> const&, long long, AI::think(primitive::input_t const&)::'lambda2'(std::shared_ptr<photon_t> const&))
void chokudai_search(deque<functional_priority_queue<pair<double, weak_ptr<photon_t> > > > & que, config_t const & config, int initial_turn, int beam_width, int beam_depth, int beam_generation, shared_ptr<photon_t> const & initial, ll time_limit_msec, F cont) {
    assert (initial_turn + beam_depth < config.packs.size());
    assert (beam_depth + 1 < que.size());
    clock_check check(time_limit_msec);
    int begin = 0;
    int loop = 0;
    while (check() and begin < beam_depth) {
        repeat_from (i, begin, beam_depth) {
            repeat (j, beam_width) {
                loop += 1;
                if (que[i].empty()) {
                    if (i == begin) ++ begin;
                    break;
                }
                shared_ptr<photon_t> pho = que[i].top().second.lock(); que[i].pop();
                if (not pho) { -- j; continue; } // 無視して同じ深さをもう一度
                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 (npho->beam_generation == beam_generation) continue;
                    que[i+1].emplace(npho->evaluation.score, npho);
                    if (beam_generation != -1) npho->beam_generation = beam_generation;
                }
                if (loop % 100 == 0) {
                    anneal_photon(initial, outputs_photon_from(pho, initial_turn), config, que, beam_generation, cont);
                }
            }
        }
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movl %r9d, %ebx
movl %r8d, %ebp
movl %ecx, 0x3c(%rsp)
movl %edx, 0x38(%rsp)
movq %rsi, 0x70(%rsp)
movq %rdi, 0x68(%rsp)
callq 0x2040
imulq $0xf4240, 0x128(%rsp), %r14 # imm = 0xF4240
addq %rax, %r14
callq 0x2040
movq %r14, 0xa8(%rsp)
cmpq %r14, %rax
setge %al
movl %ebp, 0x30(%rsp)
testl %ebp, %ebp
setle %cl
orb %al, %cl
jne 0x9104
movq 0x68(%rsp), %rax
leaq 0x10(%rax), %r13
movslq 0x38(%rsp), %rax
movq %rax, 0xb8(%rsp)
movl 0x30(%rsp), %eax
movq %rax, 0xb0(%rsp)
xorl %r14d, %r14d
leaq 0x40(%rsp), %r12
xorl %ecx, %ecx
movslq %ecx, %r15
cmpl $0x0, 0x3c(%rsp)
jle 0x90d6
movl %ecx, 0x34(%rsp)
leaq 0x1(%r15), %rax
movq %rax, 0xc8(%rsp)
xorl %ebp, %ebp
movq %r15, 0xc0(%rsp)
incl %r14d
movq %r13, %rdi
movq %r15, %rsi
callq 0xa520
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x90c8
movq %r13, %rdi
movq %r15, %rsi
callq 0xa520
movq (%rax), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, 0x58(%rsp)
testq %rdx, %rdx
je 0x8e28
movl 0x8(%rdx), %eax
testl %eax, %eax
je 0x8e1f
leal 0x1(%rax), %esi
lock
cmpxchgl %esi, 0x8(%rdx)
jne 0x8e0f
jmp 0x8e28
movq $0x0, 0x58(%rsp)
movq 0x58(%rsp), %rax
testq %rax, %rax
je 0x8e3c
movl 0x8(%rax), %eax
testl %eax, %eax
sete %al
jmp 0x8e3e
movb $0x1, %al
testb %al, %al
movq %r14, 0x78(%rsp)
jne 0x8e4d
movq 0x8(%rcx), %rax
jmp 0x8e4f
xorl %eax, %eax
movq %rax, 0x50(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0xa520
movq %rax, %rdi
callq 0x85f6
cmpq $0x0, 0x50(%rsp)
je 0x9010
leaq (%r15,%r15,8), %rax
movq 0x70(%rsp), %rcx
addq (%rcx), %rax
movq 0xb8(%rsp), %rcx
leaq (%rcx,%rcx,8), %rsi
addq %rax, %rsi
leaq 0x50(%rsp), %rdi
callq 0x3c0c
movl %ebp, 0x64(%rsp)
movq $-0x2, %r14
movl $0x140, %ebp            # imm = 0x140
xorl %r15d, %r15d
movq 0x50(%rsp), %rax
addq %rbp, %rax
movq -0x8(%r15,%rax), %rcx
movq %rcx, 0x40(%rsp)
movq (%r15,%rax), %rax
movq %rax, 0x48(%rsp)
testq %rax, %rax
je 0x8ee0
movq 0xc0ee(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x8edc
incl 0x8(%rax)
jmp 0x8ee0
lock
incl 0x8(%rax)
cmpq $0x0, 0x40(%rsp)
je 0x8f87
leaq 0x90(%rsp), %rdi
leaq 0x130(%rsp), %rsi
movq %r12, %rdx
callq 0x8686
movaps 0x90(%rsp), %xmm0
xorps %xmm1, %xmm1
movaps %xmm1, 0x90(%rsp)
movq 0x48(%rsp), %rdi
movups %xmm0, 0x40(%rsp)
testq %rdi, %rdi
je 0x8f2b
callq 0x7136
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x8f3d
callq 0x7136
movq 0x40(%rsp), %rax
testq %rax, %rax
je 0x8f87
cmpl %ebx, 0x100(%rax)
je 0x8f87
movq %r13, %rdi
movq 0xc8(%rsp), %rsi
callq 0xa520
movq 0x40(%rsp), %rsi
movl $0xc8, %ecx
addq %rcx, %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x7f5a
cmpl $-0x1, %ebx
je 0x8f87
movq 0x40(%rsp), %rax
movl %ebx, 0x100(%rax)
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x8f96
callq 0x7136
addq $0x10, %r15
cmpq $0x40, %r15
jne 0x8eab
incq %r14
addq $0x40, %rbp
cmpq $0xa, %r14
jne 0x8ea8
movq 0x78(%rsp), %r14
imull $0xc28f5c29, %r14d, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c29, %eax        # imm = 0x28F5C29
movl 0x64(%rsp), %ebp
jae 0x909f
movq 0x50(%rsp), %rcx
movq 0x58(%rsp), %rax
movq %rcx, 0x80(%rsp)
movq %rax, 0x88(%rsp)
testq %rax, %rax
leaq 0xd0(%rsp), %r15
je 0x901e
movq 0xbfba(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x901a
incl 0x8(%rax)
jmp 0x901e
movq 0x78(%rsp), %r14
jmp 0x90a9
lock
incl 0x8(%rax)
movq %r15, %rdi
leaq 0x80(%rsp), %rsi
movl 0x38(%rsp), %edx
callq 0x3f30
leaq 0x130(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movups %xmm2, 0x20(%rsp)
movups %xmm1, 0x10(%rsp)
movups %xmm0, (%rsp)
movq 0x120(%rsp), %rdi
movq %r15, %rsi
movq 0x70(%rsp), %rdx
movq 0x68(%rsp), %rcx
movl %ebx, %r8d
callq 0x89b3
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x908d
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0x88(%rsp), %rdi
testq %rdi, %rdi
je 0x909f
callq 0x7136
incl %ebp
movq 0xc0(%rsp), %r15
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x90b8
callq 0x7136
cmpl 0x3c(%rsp), %ebp
jl 0x8dd5
movl 0x34(%rsp), %ecx
jmp 0x90d6
xorl %eax, %eax
movl 0x34(%rsp), %ecx
cmpl %r15d, %ecx
sete %al
addl %eax, %ecx
incq %r15
cmpq 0xb0(%rsp), %r15
jl 0x8db0
movl %ecx, %ebp
callq 0x2040
cmpq 0xa8(%rsp), %rax
jge 0x9104
movl %ebp, %ecx
cmpl 0x30(%rsp), %ebp
jl 0x8dad
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x913b
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x913b
movq %rax, %rbx
movq 0x88(%rsp), %rdi
jmp 0x9154
movq %rax, %rbx
jmp 0x915e
jmp 0x914c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
testq %rdi, %rdi
je 0x915e
callq 0x7136
movq 0x58(%rsp), %rdi
testq %rdi, %rdi
je 0x916d
callq 0x7136
movq %rbx, %rdi
callq 0x2230