#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 EXIT_FAILURE;
int EXIT_SUCCESS;
scalar_t__ fgets(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ free(char *);
char *malloc(int);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdin;
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strstr(char *, char *);
int main(int argc, char **argv) {
  char *pattern;
  int lineCount = 1;
  int matchFound = 0;
  int invertMatch = 0;
  int lineNumber = 0;
  int quiet = 0;
  int i = 1;
  for (; i < argc; ++i) {
    if (strcmp(argv[i], "--help") == 0) {
      printf("Usage: grep-lite [OPTION]... PATTER\n"
             "Search for PATTERN in standard input. PATTERN is a\n"
             "string. grep-lite will search standard input line by\n"
             "line, and (by default) print out those lines which\n"
             "contain pattern as a substring.\n\n"
             "  -v, --invert-match     print non-matching lines\n"
             "  -n, --line-number      print line numbers with output\n"
             "  -q, --quiet            suppress all output\n\n"
             "Exit status is 0 if any line is selected, 1 otherwise;\n"
             "if any error occurs, then the exit status is 2.\n");
      return EXIT_SUCCESS;
    } else if (strcmp(argv[i], "-v") == 0 ||
               strcmp(argv[i], "--invert-match") == 0) {
      invertMatch = 1;
    } else if (strcmp(argv[i], "-n") == 0 ||
               strcmp(argv[i], "--line-number") == 0) {
      lineNumber = 1;
    } else if (strcmp(argv[i], "-q") == 0 || strcmp(argv[i], "--quiet") == 0) {
      quiet = 1;
    } else if (i == argc - 1) {
      pattern = argv[i];
    } else {
      fprintf(stderr, "Unknown switch: '%s'\nAborting...\n", argv[i]);
      return 2;
    }
  }
  if (pattern[0] == '-') {
    fprintf(stderr, "Pattern cannot begin with '-'.\nAborting...\n");
    return 2;
  }
  char *buffer = malloc(2001 * sizeof(char));
  while (fgets(buffer, 2001 - 1, stdin)) {
    if (!!strstr(buffer, pattern) ^ invertMatch) {
      if (!quiet) {
        if (lineNumber) {
          printf("%d: ", lineCount);
        }
        printf("%s", buffer);
      }
      matchFound = 1;
    }
    lineCount++;
  }
  free(buffer);
  return matchFound ? EXIT_SUCCESS : EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x1,-0x1c(%rbp)
movl   $0x0,-0x20(%rbp)
movl   $0x0,-0x24(%rbp)
movl   $0x0,-0x28(%rbp)
movl   $0x0,-0x2c(%rbp)
movl   $0x1,-0x30(%rbp)
mov    -0x30(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1369 <main+0x1f9>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe31(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    11fd <main+0x8d>
lea    0xe22(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    0x2dd5(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
jmp    1475 <main+0x305>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xfd7(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1241 <main+0xd1>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xfb8(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    124d <main+0xdd>
movl   $0x1,-0x24(%rbp)
jmp    1351 <main+0x1e1>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf99(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     1291 <main+0x121>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf7a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    129d <main+0x12d>
movl   $0x1,-0x28(%rbp)
jmp    134c <main+0x1dc>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf5a(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
je     12e1 <main+0x171>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xf3b(%rip),%rsi
call   1060 <strcmp@plt>
cmp    $0x0,%rax
jne    12ed <main+0x17d>
movl   $0x1,-0x2c(%rbp)
jmp    1347 <main+0x1d7>
mov    -0x30(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x1,%ecx
cmp    %ecx,%eax
jne    1313 <main+0x1a3>
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x18(%rbp)
jmp    1342 <main+0x1d2>
mov    0x2cbe(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x30(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xee6(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1475 <main+0x305>
jmp    1347 <main+0x1d7>
jmp    134c <main+0x1dc>
jmp    1351 <main+0x1e1>
jmp    1356 <main+0x1e6>
jmp    135b <main+0x1eb>
mov    -0x30(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x30(%rbp)
jmp    11b0 <main+0x40>
mov    -0x18(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
jne    139c <main+0x22c>
mov    0x2c58(%rip),%rax
mov    (%rax),%edi
lea    0xeae(%rip),%rsi
mov    $0x0,%al
call   1070 <fprintf@plt>
movl   $0x2,-0x4(%rbp)
jmp    1475 <main+0x305>
mov    $0x7d1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
mov    0x2c33(%rip),%rax
mov    (%rax),%edx
mov    $0x7d0,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     143f <main+0x2cf>
mov    -0x38(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1090 <strstr@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
xor    -0x24(%rbp),%eax
cmp    $0x0,%eax
je     1431 <main+0x2c1>
cmpl   $0x0,-0x2c(%rbp)
jne    142a <main+0x2ba>
cmpl   $0x0,-0x28(%rbp)
je     1418 <main+0x2a8>
mov    -0x1c(%rbp),%esi
lea    0xe52(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x38(%rbp),%rsi
lea    0xe45(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movl   $0x1,-0x20(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    13aa <main+0x23a>
mov    -0x38(%rbp),%rdi
call   1030 <free@plt>
cmpl   $0x0,-0x20(%rbp)
je     1463 <main+0x2f3>
mov    0x2b6f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
jmp    146f <main+0x2ff>
mov    0x2b66(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jl     12aa <main+0x12a>
mov    %rsi,%rbx
lea    -0x1(%rdi),%r14d
mov    %edi,%r15d
movl   $0x0,0xc(%rsp)
mov    $0x1,%ebp
lea    0xe4b(%rip),%r13
movl   $0x0,0x8(%rsp)
xor    %r12d,%r12d
jmp    11e3 <main+0x63>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    $0x1,%r12d
add    $0x1,%rbp
cmp    %rbp,%r15
je     12bd <main+0x13d>
mov    (%rbx,%rbp,8),%rdi
mov    %r13,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     139c <main+0x21c>
mov    (%rbx,%rbp,8),%rdi
lea    0xe04(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    (%rbx,%rbp,8),%rdi
lea    0xdf2(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     11d0 <main+0x50>
mov    (%rbx,%rbp,8),%rdi
lea    0xdec(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0x110>
mov    (%rbx,%rbp,8),%rdi
lea    0xdda(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1290 <main+0x110>
mov    (%rbx,%rbp,8),%rdi
lea    0xdd3(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     129d <main+0x11d>
mov    (%rbx,%rbp,8),%rdi
lea    0xdc1(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     129d <main+0x11d>
cmp    %rbp,%r14
jne    13db <main+0x25b>
mov    (%rbx,%rbp,8),%rax
mov    %rax,0x10(%rsp)
jmp    11d6 <main+0x56>
nopl   (%rax)
movl   $0x1,0x8(%rsp)
jmp    11d6 <main+0x56>
movl   $0x1,0xc(%rsp)
jmp    11d6 <main+0x56>
xor    %r12d,%r12d
movl   $0x0,0x8(%rsp)
movl   $0x0,0xc(%rsp)
mov    0x10(%rsp),%rax
cmpb   $0x2d,(%rax)
jne    12e8 <main+0x168>
mov    0x2d0a(%rip),%rax
mov    (%rax),%edi
lea    0xd80(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%eax
jmp    13cc <main+0x24c>
mov    $0x7d1,%edi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    0x2cec(%rip),%r15
mov    (%r15),%edx
mov    %rax,%rdi
mov    $0x7d0,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     13aa <main+0x22a>
mov    $0x1,%r13d
xor    %r14d,%r14d
mov    $0x1,%ebp
jmp    135f <main+0x1df>
cs nopw 0x0(%rax,%rax,1)
nop
lea    0xd51(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    $0x1,%r14d
add    $0x1,%ebp
mov    (%r15),%edx
mov    %rbx,%rdi
mov    $0x7d0,%esi
call   1060 <fgets@plt>
test   %rax,%rax
je     13ad <main+0x22d>
mov    %rbx,%rdi
mov    0x10(%rsp),%rsi
call   10a0 <strstr@plt>
xor    %ecx,%ecx
test   %eax,%eax
setne  %cl
cmp    %ecx,%r12d
cmovne %r13d,%r14d
je     1347 <main+0x1c7>
cmpl   $0x0,0xc(%rsp)
jne    1347 <main+0x1c7>
cmpl   $0x0,0x8(%rsp)
je     1330 <main+0x1b0>
lea    0xcf2(%rip),%rdi
mov    %ebp,%esi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1330 <main+0x1b0>
lea    0xce8(%rip),%rdi
call   1040 <puts@plt>
jmp    13c3 <main+0x243>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1030 <free@plt>
test   %r14d,%r14d
jne    13c3 <main+0x243>
mov    0x2c0f(%rip),%rax
jmp    13ca <main+0x24a>
mov    0x2bfe(%rip),%rax
mov    (%rax),%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2bf6(%rip),%rax
mov    (%rax),%edi
mov    (%rbx,%rbp,8),%rdx
lea    0xc46(%rip),%rsi
xor    %eax,%eax
call   1080 <fprintf@plt>
mov    $0x2,%eax
jmp    13cc <main+0x24c>

LLVM IR (-O0):
@.str = [7 x i8] c"--help\00"
@.str.1 = [480 x i8] c"Usage: grep-lite [OPTION]... PATTER\0ASearch for PATTERN in standard input. PATTERN is a\0Astring. grep-lite will search standard input line by\0Aline, and (by default) print out those lines which\0Acontain pattern as a substring.\0A\0A -v, --invert-match print non-matching lines\0A -n, --line-number print line numbers with output\0A -q, --quiet suppress all output\0A\0AExit status is 0 if any line is selected, 1 otherwise;\0Aif any error occurs, then the exit status is 2.\0A\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [3 x i8] c"-v\00"
@.str.3 = [15 x i8] c"--invert-match\00"
@.str.4 = [3 x i8] c"-n\00"
@.str.5 = [14 x i8] c"--line-number\00"
@.str.6 = [3 x i8] c"-q\00"
@.str.7 = [8 x i8] c"--quiet\00"
@stderr = global i32 0
@.str.8 = [34 x i8] c"Unknown switch: '%s'\0AAborting...\0A\00"
@.str.9 = [44 x i8] c"Pattern cannot begin with '-'.\0AAborting...\0A\00"
@stdin = global i32 0
@.str.10 = [5 x i8] c"%d: \00"
@.str.11 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 1, i32* %7
store i32 0, i32* %8
store i32 0, i32* %9
store i32 0, i32* %10
store i32 0, i32* %11
store i32 1, i32* %12
br label %14
14: ; preds = %104, %2
%15 = load i32, i32* %12
%16 = load i32, i32* %4
%17 = icmp slt i32 %15, %16
br i1 %17, label %18, label %107
18: ; preds = %14
%19 = load i8**, i8*** %5
%20 = load i32, i32* %12
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds i8*, i8** %19, i64 %21
%23 = load i8*, i8** %22
%24 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%25 = icmp eq i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %18
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([480 x i8], [480 x i8]* @.str.1, i64 0, i64 0))
%28 = load i32, i32* @EXIT_SUCCESS
store i32 %28, i32* %3
br label %161
29: ; preds = %18
%30 = load i8**, i8*** %5
%31 = load i32, i32* %12
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds i8*, i8** %30, i64 %32
%34 = load i8*, i8** %33
%35 = call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %45, label %37
37: ; preds = %29
%38 = load i8**, i8*** %5
%39 = load i32, i32* %12
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %45, label %46
45: ; preds = %37, %29
store i32 1, i32* %9
br label %102
46: ; preds = %37
%47 = load i8**, i8*** %5
%48 = load i32, i32* %12
%49 = sext i32 %48 to i64
%50 = getelementptr inbounds i8*, i8** %47, i64 %49
%51 = load i8*, i8** %50
%52 = call i64 @strcmp(i8* %51, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%53 = icmp eq i64 %52, 0
br i1 %53, label %62, label %54
54: ; preds = %46
%55 = load i8**, i8*** %5
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = call i64 @strcmp(i8* %59, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%61 = icmp eq i64 %60, 0
br i1 %61, label %62, label %63
62: ; preds = %54, %46
store i32 1, i32* %10
br label %101
63: ; preds = %54
%64 = load i8**, i8*** %5
%65 = load i32, i32* %12
%66 = sext i32 %65 to i64
%67 = getelementptr inbounds i8*, i8** %64, i64 %66
%68 = load i8*, i8** %67
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %79, label %71
71: ; preds = %63
%72 = load i8**, i8*** %5
%73 = load i32, i32* %12
%74 = sext i32 %73 to i64
%75 = getelementptr inbounds i8*, i8** %72, i64 %74
%76 = load i8*, i8** %75
%77 = call i64 @strcmp(i8* %76, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%78 = icmp eq i64 %77, 0
br i1 %78, label %79, label %80
79: ; preds = %71, %63
store i32 1, i32* %11
br label %100
80: ; preds = %71
%81 = load i32, i32* %12
%82 = load i32, i32* %4
%83 = sub nsw i32 %82, 1
%84 = icmp eq i32 %81, %83
br i1 %84, label %85, label %91
85: ; preds = %80
%86 = load i8**, i8*** %5
%87 = load i32, i32* %12
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8*, i8** %86, i64 %88
%90 = load i8*, i8** %89
store i8* %90, i8** %6
br label %99
91: ; preds = %80
%92 = load i32, i32* @stderr
%93 = load i8**, i8*** %5
%94 = load i32, i32* %12
%95 = sext i32 %94 to i64
%96 = getelementptr inbounds i8*, i8** %93, i64 %95
%97 = load i8*, i8** %96
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %92, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %97)
store i32 2, i32* %3
br label %161
99: ; preds = %85
br label %100
100: ; preds = %99, %79
br label %101
101: ; preds = %100, %62
br label %102
102: ; preds = %101, %45
br label %103
103: ; preds = %102
br label %104
104: ; preds = %103
%105 = load i32, i32* %12
%106 = add nsw i32 %105, 1
store i32 %106, i32* %12
br label %14
107: ; preds = %14
%108 = load i8*, i8** %6
%109 = getelementptr inbounds i8, i8* %108, i64 0
%110 = load i8, i8* %109
%111 = sext i8 %110 to i32
%112 = icmp eq i32 %111, 45
br i1 %112, label %113, label %116
113: ; preds = %107
%114 = load i32, i32* @stderr
%115 = call i32 (i32, i8*, ...) @fprintf(i32 %114, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
store i32 2, i32* %3
br label %161
116: ; preds = %107
%117 = call i8* @malloc(i32 2001)
store i8* %117, i8** %13
br label %118
118: ; preds = %147, %116
%119 = load i8*, i8** %13
%120 = load i32, i32* @stdin
%121 = call i64 @fgets(i8* %119, i32 2000, i32 %120)
%122 = icmp ne i64 %121, 0
br i1 %122, label %123, label %150
123: ; preds = %118
%124 = load i8*, i8** %13
%125 = load i8*, i8** %6
%126 = call i32 @strstr(i8* %124, i8* %125)
%127 = icmp ne i32 %126, 0
%128 = xor i1 %127, true
%129 = xor i1 %128, true
%130 = zext i1 %129 to i32
%131 = load i32, i32* %9
%132 = xor i32 %130, %131
%133 = icmp ne i32 %132, 0
br i1 %133, label %134, label %147
134: ; preds = %123
%135 = load i32, i32* %11
%136 = icmp ne i32 %135, 0
br i1 %136, label %146, label %137
137: ; preds = %134
%138 = load i32, i32* %10
%139 = icmp ne i32 %138, 0
br i1 %139, label %140, label %143
140: ; preds = %137
%141 = load i32, i32* %7
%142 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 %141)
br label %143
143: ; preds = %140, %137
%144 = load i8*, i8** %13
%145 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %144)
br label %146
146: ; preds = %143, %134
store i32 1, i32* %8
br label %147
147: ; preds = %146, %123
%148 = load i32, i32* %7
%149 = add nsw i32 %148, 1
store i32 %149, i32* %7
br label %118
150: ; preds = %118
%151 = load i8*, i8** %13
%152 = call i32 @free(i8* %151)
%153 = load i32, i32* %8
%154 = icmp ne i32 %153, 0
br i1 %154, label %155, label %157
155: ; preds = %150
%156 = load i32, i32* @EXIT_SUCCESS
br label %159
157: ; preds = %150
%158 = load i32, i32* @EXIT_FAILURE
br label %159
159: ; preds = %157, %155
%160 = phi i32 [ %156, %155 ], [ %158, %157 ]
store i32 %160, i32* %3
br label %161
161: ; preds = %159, %113, %91, %26
%162 = load i32, i32* %3
ret i32 %162
}

LLVM IR (-O2):
@.str = [7 x i8] c"--help\00"
@EXIT_SUCCESS = global i32 0
@.str.2 = [3 x i8] c"-v\00"
@.str.3 = [15 x i8] c"--invert-match\00"
@.str.4 = [3 x i8] c"-n\00"
@.str.5 = [14 x i8] c"--line-number\00"
@.str.6 = [3 x i8] c"-q\00"
@.str.7 = [8 x i8] c"--quiet\00"
@stderr = global i32 0
@.str.8 = [34 x i8] c"Unknown switch: '%s'\0AAborting...\0A\00"
@.str.9 = [44 x i8] c"Pattern cannot begin with '-'.\0AAborting...\0A\00"
@stdin = global i32 0
@.str.10 = [5 x i8] c"%d: \00"
@.str.11 = [3 x i8] c"%s\00"
@EXIT_FAILURE = global i32 0
@str = [479 x i8] c"Usage: grep-lite [OPTION]... PATTER\0ASearch for PATTERN in standard input. PATTERN is a\0Astring. grep-lite will search standard input line by\0Aline, and (by default) print out those lines which\0Acontain pattern as a substring.\0A\0A -v, --invert-match print non-matching lines\0A -n, --line-number print line numbers with output\0A -q, --quiet suppress all output\0A\0AExit status is 0 if any line is selected, 1 otherwise;\0Aif any error occurs, then the exit status is 2.\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp sgt i32 %0, 1
br i1 %3, label %4, label %60
4: ; preds = %2
%5 = add nsw i32 %0, -1
%6 = zext i32 %5 to i64
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %4, %53
%9 = phi i64 [ 1, %4 ], [ %58, %53 ]
%10 = phi i32 [ 0, %4 ], [ %57, %53 ]
%11 = phi i32 [ 0, %4 ], [ %56, %53 ]
%12 = phi i32 [ 0, %4 ], [ %55, %53 ]
%13 = phi i8* [ undef, %4 ], [ %54, %53 ]
%14 = getelementptr inbounds i8*, i8** %1, i64 %9
%15 = load i8*, i8** %14
%16 = tail call i64 @strcmp(i8* %15, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %21
18: ; preds = %8
%19 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([479 x i8], [479 x i8]* @str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_SUCCESS
br label %105
21: ; preds = %8
%22 = load i8*, i8** %14
%23 = tail call i64 @strcmp(i8* %22, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0))
%24 = icmp eq i64 %23, 0
br i1 %24, label %53, label %25
25: ; preds = %21
%26 = load i8*, i8** %14
%27 = tail call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%28 = icmp eq i64 %27, 0
br i1 %28, label %53, label %29
29: ; preds = %25
%30 = load i8*, i8** %14
%31 = tail call i64 @strcmp(i8* %30, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0))
%32 = icmp eq i64 %31, 0
br i1 %32, label %53, label %33
33: ; preds = %29
%34 = load i8*, i8** %14
%35 = tail call i64 @strcmp(i8* %34, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.5, i64 0, i64 0))
%36 = icmp eq i64 %35, 0
br i1 %36, label %53, label %37
37: ; preds = %33
%38 = load i8*, i8** %14
%39 = tail call i64 @strcmp(i8* %38, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %53, label %41
41: ; preds = %37
%42 = load i8*, i8** %14
%43 = tail call i64 @strcmp(i8* %42, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.7, i64 0, i64 0))
%44 = icmp eq i64 %43, 0
br i1 %44, label %53, label %45
45: ; preds = %41
%46 = icmp eq i64 %9, %6
br i1 %46, label %47, label %49
47: ; preds = %45
%48 = load i8*, i8** %14
br label %53
49: ; preds = %45
%50 = load i32, i32* @stderr
%51 = load i8*, i8** %14
%52 = tail call i32 (i32, i8*, ...) @fprintf(i32 %50, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.8, i64 0, i64 0), i8* %51)
br label %105
53: ; preds = %37, %41, %29, %33, %21, %25, %47
%54 = phi i8* [ %48, %47 ], [ %13, %25 ], [ %13, %21 ], [ %13, %33 ], [ %13, %29 ], [ %13, %41 ], [ %13, %37 ]
%55 = phi i32 [ %12, %47 ], [ 1, %25 ], [ 1, %21 ], [ %12, %33 ], [ %12, %29 ], [ %12, %41 ], [ %12, %37 ]
%56 = phi i32 [ %11, %47 ], [ %11, %25 ], [ %11, %21 ], [ 1, %33 ], [ 1, %29 ], [ %11, %41 ], [ %11, %37 ]
%57 = phi i32 [ %10, %47 ], [ %10, %25 ], [ %10, %21 ], [ %10, %33 ], [ %10, %29 ], [ 1, %41 ], [ 1, %37 ]
%58 = add nuw nsw i64 %9, 1
%59 = icmp eq i64 %58, %7
br i1 %59, label %60, label %8
60: ; preds = %53, %2
%61 = phi i8* [ undef, %2 ], [ %54, %53 ]
%62 = phi i32 [ 0, %2 ], [ %55, %53 ]
%63 = phi i32 [ 0, %2 ], [ %56, %53 ]
%64 = phi i32 [ 0, %2 ], [ %57, %53 ]
%65 = load i8, i8* %61
%66 = icmp eq i8 %65, 45
br i1 %66, label %67, label %70
67: ; preds = %60
%68 = load i32, i32* @stderr
%69 = tail call i32 (i32, i8*, ...) @fprintf(i32 %68, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.9, i64 0, i64 0))
br label %105
70: ; preds = %60
%71 = tail call dereferenceable_or_null(2001) i8* @malloc(i32 2001)
%72 = load i32, i32* @stdin
%73 = tail call i64 @fgets(i8* %71, i32 2000, i32 %72)
%74 = icmp eq i64 %73, 0
br i1 %74, label %98, label %75
75: ; preds = %70
%76 = icmp ne i32 %64, 0
%77 = icmp eq i32 %63, 0
br label %78
78: ; preds = %75, %92
%79 = phi i32 [ 0, %75 ], [ %93, %92 ]
%80 = phi i32 [ 1, %75 ], [ %94, %92 ]
%81 = tail call i32 @strstr(i8* %71, i8* %61)
%82 = icmp ne i32 %81, 0
%83 = zext i1 %82 to i32
%84 = icmp eq i32 %62, %83
%85 = select i1 %84, i1 true, i1 %76
%86 = select i1 %84, i32 %79, i32 1
br i1 %85, label %92, label %87
87: ; preds = %78
br i1 %77, label %90, label %88
88: ; preds = %87
%89 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.10, i64 0, i64 0), i32 %80)
br label %90
90: ; preds = %88, %87
%91 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([3 x i8], [3 x i8]* @.str.11, i64 0, i64 0), i8* %71)
br label %92
92: ; preds = %78, %90
%93 = phi i32 [ %86, %78 ], [ 1, %90 ]
%94 = add nuw nsw i32 %80, 1
%95 = load i32, i32* @stdin
%96 = tail call i64 @fgets(i8* %71, i32 2000, i32 %95)
%97 = icmp eq i64 %96, 0
br i1 %97, label %98, label %78
98: ; preds = %92, %70
%99 = phi i32 [ 0, %70 ], [ %93, %92 ]
%100 = tail call i32 @free(i8* %71)
%101 = icmp eq i32 %99, 0
%102 = load i32, i32* @EXIT_SUCCESS
%103 = load i32, i32* @EXIT_FAILURE
%104 = select i1 %101, i32 %103, i32 %102
br label %105
105: ; preds = %98, %67, %49, %18
%106 = phi i32 [ %20, %18 ], [ 2, %49 ], [ 2, %67 ], [ %104, %98 ]
ret i32 %106
}