// File: /workspace/github_c_makefile_star2_O3/phase[P]o/libregexp/regexec.c
// Function: regexec1
static int
regexec1(Reprog *progp,	/* program to run */
	char *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;
	char *s;
	int i, checkstart;
	Rune r, *rp, *ep;
	int n;
	Relist* tl;		/* This list, next list */
	Relist* nl;
	Relist* tle;		/* ends of this and next list */
	Relist* nle;
	int match;
	char *p;

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

	/* Execute machine once for each character, including terminal NUL */
	s = j->starts;
	do{
		/* fast check for first char */
		if(checkstart) {
			switch(j->starttype) {
			case RUNE:
				p = utfrune(s, j->startchar);
				if(p == 0 || s == j->eol)
					return match;
				s = p;
				break;
			case BOL:
				if(s == bol)
					break;
				p = utfrune(s, '\n');
				if(p == 0 || s == j->eol)
					return match;
				s = p+1;
				break;
			}
		}
		r = *(unsigned char*)s;
		if(r < Runeself)
			n = 1;
		else
			n = chartorune(&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 */
		if(match == 0)
			_renewemptythread(tl, progp->startinst, ms, s);

		/* Execute machine until current list is empty */
		for(tlp=tl; tlp->inst; tlp++){	/* assignment = */
			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.sp = s;
					continue;
				case RBRA:
					tlp->se.m[inst->r.subid].e.ep = 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->eol || 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.ep = s;
					if(mp != 0)
						_renewmatch(mp, ms, &tlp->se);
					break;
				}
				break;
			}
		}
		if(s == j->eol)
			break;
		checkstart = j->starttype && nl->inst==0;
		s += n;
	}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 0x20(%r8), %r14d
testq %rdx, %rdx
sete %al
movl %ecx, -0x30(%rbp)
testl %ecx, %ecx
setle %cl
orb %al, %cl
jne 0x8300
movl -0x30(%rbp), %edx
shlq $0x4, %rdx
movq %rbx, %rdi
xorl %esi, %esi
callq 0x2120
movq %rbx, -0x68(%rbp)
movq (%r12), %rax
xorl %r13d, %r13d
movq %r13, (%rax)
movq 0x8(%r12), %rax
movq %r13, (%rax)
movq 0x28(%r12), %r15
leaq 0x134e(%rip), %rbx      # 0x9670
movl $0x0, -0x2c(%rbp)
movq %r12, -0x60(%rbp)
testl %r14d, %r14d
je 0x8395
movl 0x20(%r12), %eax
cmpl $0xc3, %eax
je 0x8368
cmpl $0x7f, %eax
jne 0x8395
movl 0x24(%r12), %esi
movq %r15, %rdi
callq 0x8ce0
testq %rax, %rax
je 0x85ba
cmpq 0x30(%r12), %r15
movq %rax, %r15
jne 0x8395
jmp 0x85ba
cmpq -0x58(%rbp), %r15
je 0x8395
movq %r15, %rdi
movl $0xa, %esi
callq 0x8ce0
testq %rax, %rax
je 0x85ba
cmpq 0x30(%r12), %r15
je 0x85ba
incq %rax
movq %rax, %r15
movzbl (%r15), %eax
movl %eax, -0x34(%rbp)
movl $0x1, %ecx
testb %al, %al
jns 0x83b4
leaq -0x34(%rbp), %rdi
movq %r15, %rsi
callq 0x8be8
movslq %eax, %rcx
movq %rcx, -0x78(%rbp)
movl %r13d, %eax
movq %r13, %rcx
movq (%r12,%rax,8), %r13
movq 0x10(%r12,%rax,8), %rax
movq %rax, -0x80(%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)
cmpl $0x0, -0x2c(%rbp)
jne 0x8405
movq -0x70(%rbp), %rax
movq (%rax), %rsi
movq %r13, %rdi
movl -0x30(%rbp), %edx
movq %r15, %rcx
callq 0x73a6
movq (%r13), %r14
testq %r14, %r14
je 0x8578
leaq 0x8(%r13), %r12
movl (%r14), %eax
leal -0x7f(%rax), %ecx
cmpl $0x4, %ecx
ja 0x843b
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
addq $0x8, %rax
jmp 0x8473
leal -0xc0(%rax), %ecx
cmpl $0x6, %ecx
ja 0x84b8
leaq 0x1237(%rip), %rdx      # 0x9684
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpq -0x58(%rbp), %r15
je 0x84af
cmpb $0xa, -0x1(%r15)
je 0x84af
jmp 0x8565
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
movq %r15, (%rax)
jmp 0x84af
movq 0x8(%r14), %rsi
movq %r13, %rdi
movl -0x30(%rbp), %edx
movq %r12, %rcx
callq 0x7315
cmpq -0x80(%rbp), %rax
jne 0x84af
jmp 0x85b3
movq -0x60(%rbp), %rax
cmpq 0x30(%rax), %r15
je 0x84af
movl -0x34(%rbp), %eax
testl %eax, %eax
je 0x84af
cmpl $0xa, %eax
jne 0x8565
movq 0x10(%r14), %r14
jmp 0x8416
cmpl $0xff, %eax
jne 0x8565
movq %r15, 0x10(%r13)
movl $0x1, -0x2c(%rbp)
movq -0x68(%rbp), %rdi
testq %rdi, %rdi
je 0x8565
movl -0x30(%rbp), %esi
movq %r12, %rdx
callq 0x7284
jmp 0x8565
movl 0x8(%r14), %eax
cmpl -0x34(%rbp), %eax
je 0x854c
jmp 0x8565
movq 0x8(%r14), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x8565
movl -0x34(%rbp), %edx
cmpl (%rax), %edx
jb 0x850f
cmpl 0x4(%rax), %edx
jbe 0x854c
addq $0x8, %rax
cmpq %rcx, %rax
jb 0x8506
jmp 0x8565
movq 0x8(%r14), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x853f
movl -0x34(%rbp), %edx
cmpl (%rax), %edx
jb 0x8536
cmpl 0x4(%rax), %edx
jbe 0x853f
addq $0x8, %rax
cmpq %rcx, %rax
jb 0x852d
cmpq %rcx, %rax
jne 0x8565
jmp 0x854c
cmpl $0xa, -0x34(%rbp)
je 0x8565
movq 0x10(%r14), %rsi
movq -0x40(%rbp), %rdi
movl -0x30(%rbp), %edx
movq %r12, %rcx
callq 0x7315
cmpq -0x48(%rbp), %rax
je 0x85b3
movq 0x208(%r13), %r14
addq $0x208, %r13            # imm = 0x208
jmp 0x8409
movq -0x60(%rbp), %r12
cmpq 0x30(%r12), %r15
je 0x85ba
cmpl $0x0, 0x20(%r12)
je 0x859c
xorl %r14d, %r14d
movq -0x40(%rbp), %rax
cmpq $0x0, (%rax)
sete %r14b
jmp 0x859f
xorl %r14d, %r14d
movq -0x50(%rbp), %r13
addq -0x78(%rbp), %r15
cmpl $0x0, -0x34(%rbp)
jne 0x832d
jmp 0x85ba
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movl -0x2c(%rbp), %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq