#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*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ normalize(char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ stdout;
int /*<<< orphan*/ strncpy(char *, char *, int);
char *strstr(char *, char *);
void do_pattern_matching(bool ignore_case, bool contain_number_lines,
                         char *filename, FILE *file, char *pattern) {
  int lineno = 1;
  char buffer[500];
  char orig[500];
  while (fgets(buffer, 500, file) != NULL) {
    if (ignore_case) {
      strncpy(orig, buffer, 500);
      normalize(buffer);
    }
    char *match = strstr(buffer, pattern);
    if (match != NULL) {
      if (contain_number_lines) {
        fprintf(stdout, "%s, %d: %s\n", filename, lineno, orig);
      } else {
        fprintf(stdout, "%s: %s\n", filename, orig);
      }
    }
    lineno += 1;
  }
  if (!feof(file)) {
    fprintf(stderr, "Encountered error while reading %s\n", filename);
  }
}


x86 assembly (clang, -O0):
<do_pattern_matching>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %edi,-0x4(%rbp)
mov    %esi,-0x8(%rbp)
mov    %rdx,-0x10(%rbp)
mov    %rcx,-0x18(%rbp)
mov    %r8,-0x20(%rbp)
movl   $0x1,-0x24(%rbp)
lea    -0x220(%rbp),%rdi
mov    -0x18(%rbp),%rdx
mov    $0x1f4,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     125f <do_pattern_matching+0xff>
cmpl   $0x0,-0x4(%rbp)
je     11d1 <do_pattern_matching+0x71>
lea    -0x420(%rbp),%rdi
lea    -0x220(%rbp),%rsi
mov    $0x1f4,%edx
call   1030 <strncpy@plt>
lea    -0x220(%rbp),%rdi
call   1050 <normalize@plt>
lea    -0x220(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
je     1251 <do_pattern_matching+0xf1>
cmpl   $0x0,-0x8(%rbp)
je     122a <do_pattern_matching+0xca>
mov    0x2dd1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
mov    -0x24(%rbp),%ecx
lea    -0x420(%rbp),%r8
lea    0xde2(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    124c <do_pattern_matching+0xec>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    -0x420(%rbp),%rcx
lea    0xdc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
jmp    1251 <do_pattern_matching+0xf1>
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1184 <do_pattern_matching+0x24>
mov    -0x18(%rbp),%rdi
call   1070 <feof@plt>
cmp    $0x0,%eax
jne    128c <do_pattern_matching+0x12c>
mov    0x2d68(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd8f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<do_pattern_matching>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x408,%rsp
mov    %r8,%r15
mov    %rcx,%rbx
mov    %rdx,(%rsp)
mov    %esi,0xc(%rsp)
mov    %edi,%r13d
lea    0x10(%rsp),%rdi
mov    $0x1f4,%esi
mov    %rcx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1243 <do_pattern_matching+0xe3>
mov    $0x1,%ebp
lea    0x10(%rsp),%r14
lea    0x210(%rsp),%r12
jmp    11ed <do_pattern_matching+0x8d>
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax,%rax,1)
lea    0xe45(%rip),%rsi
mov    (%rsp),%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x1,%ebp
mov    %r14,%rdi
mov    $0x1f4,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     1243 <do_pattern_matching+0xe3>
test   %r13d,%r13d
je     120a <do_pattern_matching+0xaa>
mov    %r12,%rdi
mov    %r14,%rsi
mov    $0x1f4,%edx
call   1030 <strncpy@plt>
mov    %r14,%rdi
call   1050 <normalize@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11d5 <do_pattern_matching+0x75>
mov    0x2db7(%rip),%rax
mov    (%rax),%edi
cmpl   $0x0,0xc(%rsp)
je     11c0 <do_pattern_matching+0x60>
lea    0xdcf(%rip),%rsi
mov    (%rsp),%rdx
mov    %ebp,%ecx
mov    %r12,%r8
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    11d5 <do_pattern_matching+0x75>
mov    %rbx,%rdi
call   1070 <feof@plt>
test   %eax,%eax
jne    126a <do_pattern_matching+0x10a>
mov    0x2d8a(%rip),%rax
mov    (%rax),%edi
lea    0xdb5(%rip),%rsi
mov    (%rsp),%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
add    $0x408,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stdout = global i32 0
@.str = [12 x i8] c"%s, %d: %s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Encountered error while reading %s\0A\00"
define void @do_pattern_matching(i32 %0, i32 %1, i8* %2, i32* %3, i8* %4) {
%6 = alloca i32
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i32*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca [500 x i8]
%13 = alloca [500 x i8]
%14 = alloca i8*
store i32 %0, i32* %6
store i32 %1, i32* %7
store i8* %2, i8** %8
store i32* %3, i32** %9
store i8* %4, i8** %10
store i32 1, i32* %11
br label %15
15: ; preds = %50, %5
%16 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%17 = load i32*, i32** %9
%18 = call i32* @fgets(i8* %16, i32 500, i32* %17)
%19 = icmp ne i32* %18, null
br i1 %19, label %20, label %53
20: ; preds = %15
%21 = load i32, i32* %6
%22 = icmp ne i32 %21, 0
br i1 %22, label %23, label %29
23: ; preds = %20
%24 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%25 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%26 = call i32 @strncpy(i8* %24, i8* %25, i32 500)
%27 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%28 = call i32 @normalize(i8* %27)
br label %29
29: ; preds = %23, %20
%30 = getelementptr inbounds [500 x i8], [500 x i8]* %12, i64 0, i64 0
%31 = load i8*, i8** %10
%32 = call i8* @strstr(i8* %30, i8* %31)
store i8* %32, i8** %14
%33 = load i8*, i8** %14
%34 = icmp ne i8* %33, null
br i1 %34, label %35, label %50
35: ; preds = %29
%36 = load i32, i32* %7
%37 = icmp ne i32 %36, 0
br i1 %37, label %38, label %44
38: ; preds = %35
%39 = load i32, i32* @stdout
%40 = load i8*, i8** %8
%41 = load i32, i32* %11
%42 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%43 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %40, i32 %41, i8* %42)
br label %49
44: ; preds = %35
%45 = load i32, i32* @stdout
%46 = load i8*, i8** %8
%47 = getelementptr inbounds [500 x i8], [500 x i8]* %13, i64 0, i64 0
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %46, i8* %47)
br label %49
49: ; preds = %44, %38
br label %50
50: ; preds = %49, %29
%51 = load i32, i32* %11
%52 = add nsw i32 %51, 1
store i32 %52, i32* %11
br label %15
53: ; preds = %15
%54 = load i32*, i32** %9
%55 = call i32 @feof(i32* %54)
%56 = icmp ne i32 %55, 0
br i1 %56, label %61, label %57
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %8
%60 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %59)
br label %61
61: ; preds = %57, %53
ret void
}

