// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movq %rdi, %rbx
leaq 0x30(%rsp), %rdi
callq 0x39e8
movl 0x5dc1(%rip), %esi      # 0x8120
movl 0x5dbf(%rip), %eax      # 0x8124
movq %rax, (%rsp)
leaq 0x20(%rbx), %rax
movq %rax, 0x8(%rsp)
movq %rbx, 0x10(%rsp)
leaq 0x2(%rbx), %r12
leaq 0x5dce(%rip), %rbx      # 0x8150
movq (%rsp), %rax
shlq $0x20, %rax
movl %esi, %esi
orq %rax, %rsi
movq 0x8(%rsp), %rdi
callq 0x2c4d
movq %rax, %rsi
cmpl $-0x1, %esi
je 0x254b
movq %rsi, %rax
shrq $0x20, %rax
movq %rax, (%rsp)
movq %rsi, %rax
sarq $0x20, %rax
movq %rax, 0x18(%rsp)
xorl %ecx, %ecx
cmpq $0x8, %rcx
leaq 0x5d67(%rip), %rax      # 0x8130
je 0x2382
movl (%rax,%rcx,4), %eax
movq %rax, 0x20(%rsp)
movq %rcx, 0x40(%rsp)
movslq (%rbx,%rcx,4), %rax
movq %rax, 0x28(%rsp)
pushq $0x1
popq %r14
cmpq $0xf, %r14
je 0x2537
movq %r14, %rbx
imulq 0x28(%rsp), %rbx
addq 0x18(%rsp), %rbx
cmpq $0xe, %rbx
ja 0x2537
movq %r14, %r13
imulq 0x20(%rsp), %r13
addq %rsi, %r13
cmpl $0xe, %r13d
ja 0x2537
movq %rbx, %rax
shlq $0x20, %rax
movl %r13d, %ebp
orq %rax, %rbp
movq 0x10(%rsp), %rdi
movq %rsi, %r15
movq %rbp, %rsi
callq 0x2d08
movq %r15, %rsi
testb %al, %al
jne 0x2537
leaq -0x1(%r14), %rdx
movq %rdx, %rcx
imulq 0x28(%rsp), %rcx
movq 0x18(%rsp), %rax
subq %rcx, %rax
cmpq $0xe, %rax
ja 0x2537
imull 0x20(%rsp), %edx
movl %esi, %ecx
subl %edx, %ecx
cmpl $0xe, %ecx
ja 0x2537
movl $0x4000, %edx           # imm = 0x4000
shrl %cl, %edx
movq 0x8(%rsp), %rcx
testw %dx, (%rcx,%rax,2)
je 0x2537
movq %r12, %rdi
movq %rbp, %rsi
callq 0x2e81
testb %al, %al
leaq 0x5cb0(%rip), %rbp      # 0x8150
je 0x252c
leaq 0x30(%rsp), %rdi
callq 0x3a09
leaq 0x5c79(%rip), %r9       # 0x8130
andl $0x0, (%rax)
movl %r15d, 0x4(%rax)
movq (%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %r13d, 0xc(%rax)
movl %ebx, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x34(%rax)
movups %xmm0, 0x44(%rax)
andl $0x0, 0x54(%rax)
xorl %edx, %edx
cmpq $0x20, %rdx
je 0x252c
movl (%rdx,%r9), %ecx
addl %r13d, %ecx
cmpl $0xe, %ecx
ja 0x2526
movl (%rdx,%rbp), %esi
addl %ebx, %esi
cmpl $0xe, %esi
ja 0x2526
movl $0x4000, %edi           # imm = 0x4000
shrl %cl, %edi
movl %esi, %r8d
testw %di, (%r12,%r8,2)
je 0x2526
movslq 0x14(%rax), %rdi
leal 0x1(%rdi), %r8d
movl %r8d, 0x14(%rax)
movl %ecx, 0x18(%rax,%rdi,8)
movl %esi, 0x1c(%rax,%rdi,8)
addq $0x4, %rdx
jmp 0x24e5
incq %r14
movq %r15, %rsi
jmp 0x23e5
movq 0x40(%rsp), %rcx
incq %rcx
leaq 0x5c0a(%rip), %rbx      # 0x8150
jmp 0x23be
movl 0x5bce(%rip), %r12d     # 0x8120
movl 0x5bcc(%rip), %ebx      # 0x8124
leaq 0x30(%rsp), %r15
shlq $0x20, %rbx
movl %r12d, %esi
orq %rbx, %rsi
movq 0x8(%rsp), %rdi
callq 0x2c4d
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x260c
movq %r12, %rbx
shrq $0x20, %rbx
xorl %r14d, %r14d
leaq 0x5ba1(%rip), %rcx      # 0x8130
cmpq $0x20, %r14
je 0x255d
movl (%r14,%rcx), %ebp
addl %r12d, %ebp
cmpl $0xe, %ebp
ja 0x2606
leaq 0x5ba8(%rip), %rax      # 0x8150
movl (%r14,%rax), %r13d
addl %ebx, %r13d
cmpl $0xe, %r13d
ja 0x2606
movq %r13, %rax
shlq $0x20, %rax
movl %ebp, %esi
orq %rax, %rsi
movq 0x10(%rsp), %rdi
callq 0x2d08
testb %al, %al
jne 0x255d
movq %r15, %rdi
callq 0x3a09
andl $0x0, (%rax)
movl %r12d, 0x4(%rax)
movl %ebx, 0x8(%rax)
movl %ebp, 0xc(%rax)
movl %r13d, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x34(%rax)
movups %xmm0, 0x44(%rax)
andl $0x0, 0x54(%rax)
leaq 0x5b2a(%rip), %rcx      # 0x8130
addq $0x4, %r14
jmp 0x258f
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rdx
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq