// File: /workspace/github_c_makefile_star2_O3/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 0x47c5
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 0x4970
testq %rax, %rax
je 0x47d6
movq 0x2b0(%r14), %rax
cmpq $0x7fff, %rax           # imm = 0x7FFF
jl 0x47e8
leaq 0xf92f(%rip), %rsi      # 0x140f2
jmp 0x47cc
leaq 0xf918(%rip), %rsi      # 0x140e4
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 0xf909(%rip), %rdx      # 0x14101
movq %r12, %rdi
movl $0xdd, %ecx
callq 0x44d0
testq %rax, %rax
je 0x4848
movq %rax, %rbx
movq %r15, 0x298(%r14)
movl $0x1, 0x2a0(%r14)
addq $0xb4, %rax
movq %rax, 0x2a8(%r14)
cmpq %r13, %rax
je 0x4854
leaq 0xb5(%rbx), %rax
movq %rax, 0x2a8(%r14)
movb $-0x64, 0xb4(%rbx)
jmp 0x485b
leaq 0xf8be(%rip), %rsi      # 0x1410d
jmp 0x47cc
incq 0x2b0(%r14)
leaq 0xc(%rsp), %rdx
movq %r14, %rdi
xorl %esi, %esi
callq 0x4970
testq %rax, %rax
je 0x47d4
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 0x47d6
movzbl 0xb8(%rbx), %eax
cmpl $0x1, %eax
je 0x48dd
cmpl $0x8, %eax
jne 0x48e4
movb 0xbb(%rbx), %al
movb %al, 0xa0(%rbx)
jmp 0x48e4
movb $0x1, 0xa1(%rbx)
testb $0x4, 0xc(%rsp)
je 0x47d6
movq %rbx, %r12
addq $0xb8, %r12
xorl %esi, %esi
xorl %r15d, %r15d
movq %r13, 0x10(%rsp)
movb (%r12), %bpl
cmpb $0x8, %bpl
jne 0x4932
leaq 0x3(%r12), %r14
movq %r14, %rdi
movq %rsi, %r13
callq 0x41d0
movq %r13, %rsi
movq 0x10(%rsp), %r13
movslq %esi, %rsi
cmpq %rsi, %rax
cmovaeq %r14, %r15
cmovael %eax, %esi
cmpq %r12, %r13
je 0x495e
movzwl 0x1(%r12), %eax
rolw $0x8, %ax
testw %ax, %ax
je 0x495e
movzwl %ax, %eax
movl %eax, %eax
movq %rax, %rcx
negq %rcx
cmpb $0x7, %bpl
cmovneq %rax, %rcx
addq %rcx, %r12
jmp 0x4903
movq %r15, 0xa8(%rbx)
movl %esi, 0xb0(%rbx)
jmp 0x47d6