// File: /workspace/github_c_makefile_star2_O0/seanpringle[P]xoat/./regex.c
// Function: regex
regex_t*
regex(const char *pattern)
{
	int i = 0;
	unsigned int hash = 0;
	regex_t *re = NULL;
	RegexCache *rc = NULL;

	while (pattern[i])
	{
		hash = 33 * hash + pattern[i++];
	}

	// have we compiled this regex before?
	for (i = 0; i < REGEX_CACHE; i++)
	{
		rc = &regex_cache[i];
		if (rc->hash == hash && rc->pattern && !strcmp(pattern, rc->pattern))
		{
			re = &rc->regex;
			rc->used++;
			break;
		}
	}
	if (!re)
	{
		int slot = 0;
		// look for a free cache slot
		for (i = 0; i < REGEX_CACHE; i++)
		{
			if (!regex_cache[i].pattern)
			{
				slot = i;
				break;
			}
		}
		if (regex_cache[slot].pattern)
		{
			// choose the least used
			for (i = 0; i < REGEX_CACHE; i++)
			{
				if (regex_cache[i].used < regex_cache[slot].used)
				{
					slot = i;
					break;
				}
			}
		}

		rc = &regex_cache[slot];

		if (rc->pattern)
		{
			regfree(&rc->regex);
			free(rc->pattern);
		}

		rc->used = 0;
		rc->hash = 0;
		rc->pattern = NULL;

		re = &rc->regex;

		if (regcomp(re, pattern, REG_EXTENDED) != 0)
		{
			fprintf(stderr, "regex compile failure: %s", pattern);
			re = NULL;
		}
		if (re)
		{
			rc->pattern = strdup(pattern);
			rc->hash = hash;
			rc->used = 1;
		}
	}
	return re;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movl $0x0, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq $0x0, -0x18(%rbp)
movq $0x0, -0x20(%rbp)
movq -0x8(%rbp), %rax
movslq -0xc(%rbp), %rcx
cmpb $0x0, (%rax,%rcx)
je 0x3819
imull $0x21, -0x10(%rbp), %eax
movq -0x8(%rbp), %rcx
movl -0xc(%rbp), %edx
movl %edx, %esi
addl $0x1, %esi
movl %esi, -0xc(%rbp)
movslq %edx, %rdx
movsbl (%rcx,%rdx), %ecx
addl %ecx, %eax
movl %eax, -0x10(%rbp)
jmp 0x37ea
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x3890
movslq -0xc(%rbp), %rcx
leaq 0x1006f(%rip), %rax     # 0x138a0
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x10(%rbp), %eax
jne 0x3883
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3883
movq -0x8(%rbp), %rdi
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rsi
callq 0x3470
cmpl $0x0, %eax
jne 0x3883
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x20(%rbp), %rax
movl 0x50(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x50(%rax)
jmp 0x3890
jmp 0x3885
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x3820
cmpq $0x0, -0x18(%rbp)
jne 0x3a1a
movl $0x0, -0x24(%rbp)
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x38dd
movslq -0xc(%rbp), %rcx
leaq 0xffe6(%rip), %rax      # 0x138a0
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
jne 0x38d0
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x38dd
jmp 0x38d2
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x38a9
movslq -0x24(%rbp), %rcx
leaq 0xffb8(%rip), %rax      # 0x138a0
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
cmpq $0x0, 0x8(%rax)
je 0x3946
movl $0x0, -0xc(%rbp)
cmpl $0x8, -0xc(%rbp)
jge 0x3944
movslq -0xc(%rbp), %rcx
leaq 0xff92(%rip), %rax      # 0x138a0
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movl 0x50(%rax), %eax
movslq -0x24(%rbp), %rdx
leaq 0xff7d(%rip), %rcx      # 0x138a0
imulq $0x58, %rdx, %rdx
addq %rdx, %rcx
cmpl 0x50(%rcx), %eax
jae 0x3937
movl -0xc(%rbp), %eax
movl %eax, -0x24(%rbp)
jmp 0x3944
jmp 0x3939
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0x38fd
jmp 0x3946
movslq -0x24(%rbp), %rcx
leaq 0xff4f(%rip), %rax      # 0x138a0
imulq $0x58, %rcx, %rcx
addq %rcx, %rax
movq %rax, -0x20(%rbp)
movq -0x20(%rbp), %rax
cmpq $0x0, 0x8(%rax)
je 0x3981
movq -0x20(%rbp), %rdi
addq $0x10, %rdi
callq 0x34e0
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rdi
callq 0x3220
movq -0x20(%rbp), %rax
movl $0x0, 0x50(%rax)
movq -0x20(%rbp), %rax
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq $0x0, 0x8(%rax)
movq -0x20(%rbp), %rax
addq $0x10, %rax
movq %rax, -0x18(%rbp)
movq -0x18(%rbp), %rdi
movq -0x8(%rbp), %rsi
movl $0x1, %edx
callq 0x3360
cmpl $0x0, %eax
je 0x39e9
movq 0xf61c(%rip), %rax      # 0x12fe8
movq (%rax), %rdi
movq -0x8(%rbp), %rdx
leaq 0xb636(%rip), %rsi      # 0xf010
movb $0x0, %al
callq 0x3650
movq $0x0, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x3a18
movq -0x8(%rbp), %rdi
callq 0x3430
movq %rax, %rcx
movq -0x20(%rbp), %rax
movq %rcx, 0x8(%rax)
movl -0x10(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x20(%rbp), %rax
movl $0x1, 0x50(%rax)
jmp 0x3a1a
movq -0x18(%rbp), %rax
addq $0x30, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)