#define NULL ((void *)0)
typedef unsigned long size_t; // Customize by platform.
typedef long intptr_t;
typedef unsigned long uintptr_t;
typedef long scalar_t__; // Either arithmetic or pointer type.
/* By default, we understand bool (as a convenience). */
typedef int bool;
#define false 0
#define true 1

/* Forward declarations */

/* Type definitions */

/* Variables and functions */
int /*<<< orphan*/ error(char *);
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
scalar_t__ match(unsigned int, char *);
unsigned int parse(char *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ stdin;
int strlen(char *);
int main(int argc, char **argv) {
  if (argc != 2)
    error("Usage: grep pattern");
  unsigned start_state = parse(argv[1]);
  char line[9999];
  while (fgets(line, sizeof line, stdin)) {
    line[strlen(line) - 1] = '\0';
    if (match(start_state, line))
      puts(line);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x2730,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
je     118f <main+0x2f>
lea    0xe76(%rip),%rdi
call   1070 <error@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1080 <parse@plt>
mov    %eax,-0x14(%rbp)
lea    -0x2730(%rbp),%rdi
mov    0x2e3b(%rip),%rax
mov    (%rax),%edx
mov    $0x270f,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1206 <main+0xa6>
lea    -0x2730(%rbp),%rdi
call   1040 <strlen@plt>
sub    $0x1,%eax
cltq
movb   $0x0,-0x2730(%rbp,%rax,1)
mov    -0x14(%rbp),%edi
lea    -0x2730(%rbp),%rsi
call   1060 <match@plt>
cmp    $0x0,%rax
je     1201 <main+0xa1>
lea    -0x2730(%rbp),%rdi
call   1030 <puts@plt>
jmp    119f <main+0x3f>
xor    %eax,%eax
add    $0x2730,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x2710,%rsp
mov    %rsi,%rbx
cmp    $0x2,%edi
je     117f <main+0x1f>
lea    0xe86(%rip),%rdi
call   1070 <error@plt>
mov    0x8(%rbx),%rdi
call   1080 <parse@plt>
mov    %eax,%ebp
mov    0x2e57(%rip),%r14
mov    (%r14),%edx
mov    %rsp,%rbx
jmp    11a3 <main+0x43>
nopl   0x0(%rax)
mov    (%r14),%edx
mov    %rbx,%rdi
mov    $0x270f,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     11dd <main+0x7d>
mov    %rbx,%rdi
call   1040 <strlen@plt>
cltq
movb   $0x0,-0x1(%rax,%rbx,1)
mov    %ebp,%edi
mov    %rbx,%rsi
call   1060 <match@plt>
test   %rax,%rax
je     11a0 <main+0x40>
mov    %rbx,%rdi
call   1030 <puts@plt>
jmp    11a0 <main+0x40>
xor    %eax,%eax
add    $0x2710,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [20 x i8] c"Usage: grep pattern\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [9999 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 2
br i1 %9, label %10, label %12
10: ; preds = %2
%11 = call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %12
12: ; preds = %10, %2
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @parse(i8* %15)
store i32 %16, i32* %6
br label %17
17: ; preds = %35, %12
%18 = getelementptr inbounds [9999 x i8], [9999 x i8]* %7, i64 0, i64 0
%19 = load i32, i32* @stdin
%20 = call i64 @fgets(i8* %18, i32 9999, i32 %19)
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %36
22: ; preds = %17
%23 = getelementptr inbounds [9999 x i8], [9999 x i8]* %7, i64 0, i64 0
%24 = call i32 @strlen(i8* %23)
%25 = sub nsw i32 %24, 1
%26 = sext i32 %25 to i64
%27 = getelementptr inbounds [9999 x i8], [9999 x i8]* %7, i64 0, i64 %26
store i8 0, i8* %27
%28 = load i32, i32* %6
%29 = getelementptr inbounds [9999 x i8], [9999 x i8]* %7, i64 0, i64 0
%30 = call i64 @match(i32 %28, i8* %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %35
32: ; preds = %22
%33 = getelementptr inbounds [9999 x i8], [9999 x i8]* %7, i64 0, i64 0
%34 = call i32 @puts(i8* %33)
br label %35
35: ; preds = %32, %22
br label %17
36: ; preds = %17
ret i32 0
}

LLVM IR (-O2):
@.str = [20 x i8] c"Usage: grep pattern\00"
@stdin = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [9999 x i8]
%4 = icmp eq i32 %0, 2
br i1 %4, label %7, label %5
5: ; preds = %2
%6 = tail call i32 @error(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %7
7: ; preds = %5, %2
%8 = getelementptr inbounds i8*, i8** %1, i64 1
%9 = load i8*, i8** %8
%10 = tail call i32 @parse(i8* %9)
%11 = getelementptr inbounds [9999 x i8], [9999 x i8]* %3, i64 0, i64 0
%12 = load i32, i32* @stdin
%13 = call i64 @fgets(i8* %11, i32 9999, i32 %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %28, label %15
15: ; preds = %7, %24
%16 = call i32 @strlen(i8* %11)
%17 = add nsw i32 %16, -1
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds [9999 x i8], [9999 x i8]* %3, i64 0, i64 %18
store i8 0, i8* %19
%20 = call i64 @match(i32 %10, i8* %11)
%21 = icmp eq i64 %20, 0
br i1 %21, label %24, label %22
22: ; preds = %15
%23 = call i32 @puts(i8* %11)
br label %24
24: ; preds = %22, %15
%25 = load i32, i32* @stdin
%26 = call i64 @fgets(i8* %11, i32 9999, i32 %25)
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %15
28: ; preds = %24, %7
ret i32 0
}