// File: /workspace/github_cpp_makefile_star2_O3/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, 0x54(%rsp)
movl %edx, 0x50(%rsp)
movq %rsi, 0x80(%rsp)
movq %rdi, 0x78(%rsp)
callq 0x2040
imulq $0xf4240, 0x128(%rsp), %r14 # imm = 0xF4240
addq %rax, %r14
callq 0x2040
movq %r14, 0xb0(%rsp)
cmpq %r14, %rax
setge %al
movl %ebp, 0x48(%rsp)
testl %ebp, %ebp
setle %cl
orb %al, %cl
jne 0x92bd
movq 0x78(%rsp), %rax
leaq 0x10(%rax), %r13
movslq 0x50(%rsp), %rax
movq %rax, 0xc0(%rsp)
movl 0x48(%rsp), %eax
movq %rax, 0xb8(%rsp)
xorl %r14d, %r14d
leaq 0x38(%rsp), %r12
xorl %ecx, %ecx
movslq %ecx, %rax
movq %rax, %r15
incq %rax
cmpl $0x0, 0x54(%rsp)
jle 0x9292
movq %rax, 0x68(%rsp)
movl %ecx, 0x4c(%rsp)
xorl %ebp, %ebp
movq %r15, 0xc8(%rsp)
incl %r14d
movq %r13, %rdi
movq %r15, %rsi
callq 0xa59e
movq (%rax), %rcx
cmpq 0x8(%rax), %rcx
je 0x927f
movq %r13, %rdi
movq %r15, %rsi
callq 0xa59e
movq (%rax), %rcx
movq 0x10(%rcx), %rdx
movq %rdx, 0x60(%rsp)
testq %rdx, %rdx
movq %r14, 0x88(%rsp)
je 0x8fec
movl 0x8(%rdx), %eax
testl %eax, %eax
je 0x8fe3
leal 0x1(%rax), %esi
lock
cmpxchgl %esi, 0x8(%rdx)
jne 0x8fbe
movq 0x60(%rsp), %rax
testq %rax, %rax
je 0x8fec
movl 0x8(%rax), %eax
testl %eax, %eax
je 0x8fec
movq 0x8(%rcx), %rax
jmp 0x8fee
movq $0x0, 0x60(%rsp)
xorl %eax, %eax
movq %rax, 0x58(%rsp)
movq %r13, %rdi
movq %r15, %rsi
callq 0xa59e
movq %rax, %rdi
callq 0x872e
cmpq $0x0, 0x58(%rsp)
je 0x91c1
leaq (%r15,%r15,8), %rax
movq 0x80(%rsp), %rcx
addq (%rcx), %rax
movq 0xc0(%rsp), %rcx
leaq (%rcx,%rcx,8), %rsi
addq %rax, %rsi
leaq 0x58(%rsp), %rdi
callq 0x3cbe
movl %ebp, 0x74(%rsp)
movq $-0x2, %r14
movl $0x140, %ebp            # imm = 0x140
xorl %r15d, %r15d
movq 0x58(%rsp), %rcx
addq %rbp, %rcx
movq -0x8(%r15,%rcx), %rax
movq %rax, 0x38(%rsp)
movq (%r15,%rcx), %rcx
movq %rcx, 0x40(%rsp)
testq %rcx, %rcx
je 0x9087
movq 0xbf4c(%rip), %rdx      # 0x14fc0
cmpb $0x0, (%rdx)
je 0x907e
incl 0x8(%rcx)
jmp 0x9087
lock
incl 0x8(%rcx)
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x9135
leaq 0x90(%rsp), %rdi
leaq 0x130(%rsp), %rsi
movq %r12, %rdx
callq 0x8838
movq 0x90(%rsp), %rax
movq 0x98(%rsp), %rcx
xorps %xmm0, %xmm0
movaps %xmm0, 0x90(%rsp)
movq %rax, 0x38(%rsp)
movq 0x40(%rsp), %rdi
movq %rcx, 0x40(%rsp)
testq %rdi, %rdi
je 0x90f3
callq 0x730e
movq 0x98(%rsp), %rdi
testq %rdi, %rdi
je 0x90ee
callq 0x730e
movq 0x38(%rsp), %rax
testq %rax, %rax
je 0x9135
cmpl %ebx, 0x100(%rax)
je 0x9135
movq %r13, %rdi
movq 0x68(%rsp), %rsi
callq 0xa59e
movq 0x38(%rsp), %rsi
movl $0xc8, %ecx
addq %rcx, %rsi
movq %rax, %rdi
movq %r12, %rdx
callq 0x80c2
cmpl $-0x1, %ebx
je 0x9135
movq 0x38(%rsp), %rax
movl %ebx, 0x100(%rax)
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9144
callq 0x730e
addq $0x10, %r15
cmpq $0x40, %r15
jne 0x904d
incq %r14
addq $0x40, %rbp
cmpq $0xa, %r14
jne 0x904a
movq 0x88(%rsp), %r14
imull $0xc28f5c29, %r14d, %eax # imm = 0xC28F5C29
addl $0x51eb850, %eax        # imm = 0x51EB850
rorl $0x2, %eax
cmpl $0x28f5c29, %eax        # imm = 0x28F5C29
movl 0x74(%rsp), %ebp
jae 0x9256
movq 0x58(%rsp), %rcx
movq 0x60(%rsp), %rax
movq %rcx, 0xa0(%rsp)
movq %rax, 0xa8(%rsp)
testq %rax, %rax
leaq 0xd0(%rsp), %r15
je 0x91d2
movq 0xbe09(%rip), %rcx      # 0x14fc0
cmpb $0x0, (%rcx)
je 0x91ce
incl 0x8(%rax)
jmp 0x91d2
movq 0x88(%rsp), %r14
jmp 0x9260
lock
incl 0x8(%rax)
movq %r15, %rdi
leaq 0xa0(%rsp), %rsi
movl 0x50(%rsp), %edx
callq 0x3fbe
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 0x80(%rsp), %rdx
movq 0x78(%rsp), %rcx
movl %ebx, %r8d
callq 0x8b65
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x9244
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
movq 0xa8(%rsp), %rdi
testq %rdi, %rdi
je 0x9256
callq 0x730e
incl %ebp
movq 0xc8(%rsp), %r15
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x926f
callq 0x730e
cmpl 0x54(%rsp), %ebp
jl 0x8f7c
movl 0x4c(%rsp), %ecx
jmp 0x928d
xorl %eax, %eax
movl 0x4c(%rsp), %ecx
cmpl %r15d, %ecx
sete %al
addl %eax, %ecx
movq 0x68(%rsp), %rax
cmpq 0xb8(%rsp), %rax
jl 0x8f58
movl %ecx, %ebp
callq 0x2040
cmpq 0xb0(%rsp), %rax
jge 0x92bd
movl %ebp, %ecx
cmpl 0x48(%rsp), %ebp
jl 0x8f55
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 0x92f4
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2170
jmp 0x92f4
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
jmp 0x930d
movq %rax, %rbx
jmp 0x9317
jmp 0x9305
movq %rax, %rbx
movq 0x40(%rsp), %rdi
testq %rdi, %rdi
je 0x9317
callq 0x730e
movq 0x60(%rsp), %rdi
testq %rdi, %rdi
je 0x9326
callq 0x730e
movq %rbx, %rdi
callq 0x2230