// File: /workspace/github_c_makefile_star2_O3/yakushstanislav[P]EagleMQ/src/utils.c
// Function: pattern_match_length
int pattern_match_length(const char *string, int slength, const char *pattern, int plength, int nocase)
{
	while(plength)
	{
		switch(pattern[0])
		{
			case '*':
				while (pattern[1] == '*') {
					pattern++;
					plength--;
				}

				if (plength == 1)
					return 1;

				while(slength)
				{
					if (pattern_match_length(pattern + 1, plength - 1, string, slength, nocase))
						return 1;

					string++;
					slength--;
				}

				return 0;
				break;

			case '?':
				if (slength == 0)
					return 0;

				string++;
				slength--;

				break;

			case '[':
			{
				int not, match;

				pattern++;
				plength--;
				not = pattern[0] == '^';

				if (not) {
					pattern++;
					plength--;
				}

				match = 0;

				while(1) {
					if (pattern[0] == '\\')
					{
						pattern++;
						plength--;

						if (pattern[0] == string[0])
							match = 1;
					} else if (pattern[0] == ']') {
						break;
					} else if (plength == 0) {
						pattern--;
						plength++;
						break;
					} else if (pattern[1] == '-' && plength >= 3) {
						int start = pattern[0];
						int end = pattern[2];
						int c = string[0];

						if (start > end)
						{
							int t = start;
							start = end;
							end = t;
						}

						if (nocase) {
							start = tolower(start);
							end = tolower(end);
							c = tolower(c);
						}

						pattern += 2;
						plength -= 2;

						if (c >= start && c <= end)
							match = 1;
					}
					else
					{
						if (!nocase) {
							if (pattern[0] == string[0])
								match = 1;
						} else {
							if (tolower((int)pattern[0]) == tolower((int)string[0]))
								match = 1;
						}
				}

				pattern++;
				plength--;
			}

			if (not)
				match = !match;

			if (!match)
				return 0;

			string++;
			slength--;

			break;
			}

		case '\\':
			if (plength >= 2) {
				pattern++;
				plength--;
			}

		default:
			if (!nocase) {
				if (pattern[0] != string[0])
					return 0;
			} else {
				if (tolower((int)pattern[0]) != tolower((int)string[0]))
					return 0;
			}

			string++;
			slength--;

			break;
		}

		pattern++;
		plength--;

		if (slength == 0)
		{
			while(*pattern == '*') {
				pattern++;
				plength--;
			}
			break;
		}
	}

	if (plength == 0 && slength == 0)
		return 1;

	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, 0x4(%rsp)
movl %ecx, %r13d
movq %rdx, %rbx
movl %esi, %ebp
movq %rdi, 0x8(%rsp)
testl %r13d, %r13d
je 0x5152
movzbl (%rbx), %eax
cmpl $0x5a, %eax
jle 0x4f42
cmpl $0x5b, %eax
je 0x4f63
cmpl $0x5c, %eax
jne 0x507b
cmpl $0x2, %r13d
jl 0x507b
incq %rbx
decl %r13d
jmp 0x507b
cmpl $0x3f, %eax
jne 0x5072
movl %r13d, %r15d
movq %rbx, %r12
testl %ebp, %ebp
movq 0x8(%rsp), %r13
jne 0x50d7
jmp 0x514d
movl %ebp, 0x14(%rsp)
leaq 0x1(%rbx), %rax
movb 0x1(%rbx), %cl
addq $0x2, %rbx
xorl %r15d, %r15d
movb %cl, 0x3(%rsp)
cmpb $0x5e, %cl
sete %r15b
cmovneq %rax, %rbx
notl %r15d
addl %r13d, %r15d
xorl %r14d, %r14d
movq %rbx, %r12
movq 0x8(%rsp), %r13
movl $0x1, %ebp
movzbl (%r12), %eax
cmpl $0x5c, %eax
je 0x5032
cmpl $0x5d, %eax
je 0x50be
testl %r15d, %r15d
je 0x50b5
movsbl %al, %edi
cmpb $0x2d, 0x1(%r12)
jne 0x5043
cmpl $0x3, %r15d
jl 0x5043
movzbl 0x2(%r12), %ecx
cmpb %cl, %al
movl %ecx, %eax
cmovgl %edi, %eax
cmovll %edi, %ecx
movsbl (%r13), %ebx
movsbl %al, %r13d
movsbl %cl, %ebp
cmpl $0x0, 0x4(%rsp)
je 0x500b
movl %ebp, %edi
callq 0x22d0
movl %eax, %ebp
movl %r13d, %edi
callq 0x22d0
movl %eax, %r13d
movl %ebx, %edi
callq 0x22d0
movl %eax, %ebx
movl %r14d, %eax
cmpl %r13d, %ebx
jg 0x5018
movl $0x1, %eax
addq $0x2, %r12
addl $-0x2, %r15d
cmpl %ebp, %ebx
cmovgel %eax, %r14d
movq 0x8(%rsp), %r13
movl $0x1, %ebp
jmp 0x5067
decl %r15d
movb 0x1(%r12), %al
incq %r12
cmpb (%r13), %al
jmp 0x5063
cmpl $0x0, 0x4(%rsp)
je 0x505f
callq 0x22d0
movl %eax, %ebx
movsbl (%r13), %edi
callq 0x22d0
cmpl %eax, %ebx
jmp 0x5063
cmpb (%r13), %al
cmovel %ebp, %r14d
incq %r12
decl %r15d
jmp 0x4f9a
cmpl $0x2a, %eax
je 0x510c
movl %r13d, %r15d
movq %rbx, %r12
movsbl (%rbx), %edi
cmpl $0x0, 0x4(%rsp)
movq 0x8(%rsp), %r13
je 0x50aa
callq 0x22d0
movl %eax, %ebx
movsbl (%r13), %edi
callq 0x22d0
cmpl %eax, %ebx
je 0x50d7
jmp 0x514d
cmpb (%r13), %dil
je 0x50d7
jmp 0x514d
decq %r12
movl $0x1, %r15d
xorl %eax, %eax
testl %r14d, %r14d
sete %al
cmpb $0x5e, 0x3(%rsp)
cmovnel %r14d, %eax
testl %eax, %eax
movl 0x14(%rsp), %ebp
je 0x514d
incq %r13
movq %r13, 0x8(%rsp)
leaq 0x1(%r12), %rbx
leal -0x1(%r15), %r13d
decl %ebp
jne 0x4f0e
cmpb $0x2a, (%rbx)
jne 0x5155
xorl %r13d, %r13d
cmpb $0x2a, 0x2(%r12,%r13)
leaq 0x1(%r13), %r13
je 0x50f8
notl %r13d
addl %r15d, %r13d
jmp 0x5155
decl %r13d
cmpb $0x2a, 0x1(%rbx)
leaq 0x1(%rbx), %rbx
je 0x510c
movl $0x1, %r15d
testl %r13d, %r13d
je 0x515f
testl %ebp, %ebp
je 0x514d
movq 0x8(%rsp), %r14
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl %ebp, %ecx
movl 0x4(%rsp), %r8d
callq 0x4eee
testl %eax, %eax
jne 0x515f
incq %r14
decl %ebp
jne 0x512d
xorl %r15d, %r15d
jmp 0x515f
movl %ebp, %r13d
xorl %r15d, %r15d
testl %r13d, %r13d
sete %r15b
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq