// File: /workspace/github_cpp_makefile_star2_O3/davidjosepha[P]slitherlink/src/solver/solver.cpp
// Function: Solver::contradictionApplies(int, int, Contradiction const&, Orientation) const
bool Solver::contradictionApplies(int i, int j, Contradiction const & contradiction, Orientation orient) const {
    int m = contradiction.getHeight();
    int n = contradiction.getWidth();

    if (i > grid_->getHeight() - contradiction.getNumberHeight(orient)
            || j > grid_->getWidth() - contradiction.getNumberWidth(orient)) {
        return false;
    }

    std::vector<NumberPosition> const * numberPattern = contradiction.getNumberPattern();
    for (int k = 0; k < numberPattern->size(); k++) {
        NumberPosition pattern = (*numberPattern)[k];
        Coordinates adjusted = rotateNumber(pattern.coords.i, pattern.coords.j, m, n, orient);

        if (pattern.num != grid_->getNumber(adjusted.i + i, adjusted.j + j)) {
            return false;
        }
    }

    std::vector<EdgePosition> const * hLinePattern = contradiction.getHLinePattern();
    for (int k = 0; k < hLinePattern->size(); k++) {
        EdgePosition pattern = (*hLinePattern)[k];
        Coordinates adjusted = rotateHLine(pattern.coords.i, pattern.coords.j, m, n, orient);

        switch (orient) {
            case UPFLIP:
            case UP:
            case DOWNFLIP:
            case DOWN:
                if (pattern.edge != grid_->getHLine(adjusted.i + i, adjusted.j + j)) {
                    return false;
                }
                break;
            case LEFTFLIP:
            case LEFT:
            case RIGHTFLIP:
            case RIGHT:
                if (pattern.edge != grid_->getVLine(adjusted.i + i, adjusted.j + j)) {
                    return false;
                }
                break;
        }
    }

    std::vector<EdgePosition> const * vLinePattern = contradiction.getVLinePattern();
    for (int k = 0; k < vLinePattern->size(); k++) {
        EdgePosition pattern = (*vLinePattern)[k];
        Coordinates adjusted = rotateVLine(pattern.coords.i, pattern.coords.j, m, n, orient);

        switch (orient) {
            case UPFLIP:
            case UP:
            case DOWNFLIP:
            case DOWN:
                if (pattern.edge != grid_->getVLine(adjusted.i + i, adjusted.j + j)) {
                    return false;
                }
                break;
            case LEFTFLIP:
            case LEFT:
            case RIGHTFLIP:
            case RIGHT:
                if (pattern.edge != grid_->getHLine(adjusted.i + i, adjusted.j + j)) {
                    return false;
                }
                break;
        }
    }

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r8d, %ebx
movq %rcx, %r14
movq %rdx, -0x38(%rbp)
movl %esi, %r13d
movq %rdi, %r12
movl (%rcx), %eax
movl %eax, -0x30(%rbp)
movl 0x4(%rcx), %eax
movl %eax, -0x2c(%rbp)
movq 0x8(%rdi), %rax
movl 0xc(%rax), %r15d
movq %rcx, %rdi
movl %r8d, %esi
callq 0x44da
subl %eax, %r15d
movq %r13, -0x48(%rbp)
cmpl %r13d, %r15d
jl 0xaf82
movq 0x8(%r12), %rax
movl 0x10(%rax), %r15d
movq %r14, %rdi
movl %ebx, %esi
callq 0x44f0
subl %eax, %r15d
movq -0x38(%rbp), %rax
cmpl %eax, %r15d
jge 0xaf93
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, -0x40(%rbp)
movq 0x8(%r14), %rax
cmpq %rax, 0x10(%r14)
je 0xb013
movl $0x8, %r15d
xorl %r12d, %r12d
movl -0x8(%rax,%r15), %edi
movl -0x4(%rax,%r15), %esi
movl (%rax,%r15), %r13d
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl %ebx, %r8d
callq 0x6210
movq -0x48(%rbp), %rcx
leal (%rax,%rcx), %esi
shrq $0x20, %rax
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x38(%rbp), %rcx
leal (%rax,%rcx), %edx
callq 0x42dc
cmpl %eax, %r13d
jne 0xaf82
incq %r12
movq 0x8(%r14), %rax
movq 0x10(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r15
cmpq %r12, %rcx
ja 0xafaa
movq 0x20(%r14), %rax
cmpq %rax, 0x28(%r14)
je 0xb0c2
movl $0x8, %r15d
xorl %r12d, %r12d
movl -0x8(%rax,%r15), %edi
movl -0x4(%rax,%r15), %esi
movl (%rax,%r15), %r13d
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl %ebx, %r8d
callq 0x6260
cmpl $0x7, %ebx
ja 0xb095
movq %rax, %rdx
shrq $0x20, %rdx
movl $0x33, %ecx
btl %ebx, %ecx
jae 0xb075
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x48(%rbp), %rcx
leal (%rax,%rcx), %esi
addl -0x38(%rbp), %edx
callq 0x4322
jmp 0xb08c
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x48(%rbp), %rcx
leal (%rax,%rcx), %esi
addl -0x38(%rbp), %edx
callq 0x4368
cmpl %eax, %r13d
jne 0xaf82
incq %r12
movq 0x20(%r14), %rax
movq 0x28(%r14), %rcx
subq %rax, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r15
cmpq %r12, %rcx
ja 0xb02a
movq 0x38(%r14), %r8
movb $0x1, %al
cmpq %r8, 0x40(%r14)
je 0xaf84
movl $0x8, %r15d
xorl %r12d, %r12d
movl -0x8(%r8,%r15), %edi
movl -0x4(%r8,%r15), %esi
movl (%r8,%r15), %r13d
movl -0x30(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl %ebx, %r8d
callq 0x626c
cmpl $0x7, %ebx
ja 0xb146
movq %rax, %rdx
shrq $0x20, %rdx
movl $0x33, %ecx
btl %ebx, %ecx
jae 0xb126
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x48(%rbp), %rcx
leal (%rax,%rcx), %esi
addl -0x38(%rbp), %edx
callq 0x4368
jmp 0xb13d
movq -0x40(%rbp), %rcx
movq 0x8(%rcx), %rdi
movq -0x48(%rbp), %rcx
leal (%rax,%rcx), %esi
addl -0x38(%rbp), %edx
callq 0x4322
cmpl %eax, %r13d
jne 0xaf82
incq %r12
movq 0x38(%r14), %r8
movq 0x40(%r14), %rcx
subq %r8, %rcx
sarq $0x2, %rcx
movabsq $-0x5555555555555555, %rdx # imm = 0xAAAAAAAAAAAAAAAB
imulq %rdx, %rcx
addq $0xc, %r15
cmpq %r12, %rcx
ja 0xb0db
movb $0x1, %al
jmp 0xaf84