// File: /workspace/github_c_makefile_star2_O2/icarroll[P]clunk/thudlib.c
// Function: alldwarfmoves
struct movelist alldwarfmoves(struct thudboard * board)
{
    struct movelist moves;
    initlist(& moves);

    // generate attacks
    struct coord from = initpos;
    while (true)
    {
        from = nextpos(board->dwarfs, from);
        if (from.x == -1) break;

        for (int dir = 0; dir < NUMDIRS; ++dir)
        {
            int dx = DX[dir];
            int dy = DY[dir];

            for (int dist = 1; dist < SIZE ; ++dist)
            {
                struct coord to = {from.x + dx * dist,
                                   from.y + dy * dist};
                if (! inbounds(to)) break;

                if (dwarfat(board, to) || blockat(board, to)) break;

                struct coord check = {from.x - dx * (dist-1),
                                      from.y - dy * (dist-1)};
                if (! inbounds(check) || ! dwarfat(board, check)) break;

                if (trollat(board, to))
                {
                    * next(& moves) = (struct move) {true, from, to, 1, {to}};
                    break;
                }
            }
        }
    }

    // generate moves
    from = initpos;
    while (true)
    {
        from = nextpos(board->dwarfs, from);
        if (from.x == -1) break;

        for (int dir = 0; dir < NUMDIRS; ++dir)
        {
            int dx = DX[dir];
            int dy = DY[dir];

            for (int dist = 1; dist < SIZE ; ++dist)
            {
                struct coord to = {from.x + dx * dist,
                                   from.y + dy * dist};
                if (! inbounds(to)) break;

                if (occupied(board, to)) break;

                * next(& moves) = (struct move) {true, from, to, 0, {}};
            }
        }
    }

    return moves;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x39e8
movl 0x6079(%rip), %r12d     # 0x8120
movl 0x6077(%rip), %eax      # 0x8124
movq %rax, 0x8(%rsp)
movq %rbx, 0x50(%rsp)
addq $0x2, %rbx
leaq 0x606e(%rip), %r14      # 0x8130
movq 0x8(%rsp), %rax
shlq $0x20, %rax
movl %r12d, %esi
orq %rax, %rsi
movq %rbx, %rdi
callq 0x2c4d
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x21ed
movq %r12, %rax
shrq $0x20, %rax
movq %rax, 0x8(%rsp)
movq %r12, %rax
sarq $0x20, %rax
movq %rax, 0x10(%rsp)
xorl %r15d, %r15d
cmpq $0x8, %r15
je 0x20c2
movl (%r14,%r15,4), %eax
leaq 0x603e(%rip), %rcx      # 0x8150
movslq (%rcx,%r15,4), %rdx
movq 0x10(%rsp), %r8
leaq (%r8,%rdx), %rsi
xorl %ebp, %ebp
movl %r8d, %r13d
movl %eax, %edi
pushq $0xf
popq %r9
decq %r9
je 0x21e5
cmpq $0xe, %rsi
ja 0x21e5
leal (%r12,%rdi), %ecx
cmpl $0xe, %ecx
ja 0x21e5
movl $0x4000, %r10d          # imm = 0x4000
shrl %cl, %r10d
testw %r10w, (%rbx,%rsi,2)
jne 0x21e5
testw %r10w, 0x3c(%rbx,%rsi,2)
jne 0x21e5
cmpq $0xe, %r8
ja 0x21e5
leal (%r12,%rbp), %ecx
cmpl $0xe, %ecx
ja 0x21e5
movl $0x4000, %r11d          # imm = 0x4000
shrl %cl, %r11d
testw %r11w, (%rbx,%r8,2)
je 0x21e5
subl %eax, %ebp
subq %rdx, %r8
addl %eax, %edi
addl %edx, %r13d
leaq (%rsi,%rdx), %rcx
testw %r10w, 0x1e(%rbx,%rsi,2)
movq %rcx, %rsi
je 0x212a
leaq 0x20(%rsp), %rdi
callq 0x3a09
movb $0x1, (%rax)
movl %r12d, 0x4(%rax)
movq 0x8(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %r12d, %ecx
subl %ebp, %ecx
movl %ecx, 0xc(%rax)
movl %r13d, 0x10(%rax)
movl $0x1, 0x14(%rax)
movl %ecx, 0x18(%rax)
movl %r13d, 0x1c(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
andq $0x0, 0x50(%rax)
incq %r15
jmp 0x2101
movl 0x5f2d(%rip), %eax      # 0x8120
movl 0x5f2b(%rip), %ecx      # 0x8124
movq %rcx, 0x18(%rsp)
movq %rbx, 0x30(%rsp)
movq 0x18(%rsp), %rcx
shlq $0x20, %rcx
movl %eax, %esi
orq %rcx, %rsi
movq %rbx, %rdi
callq 0x2c4d
cmpl $-0x1, %eax
je 0x2325
movq %rax, %rcx
shrq $0x20, %rcx
movq %rcx, 0x18(%rsp)
movq %rax, %rcx
sarq $0x20, %rcx
movq %rcx, 0x40(%rsp)
movslq %eax, %rcx
movq %rcx, 0x38(%rsp)
xorl %ecx, %ecx
movq %rax, 0x10(%rsp)
cmpq $0x8, %rcx
je 0x2203
movslq (%r14,%rcx,4), %rdx
leaq 0x5ef6(%rip), %rax      # 0x8150
movq %rcx, 0x48(%rsp)
movslq (%rax,%rcx,4), %r12
movq 0x38(%rsp), %rax
leaq (%rax,%rdx), %r14
movq 0x40(%rsp), %rax
leaq (%rax,%r12), %r13
movq %r13, %rbp
shlq $0x20, %rbp
addq %r14, %rbp
movq %r12, %rbx
shlq $0x20, %rbx
movq %rdx, 0x8(%rsp)
addq %rdx, %rbx
pushq $0xe
popq %r15
subq $0x1, %r15
jb 0x2307
cmpq $0xe, %r13
ja 0x2307
cmpq $0xe, %r14
ja 0x2307
movq 0x50(%rsp), %rdi
movq %rbp, %rsi
callq 0x2d08
testb %al, %al
jne 0x2307
leaq 0x20(%rsp), %rdi
callq 0x3a09
movb $0x1, (%rax)
andw $0x0, 0x1(%rax)
movb $0x0, 0x3(%rax)
movq 0x10(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0x18(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %r14d, 0xc(%rax)
movl %r13d, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x34(%rax)
andl $0x0, 0x54(%rax)
movups %xmm0, 0x44(%rax)
addq 0x8(%rsp), %r14
addq %rbx, %rbp
addq %r12, %r13
jmp 0x2292
movq 0x48(%rsp), %rcx
incq %rcx
movq 0x30(%rsp), %rbx
leaq 0x5e15(%rip), %r14      # 0x8130
movq 0x10(%rsp), %rax
jmp 0x2249
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq