// File: /workspace/github_c_makefile_star2_O1/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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movq %rdx, %r14
movq %rsi, %r15
movq %rdi, %rbx
movq (%rdx), %rax
testq %rax, %rax
je 0x2c06
jmpq *%rax
movb $0x0, 0x18(%r14)
movq 0x550e(%rip), %rax      # 0x8120
movq %rax, 0x1c(%r14)
leaq 0x20(%r15), %rdi
movq 0x1c(%r14), %rsi
callq 0x2ec4
movq %rax, 0x1c(%r14)
cmpl $-0x1, %eax
je 0x2c36
movl $0x0, 0x10(%r14)
jmp 0x2c4e
movl $0x0, 0x2c(%r14)
movq 0x54db(%rip), %rax      # 0x8120
movq %rax, 0x1c(%r14)
jmp 0x2dea
movslq 0x10(%r14), %rax
cmpq $0x7, %rax
jg 0x2c16
leaq 0x54d1(%rip), %rcx      # 0x8130
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x8(%r14)
leaq 0x54e3(%rip), %rcx      # 0x8150
movl (%rcx,%rax,4), %eax
movl %eax, 0xc(%r14)
movl $0x1, 0x14(%r14)
movl 0x14(%r14), %edi
cmpl $0xe, %edi
jg 0x2d4c
movl 0x1c(%r14), %eax
movl 0x8(%r14), %r9d
movl 0xc(%r14), %r8d
movl %r9d, %ecx
imull %edi, %ecx
addl %eax, %ecx
movl %ecx, 0x24(%r14)
movl 0x20(%r14), %edx
movl %r8d, %ecx
imull %edi, %ecx
addl %edx, %ecx
movl %ecx, 0x28(%r14)
movq 0x24(%r14), %rsi
cmpl $0xf, %esi
setb %cl
testq %rsi, %rsi
setns %r11b
andb %cl, %r11b
movq %rsi, %r10
shrq $0x20, %r10
cmpl $0xf, %r10d
setl %cl
andb %r11b, %cl
cmpb $0x1, %cl
jne 0x2d4c
movl $0x4000, %r11d          # imm = 0x4000
movl %esi, %ecx
shrl %cl, %r11d
testw %r11w, 0x2(%r15,%r10,2)
jne 0x2d4c
testw %r11w, 0x20(%r15,%r10,2)
jne 0x2d4c
testw %r11w, 0x3e(%r15,%r10,2)
jne 0x2d4c
decl %edi
imull %edi, %r9d
subl %r9d, %eax
imull %edi, %r8d
subl %r8d, %edx
cmpl $0xf, %eax
setae %cl
cmpl $0xf, %edx
setae %dil
orb %cl, %dil
jne 0x2d4c
movl $0x4000, %edi           # imm = 0x4000
movl %eax, %ecx
shrl %cl, %edi
movl %edx, %eax
testw %di, 0x20(%r15,%rax,2)
je 0x2d4c
leaq 0x2(%r15), %r12
movq %r12, %rdi
callq 0x3182
testb %al, %al
jne 0x2d55
incl 0x14(%r14)
jmp 0x2c7c
incl 0x10(%r14)
jmp 0x2c4e
leaq 0x18(%r14), %rsi
movl $0x0, 0x2c(%r14)
xorl %eax, %eax
leaq 0x53c6(%rip), %rdx      # 0x8130
leaq 0x53df(%rip), %rdi      # 0x8150
movl (%rax,%rdx), %ecx
addl 0x24(%r14), %ecx
movl (%rax,%rdi), %r8d
addl 0x28(%r14), %r8d
cmpl $0xf, %ecx
setae %r9b
cmpl $0xf, %r8d
setae %r10b
orb %r9b, %r10b
jne 0x2dbd
movl $0x4000, %r9d           # imm = 0x4000
shrl %cl, %r9d
movl %r8d, %r10d
testw %r9w, (%r12,%r10,2)
je 0x2dbd
movslq 0x2c(%r14), %r9
leal 0x1(%r9), %r10d
movl %r10d, 0x2c(%r14)
movl %ecx, 0x30(%r14,%r9,8)
movl %r8d, 0x34(%r14,%r9,8)
addq $0x4, %rax
cmpq $0x20, %rax
jne 0x2d71
leaq -0x8b(%rip), %rax       # 0x2d43
movq %rax, (%r14)
movl $0x16, %ecx
movq %rbx, %rdi
rep  movsl (%rsi), %es:(%rdi)
movq %rbx, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
leaq 0x20(%r15), %rdi
movq 0x1c(%r14), %rsi
callq 0x2ec4
movq %rax, 0x1c(%r14)
cmpl $-0x1, %eax
je 0x2e0a
movl $0x0, 0x10(%r14)
jmp 0x2e13
movq $0x0, (%r14)
jmp 0x2ddb
movslq 0x10(%r14), %rax
cmpq $0x7, %rax
jg 0x2dea
leaq 0x530c(%rip), %rcx      # 0x8130
movl (%rcx,%rax,4), %ecx
movl %ecx, 0x8(%r14)
leaq 0x531e(%rip), %rdx      # 0x8150
movl (%rdx,%rax,4), %eax
movl %eax, 0xc(%r14)
addl 0x1c(%r14), %ecx
movl %ecx, 0x24(%r14)
addl 0x20(%r14), %eax
movl %eax, 0x28(%r14)
movq 0x24(%r14), %rcx
cmpl $0xf, %ecx
setb %al
testq %rcx, %rcx
setns %dl
andb %al, %dl
movq %rcx, %rax
shrq $0x20, %rax
cmpl $0xf, %eax
setl %sil
andb %dl, %sil
cmpb $0x1, %sil
jne 0x2ebb
movl $0x4000, %edx           # imm = 0x4000
shrl %cl, %edx
testw %dx, 0x2(%r15,%rax,2)
jne 0x2dea
testw %dx, 0x20(%r15,%rax,2)
jne 0x2dea
testw %dx, 0x3e(%r15,%rax,2)
jne 0x2dea
leaq 0x17(%rip), %rax        # 0x2ebb
movq %rax, (%r14)
addq $0x18, %r14
movl $0x16, %ecx
movq %rbx, %rdi
movq %r14, %rsi
jmp 0x2dd9
incl 0x10(%r14)
jmp 0x2e13