// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
testq %rdi, %rdi
je 0xab2b
movq %rcx, %r14
movl %edx, %ebp
movl %esi, %r15d
movq %rdi, %rbx
movq %rcx, %rdi
callq 0x9f98
addl $0xfffffefa, %eax       # imm = 0xFFFFFEFA
cmpl $0xa, %eax
ja 0xab2d
leaq 0x1c0d(%rip), %rcx      # 0xc514
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movq %r14, %rdi
callq 0xafb1
movl $0x40000000, %r13d      # imm = 0x40000000
jmp 0xa92c
movq %r14, %rdi
callq 0xafb1
pushq $0x1
popq %r13
xorl %r12d, %r12d
jmp 0xa943
movq %r14, %rdi
callq 0xafb1
movl $0x40000000, %r13d      # imm = 0x40000000
pushq $0x1
popq %r12
movzbl 0x8(%rbx), %eax
cmpl $0x7, %eax
ja 0xaa20
movl $0x98, %ecx
btl %eax, %ecx
jae 0xaa20
movl %r12d, 0x18(%rbx)
movl %r13d, 0x1c(%rbx)
jmp 0xab2d
movq %r14, %rdi
callq 0xafb1
callq 0x5040
movq %rax, 0x10(%rsp)
andl $0x0, (%rax)
movq 0x8(%r14), %r13
leaq 0x8(%rsp), %r12
pushq $0xa
popq %rdx
movq %r13, %rdi
movq %r12, %rsi
callq 0x50b0
movq %rax, (%rsp)
movq (%r12), %r12
movq %r12, %rcx
subq %r13, %rcx
je 0xab22
movslq 0x10(%r14), %rax
cmpq %rax, %rcx
jge 0xab22
cmpb $0x2c, (%r12)
jne 0xaa6a
movzbl 0x1(%r12), %ecx
incq %r12
cmpl $0x7d, %ecx
je 0xa9da
cmpl $0x5c, %ecx
jne 0xaac5
movl $0x40000000, %r13d      # imm = 0x40000000
jmp 0xaa6e
movq %r14, %rdi
callq 0xafb1
pushq $0x20
popq %rdi
callq 0x5170
movb $0xd, 0x8(%rax)
andq $0x0, 0x10(%rax)
leaq 0x729b(%rip), %rcx      # 0x11ca0
movq %rcx, (%rax)
movq %rbx, 0x18(%rax)
testb $0x4, 0x1(%r14)
je 0xaa55
movq %rax, %rdi
callq 0xaf9c
jmp 0xab2b
pushq $0x30
popq %rdi
callq 0x5170
movb $0xc, 0x8(%rax)
andq $0x0, 0x10(%rax)
movl %r12d, 0x18(%rax)
movl %r13d, 0x1c(%rax)
leaq 0x7210(%rip), %rcx      # 0x11c50
movq %rcx, (%rax)
movl %r15d, 0x20(%rax)
movl %ebp, 0x24(%rax)
movq %rbx, 0x28(%rax)
testb $0x4, 0x1(%r14)
jne 0xaa5d
movq %rax, %rbx
jmp 0xab2d
movq %rax, %rdi
callq 0xaf60
jmp 0xab2b
movq (%rsp), %r13
movq 0x8(%r14), %rcx
subq %rcx, %r12
movslq %r12d, %rdx
addq %rdx, %rcx
movq %rcx, 0x8(%r14)
subl %edx, %eax
movl %eax, 0x10(%r14)
movq 0x10(%rsp), %rax
cmpl $0x0, (%rax)
jne 0xab22
movq (%rsp), %rcx
cmpq %r13, %rcx
seta %al
cmpq $0x40000000, %rcx       # imm = 0x40000000
setae %cl
orb %al, %cl
jne 0xab22
movb (%r14), %r12b
movq %r14, %rdi
callq 0x9f98
testb $0x1, %r12b
jne 0xab0c
cmpl $0x10c, %eax            # imm = 0x10C
je 0xab11
jmp 0xab22
leaq 0x8(%rsp), %rsi
pushq $0xa
popq %rdx
movq %r12, %rdi
callq 0x50b0
movq %rax, %r13
leaq 0x8(%rsp), %rax
movq (%rax), %rcx
cmpq %r12, %rcx
sete %al
cmpq $0x40000000, %r13       # imm = 0x40000000
setae %dl
orb %al, %dl
jne 0xab22
movq %rcx, %rdx
subq 0x8(%r14), %rdx
movslq 0x10(%r14), %rax
cmpq %rax, %rdx
jge 0xab22
movq %rcx, %r12
jmp 0xaa6e
cmpl $0x7d, %eax
jne 0xab22
movq %r14, %rdi
callq 0xafb1
movq (%rsp), %r12
jmp 0xa943
movq (%rbx), %rax
movq %rbx, %rdi
callq *0x8(%rax)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq