// File: /workspace/github_c_makefile_star2_O2/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 $0x48, %rsp
movq %r8, %r15
movl %ecx, -0x2c(%rbp)
movq %rsi, -0x50(%rbp)
movq %rdi, -0x68(%rbp)
movl 0x24(%r8), %eax
testq %rdx, %rdx
je 0x7086
xorl %ecx, %ecx
movl -0x2c(%rbp), %esi
testl %esi, %esi
movl $0x0, %edi
cmovgl %esi, %edi
shlq $0x4, %rdi
xorps %xmm0, %xmm0
cmpq %rcx, %rdi
je 0x7086
movups %xmm0, (%rdx,%rcx)
addq $0x10, %rcx
jmp 0x7077
movq %rdx, -0x48(%rbp)
movq (%r15), %rcx
andq $0x0, (%rcx)
movq 0x8(%r15), %rcx
andq $0x0, (%rcx)
movq 0x38(%r15), %r13
xorl %ecx, %ecx
xorl %r14d, %r14d
movq %r15, -0x58(%rbp)
testl %eax, %eax
je 0x7114
movl 0x20(%r15), %eax
cmpl $0xc3, %eax
je 0x70e3
cmpl $0x7f, %eax
jne 0x7114
movq %rcx, %r12
movl 0x24(%r15), %esi
movq %r13, %rdi
callq 0x74f1
testq %rax, %rax
je 0x730f
cmpq 0x40(%r15), %r13
movq %rax, %r13
movq %r12, %rcx
jne 0x7114
jmp 0x730f
cmpq -0x50(%rbp), %r13
je 0x7114
movq %rcx, %r12
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x74f1
testq %rax, %rax
je 0x730f
cmpq 0x40(%r15), %r13
je 0x730f
movq %r12, %rcx
addq $0x4, %rax
movq %rax, %r13
movl %r14d, -0x30(%rbp)
movl (%r13), %r14d
movl %ecx, %eax
movq (%r15,%rax,8), %rbx
movq 0x10(%r15,%rax,8), %rax
movq %rax, -0x70(%rbp)
xorl $0x1, %ecx
movq (%r15,%rcx,8), %rax
movq %rcx, -0x60(%rbp)
movq 0x10(%r15,%rcx,8), %rcx
movq %rcx, -0x40(%rbp)
movq %rax, -0x38(%rbp)
andq $0x0, (%rax)
movq -0x68(%rbp), %rax
movq (%rax), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
movq %r13, %rcx
callq 0x5e74
leaq 0x156d(%rip), %rsi      # 0x86d0
movq (%rbx), %r15
testq %r15, %r15
je 0x72d2
leaq 0x8(%rbx), %r12
movl (%r15), %eax
leal -0x7f(%rax), %ecx
cmpl $0x4, %ecx
ja 0x7198
movslq (%rsi,%rcx,4), %rax
addq %rsi, %rax
jmpq *%rax
movslq 0x8(%r15), %rax
shlq $0x4, %rax
addq %r12, %rax
addq $0x8, %rax
jmp 0x71d0
leal -0xc0(%rax), %ecx
cmpl $0x6, %ecx
ja 0x721b
leaq 0x153a(%rip), %rdx      # 0x86e4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpq -0x50(%rbp), %r13
je 0x7212
cmpl $0xa, -0x4(%r13)
je 0x7212
jmp 0x72c6
movslq 0x8(%r15), %rax
shlq $0x4, %rax
addq %r12, %rax
movq %r13, (%rax)
jmp 0x7212
movq 0x8(%r15), %rsi
movq %rbx, %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x5d67
leaq 0x14e2(%rip), %rsi      # 0x86d0
cmpq -0x70(%rbp), %rax
jne 0x7212
jmp 0x730b
movq -0x58(%rbp), %rax
cmpq 0x40(%rax), %r13
je 0x7212
testl %r14d, %r14d
je 0x7212
cmpl $0xa, %r14d
jne 0x72c6
movq 0x10(%r15), %r15
jmp 0x7173
cmpl $0xff, %eax
jne 0x72c6
movq %r13, 0x10(%rbx)
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
cmpq $0x0, -0x48(%rbp)
je 0x72c6
movq -0x48(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %r12, %rdx
callq 0x5cf4
leaq 0x147f(%rip), %rsi      # 0x86d0
pushq $0x1
popq %rax
movl %eax, -0x30(%rbp)
jmp 0x72c6
cmpl %r14d, 0x8(%r15)
je 0x72a6
jmp 0x72c6
movq 0x8(%r15), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x72c6
cmpl (%rax), %r14d
jb 0x7268
cmpl 0x4(%rax), %r14d
ja 0x7268
jmp 0x72a6
movq 0x8(%r15), %rax
movq (%rax), %rcx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x7299
cmpl (%rax), %r14d
jb 0x7285
cmpl 0x4(%rax), %r14d
ja 0x7285
cmpq %rcx, %rax
jne 0x72c6
jmp 0x72a6
cmpl $0xa, %r14d
je 0x72c6
movq 0x10(%r15), %rsi
movq -0x38(%rbp), %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x5d67
leaq 0x1410(%rip), %rsi      # 0x86d0
cmpq -0x40(%rbp), %rax
je 0x730b
addq $0x208, %rbx            # imm = 0x208
jmp 0x7163
movq -0x58(%rbp), %r15
cmpq 0x40(%r15), %r13
movq -0x60(%rbp), %rcx
je 0x7321
cmpl $0x0, 0x24(%r15)
je 0x72f6
xorl %eax, %eax
movq -0x38(%rbp), %rdx
cmpq $0x0, (%rdx)
sete %al
jmp 0x72f8
xorl %eax, %eax
addq $0x4, %r13
testl %r14d, %r14d
movl -0x30(%rbp), %r14d
jne 0x70a6
jmp 0x730f
pushq $-0x1
popq %r14
movl %r14d, %eax
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x30(%rbp), %r14d
jmp 0x730f
nop