// File: /workspace/github_c_makefile_star2_O3/phase[P]o/libregexp/rregexec.c
// Function: rregexec1
static int
rregexec1(Reprog *progp,	/* program to run */
	Rune *bol,		/* string to run machine on */
	Resub *mp,		/* subexpression elements */
	int ms,			/* number of elements at mp */
	Reljunk *j)
{
	int flag=0;
	Reinst *inst;
	Relist *tlp;
	Rune *s;
	int i, checkstart;
	Rune r, *rp, *ep;
	Relist* tl;		/* This list, next list */
	Relist* nl;
	Relist* tle;		/* ends of this and next list */
	Relist* nle;
	int match;
	Rune *p;

	match = 0;
	checkstart = j->startchar;
	if(mp)
		for(i=0; i<ms; i++) {
			mp[i].s.rsp = 0;
			mp[i].e.rep = 0;
		}
	j->relist[0][0].inst = 0;
	j->relist[1][0].inst = 0;

	/* Execute machine once for each character, including terminal NUL */
	s = j->rstarts;
	do{
		/* fast check for first char */
		if(checkstart) {
			switch(j->starttype) {
			case RUNE:
				p = runestrchr(s, j->startchar);
				if(p == 0 || s == j->reol)
					return match;
				s = p;
				break;
			case BOL:
				if(s == bol)
					break;
				p = runestrchr(s, '\n');
				if(p == 0 || s == j->reol)
					return match;
				s = p+1;
				break;
			}
		}

		r = *s;

		/* switch run lists */
		tl = j->relist[flag];
		tle = j->reliste[flag];
		nl = j->relist[flag^=1];
		nle = j->reliste[flag];
		nl->inst = 0;

		/* Add first instruction to current list */
		_rrenewemptythread(tl, progp->startinst, ms, s);

		/* Execute machine until current list is empty */
		for(tlp=tl; tlp->inst; tlp++){
			for(inst=tlp->inst; ; inst = inst->l.next){
				switch(inst->type){
				case RUNE:	/* regular character */
					if(inst->r.r == r)
						if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle)
							return -1;
					break;
				case LBRA:
					tlp->se.m[inst->r.subid].s.rsp = s;
					continue;
				case RBRA:
					tlp->se.m[inst->r.subid].e.rep = s;
					continue;
				case ANY:
					if(r != '\n')
						if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle)
							return -1;
					break;
				case ANYNL:
					if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle)
							return -1;
					break;
				case BOL:
					if(s == bol || *(s-1) == '\n')
						continue;
					break;
				case EOL:
					if(s == j->reol || r == 0 || r == '\n')
						continue;
					break;
				case CCLASS:
					ep = inst->r.cp->end;
					for(rp = inst->r.cp->spans; rp < ep; rp += 2)
						if(r >= rp[0] && r <= rp[1]){
							if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle)
								return -1;
							break;
						}
					break;
				case NCCLASS:
					ep = inst->r.cp->end;
					for(rp = inst->r.cp->spans; rp < ep; rp += 2)
						if(r >= rp[0] && r <= rp[1])
							break;
					if(rp == ep)
						if(_renewthread(nl, inst->l.next, ms, &tlp->se)==nle)
							return -1;
					break;
				case OR:
					/* evaluate right choice later */
					if(_renewthread(tlp, inst->r.right, ms, &tlp->se) == tle)
						return -1;
					/* efficiency: advance and re-evaluate */
					continue;
				case END:	/* Match! */
					match = 1;
					tlp->se.m[0].e.rep = s;
					if(mp != 0)
						_renewmatch(mp, ms, &tlp->se);
					break;
				}
				break;
			}
		}
		if(s == j->reol)
			break;
		checkstart = j->startchar && nl->inst==0;
		s++;
	}while(r);
	return match;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x58, %rsp
