#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 */
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ do_pattern_matching(int, int, char *, int /*<<< orphan*/ *,
                                       char *);
int errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ normalize(char *);
int should_contain_number_lines(char *, int);
int should_ignore_case(char *, int);
int /*<<< orphan*/ stderr;
int strlen(char *);
int main(int argc, char **argv) {
  if (argc < 3) {
    fprintf(stderr, "Usage: %s [options] STRING FILE...\n", argv[0]);
    exit(-1);
  }
  bool ignore_case = false;
  bool contain_number_lines = false;
  int i = 1;
  for (; i < argc - 2; i++) {
    if (argv[i][0] != '-')
      break;
    ignore_case = should_ignore_case(argv[i], ignore_case);
    contain_number_lines =
        should_contain_number_lines(argv[i], contain_number_lines);
  }
  char *pattern = argv[i];
  if (strlen(pattern) > 100) {
    fprintf(stderr, "Pattern is longer than %d length\n", 100);
    exit(-1);
  }
  if (ignore_case) {
    normalize(pattern);
  }
  for (i += 1; i < argc; i++) {
    FILE *file = fopen(argv[i], "r");
    if (file == NULL) {
      fprintf(stderr, "Error opening file: %s, error: %d\n", argv[i], errno);
      continue;
    }
    do_pattern_matching(ignore_case, contain_number_lines, argv[i], file,
                        pattern);
    fclose(file);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
jge    11d8 <main+0x48>
mov    0x2e29(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe39(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
movl   $0x0,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
movl   $0x1,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
mov    -0x8(%rbp),%ecx
sub    $0x2,%ecx
cmp    %ecx,%eax
jge    1257 <main+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
movsbl (%rax),%eax
cmp    $0x2d,%eax
je     121b <main+0x8b>
jmp    1257 <main+0xc7>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x14(%rbp),%esi
call   10b0 <should_ignore_case@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x18(%rbp),%esi
call   10a0 <should_contain_number_lines@plt>
mov    %eax,-0x18(%rbp)
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    11ed <main+0x5d>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
cmp    $0x64,%eax
jle    129f <main+0x10f>
mov    0x2d60(%rip),%rax
mov    (%rax),%edi
lea    0xd9b(%rip),%rsi
mov    $0x64,%edx
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
je     12b2 <main+0x122>
mov    -0x28(%rbp),%rdi
call   1050 <normalize@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1355 <main+0x1c5>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xd6c(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    131f <main+0x18f>
mov    0x2ceb(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    0x2cce(%rip),%rax
mov    (%rax),%ecx
lea    0xd35(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1347 <main+0x1b7>
mov    -0x14(%rbp),%edi
mov    -0x18(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
mov    -0x30(%rbp),%rcx
mov    -0x28(%rbp),%r8
call   1080 <do_pattern_matching@plt>
mov    -0x30(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    12bb <main+0x12b>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
mov    %rsi,%r13
mov    %rdi,0x8(%rsp)
cmp    $0x3,%edi
jge    11d0 <main+0x40>
mov    0x2e2e(%rip),%rax
mov    (%rax),%edi
mov    0x0(%r13),%rdx
lea    0xe41(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
jne    11df <main+0x4f>
xor    %r15d,%r15d
mov    $0x1,%r14d
xor    %ebx,%ebx
jmp    1231 <main+0xa1>
mov    0x8(%rsp),%rax
lea    -0x2(%rax),%r14d
mov    %r14d,%r12d
xor    %ebx,%ebx
mov    $0x1,%ebp
xor    %r15d,%r15d
cs nopw 0x0(%rax,%rax,1)
nop
mov    0x0(%r13,%rbp,8),%rdi
cmpb   $0x2d,(%rdi)
jne    122e <main+0x9e>
mov    %ebx,%esi
call   10b0 <should_ignore_case@plt>
mov    %eax,%ebx
mov    0x0(%r13,%rbp,8),%rdi
mov    %r15d,%esi
call   10a0 <should_contain_number_lines@plt>
mov    %eax,%r15d
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1200 <main+0x70>
jmp    1231 <main+0xa1>
mov    %ebp,%r14d
mov    %r14d,%eax
mov    0x0(%r13,%rax,8),%rdi
mov    %rdi,0x10(%rsp)
call   1040 <strlen@plt>
cmp    $0x65,%eax
jl     126e <main+0xde>
mov    0x2d91(%rip),%rax
mov    (%rax),%edi
lea    0xdcc(%rip),%rsi
mov    $0x64,%edx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>
test   %ebx,%ebx
je     127c <main+0xec>
mov    0x10(%rsp),%rdi
call   1050 <normalize@plt>
add    $0x1,%r14d
cmp    0x8(%rsp),%r14d
jge    1317 <main+0x187>
mov    %r14d,%eax
lea    0x0(,%rax,8),%r12
add    %r13,%r12
lea    0xda6(%rip),%rbp
jmp    12e0 <main+0x150>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
mov    %rax,%r13
mov    (%r12),%rdx
mov    %ebx,%edi
mov    %r15d,%esi
mov    %rax,%rcx
mov    0x10(%rsp),%r8
call   1080 <do_pattern_matching@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
add    $0x8,%r12
add    $0x1,%r14d
cmp    0x8(%rsp),%r14d
jge    1317 <main+0x187>
mov    (%r12),%rdi
mov    %rbp,%rsi
call   1070 <fopen@plt>
test   %rax,%rax
jne    12b0 <main+0x120>
mov    0x2ce8(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
mov    0x2cd3(%rip),%rax
mov    (%rax),%ecx
lea    0xd3a(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    12d1 <main+0x141>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: %s [options] STRING FILE...\0A\00"
@.str.1 = [34 x i8] c"Pattern is longer than %d length\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [35 x i8] c"Error opening file: %s, error: %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i8*
%10 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp slt i32 %11, 3
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 0
%17 = load i8*, i8** %16
%18 = call i32 (i32, i8*, ...) @fprintf(i32 %14, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %17)
%19 = call i32 @exit(i32 -1)
unreachable
20: ; preds = %2
store i32 0, i32* %6
store i32 0, i32* %7
store i32 1, i32* %8
br label %21
21: ; preds = %52, %20
%22 = load i32, i32* %8
%23 = load i32, i32* %4
%24 = sub nsw i32 %23, 2
%25 = icmp slt i32 %22, %24
br i1 %25, label %26, label %55
26: ; preds = %21
%27 = load i8**, i8*** %5
%28 = load i32, i32* %8
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8*, i8** %27, i64 %29
%31 = load i8*, i8** %30
%32 = getelementptr inbounds i8, i8* %31, i64 0
%33 = load i8, i8* %32
%34 = sext i8 %33 to i32
%35 = icmp ne i32 %34, 45
br i1 %35, label %36, label %37
36: ; preds = %26
br label %55
37: ; preds = %26
%38 = load i8**, i8*** %5
%39 = load i32, i32* %8
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds i8*, i8** %38, i64 %40
%42 = load i8*, i8** %41
%43 = load i32, i32* %6
%44 = call i32 @should_ignore_case(i8* %42, i32 %43)
store i32 %44, i32* %6
%45 = load i8**, i8*** %5
%46 = load i32, i32* %8
%47 = sext i32 %46 to i64
%48 = getelementptr inbounds i8*, i8** %45, i64 %47
%49 = load i8*, i8** %48
%50 = load i32, i32* %7
%51 = call i32 @should_contain_number_lines(i8* %49, i32 %50)
store i32 %51, i32* %7
br label %52
52: ; preds = %37
%53 = load i32, i32* %8
%54 = add nsw i32 %53, 1
store i32 %54, i32* %8
br label %21
55: ; preds = %36, %21
%56 = load i8**, i8*** %5
%57 = load i32, i32* %8
%58 = sext i32 %57 to i64
%59 = getelementptr inbounds i8*, i8** %56, i64 %58
%60 = load i8*, i8** %59
store i8* %60, i8** %9
%61 = load i8*, i8** %9
%62 = call i32 @strlen(i8* %61)
%63 = icmp sgt i32 %62, 100
br i1 %63, label %64, label %68
64: ; preds = %55
%65 = load i32, i32* @stderr
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 100)
%67 = call i32 @exit(i32 -1)
unreachable
68: ; preds = %55
%69 = load i32, i32* %6
%70 = icmp ne i32 %69, 0
br i1 %70, label %71, label %74
71: ; preds = %68
%72 = load i8*, i8** %9
%73 = call i32 @normalize(i8* %72)
br label %74
74: ; preds = %71, %68
%75 = load i32, i32* %8
%76 = add nsw i32 %75, 1
store i32 %76, i32* %8
br label %77
77: ; preds = %112, %74
%78 = load i32, i32* %8
%79 = load i32, i32* %4
%80 = icmp slt i32 %78, %79
br i1 %80, label %81, label %115
81: ; preds = %77
%82 = load i8**, i8*** %5
%83 = load i32, i32* %8
%84 = sext i32 %83 to i64
%85 = getelementptr inbounds i8*, i8** %82, i64 %84
%86 = load i8*, i8** %85
%87 = call i32* @fopen(i8* %86, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
store i32* %87, i32** %10
%88 = load i32*, i32** %10
%89 = icmp eq i32* %88, null
br i1 %89, label %90, label %99
90: ; preds = %81
%91 = load i32, i32* @stderr
%92 = load i8**, i8*** %5
%93 = load i32, i32* %8
%94 = sext i32 %93 to i64
%95 = getelementptr inbounds i8*, i8** %92, i64 %94
%96 = load i8*, i8** %95
%97 = load i32, i32* @errno
%98 = call i32 (i32, i8*, ...) @fprintf(i32 %91, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %96, i32 %97)
br label %112
99: ; preds = %81
%100 = load i32, i32* %6
%101 = load i32, i32* %7
%102 = load i8**, i8*** %5
%103 = load i32, i32* %8
%104 = sext i32 %103 to i64
%105 = getelementptr inbounds i8*, i8** %102, i64 %104
%106 = load i8*, i8** %105
%107 = load i32*, i32** %10
%108 = load i8*, i8** %9
%109 = call i32 @do_pattern_matching(i32 %100, i32 %101, i8* %106, i32* %107, i8* %108)
%110 = load i32*, i32** %10
%111 = call i32 @fclose(i32* %110)
br label %112
112: ; preds = %99, %90
%113 = load i32, i32* %8
%114 = add nsw i32 %113, 1
store i32 %114, i32* %8
br label %77
115: ; preds = %77
%116 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [36 x i8] c"Usage: %s [options] STRING FILE...\0A\00"
@.str.1 = [34 x i8] c"Pattern is longer than %d length\0A\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [35 x i8] c"Error opening file: %s, error: %d\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 3
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = add nsw i32 %0, -2
%6 = icmp eq i32 %0, 3
br i1 %6, label %30, label %7
7: ; preds = %4
%8 = zext i32 %5 to i64
br label %14
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8*, i8** %1
%12 = tail call i32 (i32, i8*, ...) @fprintf(i32 %10, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str, i64 0, i64 0), i8* %11)
%13 = tail call i32 @exit(i32 -1)
unreachable
14: ; preds = %7, %22
%15 = phi i64 [ 1, %7 ], [ %26, %22 ]
%16 = phi i32 [ 0, %7 ], [ %23, %22 ]
%17 = phi i32 [ 0, %7 ], [ %25, %22 ]
%18 = getelementptr inbounds i8*, i8** %1, i64 %15
%19 = load i8*, i8** %18
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 45
br i1 %21, label %22, label %28
22: ; preds = %14
%23 = tail call i32 @should_ignore_case(i8* %19, i32 %16)
%24 = load i8*, i8** %18
%25 = tail call i32 @should_contain_number_lines(i8* %24, i32 %17)
%26 = add nuw nsw i64 %15, 1
%27 = icmp eq i64 %26, %8
br i1 %27, label %30, label %14
28: ; preds = %14
%29 = trunc i64 %15 to i32
br label %30
30: ; preds = %22, %28, %4
%31 = phi i32 [ 1, %4 ], [ %29, %28 ], [ %5, %22 ]
%32 = phi i32 [ 0, %4 ], [ %17, %28 ], [ %25, %22 ]
%33 = phi i32 [ 0, %4 ], [ %16, %28 ], [ %23, %22 ]
%34 = zext i32 %31 to i64
%35 = getelementptr inbounds i8*, i8** %1, i64 %34
%36 = load i8*, i8** %35
%37 = tail call i32 @strlen(i8* %36)
%38 = icmp sgt i32 %37, 100
br i1 %38, label %39, label %43
39: ; preds = %30
%40 = load i32, i32* @stderr
%41 = tail call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.1, i64 0, i64 0), i32 100)
%42 = tail call i32 @exit(i32 -1)
unreachable
43: ; preds = %30
%44 = icmp eq i32 %33, 0
br i1 %44, label %47, label %45
45: ; preds = %43
%46 = tail call i32 @normalize(i8* %36)
br label %47
47: ; preds = %45, %43
%48 = add i32 %31, 1
%49 = icmp slt i32 %48, %0
br i1 %49, label %50, label %71
50: ; preds = %47
%51 = zext i32 %48 to i64
br label %52
52: ; preds = %50, %67
%53 = phi i64 [ %51, %50 ], [ %68, %67 ]
%54 = getelementptr inbounds i8*, i8** %1, i64 %53
%55 = load i8*, i8** %54
%56 = tail call i32* @fopen(i8* %55, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%57 = icmp eq i32* %56, null
br i1 %57, label %58, label %63
58: ; preds = %52
%59 = load i32, i32* @stderr
%60 = load i8*, i8** %54
%61 = load i32, i32* @errno
%62 = tail call i32 (i32, i8*, ...) @fprintf(i32 %59, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.3, i64 0, i64 0), i8* %60, i32 %61)
br label %67
63: ; preds = %52
%64 = load i8*, i8** %54
%65 = tail call i32 @do_pattern_matching(i32 %33, i32 %32, i8* %64, i32* %56, i8* %36)
%66 = tail call i32 @fclose(i32* %56)
br label %67
67: ; preds = %63, %58
%68 = add nuw nsw i64 %53, 1
%69 = trunc i64 %68 to i32
%70 = icmp slt i32 %69, %0
br i1 %70, label %52, label %71
71: ; preds = %67, %47
%72 = tail call i32 @exit(i32 0)
unreachable
}