// File: /workspace/github_c_makefile_star2_O0/ravenexp[P]aatrace/search.c
// Function: aatrace_search_tile
int aatrace_search_tile(const struct aatrace_pic* src,
			const struct aatrace_font* font,
			int tl, int tc,
			const struct aatrace_match_ctx* m_ctx,
			const struct aatrace_search_ctx* ctx)
{
	unsigned char tilebuf[FH][FW];
	struct match_result r, best_r = {0, -1};
	int dx, dy;
	int xr, yr;

	switch (ctx->method) {
	case AATRACE_SEARCH_METHOD_DIAMOND:
	case AATRACE_SEARCH_METHOD_BOX:
		xr = yr = 1;
		break;

	case AATRACE_SEARCH_METHOD_AREA:
		xr = ctx->hrange;
		yr = ctx->vrange;
		break;

	case AATRACE_SEARCH_METHOD_NONE:
	default:
		xr = yr = 0;
	}

	for (dy = -yr; dy <= yr; dy++)
		for (dx = -xr; dx <= xr; dx++) {
			if (tc*FW + dx < 0 || (tc + 1)*FW + dx > src->w)
				continue;
			if (tl*FH + dy < 0 || (tl + 1)*FH + dy > src->h)
				continue;

			if (ctx->method == AATRACE_SEARCH_METHOD_DIAMOND &&
			    dx*dy != 0)
				continue;

			aatrace_bitblt(&tilebuf[0][0], src->buf,
				       FW, src->ll,
				       0, 0, tc*FW + dx, tl*FH + dy,
				       FW, FH);

			r = aatrace_match_tile(&tilebuf[0][0], font->pic.buf,
					       font->nchars, m_ctx);

			if (ctx->flags & AATRACE_SEARCH_FLAG_COVERAGE) {
				r.score += aatrace_cover_tile_score(src, font, tl, tc, dx, dy, m_ctx);
			}

			if (r.score < best_r.score)
				best_r = r;

			if (best_r.score == 0)
				break;
		}

	return best_r.ch;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x100, %rsp            # imm = 0x100
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl %edx, -0x14(%rbp)
movl %ecx, -0x18(%rbp)
movq %r8, -0x20(%rbp)
movq %r9, -0x28(%rbp)
movabsq $-0x100000000, %rax     # imm = 0xFFFFFFFF00000000
movq %rax, -0xc0(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xdc(%rbp)
subl $0x1, %eax
je 0x2784
jmp 0x2735
movl -0xdc(%rbp), %eax
addl $-0x2, %eax
subl $0x2, %eax
jb 0x2752
jmp 0x2745
movl -0xdc(%rbp), %eax
subl $0x4, %eax
je 0x2768
jmp 0x2786
movl $0x1, -0xd0(%rbp)
movl $0x1, -0xcc(%rbp)
jmp 0x279a
movq -0x28(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0xcc(%rbp)
movq -0x28(%rbp), %rax
movl 0xc(%rax), %eax
movl %eax, -0xd0(%rbp)
jmp 0x279a
jmp 0x2786
movl $0x0, -0xd0(%rbp)
movl $0x0, -0xcc(%rbp)
xorl %eax, %eax
subl -0xd0(%rbp), %eax
movl %eax, -0xc8(%rbp)
movl -0xc8(%rbp), %eax
cmpl -0xd0(%rbp), %eax
jg 0x2978
xorl %eax, %eax
subl -0xcc(%rbp), %eax
movl %eax, -0xc4(%rbp)
movl -0xc4(%rbp), %eax
cmpl -0xcc(%rbp), %eax
jg 0x2962
movl -0x18(%rbp), %eax
shll $0x3, %eax
addl -0xc4(%rbp), %eax
cmpl $0x0, %eax
jl 0x2803
movl -0x18(%rbp), %eax
addl $0x1, %eax
shll $0x3, %eax
addl -0xc4(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0xc(%rcx), %eax
jle 0x2808
jmp 0x294e
movl -0x14(%rbp), %eax
shll $0x4, %eax
addl -0xc8(%rbp), %eax
cmpl $0x0, %eax
jl 0x2831
movl -0x14(%rbp), %eax
addl $0x1, %eax
shll $0x4, %eax
addl -0xc8(%rbp), %eax
movq -0x8(%rbp), %rcx
cmpl 0x10(%rcx), %eax
jle 0x2836
jmp 0x294e
movq -0x28(%rbp), %rax
cmpl $0x2, (%rax)
jne 0x2856
movl -0xc4(%rbp), %eax
imull -0xc8(%rbp), %eax
cmpl $0x0, %eax
je 0x2856
jmp 0x294e
leaq -0xb0(%rbp), %rdi
movq -0x8(%rbp), %rax
movq (%rax), %rsi
movq -0x8(%rbp), %rax
movl 0x8(%rax), %ecx
movl -0x18(%rbp), %r10d
shll $0x3, %r10d
addl -0xc4(%rbp), %r10d
movl -0x14(%rbp), %eax
shll $0x4, %eax
addl -0xc8(%rbp), %eax
movl $0x8, %edx
xorl %r9d, %r9d
movl %r9d, %r8d
movl %r10d, (%rsp)
movl %eax, 0x8(%rsp)
movl $0x8, 0x10(%rsp)
movl $0x10, 0x18(%rsp)
callq 0x2990
leaq -0xb0(%rbp), %rdi
movq -0x10(%rbp), %rax
movq (%rax), %rsi
movq -0x10(%rbp), %rax
movl 0x20(%rax), %edx
movq -0x20(%rbp), %rcx
callq 0x2200
movq %rax, -0xd8(%rbp)
movq -0xd8(%rbp), %rax
movq %rax, -0xb8(%rbp)
movq -0x28(%rbp), %rax
movl 0x4(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x2925
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl -0x14(%rbp), %edx
movl -0x18(%rbp), %ecx
movl -0xc4(%rbp), %r8d
movl -0xc8(%rbp), %r9d
movq -0x20(%rbp), %rax
movq %rax, (%rsp)
callq 0x24a0
addl -0xb4(%rbp), %eax
movl %eax, -0xb4(%rbp)
movl -0xb4(%rbp), %eax
cmpl -0xbc(%rbp), %eax
jae 0x2941
movq -0xb8(%rbp), %rax
movq %rax, -0xc0(%rbp)
cmpl $0x0, -0xbc(%rbp)
jne 0x294c
jmp 0x2962
jmp 0x294e
movl -0xc4(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc4(%rbp)
jmp 0x27c8
jmp 0x2964
movl -0xc8(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc8(%rbp)
jmp 0x27a8
movl -0xc0(%rbp), %eax
addq $0x100, %rsp            # imm = 0x100
popq %rbp
retq
nopw (%rax,%rax)