// File: /workspace/github_cpp_makefile_star2_O1/kmyk[P]topcoder-marathon-match-100-same-color-pairs/./SameColorPairs.cpp
// Function: void apply_rects_with_preceding_cells<__gnu_cxx::__normal_iterator<std::array<int, 4ul>*, std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>>>, std::back_insert_iterator<std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>>>>(int, std::array<signed char, 10000ul>&, std::vector<std::pair<int, int>, std::allocator<std::pair<int, int>>>&, __gnu_cxx::__normal_iterator<std::array<int, 4ul>*, std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>>>, __gnu_cxx::__normal_iterator<std::array<int, 4ul>*, std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>>>, int, std::back_insert_iterator<std::vector<std::array<int, 4ul>, std::allocator<std::array<int, 4ul>>>>)
void apply_rects_with_preceding_cells(int W, array<int8_t, MAX_H * MAX_W> & board, vector<pair<int, int> > & preciding, InputIterator first, InputIterator last, int skip_i, OutputIterator dest) {
    auto check_use = [&](int y1, int x1, int y2, int x2) {
        if (not is_valid_pair(W, board, make_pair(y1, x1), make_pair(y2, x2))) return false;
        board[y1 * W + x1] = -1;
        board[y2 * W + x2] = -1;
        *(dest ++) = { y1, x1, y2, x2 };
        return true;
    };
    for (; first != last; ++ first) {
        if ((skip_i --) == 0) continue;
        int y1 = (*first)[0];
        int x1 = (*first)[1];
        int y2 = (*first)[2];
        int x2 = (*first)[3];
        for (auto const & p : preciding) {
            int y, x; tie(y, x) = p;
            if (check_use(y, x, y1, x1) or check_use(y, x, y2, x2)) {
                preciding.clear();
                goto next;
            }
        }
        check_use(y1, x1, y2, x2);
next: ;
    }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
movq %rdx, 0x60(%rsp)
movq %rsi, 0x20(%rsp)
movl %edi, 0xc(%rsp)
movq %r8, 0x68(%rsp)
movq %rcx, 0x50(%rsp)
cmpq %r8, %rcx
je 0x70f8
subl $0x1, %r9d
movl %r9d, 0x5c(%rsp)
jb 0x70da
movq 0x50(%rsp), %rax
movl (%rax), %ecx
movq %rcx, 0x48(%rsp)
movl 0x4(%rax), %ecx
movq %rcx, 0x40(%rsp)
movl 0x8(%rax), %ecx
movq %rcx, 0x38(%rsp)
movl 0xc(%rax), %eax
movq %rax, 0x30(%rsp)
movq 0x60(%rsp), %rax
movq (%rax), %r14
movq 0x8(%rax), %rax
movq %rax, 0x90(%rsp)
cmpq %rax, %r14
sete %r12b
je 0x701f
movq 0x40(%rsp), %rdx
movq %rdx, %rcx
shlq $0x20, %rcx
movq 0x48(%rsp), %rax
orq %rax, %rcx
movq %rcx, 0x88(%rsp)
movl 0xc(%rsp), %ecx
imull %ecx, %eax
addl %edx, %eax
cltq
movq %rax, 0x78(%rsp)
movq 0x30(%rsp), %rdx
movq %rdx, %rsi
shlq $0x20, %rsi
movq 0x38(%rsp), %rax
orq %rax, %rsi
movq %rsi, 0x80(%rsp)
imull %ecx, %eax
addl %edx, %eax
cltq
movq %rax, 0x70(%rsp)
movl (%r14), %r15d
movl 0x4(%r14), %r13d
movq %r13, %rbp
shlq $0x20, %rbp
orq %r15, %rbp
movq %rbp, 0x10(%rsp)
movq 0x88(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %edi
movq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x2eb7
testb %al, %al
je 0x6f51
movl %eax, %ebx
movl %r15d, %eax
imull 0xc(%rsp), %eax
addl %r13d, %eax
cltq
movq 0x20(%rsp), %rcx
movb $-0x1, %dl
movb %dl, (%rcx,%rax)
movq 0x78(%rsp), %rax
movb %dl, (%rcx,%rax)
movl %r15d, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movq 0x48(%rsp), %rax
movl %eax, 0x18(%rsp)
movq 0x40(%rsp), %rax
movl %eax, 0x1c(%rsp)
movq 0xd0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x6f3f
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0x6f49
leaq 0x10(%rsp), %rdx
callq 0x8060
testb %bl, %bl
jne 0x7003
movq %rbp, 0x10(%rsp)
movq 0x80(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %edi
movq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x2eb7
testb %al, %al
je 0x6feb
movl %eax, %ebx
movl %r15d, %eax
imull 0xc(%rsp), %eax
addl %r13d, %eax
cltq
movq 0x20(%rsp), %rcx
movb $-0x1, %dl
movb %dl, (%rcx,%rax)
movq 0x70(%rsp), %rax
movb %dl, (%rcx,%rax)
movl %r15d, 0x10(%rsp)
movl %r13d, 0x14(%rsp)
movq 0x38(%rsp), %rax
movl %eax, 0x18(%rsp)
movq 0x30(%rsp), %rax
movl %eax, 0x1c(%rsp)
movq 0xd0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x6fdd
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0x6fe7
leaq 0x10(%rsp), %rdx
callq 0x8060
testb %bl, %bl
jne 0x7003
addq $0x8, %r14
cmpq 0x90(%rsp), %r14
sete %r12b
jne 0x6ea2
jmp 0x701f
movq 0x60(%rsp), %rcx
movq (%rcx), %rax
cmpq %rax, 0x8(%rcx)
je 0x7015
movq %rax, 0x8(%rcx)
testb $0x1, %r12b
je 0x70da
movq 0x40(%rsp), %rax
shlq $0x20, %rax
addq 0x48(%rsp), %rax
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
shlq $0x20, %rax
addq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movl 0xc(%rsp), %edi
movq 0x20(%rsp), %rsi
leaq 0x10(%rsp), %rdx
leaq 0x28(%rsp), %rcx
callq 0x2eb7
testb %al, %al
je 0x70da
movq 0x48(%rsp), %rdi
movl %edi, %eax
movl 0xc(%rsp), %edx
imull %edx, %eax
movq 0x40(%rsp), %r8
addl %r8d, %eax
cltq
movq 0x20(%rsp), %rcx
movb $-0x1, %sil
movb %sil, (%rcx,%rax)
movq 0x38(%rsp), %r9
movl %r9d, %eax
imull %edx, %eax
movq 0x30(%rsp), %rdx
addl %edx, %eax
cltq
movb %sil, (%rcx,%rax)
movl %edi, 0x10(%rsp)
movl %r8d, 0x14(%rsp)
movl %r9d, 0x18(%rsp)
movl %edx, 0x1c(%rsp)
movq 0xd0(%rsp), %rdi
movq 0x8(%rdi), %rsi
cmpq 0x10(%rdi), %rsi
je 0x70d0
movups 0x10(%rsp), %xmm0
movups %xmm0, (%rsi)
addq $0x10, 0x8(%rdi)
jmp 0x70da
leaq 0x10(%rsp), %rdx
callq 0x8060
movq 0x50(%rsp), %rax
addq $0x10, %rax
movq %rax, 0x50(%rsp)
cmpq 0x68(%rsp), %rax
movl 0x5c(%rsp), %r9d
jne 0x6dfa
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq