// File: /workspace/github_c_makefile_star2_O1/haxlang[P]hax/haxUtil.c
// Function: HaxCompileRegexp
regexp *
HaxCompileRegexp(
    Hax_Interp *interp,			/* For use in error reporting. */
    char *string			/* String for which to produce
					 * compiled regular expression. */)
{
    Interp *iPtr = (Interp *) interp;
    Hax_Memoryp *memoryp = iPtr->memoryp;
    int i, length;
    regexp *result;

    length = strlen(string);
    for (i = 0; i < NUM_REGEXPS; i++) {
	if ((length == iPtr->patLengths[i])
		&& (strcmp(string, iPtr->patterns[i]) == 0)) {
	    /*
	     * Move the matched pattern to the first slot in the
	     * cache and shift the other patterns down one position.
	     */

	    if (i != 0) {
		int j;
		char *cachedString;

		cachedString = iPtr->patterns[i];
		result = iPtr->regexps[i];
		for (j = i-1; j >= 0; j--) {
		    iPtr->patterns[j+1] = iPtr->patterns[j];
		    iPtr->patLengths[j+1] = iPtr->patLengths[j];
		    iPtr->regexps[j+1] = iPtr->regexps[j];
		}
		iPtr->patterns[0] = cachedString;
		iPtr->patLengths[0] = length;
		iPtr->regexps[0] = result;
	    }
	    return iPtr->regexps[0];
	}
    }

    /*
     * No match in the cache.  Compile the string and add it to the
     * cache.
     */

    iPtr->haxRegexpError = NULL;
    result = RegComp(interp, string);
    if (iPtr->haxRegexpError != NULL) {
	Hax_AppendResult(interp,
	    "couldn't compile regular expression pattern: ",
	    iPtr->haxRegexpError, (char *) NULL);
	return NULL;
    }
    if (iPtr->patterns[NUM_REGEXPS-1] != NULL) {
	ckfree(memoryp, iPtr->patterns[NUM_REGEXPS-1]);
	ckfree(memoryp, (char *) iPtr->regexps[NUM_REGEXPS-1]);
    }
    for (i = NUM_REGEXPS - 2; i >= 0; i--) {
	iPtr->patterns[i+1] = iPtr->patterns[i];
	iPtr->patLengths[i+1] = iPtr->patLengths[i];
	iPtr->regexps[i+1] = iPtr->regexps[i];
    }
    iPtr->patterns[0] = (char *) ckalloc(memoryp, (unsigned) (length+1));
    strcpy(iPtr->patterns[0], string);
    iPtr->patLengths[0] = length;
    iPtr->regexps[0] = result;
    return result;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %r15
movq %rdi, %rbx
movq 0x280(%rdi), %rax
movq %rax, 0x10(%rsp)
movq %rsi, %rdi
callq 0x41d0
movq %rax, %r14
leaq 0x128(%rbx), %rax
movq %rax, 0x8(%rsp)
leaq 0x168(%rbx), %rbp
xorl %r12d, %r12d
cmpl %r14d, -0x18(%rbp,%r12,4)
jne 0x11ff2
movq -0x40(%rbp,%r12,8), %r13
movq %r15, %rdi
movq %r13, %rsi
callq 0x4310
testl %eax, %eax
je 0x1203c
incq %r12
cmpq $0x5, %r12
jne 0x11fd7
movq $0x0, 0x290(%rbx)
movq %rbx, %rdi
movq %r15, %rsi
callq 0x40d0
movq 0x290(%rbx), %rdx
testq %rdx, %rdx
je 0x120ae
leaq 0x5464(%rip), %rsi      # 0x1748c
xorl %r13d, %r13d
movq %rbx, %rdi
xorl %ecx, %ecx
xorl %eax, %eax
callq 0x4500
jmp 0x1216b
movq %r12, %rax
subq $0x1, %rax
jb 0x120a2
movq 0x168(%rbx,%r12,8), %rcx
movl %eax, %edx
movq 0x128(%rbx,%rdx,8), %rsi
movq %rsi, 0x130(%rbx,%rax,8)
movl 0x150(%rbx,%rdx,4), %esi
movl %esi, 0x154(%rbx,%rax,4)
movq 0x168(%rbx,%rdx,8), %rdx
movq %rdx, 0x170(%rbx,%rax,8)
leaq -0x1(%rax), %rdx
incq %rax
cmpq $0x1, %rax
movq %rdx, %rax
jg 0x1204d
movq %r13, 0x128(%rbx)
movl %r14d, 0x150(%rbx)
movq %rcx, 0x168(%rbx)
movq 0x168(%rbx), %r13
jmp 0x1216b
movq %rax, %r13
movq 0x148(%rbx), %rsi
testq %rsi, %rsi
movq 0x10(%rsp), %r12
je 0x120f0
leaq 0x5371(%rip), %rbp      # 0x1743a
movq %r12, %rdi
movq %rbp, %rdx
movl $0x582, %ecx            # imm = 0x582
callq 0x4280
movq 0x188(%rbx), %rsi
movq %r12, %rdi
movq %rbp, %rdx
movl $0x583, %ecx            # imm = 0x583
callq 0x4280
movq 0x8(%rsp), %rax
movups (%rax), %xmm0
movups 0x10(%rax), %xmm1
movups %xmm1, 0x140(%rbx)
movups %xmm0, 0x130(%rbx)
xorl %eax, %eax
movl 0x15c(%rbx,%rax,4), %ecx
movl %ecx, 0x160(%rbx,%rax,4)
movq 0x180(%rbx,%rax,8), %rcx
movq %rcx, 0x188(%rbx,%rax,8)
decq %rax
cmpq $-0x4, %rax
jne 0x1210c
leal 0x1(%r14), %esi
leaq 0x52fc(%rip), %rdx      # 0x1743a
movq %r12, %rdi
movl $0x58a, %ecx            # imm = 0x58A
callq 0x44c0
movq %rax, 0x128(%rbx)
movq %rax, %rdi
movq %r15, %rsi
callq 0x40f0
movl %r14d, 0x150(%rbx)
movq %r13, 0x168(%rbx)
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq