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

    ctx->move.isdwarfmove = false;

    // generate attacks
    ctx->move.from = initpos;
    while (true)
    {
        ctx->move.from = nextpos(board->trolls, 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;

                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) || ! trollat(board, check)) break;

                if (hasneighbor(board->dwarfs, ctx->move.to))
                {
                    ctx->move.numcapts = 0;
                    for (int i=0; i < NUMDIRS; ++i)
                    {
                        struct coord capt = {ctx->move.to.x + DX[i],
                                             ctx->move.to.y + DY[i]};
                        if (inbounds(capt) && dwarfat(board, capt))
                        {
                            ctx->move.capts[ctx->move.numcapts++] = capt;
                        }
                    }

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

    // generate moves
    ctx->move.numcapts = 0;
    ctx->move.from = initpos;
    while (true)
    {
        ctx->move.from = nextpos(board->trolls, 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];

            ctx->move.to.x = ctx->move.from.x + ctx->dx;
            ctx->move.to.y = ctx->move.from.y + ctx->dy;

            if (! inbounds(ctx->move.to)) continue;

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

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

    ctx->resume = NULL;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x60, %rsp
movq %rdi, -0x48(%rbp)
movq %rdi, -0x40(%rbp)
movq %rsi, -0x8(%rbp)
movq %rdx, -0x10(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, (%rax)
je 0x32b2
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x50(%rbp)
jmp 0x36a2
movq -0x10(%rbp), %rax
movb $0x0, 0x18(%rax)
movq -0x10(%rbp), %rax
movq 0x5e5b(%rip), %rcx      # 0x9120
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x58(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rax
movq 0x1c(%rax), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x58(%rbp), %rax
movq %rcx, -0x18(%rbp)
movq -0x18(%rbp), %rcx
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x3308
jmp 0x3554
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x10(%rax)
jge 0x354f
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x5e00(%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 0x5e07(%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 0x353b
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 0x33c0
jmp 0x353b
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x3800
testb $0x1, %al
jne 0x33d7
jmp 0x33dc
jmp 0x353b
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 0x342b
jmp 0x343c
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0x37d0
testb $0x1, %al
jne 0x3441
jmp 0x353b
movq -0x8(%rbp), %rdi
addq $0x2, %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x3a60
testb $0x1, %al
jne 0x345f
jmp 0x3527
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movl $0x0, -0x24(%rbp)
cmpl $0x8, -0x24(%rbp)
jge 0x34fc
movq -0x10(%rbp), %rax
movl 0x24(%rax), %eax
movslq -0x24(%rbp), %rdx
leaq 0x5ca3(%rip), %rcx      # 0x9130
addl (%rcx,%rdx,4), %eax
movl %eax, -0x2c(%rbp)
movq -0x10(%rbp), %rax
movl 0x28(%rax), %eax
movslq -0x24(%rbp), %rdx
leaq 0x5cab(%rip), %rcx      # 0x9150
addl (%rcx,%rdx,4), %eax
movl %eax, -0x28(%rbp)
movq -0x2c(%rbp), %rdi
callq 0x3730
testb $0x1, %al
jne 0x34ba
jmp 0x34ec
movq -0x8(%rbp), %rdi
movq -0x2c(%rbp), %rsi
callq 0x3770
testb $0x1, %al
jne 0x34cd
jmp 0x34ec
movq -0x10(%rbp), %rax
movq -0x10(%rbp), %rdx
movl 0x2c(%rdx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movl %esi, 0x2c(%rdx)
movslq %ecx, %rcx
movq -0x2c(%rbp), %rdx
movq %rdx, 0x30(%rax,%rcx,8)
jmp 0x34ee
movl -0x24(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x24(%rbp)
jmp 0x3471
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
leaq 0x1a(%rip), %rcx        # 0x3525
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
movl $0x58, %edx
callq 0x11c0
jmp 0x3698
jmp 0x3529
jmp 0x3529
movq -0x10(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
jmp 0x335e
jmp 0x353d
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x3313
jmp 0x32c9
movq -0x10(%rbp), %rax
movl $0x0, 0x2c(%rax)
movq -0x10(%rbp), %rax
movq 0x5bb6(%rip), %rcx      # 0x9120
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x60(%rbp)
movq -0x8(%rbp), %rdi
addq $0x20, %rdi
movq -0x10(%rbp), %rax
movq 0x1c(%rax), %rsi
callq 0x36b0
movq %rax, %rcx
movq -0x60(%rbp), %rax
movq %rcx, -0x34(%rbp)
movq -0x34(%rbp), %rcx
movq %rcx, 0x1c(%rax)
movq -0x10(%rbp), %rax
cmpl $-0x1, 0x1c(%rax)
jne 0x35ad
jmp 0x368d
movq -0x10(%rbp), %rax
movl $0x0, 0x10(%rax)
movq -0x10(%rbp), %rax
cmpl $0x8, 0x10(%rax)
jge 0x3688
movq -0x10(%rbp), %rax
movslq 0x10(%rax), %rcx
leaq 0x5b5b(%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 0x5b62(%rip), %rax      # 0x9150
movl (%rax,%rcx,4), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x10(%rbp), %rax
movl 0x1c(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0x8(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x10(%rbp), %rax
movl 0x20(%rax), %ecx
movq -0x10(%rbp), %rax
addl 0xc(%rax), %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x28(%rax)
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rdi
callq 0x3730
testb $0x1, %al
jne 0x3635
jmp 0x3676
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0x24(%rax), %rsi
callq 0x3800
testb $0x1, %al
jne 0x364c
jmp 0x364e
jmp 0x3688
movq -0x48(%rbp), %rdi
movq -0x10(%rbp), %rax
leaq 0x17(%rip), %rcx        # 0x3674
movq %rcx, (%rax)
movq -0x10(%rbp), %rsi
addq $0x18, %rsi
movl $0x58, %edx
callq 0x11c0
jmp 0x3698
jmp 0x3676
movq -0x10(%rbp), %rax
movl 0x10(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x10(%rax)
jmp 0x35b8
jmp 0x356e
movq -0x10(%rbp), %rax
movq $0x0, (%rax)
movq -0x40(%rbp), %rax
addq $0x60, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rax
jmpq *%rax
nopl (%rax,%rax)