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

    // generate attacks
    struct coord from = initpos;
    while (true)
    {
        from = nextpos(board->trolls, 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;

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

                if (hasneighbor(board->dwarfs, to))
                {
                    struct move * move = next(& moves);
                    * move = (struct move) {false, from, to, 0, {}};

                    for (int i=0; i < NUMDIRS; ++i)
                    {
                        struct coord capt = {to.x + DX[i],
                                             to.y + DY[i]};
                        if (inbounds(capt) && dwarfat(board, capt))
                        {
                            move->capts[move->numcapts++] = capt;
                        }
                    }
                }
            }
        }
    }

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

        for (int dir = 0; dir < NUMDIRS; ++dir)
        {
            struct coord to = {from.x + DX[dir],
                               from.y + DY[dir]};

            if (! inbounds(to)) continue;

            if (occupied(board, to)) break;

            * next(& moves) = (struct move) {false, 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 0x6751(%rip), %rax      # 0x9120
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
movq -0x20(%rbp), %rsi
callq 0x36b0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x29fb
jmp 0x2c19
movl $0x0, -0x2c(%rbp)
cmpl $0x8, -0x2c(%rbp)
jge 0x2c14
movslq -0x2c(%rbp), %rcx
leaq 0x6719(%rip), %rax      # 0x9130
movl (%rax,%rcx,4), %eax
movl %eax, -0x30(%rbp)
movslq -0x2c(%rbp), %rcx
leaq 0x6728(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %eax
movl %eax, -0x34(%rbp)
movl $0x1, -0x38(%rbp)
cmpl $0xf, -0x38(%rbp)
jge 0x2c04
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 0x2a6f
jmp 0x2c04
movq -0x18(%rbp), %rdi
movq -0x40(%rbp), %rsi
callq 0x3800
testb $0x1, %al
jne 0x2a82
jmp 0x2a87
jmp 0x2c04
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 0x2abe
jmp 0x2acf
movq -0x18(%rbp), %rdi
movq -0x48(%rbp), %rsi
callq 0x37d0
testb $0x1, %al
jne 0x2ad4
jmp 0x2c04
movq -0x18(%rbp), %rdi
addq $0x2, %rdi
movq -0x40(%rbp), %rsi
callq 0x3a60
testb $0x1, %al
jne 0x2aee
jmp 0x2bf4
leaq -0x10(%rbp), %rdi
callq 0x4ea0
movq %rax, -0x50(%rbp)
movq -0x50(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0xa8(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x1040
movq -0x128(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0xa4(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0x9c(%rbp)
leaq -0xa8(%rbp), %rsi
movl $0x58, %edx
callq 0x11c0
movl $0x0, -0xac(%rbp)
cmpl $0x8, -0xac(%rbp)
jge 0x2bf2
movl -0x40(%rbp), %eax
movslq -0xac(%rbp), %rdx
leaq 0x65c1(%rip), %rcx      # 0x9130
addl (%rcx,%rdx,4), %eax
movl %eax, -0xb4(%rbp)
movl -0x3c(%rbp), %eax
movslq -0xac(%rbp), %rdx
leaq 0x65c7(%rip), %rcx      # 0x9150
addl (%rcx,%rdx,4), %eax
movl %eax, -0xb0(%rbp)
movq -0xb4(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x2ba4
jmp 0x2bdc
movq -0x18(%rbp), %rdi
movq -0xb4(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x2bba
jmp 0x2bdc
movq -0x50(%rbp), %rax
movq -0x50(%rbp), %rdx
movl 0x14(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x14(%rdx)
movslq %ecx, %rcx
movq -0xb4(%rbp), %rdx
movq %rdx, 0x18(%rax,%rcx,8)
jmp 0x2bde
movl -0xac(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xac(%rbp)
jmp 0x2b51
jmp 0x2bf4
jmp 0x2bf6
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0x2a35
jmp 0x2c06
movl -0x2c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x2c(%rbp)
jmp 0x2a02
jmp 0x29d3
movq 0x6500(%rip), %rax      # 0x9120
movq %rax, -0x20(%rbp)
movq -0x18(%rbp), %rdi
addq $0x20, %rdi
movq -0x20(%rbp), %rsi
callq 0x36b0
movq %rax, -0xbc(%rbp)
movq -0xbc(%rbp), %rax
movq %rax, -0x20(%rbp)
cmpl $-0x1, -0x20(%rbp)
jne 0x2c52
jmp 0x2d34
movl $0x0, -0xc0(%rbp)
cmpl $0x8, -0xc0(%rbp)
jge 0x2d2f
movl -0x20(%rbp), %eax
movslq -0xc0(%rbp), %rdx
leaq 0x64b6(%rip), %rcx      # 0x9130
addl (%rcx,%rdx,4), %eax
movl %eax, -0xc8(%rbp)
movl -0x1c(%rbp), %eax
movslq -0xc0(%rbp), %rdx
leaq 0x64bc(%rip), %rcx      # 0x9150
addl (%rcx,%rdx,4), %eax
movl %eax, -0xc4(%rbp)
movq -0xc8(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x2caf
jmp 0x2d1b
movq -0x18(%rbp), %rdi
movq -0xc8(%rbp), %rsi
callq 0x3800
testb $0x1, %al
jne 0x2cc5
jmp 0x2cc7
jmp 0x2d2f
leaq -0x10(%rbp), %rdi
callq 0x4ea0
movq %rax, -0x130(%rbp)
leaq -0x120(%rbp), %rdi
xorl %esi, %esi
movl $0x58, %edx
callq 0x1040
movq -0x130(%rbp), %rdi
movq -0x20(%rbp), %rax
movq %rax, -0x11c(%rbp)
movq -0xc8(%rbp), %rax
movq %rax, -0x114(%rbp)
leaq -0x120(%rbp), %rsi
movl $0x58, %edx
callq 0x11c0
movl -0xc0(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc0(%rbp)
jmp 0x2c5c
jmp 0x2c24
movq -0x10(%rbp), %rax
movq -0x8(%rbp), %rdx
addq $0x130, %rsp            # imm = 0x130
popq %rbp
retq
nopw %cs:(%rax,%rax)