// File: arnoldrobbins[P]mcilroy-regex/sed1.cpp
// Function: sc(Text*, Text*)
void
sc(Text *script, Text *t)
{
	int c, flags, re;
	int *q;
	int n = -1;
	int nsub;
	int delim = *t->w++;
	switch(delim) {
	case '\n':
	case '\\':
		syntax("improper delimiter");
	}
	re = recomp(&rebuf, t, delim);
	putint(script, re);
	nsub = readdr(re)->re_nsub;
	flags = script->w - script->s;
	putint(script, 0);		/* space for flags */
	while((c=*t->w++) != delim) {
		assure(script, 3+sizeof(int*));
		if(c == '\n')
			syntax("unterminated command");
		else if(c == '\\') {
			int d = *t->w;
			if(d==delim)
				;
			else if(d=='&' || d=='\\')
				*script->w++ = c;
			else if(d>='0' && d<='9') {
				if(d > '0'+nsub)
					syntax("improper backreference");
				*script->w++ = c;
			}
			c = *t->w++;
		}
		*script->w++ = c;
	}
	*script->w++ = 0;
	script->w = (uchar*)intp(script->w);
	q = (int*)(script->s + flags);
	*q = 0;
	for(;;) {
		switch(*t->w) {
		case '0': case '1': case '2': case '3': case '4':
		case '5': case '6': case '7': case '8': case '9':
			if(n != -1)
				syntax("extra flags");
			n = number(t);
			if(n == 0 || (n&(PFLAG|WFLAG)) != 0)
				syntax("count out of range");
			continue;
		case 'p':
			if(*q & PFLAG)
				syntax("extra flags");
			t->w++;
			*q |= PFLAG;
			continue;
		case 'g':
			t->w++;
			if(n != -1)
				syntax("extra flags");
			n = 0;
			continue;
		case 'w':
			t->w++;
			*q |= WFLAG;	 
			wc(script, t);
		}
		break;
	}
	*q |= n==-1? 1: n;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x50, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl $0xffffffff, -0x2c(%rbp) # imm = 0xFFFFFFFF
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
incq %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %eax
movl %eax, -0x3c(%rbp)
subl $0xa, %eax
je 0x7194
jmp 0x718a
movl -0x3c(%rbp), %eax
subl $0x5c, %eax
jne 0x71a0
jmp 0x7194
leaq 0xa35f(%rip), %rdi      # 0x114fa
callq 0x6220
movq -0x10(%rbp), %rsi
movl -0x34(%rbp), %edx
leaq 0x10fd2(%rip), %rdi     # 0x18180
callq 0x8a60
movl %eax, -0x1c(%rbp)
movq -0x8(%rbp), %rdi
movl -0x1c(%rbp), %esi
callq 0x6590
movl -0x1c(%rbp), %edi
callq 0x6670
movq (%rax), %rax
movl %eax, -0x30(%rbp)
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x18(%rbp)
movq -0x8(%rbp), %rdi
xorl %esi, %esi
callq 0x6590
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x14(%rbp)
cmpl -0x34(%rbp), %eax
je 0x7322
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x723b
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $-0x3, %rcx
addq $0x8, %rcx
addq $-0x1, %rcx
cmpq %rcx, %rax
jb 0x724b
movq -0x8(%rbp), %rdi
movl $0xb, %esi
callq 0x5ae0
jmp 0x724d
jmp 0x724d
cmpl $0xa, -0x14(%rbp)
jne 0x7264
leaq 0xa2b3(%rip), %rdi      # 0x1150d
callq 0x6220
jmp 0x7305
cmpl $0x5c, -0x14(%rbp)
jne 0x7303
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x38(%rbp)
movl -0x38(%rbp), %eax
cmpl -0x34(%rbp), %eax
jne 0x7285
jmp 0x72ec
cmpl $0x26, -0x38(%rbp)
je 0x7291
cmpl $0x5c, -0x38(%rbp)
jne 0x72ab
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rdx
movq (%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
movb %cl, (%rax)
jmp 0x72ea
cmpl $0x30, -0x38(%rbp)
jl 0x72e8
cmpl $0x39, -0x38(%rbp)
jg 0x72e8
movl -0x38(%rbp), %eax
movl -0x30(%rbp), %ecx
addl $0x30, %ecx
cmpl %ecx, %eax
jle 0x72d0
leaq 0xa257(%rip), %rdi      # 0x11522
callq 0x6220
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rdx
movq (%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
movb %cl, (%rax)
jmp 0x72ea
jmp 0x72ec
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x14(%rbp)
jmp 0x7305
movl -0x14(%rbp), %eax
movb %al, %cl
movq -0x8(%rbp), %rdx
movq (%rdx), %rax
movq %rax, %rsi
addq $0x1, %rsi
movq %rsi, (%rdx)
movb %cl, (%rax)
jmp 0x71f0
movq -0x8(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movb $0x0, (%rax)
movq -0x8(%rbp), %rax
movq (%rax), %rcx
addq $0x4, %rcx
addq $-0x1, %rcx
movq -0x8(%rbp), %rax
movq (%rax), %rdx
addq $0x4, %rdx
addq $-0x1, %rdx
subq $0x0, %rdx
andq $0x3, %rdx
xorl %eax, %eax
subq %rdx, %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0x18(%rbp), %rcx
addq %rcx, %rax
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
addl $-0x30, %eax
movl %eax, %ecx
movq %rcx, -0x48(%rbp)
subl $0x47, %eax
ja 0x7489
movq -0x48(%rbp), %rax
leaq 0x9e29(%rip), %rcx      # 0x111d8
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
cmpl $-0x1, -0x2c(%rbp)
je 0x73ca
leaq 0xa174(%rip), %rdi      # 0x11539
callq 0x6220
movq -0x10(%rbp), %rdi
callq 0x6600
movl %eax, -0x2c(%rbp)
cmpl $0x0, -0x2c(%rbp)
je 0x73e9
movl -0x2c(%rbp), %eax
andl $0xc0000000, %eax       # imm = 0xC0000000
cmpl $0x0, %eax
je 0x73f5
leaq 0xa155(%rip), %rdi      # 0x11545
callq 0x6220
jmp 0x7388
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x80000000, %eax       # imm = 0x80000000
cmpl $0x0, %eax
je 0x7413
leaq 0xa12b(%rip), %rdi      # 0x11539
callq 0x6220
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
orl $0x80000000, %ecx       # imm = 0x80000000
movl %ecx, (%rax)
jmp 0x7388
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
cmpl $-0x1, -0x2c(%rbp)
je 0x7454
leaq 0xa0ea(%rip), %rdi      # 0x11539
callq 0x6220
movl $0x0, -0x2c(%rbp)
jmp 0x7388
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x28(%rbp), %rax
movl (%rax), %ecx
orl $0x40000000, %ecx       # imm = 0x40000000
movl %ecx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x6aa0
jmp 0x748b
cmpl $-0x1, -0x2c(%rbp)
jne 0x749b
movl $0x1, %eax
movl %eax, -0x4c(%rbp)
jmp 0x74a1
movl -0x2c(%rbp), %eax
movl %eax, -0x4c(%rbp)
movl -0x4c(%rbp), %ecx
movq -0x28(%rbp), %rax
orl (%rax), %ecx
movl %ecx, (%rax)
addq $0x50, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)