// File: arnoldrobbins[P]mcilroy-regex/re2.cpp
// Function: regRep(Rex*, int, int, Cenv*)
static Rex*
regRep(Rex *e, int n1, int n2, Cenv *env)
{
	if(cdebug)
		printf("regRep %lx.%d\n",
			(unsigned long)env->cursor.p,env->cursor.n);
	int c;
	unsigned long m = 0;
	unsigned long n = RE_DUP_INF;
	char *sp, *ep;
	if(e == ERROR)
		return e;
	c = token(env);
	switch(c) {
	default:
		return e;
	case T_BANG:
		eat(env);
		return NEW(Neg(e));
	case T_QUES:
		n = 1;
		eat(env);
		break;
	case T_STAR:
		eat(env);
		break;
	case T_PLUS:
		m = 1;
		eat(env);
		break;
	case T_LEFT:
		eat(env);
		errno = 0;
		sp = (char*)env->cursor.p;
		n = m = strtoul(sp, &ep, 10);
		if(ep == sp || ep-sp >= env->cursor.n)
			goto error;
		if(*ep == ',') {
			sp = ep + 1;
			if(*sp == '\\' || *sp == '}') {
				n = RE_DUP_INF;
				ep = sp;
			} else {
				n = strtoul(sp, &ep, 10);
				if(ep == sp || n > RE_DUP_MAX)
					goto error;
				if(ep- (char*)env->cursor.p >= env->cursor.n)
					goto error;
			}
		}
		env->cursor.next(ep - (char*)env->cursor.p);
		if(errno || m > n || m > RE_DUP_MAX)
			goto error;
		else if(env->flags&REG_EXTENDED) {
			if(token(env) != '}')
				goto error;
		} else if(token(env) != T_RIGHT)
				goto error;
		eat(env);
		break;
	}
	switch(e->type) {
	case DOT:
	case CLASS:
	case ONECHAR:
		((Dup*)e)->lo = (int)m;
		((Dup*)e)->hi = (int)n;
		return e;
	}
	return NEW(Rep((int)m, (int)n, n1, n2, e));
error:
	delete e;
	return ERROR;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq $0x0, -0x30(%rbp)
movq $0x40000000, -0x38(%rbp) # imm = 0x40000000
movq -0x10(%rbp), %rax
cmpq 0x91ec(%rip), %rax      # 0x18510
jne 0xf333
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf64c
movq -0x20(%rbp), %rdi
callq 0xe7c0
movl %eax, -0x24(%rbp)
movl -0x24(%rbp), %eax
addl $0xfffffefa, %eax       # imm = 0xFFFFFEFA
movl %eax, %ecx
movq %rcx, -0x60(%rbp)
subl $0xa, %eax
ja 0xf366
movq -0x60(%rbp), %rax
leaq 0x23d3(%rip), %rcx      # 0x11730
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf64c
movq -0x20(%rbp), %rdi
callq 0x10610
movl $0x20, %edi
callq 0x51a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x68(%rbp)
movq -0x10(%rbp), %rsi
callq 0x10940
jmp 0xf39b
movq -0x68(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xd030
movq %rax, -0x8(%rbp)
jmp 0xf64c
movq -0x68(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x20, %esi
callq 0x51b0
jmp 0xf659
movq $0x1, -0x38(%rbp)
movq -0x20(%rbp), %rdi
callq 0x10610
jmp 0xf58b
movq -0x20(%rbp), %rdi
callq 0x10610
jmp 0xf58b
movq $0x1, -0x30(%rbp)
movq -0x20(%rbp), %rdi
callq 0x10610
jmp 0xf58b
movq -0x20(%rbp), %rdi
callq 0x10610
callq 0x5040
movl $0x0, (%rax)
movq -0x20(%rbp), %rax
movq 0x8(%rax), %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x50b0
movq %rax, -0x30(%rbp)
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0xf466
movq -0x48(%rbp), %rax
movq -0x40(%rbp), %rcx
subq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jl 0xf46b
jmp 0xf629
movq -0x48(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x2c, %eax
jne 0xf505
movq -0x48(%rbp), %rax
addq $0x1, %rax
movq %rax, -0x40(%rbp)
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x5c, %eax
je 0xf49f
movq -0x40(%rbp), %rax
movsbl (%rax), %eax
cmpl $0x7d, %eax
jne 0xf4b1
movq $0x40000000, -0x38(%rbp) # imm = 0x40000000
movq -0x40(%rbp), %rax
movq %rax, -0x48(%rbp)
jmp 0xf503
movq -0x40(%rbp), %rdi
leaq -0x48(%rbp), %rsi
movl $0xa, %edx
callq 0x50b0
movq %rax, -0x38(%rbp)
movq -0x48(%rbp), %rax
cmpq -0x40(%rbp), %rax
je 0xf4db
cmpq $0x3fffffff, -0x38(%rbp) # imm = 0x3FFFFFFF
jbe 0xf4e0
jmp 0xf629
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movq -0x20(%rbp), %rcx
movslq 0x10(%rcx), %rcx
cmpq %rcx, %rax
jl 0xf501
jmp 0xf629
jmp 0xf503
jmp 0xf505
movq -0x20(%rbp), %rdi
addq $0x8, %rdi
movq -0x48(%rbp), %rax
movq -0x20(%rbp), %rcx
movq 0x8(%rcx), %rcx
subq %rcx, %rax
movl %eax, %esi
callq 0x10990
callq 0x5040
cmpl $0x0, (%rax)
jne 0xf541
movq -0x30(%rbp), %rax
cmpq -0x38(%rbp), %rax
ja 0xf541
cmpq $0x3fffffff, -0x30(%rbp) # imm = 0x3FFFFFFF
jbe 0xf546
jmp 0xf629
movq -0x20(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0xf569
movq -0x20(%rbp), %rdi
callq 0xe7c0
cmpl $0x7d, %eax
je 0xf567
jmp 0xf629
jmp 0xf580
movq -0x20(%rbp), %rdi
callq 0xe7c0
cmpl $0x10c, %eax            # imm = 0x10C
je 0xf57e
jmp 0xf629
jmp 0xf580
jmp 0xf582
movq -0x20(%rbp), %rdi
callq 0x10610
movq -0x10(%rbp), %rax
movzbl 0x8(%rax), %eax
movl %eax, -0x6c(%rbp)
addl $-0x3, %eax
subl $0x2, %eax
jb 0xf5aa
jmp 0xf5a0
movl -0x6c(%rbp), %eax
subl $0x7, %eax
jne 0xf5ce
jmp 0xf5aa
movq -0x30(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x18(%rax)
movq -0x38(%rbp), %rax
movl %eax, %ecx
movq -0x10(%rbp), %rax
movl %ecx, 0x1c(%rax)
movq -0x10(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xf64c
movl $0x30, %edi
callq 0x51a0
movq %rax, %rdi
movq %rdi, %rax
movq %rax, -0x78(%rbp)
movl -0x30(%rbp), %esi
movl -0x38(%rbp), %edx
movl -0x14(%rbp), %ecx
movl -0x18(%rbp), %r8d
movq -0x10(%rbp), %r9
callq 0x109c0
jmp 0xf5fa
movq -0x78(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xd030
movq %rax, -0x8(%rbp)
jmp 0xf64c
movq -0x78(%rbp), %rdi
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
movl $0x30, %esi
callq 0x51b0
jmp 0xf659
movq -0x10(%rbp), %rax
movq %rax, -0x80(%rbp)
cmpq $0x0, %rax
je 0xf641
movq -0x80(%rbp), %rdi
movq (%rdi), %rax
callq *0x8(%rax)
movq 0x8ec8(%rip), %rax      # 0x18510
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x52d0
nopw %cs:(%rax,%rax)