// File: arnoldrobbins[P]mcilroy-regex/sed0.cpp
// Function: main
int
main(int argc, char **argv)
{
	static Text script;
	static Text data;
	for(;;) {
		switch(getopt(argc, argv, "bnf:e:")) {
		case 'b':
			bflag++;
			continue;
		case 'e':
			copyscript(&data, (uchar*)optarg);
			continue;
		case 'f':
			readscript(&data, optarg);
			continue;
		case 'n':
			nflag++;
			continue;
		case '?':
			quit("usage: sed [-n] script [files]\n"
			"     sed [-n] [-f scriptfile] "
			      "[-e script] [files]");
		case -1:
			break;
		}
		break;
	}
	if(data.s == 0) {
		if(optind >= argc)
			quit("no script");
		copyscript(&data, (uchar*)argv[optind++]);
	}
	if(ustrncmp(data.s, "#n", 2) == 0)
		nflag = 1;
	copyscript(&data, (uchar*)"\n\n");  /* e.g. s/a/\ */
	compile(&script, &data);
	// printscript(&script); //  debugging

	initinput(argc-optind, argv+optind);
	for(;;) {
		data.w = data.s;
		if(!readline(&data))
			break;
		execute(&script, &data);
	}
	if(fclose(stdout) == EOF)
		quit(stdouterr);
	return 0;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x20, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0xbbb0(%rip), %rdx      # 0x11004
callq 0x5080
movl %eax, %ecx
movl %ecx, -0x14(%rbp)
subl $-0x1, %eax
je 0x5508
jmp 0x5469
movl -0x14(%rbp), %eax
subl $0x3f, %eax
je 0x54fa
jmp 0x5477
movl -0x14(%rbp), %eax
subl $0x62, %eax
je 0x549f
jmp 0x5481
movl -0x14(%rbp), %eax
subl $0x65, %eax
je 0x54b0
jmp 0x548b
movl -0x14(%rbp), %eax
subl $0x66, %eax
je 0x54cb
jmp 0x5495
movl -0x14(%rbp), %eax
subl $0x6e, %eax
je 0x54e6
jmp 0x550a
movl 0x12c83(%rip), %eax     # 0x18128
addl $0x1, %eax
movl %eax, 0x12c7a(%rip)     # 0x18128
jmp 0x5446
movq 0x11b09(%rip), %rax     # 0x16fc0
movq (%rax), %rsi
leaq 0x12c87(%rip), %rdi     # 0x18148
callq 0x5640
jmp 0x5446
movq 0x11aee(%rip), %rax     # 0x16fc0
movq (%rax), %rsi
leaq 0x12c6c(%rip), %rdi     # 0x18148
callq 0x5710
jmp 0x5446
movl 0x12c30(%rip), %eax     # 0x1811c
addl $0x1, %eax
movl %eax, 0x12c27(%rip)     # 0x1811c
jmp 0x5446
leaq 0xbb0a(%rip), %rdi      # 0x1100b
movb $0x0, %al
callq 0x5820
jmp 0x550a
jmp 0x550c
cmpq $0x0, 0x12c44(%rip)     # 0x18158
jne 0x5560
movq 0x11ac3(%rip), %rax     # 0x16fe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x5532
leaq 0xbb31(%rip), %rdi      # 0x1105c
movb $0x0, %al
callq 0x5820
movq -0x10(%rbp), %rax
movq 0x11aa3(%rip), %rcx     # 0x16fe0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0x11a95(%rip), %rdx     # 0x16fe0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x12bed(%rip), %rdi     # 0x18148
callq 0x5640
movq 0x12bf1(%rip), %rdi     # 0x18158
leaq 0xbaf8(%rip), %rsi      # 0x11066
movl $0x2, %edx
callq 0x50f0
cmpl $0x0, %eax
jne 0x5587
movl $0x1, 0x12b95(%rip)     # 0x1811c
leaq 0x12bba(%rip), %rdi     # 0x18148
leaq 0xbad4(%rip), %rsi      # 0x11069
callq 0x5640
leaq 0x12b8f(%rip), %rdi     # 0x18130
leaq 0x12ba0(%rip), %rsi     # 0x18148
callq 0x5de0
movl -0x8(%rbp), %edi
movq 0x11a29(%rip), %rax     # 0x16fe0
subl (%rax), %edi
movq -0x10(%rbp), %rsi
movq 0x11a1c(%rip), %rax     # 0x16fe0
movslq (%rax), %rax
shlq $0x3, %rax
addq %rax, %rsi
callq 0x5900
movq 0x12b7e(%rip), %rax     # 0x18158
movq %rax, 0x12b67(%rip)     # 0x18148
leaq 0x12b60(%rip), %rdi     # 0x18148
callq 0x5970
cmpl $0x0, %eax
jne 0x55f4
jmp 0x5609
leaq 0x12b35(%rip), %rdi     # 0x18130
leaq 0x12b46(%rip), %rsi     # 0x18148
callq 0x7570
jmp 0x55d3
movq 0x119a0(%rip), %rax     # 0x16fb0
movq (%rax), %rdi
callq 0x5190
cmpl $-0x1, %eax
jne 0x562e
leaq 0x1208c(%rip), %rax     # 0x176b0
movq (%rax), %rdi
movb $0x0, %al
callq 0x5820
xorl %eax, %eax
addq $0x20, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)