// File: kmyk[P]codevs-for-student-2016/Main.cpp
// Function: void update_photon_obstacles<AI::think(primitive::input_t const&)::'lambda'(std::shared_ptr<photon_t> const&)>(std::shared_ptr<photon_t> const&, int, std::vector<primitive::blocks_t<3ul, 3ul>, std::allocator<primitive::blocks_t<3ul, 3ul>>> const&, AI::think(primitive::input_t const&)::'lambda'(std::shared_ptr<photon_t> const&))
void update_photon_obstacles(shared_ptr<photon_t> const & pho, int updated_obstacles, vector<pack_t> const & packs, F cont) {
    if (pho->obstacles == updated_obstacles) {
        // nop
    } else {
        int         consumed = count_consumed_obstacles(packs[pho->turn],    pho->obstacles);
        int updated_consumed = count_consumed_obstacles(packs[pho->turn], updated_obstacles);
        pho->obstacles = updated_obstacles;
        evaluate_photon_for_search(pho);
        if (consumed != updated_consumed) {
            repeat_from (x, - pack_size + 1, width) repeat (r, 4) {
                pho->cached[x+pack_size-1][r] = false;
                pho->next[x+pack_size-1][r] = nullptr; // 開放
            }
            cont(pho);
        } else {
            repeat_from (x, - pack_size + 1, width) repeat (r, 4) {
                if (not pho->cached[x+pack_size-1][r]) continue;
                shared_ptr<photon_t> npho = pho->next[x+pack_size-1][r];
                if (not npho) continue;
                int next_obstacles = pho->obstacles - updated_consumed - count_obstacles_from_delta(pho->score, npho->result.score);
                update_photon_obstacles(npho, next_obstacles, packs, cont);
            }
        }
    }
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0xb0, %rsp
movq %rcx, -0x8(%rbp)
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movq %rdx, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xec10
jmp 0xeefd
movq -0x20(%rbp), %rax
movq %rax, -0x90(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movq -0x90(%rbp), %rdi
movslq (%rax), %rsi
callq 0x122f0
movq %rax, -0x88(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movq -0x88(%rbp), %rdi
movl 0x8(%rax), %esi
callq 0x2d40
movl %eax, -0x24(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x80(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movq -0x80(%rbp), %rdi
movslq (%rax), %rsi
callq 0x122f0
movq %rax, %rdi
movl -0x14(%rbp), %esi
callq 0x2d40
movl %eax, -0x28(%rbp)
movl -0x14(%rbp), %eax
movl %eax, -0x78(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movl -0x78(%rbp), %ecx
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rdi
callq 0x4310
movl -0x24(%rbp), %eax
cmpl -0x28(%rbp), %eax
je 0xed81
movl $0xfffffffe, -0x2c(%rbp) # imm = 0xFFFFFFFE
cmpl $0xa, -0x2c(%rbp)
jge 0xed6f
movl $0x0, -0x30(%rbp)
cmpl $0x4, -0x30(%rbp)
jge 0xed5f
movq -0x10(%rbp), %rdi
callq 0x76d0
movq %rax, %rdi
addq $0x104, %rdi            # imm = 0x104
movl -0x2c(%rbp), %eax
addl $0x3, %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x7a20
movq %rax, %rdi
movslq -0x30(%rbp), %rsi
callq 0x7a50
movb $0x0, (%rax)
leaq -0x40(%rbp), %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x7d90
movq -0x10(%rbp), %rdi
callq 0x76d0
movq %rax, %rdi
addq $0x138, %rdi            # imm = 0x138
movl -0x2c(%rbp), %eax
addl $0x3, %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x7b30
movq %rax, %rdi
movslq -0x30(%rbp), %rsi
callq 0x7b60
movq %rax, %rdi
leaq -0x40(%rbp), %rsi
callq 0x7d60
leaq -0x40(%rbp), %rdi
callq 0x78c0
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0xecc2
jmp 0xed61
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0xecb1
movq -0x10(%rbp), %rsi
leaq -0x8(%rbp), %rdi
callq 0x12310
jmp 0xeefb
movl $0xfffffffe, -0x44(%rbp) # imm = 0xFFFFFFFE
cmpl $0xa, -0x44(%rbp)
jge 0xeef9
movl $0x0, -0x48(%rbp)
cmpl $0x4, -0x48(%rbp)
jge 0xeee9
movq -0x10(%rbp), %rdi
callq 0x76d0
movq %rax, %rdi
addq $0x104, %rdi            # imm = 0x104
movl -0x44(%rbp), %eax
addl $0x3, %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x7a20
movq %rax, %rdi
movslq -0x48(%rbp), %rsi
callq 0x7a50
testb $0x1, (%rax)
jne 0xeddd
jmp 0xeec4
movq -0x10(%rbp), %rdi
callq 0x76d0
movq %rax, %rdi
addq $0x138, %rdi            # imm = 0x138
movl -0x44(%rbp), %eax
addl $0x3, %eax
subl $0x1, %eax
movslq %eax, %rsi
callq 0x7b30
movq %rax, %rdi
movslq -0x48(%rbp), %rsi
callq 0x7b60
movq %rax, %rsi
leaq -0x58(%rbp), %rdi
callq 0x7c70
leaq -0x58(%rbp), %rdi
callq 0x7d10
testb $0x1, %al
jne 0xee2f
movl $0xd, -0x5c(%rbp)
jmp 0xeeae
movq -0x10(%rbp), %rdi
callq 0x76d0
movl 0x8(%rax), %eax
movl -0x28(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x94(%rbp)
movq -0x10(%rbp), %rdi
callq 0x76d0
movl 0x4(%rax), %eax
movl %eax, -0xa4(%rbp)
leaq -0x58(%rbp), %rdi
movq %rdi, -0xa0(%rbp)
callq 0x76d0
movl -0xa4(%rbp), %edi
movl 0xbc(%rax), %esi
callq 0x2dc0
movq -0xa0(%rbp), %rdi
movl %eax, %ecx
movl -0x94(%rbp), %eax
subl %ecx, %eax
movl %eax, -0x60(%rbp)
movl -0x60(%rbp), %esi
movq -0x20(%rbp), %rdx
movq -0x8(%rbp), %rax
movq %rax, -0x68(%rbp)
movq -0x68(%rbp), %rcx
callq 0xebe0
jmp 0xeea7
movl $0x0, -0x5c(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x78c0
movl -0x5c(%rbp), %eax
testl %eax, %eax
je 0xeec2
jmp 0xeec0
jmp 0xeec4
jmp 0xeec4
movl -0x48(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x48(%rbp)
jmp 0xed99
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x70(%rbp)
movl %eax, -0x74(%rbp)
leaq -0x58(%rbp), %rdi
callq 0x78c0
jmp 0xef06
jmp 0xeeeb
movl -0x44(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
jmp 0xed88
jmp 0xeefb
jmp 0xeefd
addq $0xb0, %rsp
popq %rbp
retq
movq -0x70(%rbp), %rdi
callq 0x22f0
nop