// File: arnoldrobbins[P]mcilroy-regex/re1.cpp
// Function: regnexec
int regnexec(const regex_t *preg, const char *string, size_t len,
	     size_t nmatch, regmatch_t *match, int eflags)
{
	int i;
	if(preg->rex == 0)	// not required, but kind
		return REG_BADPAT;
	Eenv env(preg, eflags, (uchar*)string, len);
	if(env.flags&SPACE)
		return REG_ESPACE;
	if(env.flags&REG_NOSUB)
		nmatch = 0;
	for(i=0; (unsigned)i<nmatch && (unsigned)i<=preg->re_nsub; i++)
		env.match[i] = NOMATCH;

	while(preg->rex->parse((uchar*)string,Done::done,&env) == NONE) {
		if(env.flags & ONCE)
			return REG_NOMATCH;
		if((uchar*)++string > env.last)
			return REG_NOMATCH;
		env.best[0].rm_so++;
	}
	if(env.flags & SPACE)
		return REG_ESPACE;

	for(i=0; (unsigned)i<nmatch; i++)
		if((unsigned)i <= preg->re_nsub)
			match[i] = env.best[i];
		else
			match[i] = NOMATCH;
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x5e0, %rsp            # imm = 0x5E0
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movl %r9d, -0x34(%rbp)
movq -0x10(%rbp), %rax
cmpq $0x0, 0x8(%rax)
jne 0xb96a
movl $0x2, -0x4(%rbp)
jmp 0xbbe6
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %edx
movq -0x18(%rbp), %rcx
movq -0x20(%rbp), %r8
leaq -0x5a0(%rbp), %rdi
callq 0xc4d0
movl -0x5a0(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xb9ab
movl $0xc, -0x4(%rbp)
movl $0x1, -0x5a4(%rbp)
jmp 0xbbda
movl -0x5a0(%rbp), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xb9c1
movq $0x0, -0x28(%rbp)
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
movl %eax, %ecx
xorl %eax, %eax
cmpq -0x28(%rbp), %rcx
movb %al, -0x5b5(%rbp)
jae 0xb9ee
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
setbe %al
movb %al, -0x5b5(%rbp)
movb -0x5b5(%rbp), %al
testb $0x1, %al
jne 0xb9fa
jmp 0xba5c
leaq -0x2d8(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0xbf80
movq %rax, -0x5c0(%rbp)
jmp 0xba12
movq -0x5c0(%rbp), %rax
movq 0xc0b0(%rip), %rcx      # 0x17ad0
movq %rcx, (%rax)
movq 0xc0ae(%rip), %rcx      # 0x17ad8
movq %rcx, 0x8(%rax)
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xb9c8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x5b0(%rbp)
movl %eax, -0x5b4(%rbp)
leaq -0x5a0(%rbp), %rdi
callq 0xc6a0
jmp 0xbbf2
jmp 0xba5e
movq -0x10(%rbp), %rax
movq 0x8(%rax), %rdi
movq -0x18(%rbp), %rsi
leaq 0xc88f(%rip), %rax      # 0x18300
movq (%rax), %rdx
movq (%rdi), %rax
movq 0x20(%rax), %rax
leaq -0x5a0(%rbp), %rcx
callq *%rax
movl %eax, -0x5c4(%rbp)
jmp 0xba8c
movl -0x5c4(%rbp), %eax
cmpl $0x0, %eax
jne 0xbb15
movl -0x5a0(%rbp), %eax
andl $0x1000, %eax           # imm = 0x1000
cmpl $0x0, %eax
je 0xbabd
movl $0x1, -0x4(%rbp)
movl $0x1, -0x5a4(%rbp)
jmp 0xbbda
movq -0x18(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x18(%rbp)
cmpq -0x588(%rbp), %rax
jbe 0xbae8
movl $0x1, -0x4(%rbp)
movl $0x1, -0x5a4(%rbp)
jmp 0xbbda
leaq -0x188(%rbp), %rdi
xorl %esi, %esi
callq 0xbf80
movq %rax, -0x5d0(%rbp)
jmp 0xbaff
movq -0x5d0(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
jmp 0xba5e
movl -0x5a0(%rbp), %eax
andl $0x400, %eax            # imm = 0x400
cmpl $0x0, %eax
je 0xbb3b
movl $0xc, -0x4(%rbp)
movl $0x1, -0x5a4(%rbp)
jmp 0xbbda
movl $0x0, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpq -0x28(%rbp), %rax
jae 0xbbc9
movl -0x38(%rbp), %eax
movq -0x10(%rbp), %rcx
cmpq (%rcx), %rax
ja 0xbb95
leaq -0x188(%rbp), %rdi
movl -0x38(%rbp), %esi
callq 0xbf80
movq %rax, -0x5d8(%rbp)
jmp 0xbb6f
movq -0x5d8(%rbp), %rcx
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rdx
shlq $0x4, %rdx
addq %rdx, %rax
movq (%rcx), %rdx
movq %rdx, (%rax)
movq 0x8(%rcx), %rcx
movq %rcx, 0x8(%rax)
jmp 0xbbb9
movq -0x30(%rbp), %rax
movslq -0x38(%rbp), %rcx
shlq $0x4, %rcx
addq %rcx, %rax
movq 0xbf25(%rip), %rcx      # 0x17ad0
movq %rcx, (%rax)
movq 0xbf23(%rip), %rcx      # 0x17ad8
movq %rcx, 0x8(%rax)
jmp 0xbbbb
movl -0x38(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x38(%rbp)
jmp 0xbb42
movl $0x0, -0x4(%rbp)
movl $0x1, -0x5a4(%rbp)
leaq -0x5a0(%rbp), %rdi
callq 0xc6a0
movl -0x4(%rbp), %eax
addq $0x5e0, %rsp            # imm = 0x5E0
popq %rbp
retq
movq -0x5b0(%rbp), %rdi
callq 0x52d0
nop