// File: /workspace/github_c_makefile_star2_O2/haxlang[P]hax/haxRegexp.c
// Function: RegComp
regexp *
RegComp(Hax_Interp *interp, char *exp)
{
	Interp *iPtr = (Interp *) interp;
	Hax_Memoryp *memoryp = iPtr->memoryp;
	regexp *r;
	char *scan;
	char *longest;
	int len;
	int flags;

	if (exp == NULL)
		FAIL((char *) "NULL argument");

	/* First pass: determine size, legality. */
	iPtr->regparse = exp;
	iPtr->regnpar = 1;
	iPtr->regsize = 0L;
	iPtr->regcode = &iPtr->regdummy;
	RegC(interp, MAGIC);
	if (Reg(interp, 0, &flags) == NULL)
		return(NULL);

	/* Small enough for pointer-storage convention? */
	if (iPtr->regsize >= 32767L)		/* Probably could be 65535L. */
		FAIL((char *) "regexp too big");

	/* Allocate space. */
	r = (regexp *)ckalloc(memoryp, sizeof(regexp) + (unsigned)iPtr->regsize);
	if (r == NULL)
		FAIL((char *) "out of space");

	/* Second pass: emit code. */
	iPtr->regparse = exp;
	iPtr->regnpar = 1;
	iPtr->regcode = r->program;
	RegC(interp, MAGIC);
	if (Reg(interp, 0, &flags) == NULL)
		return(NULL);

	/* Dig out information for optimizations. */
	r->regstart = '\0';	/* Worst-case defaults. */
	r->reganch = 0;
	r->regmust = NULL;
	r->regmlen = 0;
	scan = r->program+1;			/* First BRANCH. */
	if (OP(RegNext(interp, scan)) == END) {		/* Only one top-level choice. */
		scan = OPERAND(scan);

		/* Starting-point info. */
		if (OP(scan) == EXACTLY)
			r->regstart = *OPERAND(scan);
		else if (OP(scan) == BOL)
			r->reganch++;

		/*
		 * If there's something expensive in the r.e., find the
		 * longest literal string that must appear and make it the
		 * regmust.  Resolve ties in favor of later strings, since
		 * the regstart check works with the beginning of the r.e.
		 * and avoiding duplication strengthens checking.  Not a
		 * strong reason, but sufficient in the absence of others.
		 */
		if (flags&SPSTART) {
			longest = NULL;
			len = 0;
			for (; scan != NULL; scan = RegNext(interp, scan))
				if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) {
					longest = OPERAND(scan);
					len = strlen(OPERAND(scan));
				}
			r->regmust = longest;
			r->regmlen = len;
		}
	}

	return(r);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
testq %rsi, %rsi
je 0x47d2
movq %rsi, %r15
movq 0x280(%rbx), %r12
movq %rsi, 0x298(%rbx)
movl $0x1, 0x2a0(%rbx)
leaq 0x2a4(%rbx), %r13
movq %r13, 0x2a8(%rbx)
movq $0x1, 0x2b0(%rbx)
xorl %r14d, %r14d
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x493f
testq %rax, %rax
je 0x47e4
movq 0x2b0(%rbx), %rax
cmpq $0x7fff, %rax           # imm = 0x7FFF
jl 0x47f6
leaq 0xe922(%rip), %rsi      # 0x130f2
jmp 0x47d9
leaq 0xe90b(%rip), %rsi      # 0x130e4
movq %rbx, %rdi
callq 0x4220
xorl %r14d, %r14d
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %esi
addq $0xb8, %rsi
leaq 0xe8fb(%rip), %rdx      # 0x13101
movq %r12, %rdi
movl $0xdd, %ecx
callq 0x44e0
testq %rax, %rax
je 0x4856
movq %rax, %r14
movq %r15, 0x298(%rbx)
movl $0x1, 0x2a0(%rbx)
addq $0xb4, %rax
movq %rax, 0x2a8(%rbx)
cmpq %r13, %rax
je 0x4862
leaq 0xb5(%r14), %rax
movq %rax, 0x2a8(%rbx)
movb $-0x64, 0xb4(%r14)
jmp 0x4869
leaq 0xe8b0(%rip), %rsi      # 0x1310d
jmp 0x47d9
incq 0x2b0(%rbx)
leaq 0x4(%rsp), %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x493f
testq %rax, %rax
je 0x47e1
andw $0x0, 0xa0(%r14)
andq $0x0, 0xa8(%r14)
andl $0x0, 0xb0(%r14)
leaq 0xb5(%r14), %rsi
movq %rbx, %rdi
callq 0x4ad2
cmpb $0x0, (%rax)
jne 0x47e4
movzbl 0xb8(%r14), %eax
cmpl $0x1, %eax
je 0x48d4
cmpl $0x8, %eax
jne 0x48dc
movb 0xbb(%r14), %al
movb %al, 0xa0(%r14)
jmp 0x48dc
movb $0x1, 0xa1(%r14)
testb $0x4, 0x4(%rsp)
je 0x47e4
movq %r14, %r15
addq $0xb8, %r15
xorl %r13d, %r13d
xorl %ebp, %ebp
testq %r15, %r15
je 0x492c
cmpb $0x8, (%r15)
jne 0x491c
leaq 0x3(%r15), %r12
movq %r12, %rdi
callq 0x41d0
movslq %ebp, %rcx
cmpq %rcx, %rax
cmovaeq %r12, %r13
cmovbl %ebp, %eax
movl %eax, %ebp
movq %rbx, %rdi
movq %r15, %rsi
callq 0x4ad2
movq %rax, %r15
jmp 0x48f6
movq %r13, 0xa8(%r14)
movl %ebp, 0xb0(%r14)
jmp 0x47e4