// File: /workspace/github_c_makefile_star2_O3/icarroll[P]clunk/thudlib.c
// Function: nextdwarfplay
struct move nextdwarfplay(struct thudboard * board, struct genstate * ctx)
{
    if (ctx->resume) goto * ctx->resume;

    ctx->move.isdwarfmove = true;

    // generate attacks
    ctx->move.numcapts = 1;
    ctx->move.from = initpos;
    while (true)
    {
        ctx->move.from = nextpos(board->dwarfs, ctx->move.from);
        if (ctx->move.from.x == -1) break;

        for (ctx->dir = 0; ctx->dir < NUMDIRS; ++ctx->dir)
        {
            ctx->dx = DX[ctx->dir];
            ctx->dy = DY[ctx->dir];

            for (ctx->dist = 1; ctx->dist < SIZE ; ++ctx->dist)
            {
                ctx->move.to.x = ctx->move.from.x + ctx->dx * ctx->dist;
                ctx->move.to.y = ctx->move.from.y + ctx->dy * ctx->dist;
                if (! inbounds(ctx->move.to)) break;

                if (dwarfat(board, ctx->move.to)
                    || blockat(board, ctx->move.to)) break;

                struct coord check;
                check.x = ctx->move.from.x - ctx->dx * (ctx->dist-1);
                check.y = ctx->move.from.y - ctx->dy * (ctx->dist-1);
                if (! inbounds(check) || ! dwarfat(board, check)) break;

                if (trollat(board, ctx->move.to))
                {
                    ctx->move.capts[0] = ctx->move.to;

                    ctx->resume = && dwarfresume1;
                    return ctx->move;
dwarfresume1:
                    break;
                }
            }
        }
    }

    // generate moves
    ctx->move.numcapts = 0;
    ctx->move.from = initpos;
    while (true)
    {
        ctx->move.from = nextpos(board->dwarfs, ctx->move.from);
        if (ctx->move.from.x == -1) break;

        for (ctx->dir = 0; ctx->dir < NUMDIRS; ++ctx->dir)
        {
            ctx->dx = DX[ctx->dir];
            ctx->dy = DY[ctx->dir];

            for (ctx->dist = 1; ctx->dist < SIZE ; ++ctx->dist)
            {
                ctx->move.to.x = ctx->move.from.x + ctx->dx * ctx->dist;
                ctx->move.to.y = ctx->move.from.y + ctx->dy * ctx->dist;
                if (! inbounds(ctx->move.to)) break;

                if (occupied(board, ctx->move.to)) break;

                ctx->resume = && dwarfresume2;
                return ctx->move;
dwarfresume2:
                continue;
            }
        }
    }