LLVM IR (-O2):
@stdout = global i32 0
@.str = [12 x i8] c"%s, %d: %s\0A\00"
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@stderr = global i32 0
@.str.2 = [36 x i8] c"Encountered error while reading %s\0A\00"
define void @do_pattern_matching(i32 %0, i32 %1, i8* %2, i32* nocapture %3, i8* nocapture %4) {
%6 = alloca [500 x i8]
%7 = alloca [500 x i8]
%8 = getelementptr inbounds [500 x i8], [500 x i8]* %6, i64 0, i64 0
%9 = getelementptr inbounds [500 x i8], [500 x i8]* %7, i64 0, i64 0
%10 = call i32* @fgets(i8* %8, i32 500, i32* %3)
%11 = icmp eq i32* %10, null
br i1 %11, label %33, label %12
12: ; preds = %5
%13 = icmp eq i32 %0, 0
%14 = icmp eq i32 %1, 0
br label %15
15: ; preds = %12, %29
%16 = phi i32 [ 1, %12 ], [ %30, %29 ]
br i1 %13, label %20, label %17
17: ; preds = %15
%18 = call i32 @strncpy(i8* %9, i8* %8, i32 500)
%19 = call i32 @normalize(i8* %8)
br label %20
20: ; preds = %17, %15
%21 = call i8* @strstr(i8* %8, i8* dereferenceable(1) %4)
%22 = icmp eq i8* %21, null
br i1 %22, label %29, label %23
23: ; preds = %20
%24 = load i32, i32* @stdout
br i1 %14, label %27, label %25
25: ; preds = %23
%26 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* %2, i32 %16, i8* %9)
br label %29
27: ; preds = %23
%28 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %2, i8* %9)
br label %29
29: ; preds = %25, %27, %20
%30 = add nuw nsw i32 %16, 1
%31 = call i32* @fgets(i8* %8, i32 500, i32* %3)
%32 = icmp eq i32* %31, null
br i1 %32, label %33, label %15
33: ; preds = %29, %5
%34 = call i32 @feof(i32* %3)
%35 = icmp eq i32 %34, 0
br i1 %35, label %36, label %39
36: ; preds = %33
%37 = load i32, i32* @stderr
%38 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %37, i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %39
39: ; preds = %36, %33
ret void
}