// File: /workspace/github_c_makefile_star2_O1/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 0x4ccb
movzbl (%rbx), %eax
cmpl $0x5a, %eax
jle 0x4aae
cmpl $0x5b, %eax
je 0x4ad1
cmpl $0x5c, %eax
jne 0x4be9
cmpl $0x2, %r13d
jl 0x4be9
incq %rbx
decl %r13d
jmp 0x4be9
cmpl $0x3f, %eax
jne 0x4be0
testl %ebp, %ebp
je 0x4cc6
incq 0x8(%rsp)
decl %ebp
movl %r13d, %r15d
movq %rbx, %r12
jmp 0x4c58
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 0x4ba0
cmpl $0x5d, %eax
je 0x4c35
testl %r15d, %r15d
je 0x4c2c
movsbl %al, %edi
cmpb $0x2d, 0x1(%r12)
jne 0x4bb1
cmpl $0x3, %r15d
jl 0x4bb1
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 0x4b79
movl %ebp, %edi
callq 0x22e0
movl %eax, %ebp
movl %r13d, %edi
callq 0x22e0
movl %eax, %r13d
movl %ebx, %edi
callq 0x22e0
movl %eax, %ebx
movl %r14d, %eax
cmpl %r13d, %ebx
jg 0x4b86
movl $0x1, %eax
addq $0x2, %r12
addl $-0x2, %r15d
cmpl %ebp, %ebx
cmovgel %eax, %r14d
movq 0x8(%rsp), %r13
movl $0x1, %ebp
jmp 0x4bd5
decl %r15d
movb 0x1(%r12), %al
incq %r12
cmpb (%r13), %al
jmp 0x4bd1
cmpl $0x0, 0x4(%rsp)
je 0x4bcd
callq 0x22e0
movl %eax, %ebx
movsbl (%r13), %edi
callq 0x22e0
cmpl %eax, %ebx
jmp 0x4bd1
cmpb (%r13), %al
cmovel %ebp, %r14d
incq %r12
decl %r15d
jmp 0x4b08
cmpl $0x2a, %eax
je 0x4c85
movl %r13d, %r15d
movq %rbx, %r12
movsbl (%rbx), %edi
cmpl $0x0, 0x4(%rsp)
movq 0x8(%rsp), %r14
je 0x4c17
callq 0x22e0
movl %eax, %ebx
movsbl (%r14), %edi
callq 0x22e0
cmpl %eax, %ebx
je 0x4c20
jmp 0x4cc6
cmpb (%r14), %dil
jne 0x4cc6
incq %r14
movq %r14, 0x8(%rsp)
decl %ebp
jmp 0x4c58
decq %r12
movl $0x1, %r15d
cmpb $0x5e, 0x3(%rsp)
sete %cl
testl %r14d, %r14d
setne %al
xorb %cl, %al
je 0x4cc6
movzbl %al, %eax
movl 0x14(%rsp), %ebp
subl %eax, %ebp
addq %rax, %r13
movq %r13, 0x8(%rsp)
leaq 0x1(%r12), %rbx
leal -0x1(%r15), %r13d
testl %ebp, %ebp
jne 0x4a7a
cmpb $0x2a, (%rbx)
jne 0x4cce
xorl %r13d, %r13d
cmpb $0x2a, 0x2(%r12,%r13)
leaq 0x1(%r13), %r13
je 0x4c71
notl %r13d
addl %r15d, %r13d
jmp 0x4cce
decl %r13d
cmpb $0x2a, 0x1(%rbx)
leaq 0x1(%rbx), %rbx
je 0x4c85
movl $0x1, %r15d
testl %r13d, %r13d
je 0x4cd8
testl %ebp, %ebp
je 0x4cc6
movq 0x8(%rsp), %r14
movq %rbx, %rdi
movl %r13d, %esi
movq %r14, %rdx
movl %ebp, %ecx
movl 0x4(%rsp), %r8d
callq 0x4a5a
testl %eax, %eax
jne 0x4cd8
incq %r14
decl %ebp
jne 0x4ca6
xorl %r15d, %r15d
jmp 0x4cd8
xorl %r13d, %r13d
xorl %r15d, %r15d
orl %ebp, %r13d
sete %r15b
movl %r15d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq