// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x130, %rsp            # imm = 0x130
movq %rdi, -0x18(%rbp)
leaq -0x10(%rbp), %rdi
callq 0x4e60
movq 0x6ac1(%rip), %rax      # 0x9120
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
movq -0x20(%rbp), %rsi
callq 0x36b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x268b
jmp 0x2820
movl $0x0, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jge 0x281b
movslq -0x2c(%rbp), %rcx
leaq 0x6a89(%rip), %rax      # 0x9130
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0x6a98(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
cmpl $0xf, -0x38(%rbp)
jge 0x280b
movl -0x20(%rbp), %eax
movl -0x30(%rbp), %ecx
imull -0x38(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x40(%rbp)
movl -0x1c(%rbp), %eax
movl -0x34(%rbp), %ecx
imull -0x38(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0x3c(%rbp)
movq -0x40(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x26ff
jmp 0x280b
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x2723
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x37a0
testb $0x1, %al
jne 0x2723
jmp 0x2728
jmp 0x280b
movl -0x20(%rbp), %eax
movl -0x30(%rbp), %ecx
movl -0x38(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
subl %ecx, %eax
movl %eax, -0x48(%rbp)
movl -0x1c(%rbp), %eax
movl -0x34(%rbp), %ecx
movl -0x38(%rbp), %edx
subl $0x1, %edx
imull %edx, %ecx
subl %ecx, %eax
movl %eax, -0x44(%rbp)
movq -0x48(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x275f
jmp 0x2770
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x2775
jmp 0x280b
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x37d0
testb $0x1, %al
jne 0x2788
jmp 0x27fb
leaq -0x10(%rbp), %rdi
callq 0x4ea0
movq %rax, -0x120(%rbp)
movb $0x1, -0xa0(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x9c(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x94(%rbp)
movl $0x1, -0x8c(%rbp)
leaq -0xa0(%rbp), %rdi
addq $0x18, %rdi
xorl %esi, %esi
movl $0x40, %edx
callq 0x1040
movq -0x120(%rbp), %rdi
movq -0x40(%rbp), %rax
movq %rax, -0x88(%rbp)
leaq -0xa0(%rbp), %rsi
movl $0x58, %edx
callq 0x11c0
jmp 0x280b
jmp 0x27fd
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x26c5
jmp 0x280d
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2692
jmp 0x2663
movq 0x68f9(%rip), %rax      # 0x9120
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
movq -0x20(%rbp), %rsi
callq 0x36b0
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x2859
jmp 0x299c
movl $0x0, -0xac(%rbp)
cmpl $0x8, -0xac(%rbp)
jge 0x2997
movslq -0xac(%rbp), %rcx
leaq 0x68b2(%rip), %rax      # 0x9130
movl (%rax,%rcx,4), %eax
movl %eax, -0xb0(%rbp)
movslq -0xac(%rbp), %rcx
leaq 0x68bb(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %eax
movl %eax, -0xb4(%rbp)
movl $0x1, -0xb8(%rbp)
cmpl $0xf, -0xb8(%rbp)
jge 0x2981
movl -0x20(%rbp), %eax
movl -0xb0(%rbp), %ecx
imull -0xb8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xc0(%rbp)
movl -0x1c(%rbp), %eax
movl -0xb4(%rbp), %ecx
imull -0xb8(%rbp), %ecx
addl %ecx, %eax
movl %eax, -0xbc(%rbp)
movq -0xc0(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x28fa
jmp 0x2981
movq -0x18(%rbp), %rdi
movq -0xc0(%rbp), %rsi
callq 0x3800
testb $0x1, %al
jne 0x2910
jmp 0x2912
jmp 0x2981
leaq -0x10(%rbp), %rdi
callq 0x4ea0
movq %rax, -0x128(%rbp)
leaq -0x118(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x1040
movq -0x128(%rbp), %rdi
movb $0x1, -0x118(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0x114(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0x10c(%rbp)
leaq -0x118(%rbp), %rsi
movl $0x58, %edx
callq 0x11c0
movl -0xb8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xb8(%rbp)
jmp 0x28a8
jmp 0x2983
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x2863
jmp 0x282b
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopl (%rax)