// File: 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
subq $0xf0, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movl %r8d, -0x24(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0x20(%rbp), %rdi
callq 0xfef0
movl %eax, -0x28(%rbp)
movq -0x20(%rbp), %rdi
callq 0xff00
movl %eax, %ecx
movq -0xa0(%rbp), %rax
movl %ecx, -0x2c(%rbp)
movl -0x14(%rbp), %ecx
movl %ecx, -0x94(%rbp)
movq 0x8(%rax), %rdi
callq 0x2ad0
movl %eax, -0x98(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x6000
movl -0x98(%rbp), %ecx
movl %eax, %edx
movl -0x94(%rbp), %eax
subl %edx, %ecx
cmpl %ecx, %eax
jg 0xd3e0
movq -0xa0(%rbp), %rax
movl -0x18(%rbp), %ecx
movl %ecx, -0xa4(%rbp)
movq 0x8(%rax), %rdi
callq 0x2af0
movl %eax, -0xa8(%rbp)
movq -0x20(%rbp), %rdi
movl -0x24(%rbp), %esi
callq 0x6070
movl -0xa8(%rbp), %ecx
movl %eax, %edx
movl -0xa4(%rbp), %eax
subl %edx, %ecx
cmpl %ecx, %eax
jle 0xd3e9
movb $0x0, -0x1(%rbp)
jmp 0xd726
movq -0x20(%rbp), %rdi
callq 0xff20
movq %rax, -0x38(%rbp)
movl $0x0, -0x3c(%rbp)
movslq -0x3c(%rbp), %rax
movq %rax, -0xb0(%rbp)
movq -0x38(%rbp), %rdi
callq 0x81f0
movq %rax, %rcx
movq -0xb0(%rbp), %rax
cmpq %rcx, %rax
jae 0xd4a4
movq -0x38(%rbp), %rdi
movslq -0x3c(%rbp), %rsi
callq 0xfe90
movq (%rax), %rcx
movq %rcx, -0x48(%rbp)
movl 0x8(%rax), %eax
movl %eax, -0x40(%rbp)
movl -0x48(%rbp), %edi
movl -0x44(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x24(%rbp), %r8d
callq 0xa990
movq %rax, %rcx
movq -0xa0(%rbp), %rax
movq %rcx, -0x50(%rbp)
movl -0x40(%rbp), %ecx
movl %ecx, -0xb4(%rbp)
movq 0x8(%rax), %rdi
movl -0x50(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x4c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0x5b50
movl %eax, %ecx
movl -0xb4(%rbp), %eax
cmpl %ecx, %eax
je 0xd494
movb $0x0, -0x1(%rbp)
jmp 0xd726
jmp 0xd496
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0xd3fd
movq -0x20(%rbp), %rdi
callq 0xff40
movq %rax, -0x58(%rbp)
movl $0x0, -0x5c(%rbp)
movslq -0x5c(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0x58(%rbp), %rdi
callq 0x79f0
movq %rax, %rcx
movq -0xc0(%rbp), %rax
cmpq %rcx, %rax
jae 0xd5da
movq -0x58(%rbp), %rdi
movslq -0x5c(%rbp), %rsi
callq 0xfdf0
movl 0x8(%rax), %ecx
movl %ecx, -0x60(%rbp)
movq (%rax), %rax
movq %rax, -0x68(%rbp)
movl -0x68(%rbp), %edi
movl -0x64(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x24(%rbp), %r8d
callq 0xaa60
movq %rax, -0x70(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xc4(%rbp)
subl $0x2, %eax
jb 0xd552
jmp 0xd522
movl -0xc4(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0xd58e
jmp 0xd532
movl -0xc4(%rbp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0xd552
jmp 0xd542
movl -0xc4(%rbp), %eax
addl $-0x6, %eax
subl $0x2, %eax
jb 0xd58e
jmp 0xd5ca
movq -0xa0(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, -0xc8(%rbp)
movq 0x8(%rax), %rdi
movl -0x70(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x6c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0x5bf0
movl %eax, %ecx
movl -0xc8(%rbp), %eax
cmpl %ecx, %eax
je 0xd58c
movb $0x0, -0x1(%rbp)
jmp 0xd726
jmp 0xd5ca
movq -0xa0(%rbp), %rax
movl -0x60(%rbp), %ecx
movl %ecx, -0xcc(%rbp)
movq 0x8(%rax), %rdi
movl -0x70(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x6c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0x5c90
movl %eax, %ecx
movl -0xcc(%rbp), %eax
cmpl %ecx, %eax
je 0xd5c8
movb $0x0, -0x1(%rbp)
jmp 0xd726
jmp 0xd5ca
jmp 0xd5cc
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0xd4b8
movq -0x20(%rbp), %rdi
callq 0xff60
movq %rax, -0x78(%rbp)
movl $0x0, -0x7c(%rbp)
movslq -0x7c(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq -0x78(%rbp), %rdi
callq 0x79f0
movq %rax, %rcx
movq -0xd8(%rbp), %rax
cmpq %rcx, %rax
jae 0xd722
movq -0x78(%rbp), %rdi
movslq -0x7c(%rbp), %rsi
callq 0xfdf0
movl 0x8(%rax), %ecx
movl %ecx, -0x80(%rbp)
movq (%rax), %rax
movq %rax, -0x88(%rbp)
movl -0x88(%rbp), %edi
movl -0x84(%rbp), %esi
movl -0x28(%rbp), %edx
movl -0x2c(%rbp), %ecx
movl -0x24(%rbp), %r8d
callq 0xaaa0
movq %rax, -0x90(%rbp)
movl -0x24(%rbp), %eax
movl %eax, -0xdc(%rbp)
subl $0x2, %eax
jb 0xd694
jmp 0xd664
movl -0xdc(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0xd6d3
jmp 0xd674
movl -0xdc(%rbp), %eax
addl $-0x4, %eax
subl $0x2, %eax
jb 0xd694
jmp 0xd684
movl -0xdc(%rbp), %eax
addl $-0x6, %eax
subl $0x2, %eax
jb 0xd6d3
jmp 0xd712
movq -0xa0(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, -0xe0(%rbp)
movq 0x8(%rax), %rdi
movl -0x90(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x8c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0x5c90
movl %eax, %ecx
movl -0xe0(%rbp), %eax
cmpl %ecx, %eax
je 0xd6d1
movb $0x0, -0x1(%rbp)
jmp 0xd726
jmp 0xd712
movq -0xa0(%rbp), %rax
movl -0x80(%rbp), %ecx
movl %ecx, -0xe4(%rbp)
movq 0x8(%rax), %rdi
movl -0x90(%rbp), %esi
addl -0x14(%rbp), %esi
movl -0x8c(%rbp), %edx
addl -0x18(%rbp), %edx
callq 0x5bf0
movl %eax, %ecx
movl -0xe4(%rbp), %eax
cmpl %ecx, %eax
je 0xd710
movb $0x0, -0x1(%rbp)
jmp 0xd726
jmp 0xd712
jmp 0xd714
movl -0x7c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x7c(%rbp)
jmp 0xd5ee
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0xf0, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)