// File: arnoldrobbins[P]mcilroy-regex/re1.cpp
// Function: Done::parse(unsigned char*, Rex*, Eenv*)
int Done::parse(uchar *s, Rex*, Eenv *env)
{
	if(edebug & (1<<DONE)) {
		dprint("Done", s);
		printpos(&env->pos[0], env->npos, env);
	}
	if(env->flags&REG_ANCH && s!=env->last)
		return NONE;
	if(env->flags & REG_NOSUB)
		return BEST;
	int n = s - env->p;
	int nsub = env->preg->re_nsub;
	if((env->flags&HARD) == 0) {
		env->best[0].rm_eo = n;
		memmove(&env->best[1], &env->match[1],
			nsub*sizeof(regmatch_t));
		return BEST;
	}
	if(env->best[0].rm_eo >= 0) {	/* only happens on HARD */
		long d = env->best[0].rm_eo;
		if(n < d)
			return GOOD;
		if(n == d) {
			if(edebug & (1<<DONE))
				printpos(&env->bestpos[0],
					 env->nbestpos, env);
		   	d = better(&env->bestpos[0],
				   &env->pos[0],
				   &env->bestpos[env->nbestpos],
				   &env->pos[env->npos]);
			if(d <= 0)
				return GOOD;
		}
	}
	env->best[0].rm_eo = n;
	memmove(&env->best[1], &env->match[1],
		nsub*sizeof(regmatch_t));
	n = env->npos;
	if(env->bestpos.assure(n)) {
		env->flags |= SPACE;
		return BAD;
	}
	env->nbestpos = n;
	memmove(&env->bestpos[0], &env->pos[0], n*sizeof(Pos));
	return GOOD;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x80, %eax
cmpl $0x0, %eax
je 0xb515
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
cmpq 0x18(%rcx), %rax
je 0xb515
movl $0x0, -0x4(%rbp)
jmp 0xb79a
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0xb52f
movl $0x2, -0x4(%rbp)
jmp 0xb79a
movq -0x18(%rbp), %rax
movq -0x28(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movl %eax, -0x30(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
jne 0xb5cf
movslq -0x2c(%rbp), %rax
movq %rax, -0x48(%rbp)
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
xorl %esi, %esi
callq 0xbf80
movq -0x48(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
movl $0x1, %esi
callq 0xbf80
movq %rax, -0x40(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movl $0x1, %esi
callq 0xbf80
movq -0x40(%rbp), %rdi
movq %rax, %rsi
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
callq 0x52b0
movl $0x2, -0x4(%rbp)
jmp 0xb79a
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
xorl %esi, %esi
callq 0xbf80
cmpq $0x0, 0x8(%rax)
jl 0xb6b3
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
xorl %esi, %esi
callq 0xbf80
movq 0x8(%rax), %rax
movq %rax, -0x38(%rbp)
movslq -0x2c(%rbp), %rax
cmpq -0x38(%rbp), %rax
jge 0xb61c
movl $0x1, -0x4(%rbp)
jmp 0xb79a
movslq -0x2c(%rbp), %rax
cmpq -0x38(%rbp), %rax
jne 0xb6b1
movq -0x28(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
xorl %esi, %esi
callq 0xbd20
movq %rax, -0x60(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
callq 0xbd20
movq %rax, -0x58(%rbp)
movq -0x28(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
movq -0x28(%rbp), %rax
movl 0x24(%rax), %esi
callq 0xbd20
movq %rax, -0x50(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
movq -0x28(%rbp), %rax
movl 0x20(%rax), %esi
callq 0xbd20
movq -0x60(%rbp), %rdi
movq -0x58(%rbp), %rsi
movq -0x50(%rbp), %rdx
movq %rax, %rcx
callq 0xb7b0
cltq
movq %rax, -0x38(%rbp)
cmpq $0x0, -0x38(%rbp)
jg 0xb6af
movl $0x1, -0x4(%rbp)
jmp 0xb79a
jmp 0xb6b1
jmp 0xb6b3
movslq -0x2c(%rbp), %rax
movq %rax, -0x70(%rbp)
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
xorl %esi, %esi
callq 0xbf80
movq -0x70(%rbp), %rcx
movq %rcx, 0x8(%rax)
movq -0x28(%rbp), %rdi
addq $0x418, %rdi            # imm = 0x418
movl $0x1, %esi
callq 0xbf80
movq %rax, -0x68(%rbp)
movq -0x28(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movl $0x1, %esi
callq 0xbf80
movq -0x68(%rbp), %rdi
movq %rax, %rsi
movslq -0x30(%rbp), %rdx
shlq $0x4, %rdx
callq 0x52b0
movq -0x28(%rbp), %rax
movl 0x20(%rax), %eax
movl %eax, -0x2c(%rbp)
movq -0x28(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
movl -0x2c(%rbp), %esi
callq 0xbce0
cmpl $0x0, %eax
je 0xb750
movq -0x28(%rbp), %rax
movl (%rax), %ecx
orl $0x400, %ecx            # imm = 0x400
movl %ecx, (%rax)
movl $0x3, -0x4(%rbp)
jmp 0xb79a
movl -0x2c(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, 0x24(%rax)
movq -0x28(%rbp), %rdi
addq $0x178, %rdi            # imm = 0x178
xorl %esi, %esi
callq 0xbd20
movq %rax, -0x78(%rbp)
movq -0x28(%rbp), %rdi
addq $0x28, %rdi
xorl %esi, %esi
callq 0xbd20
movq -0x78(%rbp), %rdi
movq %rax, %rsi
movslq -0x2c(%rbp), %rdx
shlq $0x4, %rdx
callq 0x52b0
movl $0x1, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)