// File: /workspace/github_c_makefile_star2_O2/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, %r14
movl %ecx, -0x2c(%rbp)
movq %rsi, -0x60(%rbp)
movq %rdi, -0x70(%rbp)
movl 0x20(%r8), %eax
testq %rdx, %rdx
je 0x6b87
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 0x6b87
movups %xmm0, (%rdx,%rcx)
addq $0x10, %rcx
jmp 0x6b78
movq %rdx, -0x50(%rbp)
movq (%r14), %rcx
andq $0x0, (%rcx)
movq 0x8(%r14), %rcx
andq $0x0, (%rcx)
movq 0x28(%r14), %r13
movq $0x0, -0x58(%rbp)
leaq 0x1af3(%rip), %rbx      # 0x86a0
xorl %r15d, %r15d
movq %r14, -0x68(%rbp)
testl %eax, %eax
je 0x6c15
movl 0x20(%r14), %eax
cmpl $0xc3, %eax
je 0x6beb
cmpl $0x7f, %eax
jne 0x6c15
movl 0x24(%r14), %esi
movq %r13, %rdi
callq 0x7527
testq %rax, %rax
je 0x6e1f
cmpq 0x30(%r14), %r13
movq %rax, %r13
jne 0x6c15
jmp 0x6e1f
cmpq -0x60(%rbp), %r13
je 0x6c15
movq %r13, %rdi
pushq $0xa
popq %rsi
callq 0x7527
testq %rax, %rax
je 0x6e1f
cmpq 0x30(%r14), %r13
je 0x6e1f
incq %rax
movq %rax, %r13
movl %r15d, -0x34(%rbp)
movzbl (%r13), %eax
movl %eax, -0x30(%rbp)
pushq $0x1
popq %rcx
testb %al, %al
jns 0x6c37
leaq -0x30(%rbp), %rdi
movq %r13, %rsi
callq 0x7428
movslq %eax, %rcx
movq %rcx, -0x78(%rbp)
movq -0x58(%rbp), %rcx
movl %ecx, %eax
movq (%r14,%rax,8), %r15
movq 0x10(%r14,%rax,8), %rax
movq %rax, -0x80(%rbp)
xorl $0x1, %ecx
movq (%r14,%rcx,8), %rax
movq %rcx, -0x58(%rbp)
movq 0x10(%r14,%rcx,8), %rcx
movq %rcx, -0x48(%rbp)
movq %rax, -0x40(%rbp)
andq $0x0, (%rax)
cmpl $0x0, -0x34(%rbp)
jne 0x6c85
movq -0x70(%rbp), %rax
movq (%rax), %rsi
movq %r15, %rdi
movl -0x2c(%rbp), %edx
movq %r13, %rcx
callq 0x5df2
movq (%r15), %r14
testq %r14, %r14
je 0x6de5
leaq 0x8(%r15), %r12
movl (%r14), %eax
leal -0x7f(%rax), %ecx
cmpl $0x4, %ecx
ja 0x6cba
movslq (%rbx,%rcx,4), %rax
addq %rbx, %rax
jmpq *%rax
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
addq $0x8, %rax
jmp 0x6cf2
leal -0xc0(%rax), %ecx
cmpl $0x6, %ecx
ja 0x6d37
leaq 0x19e8(%rip), %rdx      # 0x86b4
movslq (%rdx,%rcx,4), %rax
addq %rdx, %rax
jmpq *%rax
cmpq -0x60(%rbp), %r13
je 0x6d2e
cmpb $0xa, -0x1(%r13)
je 0x6d2e
jmp 0x6dd9
movslq 0x8(%r14), %rax
shlq $0x4, %rax
addq %r12, %rax
movq %r13, (%rax)
jmp 0x6d2e
movq 0x8(%r14), %rsi
movq %r15, %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x5d67
cmpq -0x80(%rbp), %rax
jne 0x6d2e
jmp 0x6e1b
movq -0x68(%rbp), %rax
cmpq 0x30(%rax), %r13
je 0x6d2e
movl -0x30(%rbp), %eax
testl %eax, %eax
je 0x6d2e
cmpl $0xa, %eax
jne 0x6dd9
movq 0x10(%r14), %r14
jmp 0x6c95
cmpl $0xff, %eax
jne 0x6dd9
movq %r13, 0x10(%r15)
pushq $0x1
popq %rax
movl %eax, -0x34(%rbp)
cmpq $0x0, -0x50(%rbp)
je 0x6dd9
movq -0x50(%rbp), %rdi
movl -0x2c(%rbp), %esi
movq %r12, %rdx
callq 0x5cf4
pushq $0x1
popq %rax
movl %eax, -0x34(%rbp)
jmp 0x6dd9
movl 0x8(%r14), %eax
cmpl -0x30(%rbp), %eax
je 0x6dc0
jmp 0x6dd9
movq 0x8(%r14), %rax
movq (%rax), %rcx
movl -0x30(%rbp), %edx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x6dd9
cmpl (%rax), %edx
jb 0x6d83
cmpl 0x4(%rax), %edx
ja 0x6d83
jmp 0x6dc0
movq 0x8(%r14), %rax
movq (%rax), %rcx
movl -0x30(%rbp), %edx
addq $0x8, %rax
cmpq %rcx, %rax
jae 0x6db3
cmpl (%rax), %edx
jb 0x6da1
cmpl 0x4(%rax), %edx
ja 0x6da1
cmpq %rcx, %rax
jne 0x6dd9
jmp 0x6dc0
cmpl $0xa, -0x30(%rbp)
je 0x6dd9
movq 0x10(%r14), %rsi
movq -0x40(%rbp), %rdi
movl -0x2c(%rbp), %edx
movq %r12, %rcx
callq 0x5d67
cmpq -0x48(%rbp), %rax
je 0x6e1b
addq $0x208, %r15            # imm = 0x208
jmp 0x6c85
movq -0x68(%rbp), %r14
cmpq 0x30(%r14), %r13
je 0x6e31
cmpl $0x0, 0x20(%r14)
movl -0x34(%rbp), %r15d
je 0x6e09
xorl %eax, %eax
movq -0x40(%rbp), %rcx
cmpq $0x0, (%rcx)
sete %al
jmp 0x6e0b
xorl %eax, %eax
addq -0x78(%rbp), %r13
cmpl $0x0, -0x30(%rbp)
jne 0x6bb4
jmp 0x6e1f
pushq $-0x1
popq %r15
movl %r15d, %eax
addq $0x58, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movl -0x34(%rbp), %r15d
jmp 0x6e1f
nop