// File: /workspace/github_c_makefile_star2_O3/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 $0x48, %rsp
movq %rdi, %rbx
leaq 0x20(%rsp), %rdi
callq 0x3ce8
movq %rbx, 0x18(%rsp)
addq $0x2, %rbx
movq 0x5f26(%rip), %r15      # 0x8120
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e0d
movq %rax, %rcx
cmpl $-0x1, %ecx
je 0x235a
leaq 0x5f18(%rip), %r11      # 0x8130
movq %rcx, %r15
movq %r15, %rdx
shrq $0x20, %rdx
movq %rdx, 0x8(%rsp)
movq %r15, 0x10(%rsp)
sarq $0x20, %r15
xorl %r13d, %r13d
movl (%r11,%r13,4), %edx
leaq 0x5f12(%rip), %rax      # 0x8150
movslq (%rax,%r13,4), %rsi
leal (%rcx,%rdx), %ebp
leaq (%r15,%rsi), %r12
movl $0xe, %edi
movq %r15, %r8
movq %rcx, %r14
movl %ecx, %eax
cmpq $0xe, %r12
ja 0x230d
cmpl $0xe, %ebp
ja 0x230d
movl $0x4000, %r9d           # imm = 0x4000
movl %ebp, %ecx
shrl %cl, %r9d
testw %r9w, (%rbx,%r12,2)
jne 0x230d
testw %r9w, 0x3c(%rbx,%r12,2)
jne 0x230d
cmpq $0xe, %r8
ja 0x230d
cmpl $0xe, %eax
ja 0x230d
movl $0x4000, %r10d          # imm = 0x4000
movl %eax, %ecx
shrl %cl, %r10d
testw %r10w, (%rbx,%r8,2)
je 0x230d
testw %r9w, 0x1e(%rbx,%r12,2)
jne 0x22c1
addl %edx, %ebp
addq %rsi, %r12
subl %edx, %eax
subq %rsi, %r8
decq %rdi
jne 0x2256
jmp 0x230d
leaq 0x20(%rsp), %rdi
callq 0x3d09
leaq 0x5e5e(%rip), %r11      # 0x8130
movb $0x1, (%rax)
movl %r14d, 0x4(%rax)
movq 0x8(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %ebp, 0xc(%rax)
movl %r12d, 0x10(%rax)
movl $0x1, 0x14(%rax)
movl %ebp, 0x18(%rax)
movl %r12d, 0x1c(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq $0x0, 0x50(%rax)
incq %r13
cmpq $0x8, %r13
movq %r14, %rcx
jne 0x2233
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq 0x10(%rsp), %rdx
andq %rax, %rdx
movl %ecx, %esi
orq %rdx, %rsi
movq %rbx, %rdi
callq 0x2e0d
leaq 0x5ded(%rip), %r11      # 0x8130
movq %rax, %r15
movl %r15d, %ecx
cmpl $-0x1, %r15d
jne 0x221b
movq 0x5dc6(%rip), %r15      # 0x8120
movq %rbx, %rdi
movq %r15, %rsi
callq 0x2e0d
movq %rax, 0x8(%rsp)
cmpl $-0x1, %eax
je 0x2499
movq 0x8(%rsp), %rcx
movq %rbx, 0x30(%rsp)
movq %rcx, %rax
shrq $0x20, %rax
movq %rax, 0x10(%rsp)
movq %rcx, 0x38(%rsp)
sarq $0x20, %rcx
movq %rcx, 0x40(%rsp)
xorl %r15d, %r15d
movq 0x18(%rsp), %rdx
leaq 0x5d8a(%rip), %rax      # 0x8130
movl (%rax,%r15,4), %r12d
leaq 0x5d9f(%rip), %rax      # 0x8150
movslq (%rax,%r15,4), %r13
movq 0x8(%rsp), %rax
leal (%rax,%r12), %ebp
movq 0x40(%rsp), %rax
leaq (%rax,%r13), %r14
movl $0xe, %ebx
cmpq $0xe, %r14
ja 0x2458
cmpl $0xe, %ebp
ja 0x2458
movl $0x4000, %eax           # imm = 0x4000
movl %ebp, %ecx
shrl %cl, %eax
testw %ax, 0x2(%rdx,%r14,2)
jne 0x2458
testw %ax, 0x20(%rdx,%r14,2)
jne 0x2458
testw %ax, 0x3e(%rdx,%r14,2)
jne 0x2458
leaq 0x20(%rsp), %rdi
callq 0x3d09
movq 0x18(%rsp), %rdx
movb $0x1, (%rax)
movw $0x0, 0x1(%rax)
movb $0x0, 0x3(%rax)
movq 0x8(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0x10(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %ebp, 0xc(%rax)
movl %r14d, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x34(%rax)
movups %xmm0, 0x44(%rax)
movl $0x0, 0x54(%rax)
addl %r12d, %ebp
addq %r13, %r14
decq %rbx
jne 0x23cc
incq %r15
cmpq $0x8, %r15
jne 0x239f
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq 0x38(%rsp), %rcx
andq %rax, %rcx
movl 0x8(%rsp), %esi
orq %rcx, %rsi
movq 0x30(%rsp), %rdi
callq 0x2e0d
movq %rax, %rcx
movq %rax, 0x8(%rsp)
cmpl $-0x1, %ecx
jne 0x237d
movq 0x20(%rsp), %rax
movq 0x28(%rsp), %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq