// File: davidjosepha[P]slitherlink/src/shared/grid.cpp
// Function: Grid::setHLine(int, int, Edge)
bool Grid::setHLine(int i, int j, Edge edge) {
    assert(0 <= i && i < m_+1 && 0 <= j && j < n_);

    if (edge == EMPTY) {
        return true;
    }

    Edge prevEdge = getHLine(i, j);
    if (prevEdge == EMPTY) {
        hlines_[i][j] = edge;
    } else if (prevEdge != edge) {
        return false;
    } else if (prevEdge == edge) {
        return true;
    }

    // Update contour information
    if (edge == LINE) {
        updateContourMatrix(i, j, true);
    }

    // Update which parts of grid have possible rules that could be applied
    for (int x = std::max(0, i-3); x < std::min(i+1, getHeight()); x++) {
        for (int y = std::max(0, j-2); y < std::min(j+1, getWidth()); y++) {
            updateMatrix_[x][y] = true;
        }
    }

    // Update which parts of grid have possible contradictions
    for (int x = std::max(0, i-2); x < std::min(i+1, getHeight()); x++) {
        for (int y = std::max(0, j-1); y < std::min(j+1, getWidth()); y++) {
            contraMatrix_[x][y] = true;
        }
    }

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x90, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movl %ecx, -0x1c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
xorl %eax, %eax
xorl %ecx, %ecx
cmpl -0x14(%rbp), %ecx
movb %al, -0x71(%rbp)
jg 0x38be
movq -0x80(%rbp), %rax
movl -0x14(%rbp), %ecx
movl 0xc(%rax), %edx
addl $0x1, %edx
xorl %eax, %eax
cmpl %edx, %ecx
movb %al, -0x71(%rbp)
jge 0x38be
xorl %eax, %eax
xorl %ecx, %ecx
cmpl -0x18(%rbp), %ecx
movb %al, -0x71(%rbp)
jg 0x38be
movq -0x80(%rbp), %rcx
movl -0x18(%rbp), %eax
cmpl 0x10(%rcx), %eax
setl %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
testb $0x1, %al
jne 0x38c7
jmp 0x38c9
jmp 0x38e8
leaq 0x1175e(%rip), %rdi     # 0x1502e
leaq 0x1177e(%rip), %rsi     # 0x15055
movl $0x81, %edx
leaq 0x11786(%rip), %rcx     # 0x15069
callq 0x2120
cmpl $0x0, -0x1c(%rbp)
jne 0x38f7
movb $0x1, -0x1(%rbp)
jmp 0x3b45
movq -0x80(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
callq 0x5bf0
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
jne 0x392b
movq -0x80(%rbp), %rax
movl -0x1c(%rbp), %edx
movq 0x20(%rax), %rax
movslq -0x14(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x18(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
jmp 0x3951
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
je 0x393c
movb $0x0, -0x1(%rbp)
jmp 0x3b45
movl -0x20(%rbp), %eax
cmpl -0x1c(%rbp), %eax
jne 0x394d
movb $0x1, -0x1(%rbp)
jmp 0x3b45
jmp 0x394f
jmp 0x3951
cmpl $0x1, -0x1c(%rbp)
jne 0x396b
movq -0x80(%rbp), %rdi
movl -0x14(%rbp), %esi
movl -0x18(%rbp), %edx
movl $0x1, %ecx
callq 0x3b60
movl $0x0, -0x28(%rbp)
movl -0x14(%rbp), %eax
subl $0x3, %eax
movl %eax, -0x2c(%rbp)
leaq -0x28(%rbp), %rdi
leaq -0x2c(%rbp), %rsi
callq 0x49e0
movl (%rax), %eax
movl %eax, -0x24(%rbp)
movq -0x80(%rbp), %rdi
movl -0x24(%rbp), %eax
movl %eax, -0x84(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
callq 0x2ad0
movl %eax, -0x34(%rbp)
leaq -0x30(%rbp), %rdi
leaq -0x34(%rbp), %rsi
callq 0x4a20
movq %rax, %rcx
movl -0x84(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3a56
movl $0x0, -0x3c(%rbp)
movl -0x18(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x40(%rbp)
leaq -0x3c(%rbp), %rdi
leaq -0x40(%rbp), %rsi
callq 0x49e0
movl (%rax), %eax
movl %eax, -0x38(%rbp)
movq -0x80(%rbp), %rdi
movl -0x38(%rbp), %eax
movl %eax, -0x88(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x44(%rbp)
callq 0x2af0
movl %eax, -0x48(%rbp)
leaq -0x44(%rbp), %rdi
leaq -0x48(%rbp), %rsi
callq 0x4a20
movq %rax, %rcx
movl -0x88(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3a46
movq -0x80(%rbp), %rax
movq 0x30(%rax), %rax
movslq -0x24(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x38(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x39eb
jmp 0x3a48
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x398d
movl $0x0, -0x50(%rbp)
movl -0x14(%rbp), %eax
subl $0x2, %eax
movl %eax, -0x54(%rbp)
leaq -0x50(%rbp), %rdi
leaq -0x54(%rbp), %rsi
callq 0x49e0
movl (%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0x80(%rbp), %rdi
movl -0x4c(%rbp), %eax
movl %eax, -0x8c(%rbp)
movl -0x14(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
callq 0x2ad0
movl %eax, -0x5c(%rbp)
leaq -0x58(%rbp), %rdi
leaq -0x5c(%rbp), %rsi
callq 0x4a20
movq %rax, %rcx
movl -0x8c(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3b41
movl $0x0, -0x64(%rbp)
movl -0x18(%rbp), %eax
subl $0x1, %eax
movl %eax, -0x68(%rbp)
leaq -0x64(%rbp), %rdi
leaq -0x68(%rbp), %rsi
callq 0x49e0
movl (%rax), %eax
movl %eax, -0x60(%rbp)
movq -0x80(%rbp), %rdi
movl -0x60(%rbp), %eax
movl %eax, -0x90(%rbp)
movl -0x18(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x6c(%rbp)
callq 0x2af0
movl %eax, -0x70(%rbp)
leaq -0x6c(%rbp), %rdi
leaq -0x70(%rbp), %rsi
callq 0x4a20
movq %rax, %rcx
movl -0x90(%rbp), %eax
cmpl (%rcx), %eax
jge 0x3b31
movq -0x80(%rbp), %rax
movq 0x38(%rax), %rax
movslq -0x4c(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x60(%rbp), %rcx
movb $0x1, (%rax,%rcx)
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x3ad6
jmp 0x3b33
movl -0x4c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3a78
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x90, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)