// File: /workspace/github_c_makefile_star2_O0/icarroll[P]clunk/thudlib.c
// Function: legaldwarfmove
bool legaldwarfmove(struct thudboard * board, struct move * move)
{
    // moving dwarf must be present
    if (! dwarfat(board, move->from)) return false;

    int dx = move->to.x - move->from.x;
    int dy = move->to.y - move->from.y;
    // can only move horizontal, vertical, or diagonal
    if (dx == 0)
    {
        // move length must be non-zero
        if (dy == 0) return false;
    }
    else if (dy != 0 && abs(dx) != abs(dy)) return false;

    int dist = max(abs(dx), abs(dy));
    int sx = signum(dx);
    int sy = signum(dy);

    // path must be clear
    for (int i=1; i < dist; ++i)
    {
        struct coord cur = {move->from.x + sx * i,
                            move->from.y + sy * i};
        if (occupied(board, cur)) return false;
    }

    if (move->numcapts)
    {
        // can only make one capture
        if (move->numcapts > 1) return false;
        // can only capture at move target
        else if (move->capts[0].x != move->to.x
                 || move->capts[0].y != move->to.y) return false;
        // target troll must be present
        else if (! trollat(board, move->capts[0])) return false;

        // can only capture using throw line
        for (int i=1; i < dist; ++i)
        {
            struct coord cur = {move->from.x - sx * i,
                                move->from.y - sy * i};
            if (! dwarfat(board, cur)) return false;
        }
    }
    // if not capturing, target must be clear
    else if (occupied(board, move->to)) return false;

    return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x4(%rax), %rsi
callq 0x3770
testb $0x1, %al
jne 0x412e
movb $0x0, -0x1(%rbp)
jmp 0x430a
movq -0x18(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x4(%rcx), %eax
movl %eax, -0x1c(%rbp)
movq -0x18(%rbp), %rax
movl 0x10(%rax), %eax
movq -0x18(%rbp), %rcx
subl 0x8(%rcx), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x1c(%rbp)
jne 0x4167
cmpl $0x0, -0x20(%rbp)
jne 0x4165
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x4190
cmpl $0x0, -0x20(%rbp)
je 0x418e
movl -0x1c(%rbp), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl -0x20(%rbp), %ecx
movl %ecx, %edx
negl %edx
cmovnsl %edx, %ecx
cmpl %ecx, %eax
je 0x418e
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x4190
movl -0x1c(%rbp), %edi
movl %edi, %eax
negl %eax
cmovnsl %eax, %edi
movl -0x20(%rbp), %esi
movl %esi, %eax
negl %eax
cmovnsl %eax, %esi
callq 0x2610
movl %eax, -0x24(%rbp)
movl -0x1c(%rbp), %edi
callq 0x4560
movl %eax, -0x28(%rbp)
movl -0x20(%rbp), %edi
callq 0x4560
movl %eax, -0x2c(%rbp)
movl $0x1, -0x30(%rbp)
movl -0x30(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x4220
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl -0x28(%rbp), %ecx
imull -0x30(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x38(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x2c(%rbp), %ecx
imull -0x30(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x34(%rbp)
movq -0x10(%rbp), %rdi
movq -0x38(%rbp), %rsi
callq 0x3800
testb $0x1, %al
jne 0x420a
jmp 0x4213
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x4215
movl -0x30(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x30(%rbp)
jmp 0x41c9
movq -0x18(%rbp), %rax
cmpl $0x0, 0x14(%rax)
je 0x42e7
movq -0x18(%rbp), %rax
cmpl $0x1, 0x14(%rax)
jle 0x4241
movb $0x0, -0x1(%rbp)
jmp 0x430a
movq -0x18(%rbp), %rax
movl 0x18(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jne 0x4261
movq -0x18(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x18(%rbp), %rcx
cmpl 0x10(%rcx), %eax
je 0x426a
movb $0x0, -0x1(%rbp)
jmp 0x430a
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0x18(%rax), %rsi
callq 0x37d0
testb $0x1, %al
jne 0x4288
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x428a
jmp 0x428c
movl $0x1, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
cmpl -0x24(%rbp), %eax
jge 0x42e5
movq -0x18(%rbp), %rax
movl 0x4(%rax), %eax
movl -0x28(%rbp), %ecx
imull -0x3c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x18(%rbp), %rax
movl 0x8(%rax), %eax
movl -0x2c(%rbp), %ecx
imull -0x3c(%rbp), %ecx
subl %ecx, %eax
movl %eax, -0x40(%rbp)
movq -0x10(%rbp), %rdi
movq -0x44(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x42d8
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x42da
movl -0x3c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x3c(%rbp)
jmp 0x4293
jmp 0x4306
movq -0x10(%rbp), %rdi
movq -0x18(%rbp), %rax
movq 0xc(%rax), %rsi
callq 0x3800
testb $0x1, %al
jne 0x42fe
jmp 0x4304
movb $0x0, -0x1(%rbp)
jmp 0x430a
jmp 0x4306
movb $0x1, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)