// File: Alcaro[P]bridges/arlib/string.cpp
// Function: cstring::matches_glob(cstring, bool) const
bool cstring::matches_glob(cstring pat, bool case_insensitive) const
{
	const uint8_t * s = ptr();
	const uint8_t * p = pat.ptr();
	const uint8_t * se = s + length();
	const uint8_t * pe = p + pat.length();
	
	const uint8_t * sp = se; // weirdo trick to not need a special case for the part before first asterisk
	const uint8_t * pp = p;
	if (p == pe)
		return (s == se);
	while (s < se)
	{
		if (p < pe && *p == '*')
		{
			p++;
			if (p == pe) return true;
			pp = p;
			sp = s+1;
		}
		else if (p < pe && s < se && (*p == *s || *p == '?' || (case_insensitive && tolower(*p) == tolower(*s))))
		{
			p++;
			s++;
		}
		else
		{
			p = pp;
			s = sp;
			sp++;
		}
	}
	while (p < pe && *p == '*') p++;
	return (p == pe);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x110, %rsp            # imm = 0x110
movb %cl, %al
movq %rsi, -0x88(%rbp)
movq %rdx, -0x80(%rbp)
movq %rdi, -0x90(%rbp)
andb $0x1, %al
movb %al, -0x91(%rbp)
movq -0x90(%rbp), %rax
movq %rax, -0xd8(%rbp)
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movq %rax, -0xd0(%rbp)
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3d666
movq -0xd0(%rbp), %rax
movq %rax, -0x20(%rbp)
jmp 0x3d674
movq -0xd0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movq %rax, -0xa0(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movq %rax, -0xe0(%rbp)
movq %rax, -0x30(%rbp)
movq -0x30(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3d6b7
movq -0xe0(%rbp), %rax
movq %rax, -0x38(%rbp)
jmp 0x3d6c5
movq -0xe0(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x38(%rbp)
movq -0xd8(%rbp), %rax
movq -0x38(%rbp), %rcx
movq %rcx, -0xa8(%rbp)
movq -0xa0(%rbp), %rcx
movq %rcx, -0xf0(%rbp)
movq %rax, -0x58(%rbp)
movq -0x58(%rbp), %rax
movq %rax, -0xe8(%rbp)
movq %rax, -0x48(%rbp)
movq -0x48(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3d72b
movq -0xe8(%rbp), %rax
movq %rax, -0x10(%rbp)
movq -0x10(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x4c(%rbp)
jmp 0x3d738
movq -0xe8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x4c(%rbp)
movq -0xf0(%rbp), %rax
movl -0x4c(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xb0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0x100(%rbp)
leaq -0x88(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x70(%rbp), %rax
movq %rax, -0xf8(%rbp)
movq %rax, -0x60(%rbp)
movq -0x60(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
cmpl $0x0, %eax
jl 0x3d7a7
movq -0xf8(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rdi
callq 0x5cc0
movsbl %al, %eax
xorl $0xf, %eax
movzbl %al, %eax
movl %eax, -0x64(%rbp)
jmp 0x3d7b4
movq -0xf8(%rbp), %rax
movl 0x8(%rax), %eax
movl %eax, -0x64(%rbp)
movq -0x100(%rbp), %rax
movl -0x64(%rbp), %ecx
addq %rcx, %rax
movq %rax, -0xb8(%rbp)
movq -0xb0(%rbp), %rax
movq %rax, -0xc0(%rbp)
movq -0xa8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jne 0x3d80f
movq -0xa0(%rbp), %rax
cmpq -0xb0(%rbp), %rax
sete %al
andb $0x1, %al
movb %al, -0x71(%rbp)
jmp 0x3d9e3
jmp 0x3d811
movq -0xa0(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0x3d97d
movq -0xa8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x3d894
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2a, %eax
jne 0x3d894
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xa8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jne 0x3d86f
movb $0x1, -0x71(%rbp)
jmp 0x3d9e3
movq -0xa8(%rbp), %rax
movq %rax, -0xc8(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x3d978
movq -0xa8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
jae 0x3d948
movq -0xa0(%rbp), %rax
cmpq -0xb0(%rbp), %rax
jae 0x3d948
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
movq -0xa0(%rbp), %rcx
movzbl (%rcx), %ecx
cmpl %ecx, %eax
je 0x3d922
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x3f, %eax
je 0x3d922
testb $0x1, -0x91(%rbp)
je 0x3d948
movq -0xa8(%rbp), %rax
movzbl (%rax), %edi
callq 0x38890
movzbl %al, %eax
movl %eax, -0x104(%rbp)
movq -0xa0(%rbp), %rax
movzbl (%rax), %edi
callq 0x38890
movb %al, %cl
movl -0x104(%rbp), %eax
movzbl %cl, %ecx
cmpl %ecx, %eax
jne 0x3d948
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
movq -0xa0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa0(%rbp)
jmp 0x3d976
movq -0xc8(%rbp), %rax
movq %rax, -0xa8(%rbp)
movq -0xc0(%rbp), %rax
movq %rax, -0xa0(%rbp)
movq -0xc0(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xc0(%rbp)
jmp 0x3d978
jmp 0x3d811
jmp 0x3d97f
movq -0xa8(%rbp), %rcx
xorl %eax, %eax
cmpq -0xb8(%rbp), %rcx
movb %al, -0x105(%rbp)
jae 0x3d9ad
movq -0xa8(%rbp), %rax
movzbl (%rax), %eax
cmpl $0x2a, %eax
sete %al
movb %al, -0x105(%rbp)
movb -0x105(%rbp), %al
testb $0x1, %al
jne 0x3d9b9
jmp 0x3d9cd
movq -0xa8(%rbp), %rax
addq $0x1, %rax
movq %rax, -0xa8(%rbp)
jmp 0x3d97f
movq -0xa8(%rbp), %rax
cmpq -0xb8(%rbp), %rax
sete %al
andb $0x1, %al
movb %al, -0x71(%rbp)
movb -0x71(%rbp), %al
andb $0x1, %al
addq $0x110, %rsp            # imm = 0x110
popq %rbp
retq
nopw %cs:(%rax,%rax)