movq %r8, %r12
movq %rdx, %rbx
movq %rsi, -0x58(%rbp)
movq %rdi, -0x70(%rbp)
movl 0x24(%r8), %r14d
testq %rdx, %rdx
sete %al
movl %ecx, -0x2c(%rbp)
testl %ecx, %ecx
setle %cl
orb %al, %cl
jne 0x882d
movl -0x2c(%rbp), %edx
shlq $0x4, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2120
movq %rbx, -0x68(%rbp)
movq (%r12), %rax
xorl %ecx, %ecx
movq %rcx, (%rax)
movq 0x8(%r12), %rax
movq $0x0, -0x50(%rbp)
movq %rcx, (%rax)
movq 0x38(%r12), %r15
leaq 0xe4a(%rip), %rbx       # 0x96a0
xorl %r13d, %r13d
movq %r12, -0x60(%rbp)
testl %r14d, %r14d
je 0x88c6
movl 0x20(%r12), %eax
cmpl $0xc3, %eax
je 0x8898
cmpl $0x7f, %eax
jne 0x88c6
movl 0x24(%r12), %esi
movq %r15, %rdi
callq 0x8caa
testq %rax, %rax
je 0x8abb
cmpq 0x40(%r12), %r15
movq %rax, %r15
jne 0x88c6
jmp 0x8abb
cmpq -0x58(%rbp), %r15
je 0x88c6
movq %r15, %rdi
movl $0xa, %esi
callq 0x8caa
testq %rax, %rax
je 0x8abb
cmpq 0x40(%r12), %r15
je 0x8abb
addq $0x4, %rax
movq %rax, %r15
movl %r13d, -0x34(%rbp)
movl (%r15), %eax
movl %eax, -0x30(%rbp)
movq -0x50(%rbp), %rcx
movl %ecx, %eax
movq (%r12,%rax,8), %r13
movq 0x10(%r12,%rax,8), %rax
movq %rax, -0x78(%rbp)
xorl $0x1, %ecx
movq (%r12,%rcx,8), %rax
movq %rcx, -0x50(%rbp)
movq 0x10(%r12,%rcx,8), %rcx
movq %rcx, -0x48(%rbp)
movq %rax, -0x40(%rbp)
movq $0x0, (%rax)
movq -0x70(%rbp), %rax
movq (%rax), %rsi
movq %r13, %rdi
movl -0x2c(%rbp), %edx
movq %r15, %rcx
callq 0x742b
movq (%r13), %r14
testq %r14, %r14
je 0x8a7a
leaq 0x8(%r13), %r12
movl (%r14), %eax
leal -0x7f(%rax), %ecx
cmpl $0x4, %ecx
ja 0x894d
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
addq $0x8, %rax
jmp 0x8985
leal -0xc0(%rax), %ecx
cmpl $0x6, %ecx
ja 0x89ca
leaq 0xd55(%rip), %rdx       # 0x96b4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpq -0x58(%rbp), %r15
je 0x89c1
cmpl $0xa, -0x4(%r15)
je 0x89c1
jmp 0x8a67
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
movq %r15, (%rax)
jmp 0x89c1
movq 0x8(%r14), %rsi
movq %r13, %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x7315
cmpq -0x78(%rbp), %rax
jne 0x89c1
jmp 0x8ab5
movq -0x60(%rbp), %rax
cmpq 0x40(%rax), %r15
je 0x89c1
cmpl $0x0, -0x30(%rbp)
je 0x89c1
cmpl $0xa, -0x30(%rbp)
jne 0x8a67
movq 0x10(%r14), %r14
jmp 0x8928
cmpl $0xff, %eax
jne 0x8a67
movq %r15, 0x10(%r13)
movl $0x1, -0x34(%rbp)
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x8a67
movl -0x2c(%rbp), %esi
movq %r12, %rdx
callq 0x7284
jmp 0x8a67
movl -0x30(%rbp), %eax
cmpl %eax, 0x8(%r14)
je 0x8a4e
jmp 0x8a67
movq 0x8(%r14), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x8a67
movl -0x30(%rbp), %edx
cmpl (%rax), %edx
jb 0x8a08
movl -0x30(%rbp), %edx
cmpl 0x4(%rax), %edx
ja 0x8a08
jmp 0x8a4e
movq 0x8(%r14), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x8a41
movl -0x30(%rbp), %edx
cmpl (%rax), %edx
jb 0x8a29
movl -0x30(%rbp), %edx
cmpl 0x4(%rax), %edx
ja 0x8a29
cmpq %rcx, %rax
jne 0x8a67
jmp 0x8a4e
cmpl $0xa, -0x30(%rbp)
je 0x8a67
movq 0x10(%r14), %rsi
movq -0x40(%rbp), %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x7315
cmpq -0x48(%rbp), %rax
je 0x8ab5
movq 0x208(%r13), %r14
addq $0x208, %r13            # imm = 0x208
jmp 0x891b
movq -0x60(%rbp), %r12
cmpq 0x40(%r12), %r15
je 0x8acd
cmpl $0x0, 0x24(%r12)
movl -0x34(%rbp), %r13d
je 0x8aa2
xorl %r14d, %r14d
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
sete %r14b
jmp 0x8aa5
xorl %r14d, %r14d
addq $0x4, %r15
cmpl $0x0, -0x30(%rbp)
jne 0x885d
jmp 0x8abb
movl $0xffffffff, %r13d      # imm = 0xFFFFFFFF
movl %r13d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x34(%rbp), %r13d
jmp 0x8abb
nop