// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
leaq 0x38(%rsp), %rdi
callq 0x3d90
movq %rbx, 0x8(%rsp)
leaq 0x20(%rbx), %rdi
movq 0x5bf5(%rip), %rsi      # 0x8120
movq %rdi, 0x10(%rsp)
callq 0x2ec4
movq %rax, %rcx
cmpl $-0x1, %ecx
je 0x278a
movq 0x8(%rsp), %rax
leaq 0x2(%rax), %r11
movq %r11, 0x28(%rsp)
movq %rcx, %rax
shrq $0x20, %rax
movq %rax, 0x48(%rsp)
movq %rcx, %rbx
sarq $0x20, %rbx
movq %rcx, 0x30(%rsp)
movl %ecx, %edx
xorl %ecx, %ecx
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rdi
movq %rdx, 0x18(%rsp)
leaq 0x5baf(%rip), %rax      # 0x8130
movl (%rax,%rcx,4), %r10d
leaq 0x5bc4(%rip), %rax      # 0x8150
movq %rcx, 0x50(%rsp)
movslq (%rax,%rcx,4), %r15
movl $0x1, %ebp
movq %rbp, %r12
imulq %r15, %r12
addq %rbx, %r12
xorl %r14d, %r14d
cmpq $0xe, %r12
jg 0x25eb
movq %rbp, %r13
imulq %r10, %r13
addq %rdx, %r13
cmpl $0xe, %r13d
ja 0x25eb
movq %r12, %rsi
shlq $0x20, %rsi
js 0x25eb
movl $0x4000, %eax           # imm = 0x4000
movl %r13d, %ecx
shrl %cl, %eax
movl %r12d, %ecx
testw %ax, (%r11,%rcx,2)
jne 0x25e8
testw %ax, (%rdi,%rcx,2)
jne 0x25e8
testw %ax, 0x3e(%r9,%rcx,2)
je 0x2606
xorl %r14d, %r14d
testb %r14b, %r14b
je 0x274a
leaq 0x1(%rbp), %rax
cmpq $0xe, %rbp
movq %rax, %rbp
jb 0x259a
jmp 0x274a
leaq -0x1(%rbp), %rdx
movq %rdx, %rcx
imulq %r15, %rcx
movq %rbx, %rax
subq %rcx, %rax
xorl %r14d, %r14d
cmpq $0xe, %rax
ja 0x2722
imulq %r10, %rdx
movq 0x18(%rsp), %r8
movq %r8, %rcx
subq %rdx, %rcx
movq %r8, %rdx
cmpl $0xe, %ecx
ja 0x25eb
movl $0x4000, %edx           # imm = 0x4000
shrl %cl, %edx
testw %dx, (%rdi,%rax,2)
je 0x271f
movq %r10, 0x20(%rsp)
movl %r13d, %eax
orq %rax, %rsi
movq %r11, %rdi
callq 0x3182
movb $0x1, %r14b
testb %al, %al
je 0x272c
leaq 0x38(%rsp), %rdi
callq 0x3db1
xorl %edx, %edx
movl %edx, (%rax)
movq 0x30(%rsp), %rcx
movl %ecx, 0x4(%rax)
movq 0x48(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %r13d, 0xc(%rax)
movl %r12d, 0x10(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x14(%rax)
movups %xmm0, 0x24(%rax)
movups %xmm0, 0x34(%rax)
movups %xmm0, 0x44(%rax)
movl %edx, 0x54(%rax)
xorl %edx, %edx
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %r11
movq 0x20(%rsp), %r10
leaq 0x5a6d(%rip), %rcx      # 0x8130
movl (%rdx,%rcx), %ecx
addl %r13d, %ecx
cmpl $0xe, %ecx
ja 0x2713
leaq 0x5a7b(%rip), %rsi      # 0x8150
movl (%rdx,%rsi), %esi
addl %r12d, %esi
cmpl $0xe, %esi
ja 0x2713
movl $0x4000, %r10d          # imm = 0x4000
shrl %cl, %r10d
movl %esi, %r8d
testw %r10w, (%r11,%r8,2)
movq 0x20(%rsp), %r10
je 0x2713
movslq 0x14(%rax), %r10
leal 0x1(%r10), %r8d
movl %r8d, 0x14(%rax)
movl %ecx, 0x18(%rax,%r10,8)
movl %esi, 0x1c(%rax,%r10,8)
movq 0x20(%rsp), %r10
addq $0x4, %rdx
cmpq $0x20, %rdx
jne 0x26bc
jmp 0x2722
xorl %r14d, %r14d
movq 0x18(%rsp), %rdx
jmp 0x25eb
movq 0x8(%rsp), %r9
movq 0x10(%rsp), %rdi
movq 0x28(%rsp), %r11
movq 0x18(%rsp), %rdx
movq 0x20(%rsp), %r10
jmp 0x25eb
movq 0x50(%rsp), %rcx
incq %rcx
cmpq $0x8, %rcx
jne 0x257a
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq 0x30(%rsp), %rcx
andq %rax, %rcx
orq %rcx, %rdx
movq %rdx, %rsi
callq 0x2ec4
movq 0x28(%rsp), %r11
movq %rax, %rcx
cmpl $-0x1, %ecx
jne 0x254f
movq 0x598f(%rip), %rsi      # 0x8120
movq 0x10(%rsp), %rdi
callq 0x2ec4
movq %rax, %r12
cmpl $-0x1, %r12d
je 0x28a3
leaq 0x5981(%rip), %rsi      # 0x8130
leaq 0x599a(%rip), %r8       # 0x8150
movq %r12, %r15
movq %r15, %r13
shrq $0x20, %r13
xorl %r14d, %r14d
movq 0x8(%rsp), %rdx
movq 0x10(%rsp), %rdi
movl (%r14,%rsi), %ebp
addl %r12d, %ebp
movl $0x11, %ecx
cmpl $0xe, %ebp
ja 0x2856
movl (%r14,%r8), %ebx
addl %r13d, %ebx
cmpl $0xe, %ebx
ja 0x2856
movl $0x4000, %eax           # imm = 0x4000
movl %ebp, %ecx
shrl %cl, %eax
movl $0xf, %ecx
testw %ax, 0x2(%rdx,%rbx,2)
jne 0x2856
testw %ax, (%rdi,%rbx,2)
jne 0x2856
testw %ax, 0x3e(%rdx,%rbx,2)
jne 0x2856
leaq 0x38(%rsp), %rdi
callq 0x3db1
leaq 0x5933(%rip), %r8       # 0x8150
leaq 0x590c(%rip), %rsi      # 0x8130
movq 0x10(%rsp), %rdi
movq 0x8(%rsp), %rdx
xorl %ecx, %ecx
movl %ecx, (%rax)
movl %r12d, 0x4(%rax)
movl %r13d, 0x8(%rax)
movl %ebp, 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)
movl %ecx, 0x54(%rax)
cmpl $0x11, %ecx
je 0x285f
testl %ecx, %ecx
jne 0x286d
addq $0x4, %r14
cmpq $0x20, %r14
jne 0x27cd
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
andq %rax, %r15
movl %r12d, %esi
orq %r15, %rsi
callq 0x2ec4
leaq 0x58c4(%rip), %r8       # 0x8150
leaq 0x589d(%rip), %rsi      # 0x8130
movq %rax, %r15
movl %r15d, %r12d
cmpl $-0x1, %r15d
jne 0x27b9
movq 0x38(%rsp), %rax
movq 0x40(%rsp), %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq