// File: /workspace/github_c_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x108, %rsp            # imm = 0x108
movq %r8, %r11
movq %rcx, 0x50(%rsp)
movl %edx, 0x14(%rsp)
movq %rsi, %rbx
movl (%r9), %eax
leal -0x2(%rax), %ecx
cmpl $0x2, %ecx
jae 0x1f31
pushq $0x1
popq %rcx
movl %ecx, %edx
jmp 0x1f44
cmpl $0x4, %eax
jne 0x1f40
movl 0x8(%r9), %ecx
movl 0xc(%r9), %edx
jmp 0x1f44
xorl %ecx, %ecx
xorl %edx, %edx
movl %edx, %esi
negl %esi
movl %ecx, %eax
negl %eax
movl %eax, 0x40(%rsp)
movq 0x50(%rsp), %rax
leal (,%rax,8), %ebp
leal 0x8(,%rax,8), %r8d
movl 0x14(%rsp), %eax
movl %eax, %r10d
shll $0x4, %r10d
leal 0x10(%r10), %eax
movq %rax, 0x68(%rsp)
movl %ebp, %eax
subl %ecx, %eax
movl %eax, 0x3c(%rsp)
movq %r10, %rax
movq %r10, 0x70(%rsp)
subl %edx, %eax
movl %eax, 0x1c(%rsp)
xorl %r10d, %r10d
pushq $-0x1
popq %rax
movl %eax, 0x10(%rsp)
leaq 0x80(%rsp), %r13
movq %r11, 0x28(%rsp)
movq %rbx, 0x60(%rsp)
movq %rdi, 0x20(%rsp)
movl %ecx, 0x18(%rsp)
movl %edx, 0x44(%rsp)
movq %r8, 0x58(%rsp)
cmpl %edx, %esi
jg 0x2160
movq 0x70(%rsp), %rax
leal (%rsi,%rax), %edx
movq 0x68(%rsp), %rax
leal (%rax,%rsi), %r12d
movl 0x3c(%rsp), %r15d
movl 0x40(%rsp), %eax
movl %eax, %r14d
movq %rsi, 0x30(%rsp)
movl %edx, 0x4c(%rsp)
movl %r12d, 0x48(%rsp)
cmpl %ecx, %r14d
jg 0x2151
movl %r14d, %eax
addl %ebp, %eax
js 0x2121
leal (%r8,%r14), %eax
cmpl 0xc(%rdi), %eax
jg 0x2121
testl %edx, %edx
js 0x2121
cmpl 0x10(%rdi), %r12d
jg 0x2121
cmpl $0x2, (%r9)
jne 0x2036
movl %r14d, %eax
imull %esi, %eax
testl %eax, %eax
jne 0x2121
movq %r10, 0x78(%rsp)
movq (%rdi), %rax
movl 0x8(%rdi), %ecx
movl 0x1c(%rsp), %edx
imull %ecx, %edx
addl %r15d, %edx
movq %r13, %rsi
xorl %r12d, %r12d
cmpq $0x10, %r12
je 0x207d
xorl %r8d, %r8d
cmpq $0x8, %r8
je 0x2071
leal (%rdx,%r8), %r10d
movb (%rax,%r10), %r10b
movb %r10b, (%rsi,%r8)
incq %r8
jmp 0x205a
incq %r12
addq $0x8, %rsi
addq %rcx, %rdx
jmp 0x2051
movq (%rbx), %rsi
movl 0x20(%rbx), %edx
movq %r13, %rdi
movq %r11, %rcx
movq %r9, %r13
callq 0x1c19
movq %rbx, %rsi
movq %rax, %rbx
movq %rax, %r12
shrq $0x20, %r12
testb $0x1, 0x4(%r13)
jne 0x20aa
movq %r13, %r9
jmp 0x20d7
movq 0x28(%rsp), %rax
movq %rax, (%rsp)
movq 0x20(%rsp), %rdi
movl 0x14(%rsp), %edx
movq 0x50(%rsp), %rcx
movl %r14d, %r8d
movq 0x30(%rsp), %r9
callq 0x1d7c
movq %r13, %r9
addl %r12d, %eax
movl %eax, %r12d
movl 0x10(%rsp), %eax
cmpl %eax, %r12d
cmovbl %r12d, %eax
movq 0x78(%rsp), %r10
cmovbl %ebx, %r10d
testl %eax, %eax
leaq 0x80(%rsp), %r13
je 0x212c
movl %eax, 0x10(%rsp)
movq 0x28(%rsp), %r11
movq 0x60(%rsp), %rbx
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rsi
movq 0x58(%rsp), %r8
movl 0x4c(%rsp), %edx
movl 0x48(%rsp), %r12d
incl %r14d
incl %r15d
jmp 0x1fef
movl $0x0, 0x10(%rsp)
movq 0x28(%rsp), %r11
movq 0x60(%rsp), %rbx
movq 0x20(%rsp), %rdi
movl 0x18(%rsp), %ecx
movq 0x30(%rsp), %rsi
movq 0x58(%rsp), %r8
incl %esi
incl 0x1c(%rsp)
movl 0x44(%rsp), %edx
jmp 0x1fbc
movl %r10d, %eax
addq $0x108, %rsp            # imm = 0x108
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)