// File: 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
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
leaq 0x20(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movl %r8d, -0x1c(%rbp)
movl %r9d, -0x20(%rbp)
movq 0x18(%rbp), %rsi
leaq -0x28(%rbp), %rdi
callq 0x17ef0
movl $0x0, -0x2c(%rbp)
movl $0x0, -0x30(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x17f60
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0xe9(%rbp)
jne 0x10919
jmp 0x10928
movl -0x2c(%rbp), %eax
cmpl -0x1c(%rbp), %eax
setl %al
movb %al, -0xe9(%rbp)
movb -0xe9(%rbp), %al
testb $0x1, %al
jne 0x10937
jmp 0x10d12
movl -0x2c(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jge 0x10d0d
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x18(%rbp), %eax
jge 0x10cfd
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf4f0
movq %rax, %rdi
callq 0xffb0
testb $0x1, %al
jne 0x10980
jmp 0x10996
movl -0x34(%rbp), %eax
cmpl -0x2c(%rbp), %eax
jne 0x10991
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x10cfd
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf4f0
movq %rax, %rdi
callq 0xffd0
movq %rax, %rsi
addq $0x8, %rsi
leaq -0x48(%rbp), %rdi
callq 0x7d30
movq -0x8(%rbp), %rdi
movslq -0x34(%rbp), %rsi
callq 0xf4f0
movq %rax, %rdi
callq 0xfff0
jmp 0x109d2
leaq -0x48(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10a05
movl -0x38(%rbp), %eax
addl $-0x1, %eax
movl %eax, -0x38(%rbp)
movl $0x9, -0x58(%rbp)
jmp 0x10cce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10cf2
movq -0x10(%rbp), %rdi
movl -0x14(%rbp), %eax
movl -0x34(%rbp), %ecx
addl %ecx, %eax
movslq %eax, %rsi
callq 0x122f0
movq %rax, %rsi
leaq -0x48(%rbp), %rdi
callq 0x4c20
jmp 0x10a27
movl $0xfffffffe, -0x5c(%rbp) # imm = 0xFFFFFFFE
cmpl $0xa, -0x5c(%rbp)
jge 0x10bc0
movl $0x0, -0x60(%rbp)
cmpl $0x4, -0x60(%rbp)
jge 0x10bb0
leaq -0x48(%rbp), %rdi
callq 0x76d0
movq %rax, %rdi
addq $0x138, %rdi            # imm = 0x138
movl -0x5c(%rbp), %eax
addl $0x3, %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x7b30
movq %rax, %rdi
movslq -0x60(%rbp), %rsi
callq 0x7b60
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x7c70
leaq -0x70(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10a9e
movl $0xf, -0x58(%rbp)
jmp 0x10b8c
movq -0xe8(%rbp), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x70(%rbp), %rdx
callq 0x10080
jmp 0x10ab4
leaq -0x70(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7d60
leaq -0x80(%rbp), %rdi
callq 0x78c0
leaq -0x70(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10afd
movl $0xf, -0x58(%rbp)
jmp 0x10b8c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x78c0
jmp 0x10cf2
leaq -0x70(%rbp), %rdi
callq 0x76d0
movl 0x100(%rax), %eax
cmpl -0x20(%rbp), %eax
jne 0x10b1a
movl $0xf, -0x58(%rbp)
jmp 0x10b8c
movq -0x8(%rbp), %rdi
movl -0x34(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0xf4f0
movq %rax, -0x100(%rbp)
leaq -0x70(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x76d0
movq -0x100(%rbp), %rdi
movq -0xf8(%rbp), %rdx
movq %rax, %rsi
addq $0xc8, %rsi
callq 0xf520
jmp 0x10b61
cmpl $-0x1, -0x20(%rbp)
je 0x10b85
movl -0x20(%rbp), %eax
movl %eax, -0x104(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x76d0
movl -0x104(%rbp), %ecx
movl %ecx, 0x100(%rax)
movl $0x0, -0x58(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x78c0
movl -0x58(%rbp), %eax
testl %eax, %eax
je 0x10ba0
jmp 0x10b9e
jmp 0x10ba2
jmp 0x10ba2
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x10a3f
jmp 0x10bb2
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x10a2e
movl -0x30(%rbp), %eax
movl $0x64, %ecx
cltd
idivl %ecx
cmpl $0x0, %edx
jne 0x10cc7
movq 0x10(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0xa8(%rbp), %rdi
movq %rdi, -0x110(%rbp)
leaq -0x48(%rbp), %rsi
callq 0x7c70
movq -0x110(%rbp), %rsi
movl -0x14(%rbp), %edx
leaq -0x98(%rbp), %rdi
callq 0x5110
jmp 0x10c0e
movq -0x118(%rbp), %rdi
movq -0xe8(%rbp), %rax
movq -0x10(%rbp), %rdx
movq -0x8(%rbp), %rcx
movl -0x20(%rbp), %r8d
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups 0x20(%rax), %xmm2
movaps %xmm2, -0xc0(%rbp)
movaps %xmm1, -0xd0(%rbp)
movaps %xmm0, -0xe0(%rbp)
movaps -0xe0(%rbp), %xmm0
movaps -0xd0(%rbp), %xmm1
movaps -0xc0(%rbp), %xmm2
movq %rsp, %rax
movups %xmm2, 0x20(%rax)
movups %xmm1, 0x10(%rax)
movups %xmm0, (%rax)
leaq -0x98(%rbp), %rsi
callq 0x10400
jmp 0x10c79
leaq -0x98(%rbp), %rdi
callq 0x7e90
leaq -0xa8(%rbp), %rdi
callq 0x78c0
jmp 0x10cc7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x10cb9
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x7e90
leaq -0xa8(%rbp), %rdi
callq 0x78c0
jmp 0x10cf2
movl $0x0, -0x58(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x78c0
movl -0x58(%rbp), %eax
testl %eax, %eax
je 0x10ce2
jmp 0x10ce0
jmp 0x10ce4
jmp 0x10ce4
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x10950
leaq -0x48(%rbp), %rdi
callq 0x78c0
jmp 0x10d1b
jmp 0x10cff
movl -0x34(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x34(%rbp)
jmp 0x1093d
jmp 0x108ff
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x22f0
nopw %cs:(%rax,%rax)
nop