// File: /workspace/github_c_makefile_star2_O1/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
subq $0x18, %rsp
movq %rdi, %r14
testq %rsi, %rsi
je 0x47b5
movq %rsi, %r15
movq 0x280(%r14), %r12
movq %rsi, 0x298(%r14)
movl $0x1, 0x2a0(%r14)
leaq 0x2a4(%r14), %r13
movq %r13, 0x2a8(%r14)
movq $0x1, 0x2b0(%r14)
xorl %ebx, %ebx
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x496c
testq %rax, %rax
je 0x47c6
movq 0x2b0(%r14), %rax
cmpq $0x7fff, %rax           # imm = 0x7FFF
jl 0x47d8
leaq 0x1093f(%rip), %rsi     # 0x150f2
jmp 0x47bc
leaq 0x10928(%rip), %rsi     # 0x150e4
movq %r14, %rdi
callq 0x4220
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl %eax, %esi
addq $0xb8, %rsi
leaq 0x10919(%rip), %rdx     # 0x15101
movq %r12, %rdi
movl $0xdd, %ecx
callq 0x44c0
testq %rax, %rax
je 0x4838
movq %rax, %rbx
movq %r15, 0x298(%r14)
movl $0x1, 0x2a0(%r14)
addq $0xb4, %rax
movq %rax, 0x2a8(%r14)
cmpq %r13, %rax
je 0x4844
leaq 0xb5(%rbx), %rax
movq %rax, 0x2a8(%r14)
movb $-0x64, 0xb4(%rbx)
jmp 0x484b
leaq 0x108ce(%rip), %rsi     # 0x1510d
jmp 0x47bc
incq 0x2b0(%r14)
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x496c
testq %rax, %rax
je 0x47c4
movw $0x0, 0xa0(%rbx)
movq $0x0, 0xa8(%rbx)
movl $0x0, 0xb0(%rbx)
movzwl 0xb6(%rbx), %eax
rolw $0x8, %ax
movzwl %ax, %eax
movq %rax, %rcx
negq %rcx
cmpb $0x7, 0xb5(%rbx)
cmovneq %rax, %rcx
cmpb $0x0, 0xb5(%rbx,%rcx)
jne 0x47c6
movzbl 0xb8(%rbx), %eax
cmpl $0x1, %eax
je 0x48cd
cmpl $0x8, %eax
jne 0x48d4
movb 0xbb(%rbx), %al
movb %al, 0xa0(%rbx)
jmp 0x48d4
movb $0x1, 0xa1(%rbx)
testb $0x4, 0xc(%rsp)
je 0x47c6
movq %rbx, 0x10(%rsp)
movq %rbx, %rbp
addq $0xb8, %rbp
xorl %edx, %edx
xorl %ecx, %ecx
movb (%rbp), %r12b
cmpb $0x8, %r12b
jne 0x4927
leaq 0x3(%rbp), %r14
movq %r14, %rdi
movq %r13, %r15
movq %rcx, %r13
movq %rdx, %rbx
callq 0x41d0
movq %rbx, %rdx
movq %r13, %rcx
movq %r15, %r13
movslq %edx, %rdx
cmpq %rdx, %rax
cmovaeq %r14, %rcx
cmovael %eax, %edx
cmpq %rbp, %r13
je 0x4949
movzwl 0x1(%rbp), %eax
rolw $0x8, %ax
testw %ax, %ax
je 0x4949
movzwl %ax, %eax
movl %eax, %eax
cmpb $0x7, %r12b
jne 0x494d
subq %rax, %rbp
jmp 0x4950
xorl %ebp, %ebp
jmp 0x4950
addq %rax, %rbp
testq %rbp, %rbp
jne 0x48f2
movq 0x10(%rsp), %rbx
movq %rcx, 0xa8(%rbx)
movl %edx, 0xb0(%rbx)
jmp 0x47c6