// File: /workspace/github_c_makefile_star2_O2/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, %r12d
movq %rdx, %r13
movl %esi, %r14d
movq %rdi, 0x8(%rsp)
testl %r12d, %r12d
je 0x4ab4
movzbl (%r13), %eax
cmpl $0x3f, %eax
je 0x49bc
cmpl $0x5b, %eax
je 0x48b7
cmpl $0x5c, %eax
je 0x49d1
cmpl $0x2a, %eax
jne 0x49dd
jmp 0x4a61
movl %r14d, 0x14(%rsp)
leaq 0x1(%r13), %rax
movb 0x1(%r13), %cl
addq $0x2, %r13
xorl %ebx, %ebx
movb %cl, 0x3(%rsp)
cmpb $0x5e, %cl
sete %bl
cmovneq %rax, %r13
notl %ebx
addl %r12d, %ebx
xorl %r14d, %r14d
movq %r13, %r15
movq 0x8(%rsp), %r12
pushq $0x1
popq %r13
movzbl (%r15), %eax
cmpl $0x5c, %eax
je 0x497f
cmpl $0x5d, %eax
je 0x4a1f
testl %ebx, %ebx
je 0x4a19
movsbl %al, %edi
cmpb $0x2d, 0x1(%r15)
jne 0x498e
cmpl $0x3, %ebx
jl 0x498e
movzbl 0x2(%r15), %ecx
cmpb %cl, %al
movl %ecx, %eax
cmovgl %edi, %eax
cmovll %edi, %ecx
movsbl (%r12), %ebp
movsbl %al, %r13d
movsbl %cl, %r12d
cmpl $0x0, 0x4(%rsp)
je 0x495b
movl %r12d, %edi
callq 0x22d0
movl %eax, %r12d
movl %r13d, %edi
callq 0x22d0
movl %eax, %r13d
movl %ebp, %edi
callq 0x22d0
movl %eax, %ebp
movl %r14d, %eax
cmpl %r13d, %ebp
pushq $0x1
popq %r13
jg 0x496a
movl %r13d, %eax
addq $0x2, %r15
addl $-0x2, %ebx
cmpl %r12d, %ebp
cmovgel %eax, %r14d
movq 0x8(%rsp), %r12
jmp 0x49b2
decl %ebx
movb 0x1(%r15), %al
incq %r15
cmpb (%r12), %al
jmp 0x49ae
cmpl $0x0, 0x4(%rsp)
je 0x49aa
callq 0x22d0
movl %eax, %ebp
movsbl (%r12), %edi
callq 0x22d0
cmpl %eax, %ebp
jmp 0x49ae
cmpb (%r12), %al
cmovel %r13d, %r14d
incq %r15
decl %ebx
jmp 0x48ec
movl %r12d, %ebx
movq %r13, %r15
testl %r14d, %r14d
movq 0x8(%rsp), %r12
jne 0x4a39
jmp 0x4aab
cmpl $0x2, %r12d
jl 0x49dd
incq %r13
decl %r12d
movl %r12d, %ebx
movq %r13, %r15
movsbl (%r13), %edi
cmpl $0x0, 0x4(%rsp)
movq 0x8(%rsp), %r12
je 0x4a0e
callq 0x22d0
movl %eax, %ebp
movsbl (%r12), %edi
callq 0x22d0
cmpl %eax, %ebp
je 0x4a39
jmp 0x4aab
cmpb (%r12), %dil
je 0x4a39
jmp 0x4aab
decq %r15
movl %r13d, %ebx
xorl %eax, %eax
testl %r14d, %r14d
sete %al
cmpb $0x5e, 0x3(%rsp)
cmovnel %r14d, %eax
testl %eax, %eax
movl 0x14(%rsp), %r14d
je 0x4aab
incq %r12
movq %r12, 0x8(%rsp)
leaq 0x1(%r15), %r13
leal -0x1(%rbx), %r12d
decl %r14d
jne 0x4884
pushq $0x1
popq %rax
cmpb $0x2a, (%r15,%rax)
jne 0x4aaf
incq %rax
jmp 0x4a55
decl %r12d
cmpb $0x2a, 0x1(%r13)
leaq 0x1(%r13), %r13
je 0x4a61
pushq $0x1
popq %rbx
testl %r12d, %r12d
je 0x4abc
movl %r14d, %ebp
subl $0x1, %ebp
jb 0x4aab
movq %r13, %rdi
movl %r12d, %esi
movl %r14d, %ecx
movq 0x8(%rsp), %r14
movq %r14, %rdx
movl 0x4(%rsp), %r8d
callq 0x4863
testl %eax, %eax
jne 0x4abc
incq %r14
movq %r14, 0x8(%rsp)
movl %ebp, %r14d
jmp 0x4a7a
xorl %ebx, %ebx
jmp 0x4abc
subl %eax, %ebx
movl %ebx, %r14d
xorl %ebx, %ebx
testl %r14d, %r14d
sete %bl
movl %ebx, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq