// File: /workspace/github_cpp_makefile_star2_O3/kmyk[P]codevs-for-student-2016/Main.cpp
// Function: std::vector<std::pair<point_t, int>, std::allocator<std::pair<point_t, int>>> simulation::collect_erases<19ul, 10ul>(primitive::blocks_t<19ul, 10ul> const&, std::vector<point_t, std::allocator<point_t>> const&)
vector<pair<point_t,int> > collect_erases(blocks_t<H,W> const & field, vector<point_t> const & modified_blocks) {
        static const int dy[] = { -1, -1, 0, 1 }; // 下 右下 右 右上
        static const int dx[] = {  0,  1, 1, 1 };
        vector<pair<point_t,int> > erases;
        for (point_t p : modified_blocks) { // 変化したところだけ見る
            assert (field.at[p.x][p.y] != empty_block and field.at[p.x][p.y] != obstacle_block);
            repeat (j, 4) {
                int cnt = 1;
                int acc = field.at[p.x][p.y];
                int ly = p.y - dy[j];
                int lx = p.x - dx[j];
                for (; is_on_field(ly, lx, H, W); ++ cnt) {
                    block_t block = field.at[lx][ly];
                    if (block == empty_block) break;
                    if (acc + block > erasing_sum) break;
                    acc += block;
                    ly -= dy[j];
                    lx -= dx[j];
                }
                // しゃくとり法っぽく
                int ry = p.y + dy[j];
                int rx = p.x + dx[j];
                while (cnt --) {
                    while (is_on_field(ry, rx, H, W)) {
                        block_t block = field.at[rx][ry];
                        if (block == empty_block) break;
                        if (acc + block > erasing_sum) break;
                        acc += block;
                        ry += dy[j];
                        rx += dx[j];
                    }
                    ly += dy[j];
                    lx += dx[j];
                    if (acc == erasing_sum) erases.emplace_back(point(ly, lx), j);
                    acc -= field.at[lx][ly];
                }
            }
        }
        whole(sort, erases);
        erases.erase(whole(unique, erases), erases.end()); // 重複排除
        return erases;
    }

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
xorps %xmm0, %xmm0
movups %xmm0, (%rdi)
movq $0x0, 0x10(%rdi)
movq (%rdx), %rax
movq 0x8(%rdx), %rcx
movq %rcx, 0x18(%rsp)
cmpq %rcx, %rax
je 0xc442
movq %rbx, 0x8(%rsp)
leaq 0x33cf(%rip), %r8       # 0xf620
leaq 0x33d8(%rip), %r9       # 0xf630
movslq (%rax), %rdi
movq %rax, 0x20(%rsp)
movslq 0x4(%rax), %r10
leaq (%r10,%r10,8), %rax
leaq (%r10,%rax,2), %rax
addq %rsi, %rax
movq %rax, 0x38(%rsp)
movl $0x0, 0x4(%rsp)
xorl %ecx, %ecx
movq %rdi, 0x30(%rsp)
movq %r10, 0x28(%rsp)
movq 0x38(%rsp), %rax
movsbl (%rax,%rdi), %eax
movslq %ecx, %rcx
movl (%r8,%rcx,4), %r15d
movl (%r9,%rcx,4), %r12d
movl %r10d, %r11d
subl %r12d, %r11d
movl %edi, %ebx
movl $0x1, %ebp
subl %r15d, %ebx
js 0xc2ea
movl %eax, %ecx
cmpl $0x12, %ebx
ja 0xc2e8
cmpl $0x9, %r11d
ja 0xc2e8
movl %r11d, %eax
leaq (%rax,%rax,8), %rdx
leaq (%rax,%rdx,2), %rax
addq %rsi, %rax
movl %ebx, %edx
movsbl (%rdx,%rax), %eax
testl %eax, %eax
je 0xc2e8
addl %ecx, %eax
cmpl $0xa, %eax
jg 0xc2e8
incl %ebp
subl %r12d, %r11d
subl %r15d, %ebx
movl %eax, %ecx
jns 0xc2b0
jmp 0xc2ea
movl %ecx, %eax
addl %edi, %r15d
addl %r10d, %r12d
movslq 0x4(%rsp), %rcx
testl %r15d, %r15d
js 0xc339
cmpl $0x12, %r15d
ja 0xc339
cmpl $0x9, %r12d
ja 0xc339
movl %r12d, %edx
leaq (%rdx,%rdx,8), %rdi
leaq (%rdx,%rdi,2), %rdx
addq %rsi, %rdx
movl %r15d, %edi
movsbl (%rdi,%rdx), %r14d
testl %r14d, %r14d
je 0xc339
addl %eax, %r14d
cmpl $0xa, %r14d
jg 0xc339
addl (%r9,%rcx,4), %r12d
addl (%r8,%rcx,4), %r15d
movl %r14d, %eax
jns 0xc2fa
jmp 0xc33c
movl %eax, %r14d
movslq (%r8,%rcx,4), %rax
movslq %ebx, %rbx
addq %rax, %rbx
movslq (%r9,%rcx,4), %rax
movslq %r11d, %r11
addq %rax, %r11
cmpl $0xa, %r14d
jne 0xc3a0
movl %ebp, 0x14(%rsp)
movq %rbx, %rcx
movq %rsi, %rbp
movq %r11, %r13
movq %r11, %rax
shlq $0x20, %rax
movl %ecx, %ecx
orq %rax, %rcx
movq %rcx, 0x40(%rsp)
movq 0x8(%rsp), %rdi
leaq 0x40(%rsp), %rsi
leaq 0x4(%rsp), %rdx
callq 0xc7ea
movq %rbp, %rsi
leaq 0x328e(%rip), %r8       # 0xf620
leaq 0x3297(%rip), %r9       # 0xf630
movq %r13, %r11
movl 0x14(%rsp), %ebp
decl %ebp
leaq (%r11,%r11,8), %rax
leaq (%r11,%rax,2), %rax
addq %rsi, %rax
movsbl (%rbx,%rax), %eax
subl %eax, %r14d
movl %r14d, %eax
testl %ebp, %ebp
jne 0xc2f0
movl 0x4(%rsp), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x4(%rsp)
cmpl $0x3, %eax
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %r10
jl 0xc288
movq 0x20(%rsp), %rax
addq $0x8, %rax
cmpq 0x18(%rsp), %rax
jne 0xc258
movq 0x8(%rsp), %rbx
movq (%rbx), %r14
movq 0x8(%rbx), %r15
cmpq %r15, %r14
je 0xc445
movq %r15, %rax
subq %r14, %rax
sarq $0x2, %rax
movabsq $-0x5555555555555555, %rcx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rax, %rcx
bsrq %rcx, %rdx
xorl $0x3f, %edx
addl %edx, %edx
xorq $0x7e, %rdx
movq %r14, %rdi
movq %r15, %rsi
callq 0xc9b9
movq %r14, %rdi
movq %r15, %rsi
callq 0xca78
movq (%rbx), %r14
jmp 0xc445
xorl %r14d, %r14d
movq 0x8(%rbx), %rsi
movq %r14, %rdi
callq 0xd121
movq 0x8(%rbx), %rdx
movq %rbx, %rdi
movq %rax, %rsi
callq 0xd0ac
movq %rbx, %rax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
jmp 0xc47d
jmp 0xc476
movq %rbx, 0x8(%rsp)
jmp 0xc47d
movq %rax, %r14
movq 0x8(%rsp), %rax
movq (%rax), %rdi
testq %rdi, %rdi
je 0xc499
movq 0x10(%rax), %rsi
subq %rdi, %rsi
callq 0x2170
movq %r14, %rdi
callq 0x2230