    ctx->resume = NULL;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, (%rsp)
movabsq $0xf00000000, %r12      # imm = 0xF00000000
movq (%rdx), %rax
testq %rax, %rax
je 0x28fc
jmpq *%rax
movl 0x14(%r14), %ecx
leal 0x1(%rcx), %eax
movl %eax, 0x14(%r14)
cmpl $0xd, %ecx
jle 0x2aae
jmp 0x2b01
movb $0x1, 0x18(%r14)
movl $0x1, 0x2c(%r14)
movq 0x5810(%rip), %rsi      # 0x8120
movq %rsi, 0x1c(%r14)
leaq 0x2(%r15), %rdi
callq 0x2e0d
movq %rax, 0x1c(%r14)
cmpl $-0x1, %eax
je 0x2932
movl $0x0, 0x10(%r14)
xorl %eax, %eax
jmp 0x294a
movl $0x0, 0x2c(%r14)
movq 0x57df(%rip), %rsi      # 0x8120
movq %rsi, 0x1c(%r14)
jmp 0x2a42
cmpl $0x8, %eax
jge 0x29fa
cltq
leaq 0x57d4(%rip), %rcx      # 0x8130
movl (%rcx,%rax,4), %edi
movl %edi, 0x8(%r14)
leaq 0x57e6(%rip), %rcx      # 0x8150
movslq (%rcx,%rax,4), %r8
movl %r8d, 0xc(%r14)
movl 0x1c(%r14), %eax
movslq 0x20(%r14), %r9
leal (%r9,%r8), %r10d
leal (%rdi,%rax), %r11d
movq $-0xe, %rsi
movl %r11d, 0x24(%r14)
movl %r10d, 0x28(%r14)
movq 0x24(%r14), %rdx
cmpq %r12, %rdx
jae 0x2a03
cmpl $0xe, %edx
ja 0x2a03
movl $0x4000, %ebp           # imm = 0x4000
movl %edx, %ecx
shrl %cl, %ebp
movq %rdx, %r13
shrq $0x20, %r13
testw %bp, 0x2(%r15,%r13,2)
jne 0x2a03
testw %bp, 0x3e(%r15,%r13,2)
jne 0x2a03
cmpl $0xe, %eax
ja 0x2a03
cmpq $0xe, %r9
ja 0x2a03
movl $0x4000, %ebx           # imm = 0x4000
movl %eax, %ecx
shrl %cl, %ebx
testw %bx, 0x2(%r15,%r9,2)
je 0x2a03
testw %bp, 0x20(%r15,%r13,2)
jne 0x2a19
addl %r8d, %r10d
addl %edi, %r11d
subl %edi, %eax
subq %r8, %r9
incq %rsi
jne 0x2989
movl $0xf, %esi
jmp 0x2a06
movq 0x1c(%r14), %rsi
jmp 0x2914
addl $0xf, %esi
movl %esi, 0x14(%r14)
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x10(%r14)
jmp 0x294a
addl $0xf, %esi
movl %esi, 0x14(%r14)
leaq 0x18(%r14), %rsi
movq %rdx, 0x30(%r14)
leaq -0x25(%rip), %rax       # 0x2a0a
movq %rax, (%r14)
movl $0x16, %ecx
movq (%rsp), %rax
movq %rax, %rdi
rep  movsl (%rsi), %es:(%rdi)
jmp 0x2a6b
leaq 0x2(%r15), %rdi
callq 0x2e0d
movq %rax, 0x1c(%r14)
cmpl $-0x1, %eax
je 0x2a60
movl $0x0, 0x10(%r14)
xorl %eax, %eax
jmp 0x2a7a
movq $0x0, (%r14)
movq (%rsp), %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
cmpl $0x8, %eax
jge 0x2b10
cltq
leaq 0x56a4(%rip), %rcx      # 0x8130
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x8(%r14)
leaq 0x56b6(%rip), %rcx      # 0x8150
movl (%rcx,%rax,4), %eax
movl %eax, 0xc(%r14)
movl $0x1, 0x14(%r14)
movl $0x1, %eax
movl 0x8(%r14), %ecx
imull %eax, %ecx
addl 0x1c(%r14), %ecx
movl %ecx, 0x24(%r14)
imull 0xc(%r14), %eax
addl 0x20(%r14), %eax
movl %eax, 0x28(%r14)
movq 0x24(%r14), %rcx
cmpl $0xf, %ecx
setae %al
cmpq %r12, %rcx
setae %dl
orb %al, %dl
jne 0x2b01
movl $0x4000, %eax           # imm = 0x4000
shrl %cl, %eax
shrq $0x20, %rcx
testw %ax, 0x2(%r15,%rcx,2)
jne 0x2b01
testw %ax, 0x20(%r15,%rcx,2)
jne 0x2b01
testw %ax, 0x3e(%r15,%rcx,2)
je 0x2b19
movl 0x10(%r14), %eax
incl %eax
movl %eax, 0x10(%r14)
jmp 0x2a7a
movq 0x1c(%r14), %rsi
jmp 0x2a42
leaq -0x23d(%rip), %rax      # 0x28e3
movq %rax, (%r14)
addq $0x18, %r14
movl $0x16, %ecx
movq (%rsp), %rax
movq %rax, %rdi
movq %r14, %rsi
jmp 0x2a3e