// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x38(%rbp)
movq %rdi, -0x30(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x2ec2
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x40(%rbp)
jmp 0x3278
movq -0x10(%rbp), %rax
movb $0x1, 0x18(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x6240(%rip), %rcx      # 0x9120
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2, %rdi
movq -0x10(%rbp), %rax
movq 0x1c(%rax), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x48(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x2f23
jmp 0x30e9
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x10(%rax)
jge 0x30e4
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x61e5(%rip), %rax      # 0x9130
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x61ec(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x14(%rax)
movq -0x10(%rbp), %rax
cmpl $0xf, 0x14(%rax)
jge 0x30d0
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rdi
callq 0x3730
testb $0x1, %al
jne 0x2fdb
jmp 0x30d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x3770
testb $0x1, %al
jne 0x3007
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x37a0
testb $0x1, %al
jne 0x3007
jmp 0x300c
jmp 0x30d0
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0x8(%rcx), %ecx
movq -0x10(%rbp), %rdx
movl 0x14(%rdx), %edx
subl $0x1, %edx
imull %edx, %ecx
subl %ecx, %eax
movl %eax, -0x20(%rbp)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %eax
movq -0x10(%rbp), %rcx
movl 0xc(%rcx), %ecx
movq -0x10(%rbp), %rdx
movl 0x14(%rdx), %edx
subl $0x1, %edx
imull %edx, %ecx
subl %ecx, %eax
movl %eax, -0x1c(%rbp)
movq -0x20(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x305b
jmp 0x306c
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x306e
jmp 0x30d0
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x37d0
testb $0x1, %al
jne 0x3085
jmp 0x30bc
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rcx
movq %rcx, 0x30(%rax)
movq -0x10(%rbp), %rax
leaq 0x1a(%rip), %rcx        # 0x30ba
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
movl $0x58, %edx
callq 0x11c0
jmp 0x326e
jmp 0x30d0
jmp 0x30be
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x2f79
jmp 0x30d2
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x2f2e
jmp 0x2ee4
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x6021(%rip), %rcx      # 0x9120
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x50(%rbp)
movq -0x8(%rbp), %rdi
addq $0x2, %rdi
movq -0x10(%rbp), %rax
movq 0x1c(%rax), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x50(%rbp), %rax
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rcx
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x3142
jmp 0x3263
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x10(%rax)
jge 0x325e
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x5fc6(%rip), %rax      # 0x9130
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x5fcd(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl $0x1, 0x14(%rax)
movq -0x10(%rbp), %rax
cmpl $0xf, 0x14(%rax)
jge 0x324a
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0x8(%rax), %eax
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
movl 0xc(%rax), %eax
movq -0x10(%rbp), %rdx
imull 0x14(%rdx), %eax
addl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rdi
callq 0x3730
testb $0x1, %al
jne 0x31f7
jmp 0x324a
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x3800
testb $0x1, %al
jne 0x320e
jmp 0x3210
jmp 0x324a
movq -0x38(%rbp), %rdi
movq -0x10(%rbp), %rax
leaq 0x17(%rip), %rcx        # 0x3236
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
movl $0x58, %edx
callq 0x11c0
jmp 0x326e
jmp 0x3238
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x3198
jmp 0x324c
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x314d
jmp 0x3103
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x30(%rbp), %rax
addq $0x50, %rsp
popq %rbp
retq
movq -0x40(%rbp), %rax
jmpq *%rax
nop