// File: kmyk[P]codevs-for-student-2016/Main.cpp
// Function: void anneal_photon<AI::think(primitive::input_t const&)::'lambda2'(std::shared_ptr<photon_t> const&)>(std::shared_ptr<photon_t> const&, std::vector<primitive::output_t, std::allocator<primitive::output_t>>, primitive::config_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&)>>>>&, int, AI::think(primitive::input_t const&)::'lambda2'(std::shared_ptr<photon_t> const&))
void anneal_photon(shared_ptr<photon_t> const & initial, vector<output_t> outputs, config_t const & config, deque<functional_priority_queue<pair<double, weak_ptr<photon_t> > > > & que, int beam_generation, F cont) {
    shared_ptr<photon_t> pho = initial;
    repeat (i, outputs.size()) {
        repeat_from (x, - pack_size + 1, width) repeat (r, 4) {
            shared_ptr<photon_t> npho = step_photon(pho, config.packs[pho->turn], make_output(x, r));
            if (not npho) continue;
            npho = cont(npho);
            if (not npho) continue;
            if (npho->beam_generation != beam_generation) {
                que[i+1].emplace(npho->evaluation.score, npho);
                if (beam_generation != -1) npho->beam_generation = beam_generation;
            }
            repeat_from (j, i+1, outputs.size()) {
                npho = step_photon(npho, config.packs[npho->turn], outputs[j]);
                if (not npho) break;
                npho = cont(npho);
                if (not npho) break;
                if (npho->beam_generation != beam_generation) {
                    que[j+1].emplace(npho->evaluation.score, npho);
                    if (beam_generation != -1) npho->beam_generation = beam_generation;
                }
            }
        }
        pho = step_photon(pho, config.packs[pho->turn], outputs[i]);
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x160, %rsp            # imm = 0x160
movq %rsi, -0xd8(%rbp)
leaq 0x10(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x8(%rbp), %rsi
leaq -0x38(%rbp), %rdi
callq 0x7c70
movl $0x0, -0x3c(%rbp)
movq -0xd8(%rbp), %rdi
movslq -0x3c(%rbp), %rax
movq %rax, -0xe0(%rbp)
callq 0x17eb0
movq %rax, %rcx
movq -0xe0(%rbp), %rax
cmpq %rcx, %rax
jae 0x10884
movl $0xfffffffe, -0x40(%rbp) # imm = 0xFFFFFFFE
cmpl $0xa, -0x40(%rbp)
jge 0x107ec
movl $0x0, -0x44(%rbp)
cmpl $0x4, -0x44(%rbp)
jge 0x107dc
movq -0x18(%rbp), %rax
movq %rax, -0xf8(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0xf0(%rbp)
callq 0x76d0
movq -0xf8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x122f0
movq %rax, -0xe8(%rbp)
movl -0x40(%rbp), %edi
movl -0x44(%rbp), %esi
callq 0x2930
movq -0xf0(%rbp), %rsi
movq -0xe8(%rbp), %rdx
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rcx
leaq -0x58(%rbp), %rdi
callq 0x4ae0
jmp 0x104ee
leaq -0x58(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10518
movl $0xa, -0x70(%rbp)
jmp 0x107b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0x10896
movq -0xd0(%rbp), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x10080
jmp 0x1052e
leaq -0x58(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x7d60
leaq -0x80(%rbp), %rdi
callq 0x78c0
leaq -0x58(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10577
movl $0xa, -0x70(%rbp)
jmp 0x107b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x78c0
jmp 0x10896
leaq -0x58(%rbp), %rdi
callq 0x76d0
movl 0x100(%rax), %eax
cmpl -0x24(%rbp), %eax
je 0x105f8
movq -0x20(%rbp), %rdi
movl -0x3c(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0xf4f0
movq %rax, -0x108(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x100(%rbp)
callq 0x76d0
movq -0x108(%rbp), %rdi
movq -0x100(%rbp), %rdx
movq %rax, %rsi
addq $0xc8, %rsi
callq 0xf520
jmp 0x105d2
cmpl $-0x1, -0x24(%rbp)
je 0x105f6
movl -0x24(%rbp), %eax
movl %eax, -0x10c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x76d0
movl -0x10c(%rbp), %ecx
movl %ecx, 0x100(%rax)
jmp 0x105f8
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
movq -0xd8(%rbp), %rdi
movslq -0x84(%rbp), %rax
movq %rax, -0x118(%rbp)
callq 0x17eb0
movq %rax, %rcx
movq -0x118(%rbp), %rax
cmpq %rcx, %rax
jae 0x107b1
movq -0x18(%rbp), %rax
movq %rax, -0x130(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x128(%rbp)
callq 0x76d0
movq -0x130(%rbp), %rdi
movslq (%rax), %rsi
callq 0x122f0
movq -0xd8(%rbp), %rdi
movq %rax, -0x120(%rbp)
movslq -0x84(%rbp), %rsi
callq 0x17ed0
movq -0x128(%rbp), %rsi
movq -0x120(%rbp), %rdx
movq (%rax), %rax
movq %rax, -0xa0(%rbp)
movq -0xa0(%rbp), %rcx
leaq -0x98(%rbp), %rdi
callq 0x4ae0
jmp 0x106a2
leaq -0x58(%rbp), %rdi
leaq -0x98(%rbp), %rsi
callq 0x7d60
leaq -0x98(%rbp), %rdi
callq 0x78c0
leaq -0x58(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x106d0
jmp 0x107b1
movq -0xd0(%rbp), %rsi
leaq -0xb0(%rbp), %rdi
leaq -0x58(%rbp), %rdx
callq 0x10080
jmp 0x106e9
leaq -0x58(%rbp), %rdi
leaq -0xb0(%rbp), %rsi
callq 0x7d60
leaq -0xb0(%rbp), %rdi
callq 0x78c0
leaq -0x58(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0x10717
jmp 0x107b1
leaq -0x58(%rbp), %rdi
callq 0x76d0
movl 0x100(%rax), %eax
cmpl -0x24(%rbp), %eax
je 0x1079b
movq -0x20(%rbp), %rdi
movl -0x84(%rbp), %eax
incl %eax
movslq %eax, %rsi
callq 0xf4f0
movq %rax, -0x140(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0x138(%rbp)
callq 0x76d0
movq -0x140(%rbp), %rdi
movq -0x138(%rbp), %rdx
movq %rax, %rsi
addq $0xc8, %rsi
callq 0xf520
jmp 0x10775
cmpl $-0x1, -0x24(%rbp)
je 0x10799
movl -0x24(%rbp), %eax
movl %eax, -0x144(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x76d0
movl -0x144(%rbp), %ecx
movl %ecx, 0x100(%rax)
jmp 0x1079b
jmp 0x1079d
movl -0x84(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x84(%rbp)
jmp 0x10604
movl $0x0, -0x70(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x78c0
movl -0x70(%rbp), %eax
testl %eax, %eax
je 0x107cc
jmp 0x107ca
jmp 0x107ce
jmp 0x107ce
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0x10487
jmp 0x107de
movl -0x40(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x40(%rbp)
jmp 0x10476
movq -0x18(%rbp), %rax
movq %rax, -0x160(%rbp)
leaq -0x38(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x76d0
movq -0x160(%rbp), %rdi
movslq (%rax), %rsi
callq 0x122f0
movq -0xd8(%rbp), %rdi
movq %rax, -0x150(%rbp)
movslq -0x3c(%rbp), %rsi
callq 0x17ed0
movq -0x158(%rbp), %rsi
movq -0x150(%rbp), %rdx
movq (%rax), %rax
movq %rax, -0xc8(%rbp)
movq -0xc8(%rbp), %rcx
leaq -0xc0(%rbp), %rdi
callq 0x4ae0
jmp 0x1085a
leaq -0x38(%rbp), %rdi
leaq -0xc0(%rbp), %rsi
callq 0x7d60
leaq -0xc0(%rbp), %rdi
callq 0x78c0
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x10445
leaq -0x38(%rbp), %rdi
callq 0x78c0
addq $0x160, %rsp            # imm = 0x160
popq %rbp
retq
leaq -0x38(%rbp), %rdi
callq 0x78c0
movq -0x68(%rbp), %rdi
callq 0x22f0
nopl (%rax,%rax)