#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ stderr;
char *strdup(char *);
char *strerror(int /*<<< orphan*/);
scalar_t__ strstr(char *, char *);
char tolower(char);
int main(int argc, char **argv) {
  int i;
  FILE *f;
  char *word;
  char line[2048];
  char *lline;
  char *c;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s <word> <filename1> <filename2> ...\n", argv[0]);
    return -1;
  }
  for (word = argv[1]; *word != '\0'; word++)
    *word = tolower(*word);
  word = argv[1];
  for (i = 2; i < argc; i++) {
    f = fopen(argv[i], "r");
    if (f == NULL) {
      fprintf(stderr, "Error: %s\n", strerror(errno));
      continue;
    }
    while (fgets(line, 2048, f) != NULL) {
      lline = strdup(line);
      for (c = lline; *c != '\0'; c++)
        *c = tolower(*c);
      if (strstr(lline, word))
        printf("%s", line);
      free(lline);
    }
    fclose(f);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x850,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11eb <main+0x4b>
mov    0x2e16(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe26(%rip),%rsi
call   1070 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    138e <main+0x1ee>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     122c <main+0x8c>
mov    -0x28(%rbp),%rax
movsbl (%rax),%edi
call   1080 <tolower@plt>
mov    %al,%cl
mov    -0x28(%rbp),%rax
mov    %cl,(%rax)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    11f7 <main+0x57>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1387 <main+0x1e7>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdd0(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    12a9 <main+0x109>
mov    0x2d67(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x844(%rbp)
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x844(%rbp),%edi
mov    %rax,%rdx
lea    0xd91(%rip),%rsi
call   1070 <fprintf@plt>
jmp    1379 <main+0x1d9>
jmp    12ae <main+0x10e>
lea    -0x830(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x800,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1370 <main+0x1d0>
lea    -0x830(%rbp),%rdi
call   10a0 <strdup@plt>
mov    %rax,-0x838(%rbp)
mov    -0x838(%rbp),%rax
mov    %rax,-0x840(%rbp)
mov    -0x840(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
je     1332 <main+0x192>
mov    -0x840(%rbp),%rax
movsbl (%rax),%edi
call   1080 <tolower@plt>
mov    %al,%cl
mov    -0x840(%rbp),%rax
mov    %cl,(%rax)
mov    -0x840(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x840(%rbp)
jmp    12ee <main+0x14e>
mov    -0x838(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   10c0 <strstr@plt>
cmp    $0x0,%rax
je     135f <main+0x1bf>
lea    -0x830(%rbp),%rsi
lea    0xce1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x838(%rbp),%rdi
call   1030 <free@plt>
jmp    12ae <main+0x10e>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123f <main+0x9f>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x850,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x818,%rsp
mov    %rsi,%r12
cmp    $0x1,%edi
jg     11dc <main+0x3c>
mov    0x2e20(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe33(%rip),%rsi
call   1070 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1321 <main+0x181>
mov    %edi,%ebp
mov    0x8(%r12),%rbx
mov    (%rbx),%al
test   %al,%al
je     120b <main+0x6b>
add    $0x1,%rbx
nopl   (%rax)
movsbl %al,%edi
call   1080 <tolower@plt>
mov    %al,-0x1(%rbx)
movzbl (%rbx),%eax
add    $0x1,%rbx
test   %al,%al
jne    11f0 <main+0x50>
mov    0x8(%r12),%rbx
xor    %eax,%eax
cmp    $0x3,%ebp
jl     1321 <main+0x181>
mov    %ebp,%eax
mov    %rax,0x8(%rsp)
mov    $0x2,%r14d
lea    0x10(%rsp),%rbp
mov    %r12,(%rsp)
jmp    124b <main+0xab>
xchg   %ax,%ax
mov    %r15,%rdi
call   1040 <fclose@plt>
mov    (%rsp),%r12
add    $0x1,%r14
cmp    0x8(%rsp),%r14
je     131f <main+0x17f>
mov    (%r12,%r14,8),%rdi
lea    0xdd8(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     12f0 <main+0x150>
mov    %rax,%r15
jmp    1278 <main+0xd8>
nopl   0x0(%rax)
mov    %r13,%rdi
call   1030 <free@plt>
mov    %rbp,%rdi
mov    $0x800,%esi
mov    %r15,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     1230 <main+0x90>
mov    %rbp,%rdi
call   10a0 <strdup@plt>
mov    %rax,%r13
mov    (%rax),%al
test   %al,%al
je     12ca <main+0x12a>
lea    0x1(%r13),%r12
cs nopw 0x0(%rax,%rax,1)
nopl   0x0(%rax)
movsbl %al,%edi
call   1080 <tolower@plt>
mov    %al,-0x1(%r12)
movzbl (%r12),%eax
add    $0x1,%r12
test   %al,%al
jne    12b0 <main+0x110>
mov    %r13,%rdi
mov    %rbx,%rsi
call   10c0 <strstr@plt>
test   %rax,%rax
je     1270 <main+0xd0>
lea    0xd5a(%rip),%rdi
mov    %rbp,%rsi
call   1050 <printf@plt>
jmp    1270 <main+0xd0>
nopl   0x0(%rax,%rax,1)
mov    0x2ce9(%rip),%rax
mov    (%rax),%r15d
mov    0x2cd7(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    %r15d,%edi
lea    0xd1e(%rip),%rsi
mov    %rax,%rdx
call   1070 <fprintf@plt>
jmp    123c <main+0x9c>
xor    %eax,%eax
add    $0x818,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@stderr = global i32 0
@.str = [46 x i8] c"Usage: %s <word> <filename1> <filename2> ...\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"Error: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
%8 = alloca i8*
%9 = alloca [2048 x i8]
%10 = alloca i8*
%11 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* %4
%13 = icmp slt i32 %12, 2
br i1 %13, label %14, label %20
14: ; preds = %2
%15 = load i32, i32* @stderr
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i64 0
%18 = load i8*, i8** %17
%19 = call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %18)
store i32 -1, i32* %3
br label %100
20: ; preds = %2
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 1
%23 = load i8*, i8** %22
store i8* %23, i8** %8
br label %24
24: ; preds = %34, %20
%25 = load i8*, i8** %8
%26 = load i8, i8* %25
%27 = sext i8 %26 to i32
%28 = icmp ne i32 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %24
%30 = load i8*, i8** %8
%31 = load i8, i8* %30
%32 = call signext i8 @tolower(i8 signext %31)
%33 = load i8*, i8** %8
store i8 %32, i8* %33
br label %34
34: ; preds = %29
%35 = load i8*, i8** %8
%36 = getelementptr inbounds i8, i8* %35, i32 1
store i8* %36, i8** %8
br label %24
37: ; preds = %24
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 1
%40 = load i8*, i8** %39
store i8* %40, i8** %8
store i32 2, i32* %6
br label %41
41: ; preds = %96, %37
%42 = load i32, i32* %6
%43 = load i32, i32* %4
%44 = icmp slt i32 %42, %43
br i1 %44, label %45, label %99
45: ; preds = %41
%46 = load i8**, i8*** %5
%47 = load i32, i32* %6
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8*, i8** %46, i64 %48
%50 = load i8*, i8** %49
%51 = call i32* @fopen(i8* %50, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %51, i32** %7
%52 = load i32*, i32** %7
%53 = icmp eq i32* %52, null
br i1 %53, label %54, label %59
54: ; preds = %45
%55 = load i32, i32* @stderr
%56 = load i32, i32* @errno
%57 = call i8* @strerror(i32 %56)
%58 = call i32 @fprintf(i32 %55, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %57)
br label %96
59: ; preds = %45
br label %60
60: ; preds = %90, %59
%61 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%62 = load i32*, i32** %7
%63 = call i32* @fgets(i8* %61, i32 2048, i32* %62)
%64 = icmp ne i32* %63, null
br i1 %64, label %65, label %93
65: ; preds = %60
%66 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%67 = call i8* @strdup(i8* %66)
store i8* %67, i8** %10
%68 = load i8*, i8** %10
store i8* %68, i8** %11
br label %69
69: ; preds = %79, %65
%70 = load i8*, i8** %11
%71 = load i8, i8* %70
%72 = sext i8 %71 to i32
%73 = icmp ne i32 %72, 0
br i1 %73, label %74, label %82
74: ; preds = %69
%75 = load i8*, i8** %11
%76 = load i8, i8* %75
%77 = call signext i8 @tolower(i8 signext %76)
%78 = load i8*, i8** %11
store i8 %77, i8* %78
br label %79
79: ; preds = %74
%80 = load i8*, i8** %11
%81 = getelementptr inbounds i8, i8* %80, i32 1
store i8* %81, i8** %11
br label %69
82: ; preds = %69
%83 = load i8*, i8** %10
%84 = load i8*, i8** %8
%85 = call i64 @strstr(i8* %83, i8* %84)
%86 = icmp ne i64 %85, 0
br i1 %86, label %87, label %90
87: ; preds = %82
%88 = getelementptr inbounds [2048 x i8], [2048 x i8]* %9, i64 0, i64 0
%89 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %88)
br label %90
90: ; preds = %87, %82
%91 = load i8*, i8** %10
%92 = call i32 @free(i8* %91)
br label %60
93: ; preds = %60
%94 = load i32*, i32** %7
%95 = call i32 @fclose(i32* %94)
br label %96
96: ; preds = %93, %54
%97 = load i32, i32* %6
%98 = add nsw i32 %97, 1
store i32 %98, i32* %6
br label %41
99: ; preds = %41
store i32 0, i32* %3
br label %100
100: ; preds = %99, %14
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [46 x i8] c"Usage: %s <word> <filename1> <filename2> ...\0A\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [11 x i8] c"Error: %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2048 x i8]
%4 = getelementptr inbounds [2048 x i8], [2048 x i8]* %3, i64 0, i64 0
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %68
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i8, i8* %12
%14 = icmp eq i8 %13, 0
br i1 %14, label %24, label %15
15: ; preds = %10, %15
%16 = phi i8 [ %20, %15 ], [ %13, %10 ]
%17 = phi i8* [ %19, %15 ], [ %12, %10 ]
%18 = tail call signext i8 @tolower(i8 signext %16)
store i8 %18, i8* %17
%19 = getelementptr inbounds i8, i8* %17, i64 1
%20 = load i8, i8* %19
%21 = icmp eq i8 %20, 0
br i1 %21, label %22, label %15
22: ; preds = %15
%23 = load i8*, i8** %11
br label %24
24: ; preds = %22, %10
%25 = phi i8* [ %23, %22 ], [ %12, %10 ]
%26 = icmp sgt i32 %0, 2
br i1 %26, label %27, label %68
27: ; preds = %24
%28 = zext i32 %0 to i64
br label %29
29: ; preds = %27, %65
%30 = phi i64 [ 2, %27 ], [ %66, %65 ]
%31 = getelementptr inbounds i8*, i8** %1, i64 %30
%32 = load i8*, i8** %31
%33 = call i32* @fopen(i8* %32, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%34 = icmp eq i32* %33, null
br i1 %34, label %38, label %35
35: ; preds = %29
%36 = call i32* @fgets(i8* %4, i32 2048, i32* %33)
%37 = icmp eq i32* %36, null
br i1 %37, label %63, label %43
38: ; preds = %29
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 @fprintf(i32 %39, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.2, i64 0, i64 0), i8* %41)
br label %65
43: ; preds = %35, %59
%44 = call i8* @strdup(i8* %4)
%45 = load i8, i8* %44
%46 = icmp eq i8 %45, 0
br i1 %46, label %54, label %47
47: ; preds = %43, %47
%48 = phi i8 [ %52, %47 ], [ %45, %43 ]
%49 = phi i8* [ %51, %47 ], [ %44, %43 ]
%50 = call signext i8 @tolower(i8 signext %48)
store i8 %50, i8* %49
%51 = getelementptr inbounds i8, i8* %49, i64 1
%52 = load i8, i8* %51
%53 = icmp eq i8 %52, 0
br i1 %53, label %54, label %47
54: ; preds = %47, %43
%55 = call i64 @strstr(i8* %44, i8* %25)
%56 = icmp eq i64 %55, 0
br i1 %56, label %59, label %57
57: ; preds = %54
%58 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %4)
br label %59
59: ; preds = %57, %54
%60 = call i32 @free(i8* %44)
%61 = call i32* @fgets(i8* %4, i32 2048, i32* %33)
%62 = icmp eq i32* %61, null
br i1 %62, label %63, label %43
63: ; preds = %59, %35
%64 = call i32 @fclose(i32* %33)
br label %65
65: ; preds = %63, %38
%66 = add nuw nsw i64 %30, 1
%67 = icmp eq i64 %66, %28
br i1 %67, label %68, label %29
68: ; preds = %65, %24, %6
%69 = phi i32 [ -1, %6 ], [ 0, %24 ], [ 0, %65 ]
ret i32 %69
}