// File: arnoldrobbins[P]mcilroy-regex/sed1.cpp
// Function: compile(Text*, Text*)
void
compile(Text *script, Text *t)
{
	int loc;	/* progam counter */
	int neg;	/* ! in effect */
	int cmd;
	int naddr;
	int *q;		/* address of instruction word */
	t->w = t->s;	/* here w is a read pointer */
	while(*t->w) {
		assure(script, 4*sizeof(int));
		loc = script->w - script->s;
		synl = t->w;
		naddr = 0;
		while(blank(t)) ;
		naddr += addr(script, t);
		if(naddr && *t->w ==',') {
			t->w++;
			naddr += addr(script, t);
			if(naddr < 2)
				syntax("missing address");
		}
		q = (int*)script->w;
		if(naddr == 2)
			*q++ = INACT;
		script->w = (uchar*)(q+1);
		neg = 0;
		for(;;) {
			while(blank(t));
			cmd = *t->w++;
			if(neg && docom[cmd&0xff]==Ic)
				syntax("improper !");
			if(cmd != '!')
				break;
			neg = NEG;
		}
		if(!neg) {
			switch(adrs[cmd]) {
			case 1:
				if(naddr <= 1)
					break;
			case 0:
				if(naddr == 0)
					break;
				syntax("too many addresses");
			}
		}
		docom[cmd&0xff](script, t);
		switch(*t->w) {
		case 0:
			script->w = script->s + loc;
			break;
		default:
			if(cmd == '{')
				break;
			syntax("junk after command");
		case ';':
			if(!semicolon++)
				synwarn("semicolon separators");
		case '\n':
				t->w++;
		}
		*q = pack(neg,cmd,script->w-script->s-loc);
	}
	fixbrack(script);
	fixlabels(script);
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq -0x10(%rbp), %rax
movq 0x10(%rax), %rcx
movq -0x10(%rbp), %rax
movq %rcx, (%rax)
movq -0x10(%rbp), %rax
movq (%rax), %rax
cmpb $0x0, (%rax)
je 0x60a1
movq -0x8(%rbp), %rax
cmpq $0x0, 0x10(%rax)
je 0x5e36
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x8(%rcx), %rcx
addq $-0x10, %rcx
addq $-0x1, %rcx
cmpq %rcx, %rax
jb 0x5e46
movq -0x8(%rbp), %rdi
movl $0x10, %esi
callq 0x5ae0
jmp 0x5e48
jmp 0x5e48
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movl %eax, -0x14(%rbp)
movq -0x10(%rbp), %rax
movq (%rax), %rax
movq %rax, 0x1232d(%rip)     # 0x18198
movl $0x0, -0x20(%rbp)
movq -0x10(%rbp), %rdi
callq 0x60c0
cmpl $0x0, %eax
je 0x5e82
jmp 0x5e72
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x6110
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x0, -0x20(%rbp)
je 0x5edf
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
cmpl $0x2c, %eax
jne 0x5edf
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq 0x6110
addl -0x20(%rbp), %eax
movl %eax, -0x20(%rbp)
cmpl $0x2, -0x20(%rbp)
jge 0x5edd
leaq 0xb420(%rip), %rdi      # 0x112f8
callq 0x6220
jmp 0x5edf
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq %rax, -0x28(%rbp)
cmpl $0x2, -0x20(%rbp)
jne 0x5f05
movq -0x28(%rbp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, -0x28(%rbp)
movl $0x80000000, (%rax)     # imm = 0x80000000
movq -0x28(%rbp), %rcx
addq $0x4, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
movl $0x0, -0x18(%rbp)
jmp 0x5f1d
movq -0x10(%rbp), %rdi
callq 0x60c0
cmpl $0x0, %eax
je 0x5f2d
jmp 0x5f1d
movq -0x10(%rbp), %rcx
movq (%rcx), %rax
movq %rax, %rdx
addq $0x1, %rdx
movq %rdx, (%rcx)
movzbl (%rax), %eax
movl %eax, -0x1c(%rbp)
cmpl $0x0, -0x18(%rbp)
je 0x5f75
movl -0x1c(%rbp), %eax
andl $0xff, %eax
movslq %eax, %rcx
leaq 0x314(%rip), %rdx       # 0x6270
leaq 0x1134d(%rip), %rax     # 0x172b0
cmpq %rdx, (%rax,%rcx,8)
jne 0x5f75
leaq 0xb398(%rip), %rdi      # 0x11308
callq 0x6220
cmpl $0x21, -0x1c(%rbp)
je 0x5f7d
jmp 0x5f86
movl $0x1000000, -0x18(%rbp) # imm = 0x1000000
jmp 0x5f1b
cmpl $0x0, -0x18(%rbp)
jne 0x5fce
movslq -0x1c(%rbp), %rax
leaq 0x11219(%rip), %rcx     # 0x171b0
movzbl (%rax,%rcx), %eax
movl %eax, -0x2c(%rbp)
testl %eax, %eax
je 0x5fb8
jmp 0x5fa4
movl -0x2c(%rbp), %eax
subl $0x1, %eax
jne 0x5fcc
jmp 0x5fae
cmpl $0x1, -0x20(%rbp)
jg 0x5fb6
jmp 0x5fcc
jmp 0x5fb8
cmpl $0x0, -0x20(%rbp)
jne 0x5fc0
jmp 0x5fcc
leaq 0xb34c(%rip), %rdi      # 0x11313
callq 0x6220
jmp 0x5fce
movzbl -0x1c(%rbp), %eax
movl %eax, %ecx
leaq 0x112d5(%rip), %rax     # 0x172b0
movq (%rax,%rcx,8), %rax
movq -0x8(%rbp), %rdi
movq -0x10(%rbp), %rsi
callq *%rax
movq -0x10(%rbp), %rax
movq (%rax), %rax
movzbl (%rax), %eax
movl %eax, -0x30(%rbp)
testl %eax, %eax
je 0x6010
jmp 0x5ffc
movl -0x30(%rbp), %eax
subl $0xa, %eax
je 0x6060
jmp 0x6006
movl -0x30(%rbp), %eax
subl $0x3b, %eax
je 0x603c
jmp 0x6028
movq -0x8(%rbp), %rax
movq 0x10(%rax), %rcx
movslq -0x14(%rbp), %rax
addq %rax, %rcx
movq -0x8(%rbp), %rax
movq %rcx, (%rax)
jmp 0x606e
cmpl $0x7b, -0x1c(%rbp)
jne 0x6030
jmp 0x606e
leaq 0xb2ef(%rip), %rdi      # 0x11326
callq 0x6220
movl 0x12136(%rip), %eax     # 0x18178
movl %eax, %ecx
addl $0x1, %ecx
movl %ecx, 0x1212b(%rip)     # 0x18178
cmpl $0x0, %eax
jne 0x605e
leaq 0xb2e0(%rip), %rdi      # 0x11339
callq 0x62a0
jmp 0x6060
movq -0x10(%rbp), %rax
movq (%rax), %rcx
addq $0x1, %rcx
movq %rcx, (%rax)
movl -0x18(%rbp), %edi
movl -0x1c(%rbp), %esi
movq -0x8(%rbp), %rax
movq (%rax), %rax
movq -0x8(%rbp), %rcx
movq 0x10(%rcx), %rcx
subq %rcx, %rax
movslq -0x14(%rbp), %rcx
subq %rcx, %rax
movl %eax, %edx
callq 0x62f0
movl %eax, %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0x5dff
movq -0x8(%rbp), %rdi
callq 0x6340
movq -0x8(%rbp), %rdi
callq 0x63f0
addq $0x30, %rsp
popq %rbp
retq
nopl (%rax)