// File: /workspace/github_cpp_makefile_star2_O2/kmyk[P]topcoder-marathon-match-100-same-color-pairs/./SameColorPairs.cpp
// Function: with_compress(int, int, int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&, std::function<std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>> (int, int, int, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>> const&)>)
vector<array<int, 4> > with_compress(int H, int W, int C, vector<vector<int> > const & board, function<vector<array<int, 4> > (int, int, int, vector<vector<int> > const &)> cont) {
    // check empty rows and cols
    vector<bool> is_empty_row(H, true);
    vector<bool> is_empty_col(W, true);
    REP (y, H) REP (x, W) {
        if (board[y][x] >= 0) {
            is_empty_row[y] = false;
            is_empty_col[x] = false;
        }
    }

    // construct maps
    vector<int> map_row;
    vector<int> map_col;
    REP (y, H) if (not is_empty_row[y]) map_row.push_back(y);
    REP (x, W) if (not is_empty_col[x]) map_col.push_back(x);

    // construct the compressed board
    vector<vector<int> > nboard(map_row.size(), vector<int>(map_col.size()));
    REP (y, map_row.size()) {
        REP (x, map_col.size()) {
            nboard[y][x] = board[map_row[y]][map_col[x]];
        }
    }

    // call the continuation
    vector<array<int, 4> > rects = cont(map_row.size(), map_col.size(), C, nboard);

    // make the return value
    for (auto & rect : rects) {
        int & y1 = rect[0];
        int & x1 = rect[1];
        int & y2 = rect[2];
        int & x2 = rect[3];
        y1 = map_row[y1];
        x1 = map_col[x1];
        y2 = map_row[y2];
        x2 = map_col[x2];
    }
    return rects;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xe8, %rsp
movq %r9, 0x68(%rsp)
movq %r8, 0x60(%rsp)
movl %ecx, 0x4(%rsp)
movl %edx, %r14d
movl %esi, %r15d
movq %rdi, 0x70(%rsp)
movslq %esi, %rsi
movb $0x1, %bpl
leaq 0x98(%rsp), %rdx
movb %bpl, (%rdx)
leaq 0xc0(%rsp), %rdi
leaq 0x40(%rsp), %rbx
movq %rbx, %rcx
callq 0x3b1a
movslq %r14d, %rsi
movb %bpl, (%rbx)
leaq 0x98(%rsp), %rdi
leaq 0x40(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x3b1a
xorl %ebp, %ebp
testl %r14d, %r14d
movl $0x0, %r13d
movl %r14d, 0xc(%rsp)
cmovgl %r14d, %r13d
testl %r15d, %r15d
movl $0x0, %eax
movl %r15d, 0x8(%rsp)
cmovgl %r15d, %eax
movq %rax, 0x78(%rsp)
leaq 0xc0(%rsp), %r14
leaq 0x98(%rsp), %rbx
cmpq 0x78(%rsp), %rbp
je 0x24f5
imulq $0x18, %rbp, %r15
xorl %r12d, %r12d
cmpq %r12, %r13
je 0x24f0
movq 0x60(%rsp), %rax
movq (%rax), %rax
movq (%rax,%r15), %rax
cmpl $0x0, (%rax,%r12,4)
js 0x24eb
movq %r14, %rdi
movq %rbp, %rsi
callq 0x3b7e
notq %rdx
andq %rdx, (%rax)
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3b7e
notq %rdx
andq %rdx, (%rax)
incq %r12
jmp 0x24b1
incq %rbp
jmp 0x24a3
xorps %xmm0, %xmm0
leaq 0x40(%rsp), %rbx
andq $0x0, 0x10(%rbx)
movaps %xmm0, (%rbx)
andq $0x0, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
leaq 0xc0(%rsp), %r14
leaq 0x28(%rsp), %r12
movl 0xc(%rsp), %ebp
movl 0x8(%rsp), %r15d
movl %eax, 0x28(%rsp)
cmpl %r15d, %eax
jge 0x2554
movslq %eax, %rsi
movq %r14, %rdi
callq 0x3b7e
testq %rdx, (%rax)
jne 0x254c
movq %rbx, %rdi
movq %r12, %rsi
callq 0x3b9c
movl 0x28(%rsp), %eax
incl %eax
jmp 0x2528
xorl %eax, %eax
leaq 0x98(%rsp), %rbx
leaq 0x10(%rsp), %r14
leaq 0x28(%rsp), %r12
movl %eax, 0x28(%rsp)
cmpl %ebp, %eax
jge 0x2593
movslq %eax, %rsi
movq %rbx, %rdi
callq 0x3b7e
testq %rdx, (%rax)
jne 0x258b
movq %r14, %rdi
movq %r12, %rsi
callq 0x3b9c
movl 0x28(%rsp), %eax
incl %eax
jmp 0x2568
movq 0x40(%rsp), %r14
movq 0x48(%rsp), %rbx
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0x80(%rsp), %rdi
leaq 0x3(%rsp), %rdx
callq 0x3bba
subq %r14, %rbx
sarq $0x2, %rbx
leaq 0x28(%rsp), %rdi
leaq 0x80(%rsp), %rdx
leaq 0x2(%rsp), %rcx
movq %rbx, %rsi
callq 0x3c0c
movq 0x70(%rsp), %r12
leaq 0x80(%rsp), %rdi
callq 0x4908
movq 0x40(%rsp), %rax
movq 0x48(%rsp), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rcx
subq %rsi, %rcx
shrq $0x2, %rcx
xorl %edi, %edi
testl %ecx, %ecx
movl $0x0, %r8d
cmovgl %ecx, %r8d
testl %edx, %edx
movl $0x0, %r9d
cmovgl %edx, %r9d
cmpq %r9, %rdi
je 0x266e
movq 0x60(%rsp), %r10
movq (%r10), %r10
imulq $0x18, %rdi, %r11
addq 0x28(%rsp), %r11
xorl %ebx, %ebx
cmpq %rbx, %r8
je 0x2669
movslq (%rax,%rdi,4), %r14
imulq $0x18, %r14, %r14
movslq (%rsi,%rbx,4), %r15
movq (%r10,%r14), %r14
movl (%r14,%r15,4), %ebp
movq (%r11), %r14
movl %ebp, (%r14,%rbx,4)
incq %rbx
jmp 0x2644
incq %rdi
jmp 0x262c
leaq 0x28(%rsp), %r9
movq %r12, %rdi
movq 0x68(%rsp), %rsi
movl 0x4(%rsp), %r8d
callq 0x3c62
movq (%r12), %rax
movq 0x8(%r12), %rcx
movq 0x40(%rsp), %rdx
movq 0x10(%rsp), %rsi
cmpq %rcx, %rax
je 0x26c9
movslq (%rax), %rdi
movl (%rdx,%rdi,4), %edi
movl %edi, (%rax)
movslq 0x4(%rax), %rdi
movl (%rsi,%rdi,4), %edi
movl %edi, 0x4(%rax)
movslq 0x8(%rax), %rdi
movl (%rdx,%rdi,4), %edi
movl %edi, 0x8(%rax)
movslq 0xc(%rax), %rdi
movl (%rsi,%rdi,4), %edi
movl %edi, 0xc(%rax)
addq $0x10, %rax
jmp 0x2698
leaq 0x28(%rsp), %rdi
callq 0x3c9e
leaq 0x10(%rsp), %rdi
callq 0x4908
leaq 0x40(%rsp), %rdi
callq 0x4908
leaq 0x98(%rsp), %rdi
callq 0x3cc0
leaq 0xc0(%rsp), %rdi
callq 0x3cc0
movq %r12, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
callq 0x3c9e
jmp 0x2747
movq %rax, %rbx
leaq 0x80(%rsp), %rdi
callq 0x4908
jmp 0x2747
jmp 0x2744
movq %rax, %rbx
jmp 0x276f
jmp 0x2744
jmp 0x2744
jmp 0x2744
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x4908
leaq 0x40(%rsp), %rdi
callq 0x4908
jmp 0x2762
jmp 0x275f
movq %rax, %rbx
leaq 0x98(%rsp), %rdi
callq 0x3cc0
leaq 0xc0(%rsp), %rdi
callq 0x3cc0
movq %rbx, %rdi
callq 0x22a0