// File: davidjosepha[P]slitherlink/src/generator/loopgen.cpp
// Function: LoopGen::addCell(Coordinates)
Coordinates LoopGen::addCell(Coordinates cur) {
    assert(cur.i >= 0 && cur.i < m_ && cur.j >= 0 && cur.j < n_);

    /* check whether it's possible to expand in any direction */
    if (!isExpandable(cur)) {
        return cur;
    }

    /* pick some direction up/down/left/right from cur */
    Coordinates newpos = pickDirection(cur);

    /* and verify it's a valid choice */
    if (!inBounds(newpos) || loop_[newpos.i][newpos.j] != UNKNOWN) {
        return cur;
    }

    AdjacencyList adjacencyList = getAdjacent(newpos);

    if (!adjacencyList.u && !adjacencyList.d && !adjacencyList.l && !adjacencyList.r) {
        loop_[newpos.i][newpos.j] = OUT;
        return newpos;
    }

    loop_[newpos.i][newpos.j] = (validCell(newpos, cur)) ? EXP : OUT;
    return newpos;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rsi, -0x10(%rbp)
movq %rdi, -0x18(%rbp)
movq -0x18(%rbp), %rax
movq %rax, -0x60(%rbp)
xorl %eax, %eax
cmpl $0x0, -0x10(%rbp)
movb %al, -0x55(%rbp)
jl 0x1394f
movq -0x60(%rbp), %rdx
movl -0x10(%rbp), %ecx
xorl %eax, %eax
cmpl 0x10(%rdx), %ecx
movb %al, -0x55(%rbp)
jge 0x1394f
xorl %eax, %eax
cmpl $0x0, -0xc(%rbp)
movb %al, -0x55(%rbp)
jl 0x1394f
movq -0x60(%rbp), %rcx
movl -0xc(%rbp), %eax
cmpl 0x14(%rcx), %eax
setl %al
movb %al, -0x55(%rbp)
movb -0x55(%rbp), %al
testb $0x1, %al
jne 0x13958
jmp 0x1395a
jmp 0x13979
leaq 0x1dbb(%rip), %rdi      # 0x1571c
leaq 0x1de9(%rip), %rsi      # 0x15751
movl $0x71, %edx
leaq 0x1df7(%rip), %rcx      # 0x1576b
callq 0x2120
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rsi
callq 0x13b40
testb $0x1, %al
jne 0x1399f
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x13aa0
movq -0x60(%rbp), %rdi
movq -0x10(%rbp), %rax
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rsi
callq 0x13c20
movq -0x60(%rbp), %rdi
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x38(%rbp)
movq -0x38(%rbp), %rsi
callq 0x137c0
testb $0x1, %al
jne 0x139d3
jmp 0x139ec
movq -0x60(%rbp), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
cmpl $0x0, (%rax,%rcx,4)
je 0x139f9
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x13aa0
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x44(%rbp)
movq -0x44(%rbp), %rsi
callq 0x13c90
movl %eax, -0x3c(%rbp)
testb $0x1, -0x3c(%rbp)
jne 0x13a4d
testb $0x1, -0x3b(%rbp)
jne 0x13a4d
testb $0x1, -0x3a(%rbp)
jne 0x13a4d
testb $0x1, -0x39(%rbp)
jne 0x13a4d
movq -0x60(%rbp), %rax
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movl $0x3, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0x13aa0
movq -0x60(%rbp), %rdi
movq -0x28(%rbp), %rax
movq %rax, -0x4c(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x54(%rbp)
movq -0x4c(%rbp), %rsi
movq -0x54(%rbp), %rdx
callq 0x13d70
movb %al, %sil
movq -0x60(%rbp), %rax
movl $0x3, %edx
movl $0x1, %ecx
testb $0x1, %sil
cmovnel %ecx, %edx
movq (%rax), %rax
movslq -0x28(%rbp), %rcx
movq (%rax,%rcx,8), %rax
movslq -0x24(%rbp), %rcx
movl %edx, (%rax,%rcx,4)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
nopw (%rax,%rax)