// File: /workspace/github_c_makefile_star2_O3/lb3361[P]dosfs/ff.c
// Function: pattern_match
static int pattern_match (	/* 0:mismatched, 1:matched */
	const TCHAR* pat,	/* Matching pattern */
	const TCHAR* nam,	/* String to be tested */
	UINT skip,			/* Number of pre-skip chars (number of ?s, b8:infinite (* specified)) */
	UINT recur			/* Recursion count */
)
{
	const TCHAR *pptr, *nptr;
	DWORD pchr, nchr;
	UINT sk;


	while ((skip & 0xFF) != 0) {		/* Pre-skip name chars */
		if (!get_achar(&nam)) return 0;	/* Branch mismatched if less name chars */
		skip--;
	}
	if (*pat == 0 && skip) return 1;	/* Matched? (short circuit) */

	do {
		pptr = pat; nptr = nam;			/* Top of pattern and name to match */
		for (;;) {
			if (*pptr == '?' || *pptr == '*') {	/* Wildcard term? */
				if (recur == 0) return 0;	/* Too many wildcard terms? */
				sk = 0;
				do {	/* Analyze the wildcard term */
					if (*pptr++ == '?') sk++; else sk |= 0x100;
				} while (*pptr == '?' || *pptr == '*');
				if (pattern_match(pptr, nptr, sk, recur - 1)) return 1;	/* Test new branch (recursive call) */
				nchr = *nptr; break;	/* Branch mismatched */
			}
			pchr = get_achar(&pptr);	/* Get a pattern char */
			nchr = get_achar(&nptr);	/* Get a name char */
			if (pchr != nchr) break;	/* Branch mismatched? */
			if (pchr == 0) return 1;	/* Branch matched? (matched at end of both strings) */
		}
		get_achar(&nam);			/* nam++ */
	} while (skip && nchr);		/* Retry until end of name if infinite search is specified */

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %rcx, 0x18(%rsp)
movl %edx, %ebp
movq %rdi, %r14
movq %rsi, 0x8(%rsp)
testb %bpl, %bpl
je 0x7b4e
leaq 0x8(%rsp), %r12
xorl %r15d, %r15d
movq %r12, %rdi
callq 0x9045
cmpl $-0x1, %eax
cmovel %r15d, %eax
movl %eax, %edi
callq 0xbab9
testl %eax, %eax
je 0x7b5e
decl %ebp
testb %bpl, %bpl
jne 0x7b2d
testl %ebp, %ebp
je 0x7b70
cmpb $0x0, (%r14)
jne 0x7b70
movl $0x1, %r15d
movl %r15d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0x18(%rsp), %rax
decl %eax
movl %eax, 0x14(%rsp)
movq %rsp, %r13
leaq 0x20(%rsp), %r12
movq %r14, (%rsp)
movq 0x8(%rsp), %rax
movq %rax, 0x20(%rsp)
movq (%rsp), %rdi
movzbl (%rdi), %eax
cmpl $0x3f, %eax
je 0x7be1
cmpl $0x2a, %eax
je 0x7be1
movq %r13, %rdi
callq 0x9045
xorl %ebx, %ebx
cmpl $-0x1, %eax
cmovel %ebx, %eax
movl %eax, %edi
callq 0xbab9
movl %eax, %r15d
movq %r12, %rdi
callq 0x9045
cmpl $-0x1, %eax
je 0x7bcb
movl %eax, %ebx
movl %ebx, %edi
callq 0xbab9
cmpl %eax, %r15d
jne 0x7c2f
testl %r15d, %r15d
jne 0x7b91
jmp 0x7b58
cmpl $0x0, 0x18(%rsp)
je 0x7c61
incq %rdi
xorl %edx, %edx
leal 0x1(%rdx), %ecx
orl $0x100, %edx            # imm = 0x100
cmpb $0x3f, %al
cmovel %ecx, %edx
movzbl (%rdi), %eax
cmpl $0x3f, %eax
je 0x7c08
cmpl $0x2a, %eax
jne 0x7c0d
incq %rdi
jmp 0x7bed
movq %rdi, (%rsp)
movq 0x20(%rsp), %rbx
movq %rbx, %rsi
movl 0x14(%rsp), %ecx
callq 0x7b03
testl %eax, %eax
jne 0x7b58
movsbl (%rbx), %ebx
jmp 0x7c31
movl %eax, %ebx
leaq 0x8(%rsp), %rdi
callq 0x9045
xorl %r15d, %r15d
cmpl $-0x1, %eax
cmovel %r15d, %eax
movl %eax, %edi
callq 0xbab9
testl %ebp, %ebp
je 0x7b5e
testl %ebx, %ebx
jne 0x7b83
jmp 0x7b5e
xorl %r15d, %r15d
jmp 0x7b5e