// File: /workspace/github_c_makefile_star2_O1/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 $0x58, %rsp
movq %rdi, %rbx
leaq 0x30(%rsp), %rdi
callq 0x3d90
movq %rbx, 0x8(%rsp)
leaq 0x2(%rbx), %rdi
movq 0x5f24(%rip), %rsi      # 0x8120
movq %rdi, (%rsp)
callq 0x2ec4
movq %rax, %r11
cmpl $-0x1, %r11d
je 0x23b1
leaq 0x5f17(%rip), %r9       # 0x8130
leaq 0x5f30(%rip), %r10      # 0x8150
movq %r11, %rax
movq %rax, %rcx
shrq $0x20, %rcx
movq %rcx, 0x28(%rsp)
movq %rax, 0x40(%rsp)
sarq $0x20, %rax
movq %rax, 0x50(%rsp)
xorl %eax, %eax
movq 0x8(%rsp), %r8
movq (%rsp), %rdi
movq %r11, 0x48(%rsp)
movl (%r9,%rax,4), %r12d
movq %rax, 0x10(%rsp)
movl (%r10,%rax,4), %ecx
movslq %ecx, %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rax
movq %rcx, 0x20(%rsp)
leaq (%rax,%rcx), %r14
leal (%r11,%r12), %ebp
movl $0x1, %ebx
movq 0x50(%rsp), %r13
movl %r11d, %r15d
xorl %eax, %eax
cmpl $0xe, %r14d
ja 0x22aa
cmpl $0xe, %ebp
ja 0x22aa
movl $0x4000, %edx           # imm = 0x4000
movl %ebp, %ecx
shrl %cl, %edx
movl %r14d, %esi
testw %dx, (%rdi,%rsi,2)
jne 0x22a8
testw %dx, 0x3e(%r8,%rsi,2)
je 0x22d4
xorl %eax, %eax
testb %al, %al
je 0x2368
leaq 0x1(%rbx), %rax
addq 0x20(%rsp), %r14
addl %r12d, %ebp
subl %r12d, %r15d
subq 0x18(%rsp), %r13
cmpq $0xe, %rbx
movq %rax, %rbx
jb 0x2281
jmp 0x2368
xorl %eax, %eax
cmpq $0xe, %r13
ja 0x22aa
cmpl $0xe, %r15d
ja 0x22aa
movl $0x4000, %eax           # imm = 0x4000
movl %r15d, %ecx
shrl %cl, %eax
testw %ax, (%rdi,%r13,2)
je 0x22a8
testw %dx, 0x20(%r8,%rsi,2)
je 0x2361
leaq 0x30(%rsp), %rdi
callq 0x3db1
movq 0x48(%rsp), %r11
leaq 0x5e3f(%rip), %r10      # 0x8150
leaq 0x5e18(%rip), %r9       # 0x8130
movq (%rsp), %rdi
movq 0x8(%rsp), %r8
movb $0x1, (%rax)
movl %r11d, 0x4(%rax)
movq 0x28(%rsp), %rcx
movl %ecx, 0x8(%rax)
movl %ebp, 0xc(%rax)
movl %r14d, 0x10(%rax)
movl $0x1, 0x14(%rax)
movl %ebp, 0x18(%rax)
movl %r14d, 0x1c(%rax)
xorps %xmm0, %xmm0
movups %xmm0, 0x20(%rax)
movups %xmm0, 0x30(%rax)
movups %xmm0, 0x40(%rax)
movq $0x0, 0x50(%rax)
jmp 0x22a8
movb $0x1, %al
jmp 0x22aa
movq 0x10(%rsp), %rax
incq %rax
cmpq $0x8, %rax
jne 0x224d
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq 0x40(%rsp), %rcx
andq %rax, %rcx
movl %r11d, %esi
orq %rcx, %rsi
callq 0x2ec4
leaq 0x5db2(%rip), %r10      # 0x8150
leaq 0x5d8b(%rip), %r9       # 0x8130
movl %eax, %r11d
cmpl $-0x1, %eax
jne 0x2223
movq 0x5d68(%rip), %rsi      # 0x8120
movq (%rsp), %rdi
callq 0x2ec4
movq %rax, %rsi
cmpl $-0x1, %esi
je 0x24e7
movq %rsi, %rax
movq %rax, 0x10(%rsp)
movq %rax, %r8
shrq $0x20, %r8
xorl %r14d, %r14d
movq 0x8(%rsp), %rdx
movq (%rsp), %rdi
movq %rsi, 0x20(%rsp)
movq %r8, 0x18(%rsp)
leaq 0x5d37(%rip), %rax      # 0x8130
movl (%rax,%r14,4), %r15d
leaq 0x5d4c(%rip), %rax      # 0x8150
movl (%rax,%r14,4), %r13d
leaq (%r8,%r13), %r12
leal (%rsi,%r15), %ebp
movl $0x1, %ebx
xorl %eax, %eax
cmpl $0xe, %r12d
ja 0x2444
cmpl $0xe, %ebp
ja 0x2444
movl $0x4000, %eax           # imm = 0x4000
movl %ebp, %ecx
shrl %cl, %eax
movl %r12d, %ecx
testw %ax, (%rdi,%rcx,2)
jne 0x2442
testw %ax, 0x20(%rdx,%rcx,2)
jne 0x2442
testw %ax, 0x3e(%rdx,%rcx,2)
je 0x245d
xorl %eax, %eax
testb %al, %al
je 0x24b3
leaq 0x1(%rbx), %rax
addq %r13, %r12
addl %r15d, %ebp
cmpq $0xe, %rbx
movq %rax, %rbx
jb 0x2415
jmp 0x24b3
leaq 0x30(%rsp), %rdi
callq 0x3db1
movq 0x18(%rsp), %r8
movq 0x20(%rsp), %rsi
movq (%rsp), %rdi
movq 0x8(%rsp), %rdx
movb $0x1, (%rax)
movw $0x0, 0x1(%rax)
movb $0x0, 0x3(%rax)
movl %esi, 0x4(%rax)
movl %r8d, 0x8(%rax)
movl %ebp, 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 $0x0, 0x54(%rax)
movb $0x1, %al
jmp 0x2444
incq %r14
cmpq $0x8, %r14
jne 0x23f2
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq 0x10(%rsp), %rcx
andq %rax, %rcx
movl %esi, %esi
orq %rcx, %rsi
callq 0x2ec4
movl %eax, %esi
cmpl $-0x1, %eax
jne 0x23d0
movq 0x30(%rsp), %rax
movq 0x38(%rsp), %rdx
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq