// File: /workspace/github_cpp_makefile_star2_O1/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, 0xc8(%rsp)
movq %r8, 0xb8(%rsp)
movl %ecx, 0x64(%rsp)
movl %edx, %r12d
movl %esi, %r13d
movq %rdi, %rbp
movslq %esi, %rsi
movb $0x1, %bl
leaq 0x68(%rsp), %rdx
movb %bl, (%rdx)
leaq 0x90(%rsp), %rdi
leaq 0x30(%rsp), %r14
movq %r14, %rcx
callq 0x4266
movslq %r12d, %rsi
movb %bl, (%r14)
leaq 0x68(%rsp), %rdi
leaq 0x30(%rsp), %rdx
leaq 0x10(%rsp), %rcx
callq 0x4266
testl %r13d, %r13d
jle 0x255c
movq 0xb8(%rsp), %rax
movq (%rax), %rdx
movl %r13d, %esi
movl %r12d, %edi
xorl %eax, %eax
testl %r12d, %r12d
jle 0x2554
leaq (%rax,%rax,2), %rcx
movq (%rdx,%rcx,8), %r8
movq 0x90(%rsp), %r9
movq $-0x2, %r10
movl %eax, %ecx
rolq %cl, %r10
movq %rax, %r11
shrq $0x6, %r11
movq 0x68(%rsp), %rbx
xorl %ecx, %ecx
cmpl $0x0, (%r8,%rcx,4)
js 0x254c
andq %r10, (%r9,%r11,8)
movq %rcx, %r14
movq $-0x2, %r15
rolq %cl, %r15
shrq $0x6, %r14
andq %r15, (%rbx,%r14,8)
incq %rcx
cmpq %rcx, %rdi
jne 0x252c
incq %rax
cmpq %rsi, %rax
jne 0x24fd
movq %rbp, 0xc0(%rsp)
movabsq $-0x8000000000000000, %r15 # imm = 0x8000000000000000
xorps %xmm0, %xmm0
movaps %xmm0, 0x30(%rsp)
xorl %eax, %eax
movq %rax, 0x40(%rsp)
movq %rax, 0x20(%rsp)
movaps %xmm0, 0x10(%rsp)
movl $0x0, 0x48(%rsp)
testl %r13d, %r13d
jle 0x260d
leaq 0x3f(%r15), %rbx
leaq 0x30(%rsp), %rbp
leaq 0x48(%rsp), %r14
movslq %eax, %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0x90(%rsp), %rdx
movq %rcx, %rsi
andq %rbx, %rsi
xorl %edi, %edi
cmpq %r15, %rsi
setbe %dil
movq -0x8(%rdx,%rdi,8), %rdx
btq %rcx, %rdx
jb 0x25fe
movq 0x38(%rsp), %rsi
cmpq 0x40(%rsp), %rsi
je 0x25f3
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x38(%rsp)
jmp 0x25fe
movq %rbp, %rdi
movq %r14, %rdx
callq 0x5330
movl 0x48(%rsp), %eax
incl %eax
movl %eax, 0x48(%rsp)
cmpl %r13d, %eax
jl 0x25a2
movl $0x0, 0x48(%rsp)
testl %r12d, %r12d
jle 0x2692
xorl %eax, %eax
leaq 0x3f(%r15), %rbx
leaq 0x10(%rsp), %r13
leaq 0x48(%rsp), %r14
movslq %eax, %rcx
leaq 0x3f(%rcx), %rdx
testq %rcx, %rcx
cmovnsq %rcx, %rdx
sarq $0x6, %rdx
shlq $0x3, %rdx
addq 0x68(%rsp), %rdx
movq %rcx, %rsi
andq %rbx, %rsi
xorl %edi, %edi
cmpq %r15, %rsi
setbe %dil
movq -0x8(%rdx,%rdi,8), %rdx
btq %rcx, %rdx
jb 0x2683
movq 0x18(%rsp), %rsi
cmpq 0x20(%rsp), %rsi
je 0x2678
movl %eax, (%rsi)
addq $0x4, %rsi
movq %rsi, 0x18(%rsp)
jmp 0x2683
movq %r13, %rdi
movq %r14, %rdx
callq 0x5330
movl 0x48(%rsp), %eax
incl %eax
movl %eax, 0x48(%rsp)
cmpl %r12d, %eax
jl 0x262a
movq 0x30(%rsp), %rbx
movq 0x38(%rsp), %r14
movq 0x18(%rsp), %rsi
subq 0x10(%rsp), %rsi
sarq $0x2, %rsi
leaq 0xd0(%rsp), %rdi
leaq 0xf(%rsp), %rdx
callq 0x42ce
subq %rbx, %r14
sarq $0x2, %r14
leaq 0x48(%rsp), %rdi
leaq 0xd0(%rsp), %rdx
leaq 0xe(%rsp), %rcx
movq %r14, %rsi
callq 0x4358
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x26fa
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rdx
subq %rax, %rdx
shrq $0x2, %rdx
testl %edx, %edx
jle 0x277c
movq 0x10(%rsp), %rcx
movq 0x18(%rsp), %rsi
subq %rcx, %rsi
shrq $0x2, %rsi
movq 0xb8(%rsp), %rdi
movq (%rdi), %rdi
movq 0x48(%rsp), %r8
movl $0x7fffffff, %r11d      # imm = 0x7FFFFFFF
movq %rdx, %r9
andq %r11, %r9
movq %rsi, %r10
andq %r11, %r10
xorl %r11d, %r11d
testl %esi, %esi
jle 0x2774
leaq (%r11,%r11,2), %rbx
movq (%r8,%rbx,8), %rbx
xorl %r14d, %r14d
movslq (%rax,%r11,4), %r15
leaq (%r15,%r15,2), %r15
movslq (%rcx,%r14,4), %r12
movq (%rdi,%r15,8), %r15
movl (%r15,%r12,4), %ebp
movl %ebp, (%rbx,%r14,4)
incq %r14
cmpq %r14, %r10
jne 0x2754
incq %r11
cmpq %r9, %r11
jne 0x2745
movq 0x18(%rsp), %rcx
subq 0x10(%rsp), %rcx
shrq $0x2, %rcx
leaq 0x48(%rsp), %r9
movq 0xc0(%rsp), %rbx
movq %rbx, %rdi
movq 0xc8(%rsp), %rsi
movl 0x64(%rsp), %r8d
callq 0x43f0
movq (%rbx), %rax
movq 0x8(%rbx), %rcx
cmpq %rcx, %rax
je 0x27f1
movq 0x30(%rsp), %rdx
movq 0x10(%rsp), %rsi
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
cmpq %rcx, %rax
jne 0x27c2
leaq 0x48(%rsp), %rdi
callq 0x442c
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2812
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2829
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2862
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movl %eax, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movl %eax, 0x80(%rsp)
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x28a7
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
movq %rax, 0x90(%rsp)
movl %eax, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
movl %eax, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movq %rbx, %rax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x442c
jmp 0x28f9
movq %rax, %rbx
movq 0xd0(%rsp), %rdi
testq %rdi, %rdi
je 0x28f9
movq 0xe0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
jmp 0x28f9
jmp 0x28f6
movq %rax, %rbx
jmp 0x2960
jmp 0x28f6
movq %rax, %rbx
movq 0x10(%rsp), %rdi
testq %rdi, %rdi
je 0x2910
movq 0x20(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x30(%rsp), %rdi
testq %rdi, %rdi
je 0x2927
movq 0x40(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
movq 0x68(%rsp), %rdi
testq %rdi, %rdi
je 0x2960
movq 0x88(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
movq %rax, 0x68(%rsp)
movl %eax, 0x70(%rsp)
movq %rax, 0x78(%rsp)
movl %eax, 0x80(%rsp)
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rdi
testq %rdi, %rdi
je 0x29a5
movq 0xb0(%rsp), %rsi
subq %rdi, %rsi
callq 0x2190
xorl %eax, %eax
movq %rax, 0x90(%rsp)
movl %eax, 0x98(%rsp)
movq %rax, 0xa0(%rsp)
movl %eax, 0xa8(%rsp)
movq %rax, 0xb0(%rsp)
movq %rbx, %rdi
callq 0x2260