// File: arnoldrobbins[P]mcilroy-regex/grep.cpp
// Function: main
int
main(int argc, char **argv)
{
	for(;;) {
		switch(getopt(argc, argv, "AEFclqinsvxe:f:h")) {
		case 'A':
			options |= REG_AUGMENTED;
			if(REG_AUGMENTED)
				continue;
			
		case '?':
			fprintf(stderr,
			  "usage: grep -EFclqinsvxh pattern [file] ...\n"
			  "       grep -EFclqinsvxh -ef pattern-or-file ... [file] ...\n");
			exit(2);
		case 'E':
			Eflag = 1;
			options |= REG_EXTENDED;
			continue;
		case 'F':
			Fflag = 1;
			options |= REG_LITERAL;
			continue;
		case 'c':
			cflag = 1;
			continue;
		case 'l':
			lflag = 1;
			continue;
		case 'q':
			qflag = 1;
			continue;
		case 'i':
			options |= REG_ICASE;
			continue;
		case 'n':
			nflag = 1;
			continue;
		case 's':
			sflag = 1;
			continue;
		case 'v':
			vflag = 1;
			continue;
		case 'x':
			options |= REG_ANCH;
			continue;
		case 'h':
			hflag = 1;
			continue;
		case 'e':
			argpat.assure(nargpat);
			argpat[nargpat++] = optarg;
			continue;
		case 'f':
			filepat.assure(nfilepat);
			filepat[nfilepat++] = optarg;
			continue;
		case -1:
			break;
		}
		break;
	}
	if(nargpat + nfilepat == 0) {
		if(optind >= argc)
			error("no pattern", "");
		else
			argpat[nargpat++] = argv[optind++];
	}
	if(Fflag+Eflag > 1)
		error("-E and -F are incompatible", "");
	grepcomp();
	nfiles = argc - optind;
	if(nfiles <= 0)
		execute(stdin, "(standard input)");
	else for( ; optind<argc; optind++) {
		FILE *input = fopen(argv[optind], "r");
		if(input) {
			execute(input, argv[optind]);
			fclose(input);
		} else if(!sflag)
			error("cannot open", argv[optind]);
		else
			retval = 2;
		if(qflag && anyhits)
			break;
	}
	return anyhits? 0: retval;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x40, %rsp
movl $0x0, -0x4(%rbp)
movl %edi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movl -0x8(%rbp), %edi
movq -0x10(%rbp), %rsi
leaq 0x8d38(%rip), %rdx      # 0xd1ec
callq 0x4070
incl %eax
movl %eax, %ecx
movq %rcx, -0x20(%rbp)
subl $0x79, %eax
ja 0x4678
movq -0x20(%rbp), %rax
leaq 0x8b2f(%rip), %rcx      # 0xd004
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
movl 0xdc90(%rip), %eax      # 0x12174
orl $0x200, %eax            # imm = 0x200
movl %eax, 0xdc85(%rip)      # 0x12174
jmp 0x44a6
movq 0xdae0(%rip), %rax      # 0x11fd8
movq (%rax), %rdi
leaq 0x8cfb(%rip), %rsi      # 0xd1fd
movb $0x0, %al
callq 0x4210
movl $0x2, %edi
callq 0x41e0
movl $0x1, 0xe29b(%rip)      # 0x127b8
movl 0xdc51(%rip), %eax      # 0x12174
orl $0x1, %eax
movl %eax, 0xdc48(%rip)      # 0x12174
jmp 0x44a6
movl $0x1, 0xe281(%rip)      # 0x127bc
movl 0xdc33(%rip), %eax      # 0x12174
orl $0x100, %eax            # imm = 0x100
movl %eax, 0xdc28(%rip)      # 0x12174
jmp 0x44a6
movl $0x1, 0xe265(%rip)      # 0x127c0
jmp 0x44a6
movl $0x1, 0xe25a(%rip)      # 0x127c4
jmp 0x44a6
movl $0x1, 0xe24f(%rip)      # 0x127c8
jmp 0x44a6
movl 0xdbf0(%rip), %eax      # 0x12174
orl $0x2, %eax
movl %eax, 0xdbe7(%rip)      # 0x12174
jmp 0x44a6
movl $0x1, 0xe230(%rip)      # 0x127cc
jmp 0x44a6
movl $0x1, 0xe225(%rip)      # 0x127d0
jmp 0x44a6
movl $0x1, 0xe21a(%rip)      # 0x127d4
jmp 0x44a6
movl 0xdbaf(%rip), %eax      # 0x12174
orl $0x80, %eax
movl %eax, 0xdba4(%rip)      # 0x12174
jmp 0x44a6
movl $0x1, 0xe1f9(%rip)      # 0x127d8
jmp 0x44a6
movl 0xe2a6(%rip), %esi      # 0x12890
leaq 0xe1ef(%rip), %rdi      # 0x127e0
callq 0x4fc0
movq 0xd9c3(%rip), %rax      # 0x11fc0
movq (%rax), %rax
movq %rax, -0x28(%rbp)
movl 0xe286(%rip), %esi      # 0x12890
movl %esi, %eax
addl $0x1, %eax
movl %eax, 0xe27b(%rip)      # 0x12890
leaq 0xe1c4(%rip), %rdi      # 0x127e0
callq 0x5000
movq -0x28(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x44a6
movl 0xe315(%rip), %esi      # 0x12948
leaq 0xe25e(%rip), %rdi      # 0x12898
callq 0x4fc0
movq 0xd97a(%rip), %rax      # 0x11fc0
movq (%rax), %rax
movq %rax, -0x30(%rbp)
movl 0xe2f5(%rip), %esi      # 0x12948
movl %esi, %eax
addl $0x1, %eax
movl %eax, 0xe2ea(%rip)      # 0x12948
leaq 0xe233(%rip), %rdi      # 0x12898
callq 0x5000
movq -0x30(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x44a6
jmp 0x4678
jmp 0x467a
movl 0xe210(%rip), %eax      # 0x12890
addl 0xe2c2(%rip), %eax      # 0x12948
cmpl $0x0, %eax
jne 0x46fa
movq 0xd94e(%rip), %rax      # 0x11fe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jl 0x46ae
leaq 0x8bc6(%rip), %rdi      # 0xd266
leaq 0x8bbe(%rip), %rsi      # 0xd265
callq 0x4850
jmp 0x46f8
movq -0x10(%rbp), %rax
movq 0xd927(%rip), %rcx      # 0x11fe0
movl (%rcx), %ecx
movl %ecx, %esi
addl $0x1, %esi
movq 0xd919(%rip), %rdx      # 0x11fe0
movl %esi, (%rdx)
movslq %ecx, %rcx
movq (%rax,%rcx,8), %rax
movq %rax, -0x38(%rbp)
movl 0xe1b6(%rip), %esi      # 0x12890
movl %esi, %eax
addl $0x1, %eax
movl %eax, 0xe1ab(%rip)      # 0x12890
leaq 0xe0f4(%rip), %rdi      # 0x127e0
callq 0x5000
movq -0x38(%rbp), %rcx
movq %rcx, (%rax)
jmp 0x46fa
movl 0xe0bc(%rip), %eax      # 0x127bc
addl 0xe0b2(%rip), %eax      # 0x127b8
cmpl $0x1, %eax
jle 0x471e
leaq 0x8b5f(%rip), %rdi      # 0xd271
leaq 0x8b4c(%rip), %rsi      # 0xd265
callq 0x4850
callq 0x4880
movl -0x8(%rbp), %eax
movq 0xd8b3(%rip), %rcx      # 0x11fe0
subl (%rcx), %eax
movl %eax, 0xe57b(%rip)      # 0x12cb0
cmpl $0x0, 0xe574(%rip)      # 0x12cb0
jg 0x4759
movq 0xd88b(%rip), %rax      # 0x11fd0
movq (%rax), %rdi
leaq 0x8b3d(%rip), %rsi      # 0xd28c
callq 0x49f0
jmp 0x4823
jmp 0x475b
movq 0xd87e(%rip), %rax      # 0x11fe0
movl (%rax), %eax
cmpl -0x8(%rbp), %eax
jge 0x4821
movq -0x10(%rbp), %rax
movq 0xd868(%rip), %rcx      # 0x11fe0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rdi
leaq 0x9006(%rip), %rsi      # 0xd78c
callq 0x41d0
movq %rax, -0x18(%rbp)
cmpq $0x0, -0x18(%rbp)
je 0x47bc
movq -0x18(%rbp), %rdi
movq -0x10(%rbp), %rax
movq 0xd83b(%rip), %rcx      # 0x11fe0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
callq 0x49f0
movq -0x18(%rbp), %rdi
callq 0x4190
jmp 0x47f1
cmpl $0x0, 0xe00d(%rip)      # 0x127d0
jne 0x47e5
movq -0x10(%rbp), %rax
movq 0xd810(%rip), %rcx      # 0x11fe0
movslq (%rcx), %rcx
movq (%rax,%rcx,8), %rsi
leaq 0x8abf(%rip), %rdi      # 0xd29d
callq 0x4850
jmp 0x47ef
movl $0x2, 0xd981(%rip)      # 0x12170
jmp 0x47f1
cmpl $0x0, 0xdfd0(%rip)      # 0x127c8
je 0x4805
cmpl $0x0, 0xe4ab(%rip)      # 0x12cac
je 0x4805
jmp 0x4821
jmp 0x4807
movq 0xd7d2(%rip), %rax      # 0x11fe0
movl (%rax), %ecx
addl $0x1, %ecx
movq 0xd7c6(%rip), %rax      # 0x11fe0
movl %ecx, (%rax)
jmp 0x475b
jmp 0x4823
cmpl $0x0, 0xe482(%rip)      # 0x12cac
je 0x4833
xorl %eax, %eax
movl %eax, -0x3c(%rbp)
jmp 0x483c
movl 0xd937(%rip), %eax      # 0x12170
movl %eax, -0x3c(%rbp)
movl -0x3c(%rbp), %eax
addq $0x40, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)