#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ printf(char *, unsigned int, char *, ...);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int /*<<< orphan*/ *strstr(char *, char *);
int main(int argc, char *argv[]) {
  char *prog = argv[0];
  if (argc < 2) {
    fprintf(stderr, "Usage:%s line [file1 file2 ...]\n", prog);
    return 1;
  }
  char *dst = argv[1];
  char line[1000];
  unsigned int linenum = 0;
  if (argc == 2) {
    while (fgets(line, 1000, stdin) != NULL) {
      linenum++;
      if (strstr(line, dst) != NULL) {
        printf("find it! at line %d in stdin\n%s", linenum, line);
      }
    }
  } else {
    int i;
    FILE *fp;
    for (i = 2; i < argc; i++) {
      if ((fp = fopen(argv[i], "r")) == NULL) {
        fprintf(stderr, "error:can't open file %s\n", argv[i]);
        return 0;
      }
      while (fgets(line, 1000, fp) != NULL) {
        linenum++;
        if (strstr(line, dst) != NULL) {
          printf("find it! at line %d for %s\n %s", linenum, argv[i], line);
        }
      }
      fclose(fp);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    11b3 <main+0x53>
mov    0x2e43(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe5e(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    136b <main+0x20b>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x414(%rbp)
cmpl   $0x2,-0x8(%rbp)
jne    124b <main+0xeb>
jmp    11d8 <main+0x78>
lea    -0x410(%rbp),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     1246 <main+0xe6>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     1241 <main+0xe1>
mov    -0x414(%rbp),%esi
lea    -0x410(%rbp),%rdx
lea    0xde7(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    11d8 <main+0x78>
jmp    1364 <main+0x204>
movl   $0x2,-0x418(%rbp)
mov    -0x418(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    135f <main+0x1ff>
mov    -0x10(%rbp),%rax
movslq -0x418(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xdc7(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x420(%rbp)
cmp    $0x0,%rax
jne    12c0 <main+0x160>
mov    0x2d41(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
movslq -0x418(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xd94(%rip),%rsi
call   1060 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    136b <main+0x20b>
jmp    12c5 <main+0x165>
lea    -0x410(%rbp),%rdi
mov    -0x420(%rbp),%rdx
mov    $0x3e8,%esi
call   1050 <fgets@plt>
cmp    $0x0,%rax
je     133f <main+0x1df>
mov    -0x414(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x414(%rbp)
lea    -0x410(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1080 <strstr@plt>
cmp    $0x0,%rax
je     133a <main+0x1da>
mov    -0x414(%rbp),%esi
mov    -0x10(%rbp),%rax
movslq -0x418(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    -0x410(%rbp),%rcx
lea    0xd2a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
jmp    12c5 <main+0x165>
mov    -0x420(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x418(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x418(%rbp)
jmp    1255 <main+0xf5>
jmp    1364 <main+0x204>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x3f8,%rsp
mov    %rsi,%r14
cmp    $0x1,%edi
jg     119b <main+0x3b>
mov    (%r14),%rdx
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
lea    0xe74(%rip),%rsi
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    12cc <main+0x16c>
mov    0x8(%r14),%r12
cmp    $0x2,%edi
jne    121d <main+0xbd>
mov    0x2e3d(%rip),%r15
mov    (%r15),%rdx
lea    0x10(%rsp),%rdi
mov    $0x3e8,%esi
call   1050 <fgets@plt>
test   %rax,%rax
je     12ca <main+0x16a>
mov    $0x1,%ebx
lea    0x10(%rsp),%rbp
lea    0xe4a(%rip),%r14
jmp    11fc <main+0x9c>
nopl   0x0(%rax)
mov    (%r15),%rdx
mov    %rbp,%rdi
mov    $0x3e8,%esi
call   1050 <fgets@plt>
add    $0x1,%ebx
test   %rax,%rax
je     12ca <main+0x16a>
mov    %rbp,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     11e0 <main+0x80>
mov    %r14,%rdi
mov    %ebx,%esi
mov    %rbp,%rdx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    11e0 <main+0x80>
mov    %edi,%eax
mov    %rax,0x8(%rsp)
mov    $0x2,%r13d
lea    0x10(%rsp),%rbx
xor    %ebp,%ebp
jmp    1253 <main+0xf3>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1030 <fclose@plt>
add    $0x1,%r13
cmp    0x8(%rsp),%r13
je     12ca <main+0x16a>
mov    (%r14,%r13,8),%rdi
lea    0xde3(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     12b1 <main+0x151>
mov    %rax,%r15
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x3e8,%esi
mov    %r15,%rdx
call   1050 <fgets@plt>
test   %rax,%rax
je     1240 <main+0xe0>
add    $0x1,%ebp
mov    %rbx,%rdi
mov    %r12,%rsi
call   1080 <strstr@plt>
test   %rax,%rax
je     1270 <main+0x110>
mov    (%r14,%r13,8),%rdx
lea    0xdba(%rip),%rdi
mov    %ebp,%esi
mov    %rbx,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
jmp    1270 <main+0x110>
mov    0x2d20(%rip),%rax
mov    (%rax),%edi
mov    (%r14,%r13,8),%rdx
lea    0xd7e(%rip),%rsi
call   1060 <fprintf@plt>
xor    %eax,%eax
add    $0x3f8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@stderr = global i32 0
@.str = [33 x i8] c"Usage:%s line [file1 file2 ...]\0A\00"
@stdin = global i32* null
@.str.1 = [32 x i8] c"find it! at line %d in stdin\0A%s\00"
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [26 x i8] c"error:can't open file %s\0A\00"
@.str.4 = [31 x i8] c"find it! at line %d for %s\0A %s\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [1000 x i8]
%4 = icmp slt i32 %0, 2
br i1 %4, label %5, label %9
5: ; preds = %2
%6 = load i8*, i8** %1
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %62
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = getelementptr inbounds [1000 x i8], [1000 x i8]* %3, i64 0, i64 0
%13 = icmp eq i32 %0, 2
br i1 %13, label %16, label %14
14: ; preds = %9
%15 = zext i32 %0 to i64
br label %31
16: ; preds = %9
%17 = load i32*, i32** @stdin
%18 = call i32* @fgets(i8* %12, i32 1000, i32* %17)
%19 = icmp eq i32* %18, null
br i1 %19, label %61, label %20
20: ; preds = %16, %27
%21 = phi i32 [ %22, %27 ], [ 0, %16 ]
%22 = add i32 %21, 1
%23 = call i32* @strstr(i8* %12, i8* dereferenceable(1) %11)
%24 = icmp eq i32* %23, null
br i1 %24, label %27, label %25
25: ; preds = %20
%26 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i32 %22, i8* %12)
br label %27
27: ; preds = %25, %20
%28 = load i32*, i32** @stdin
%29 = call i32* @fgets(i8* %12, i32 1000, i32* %28)
%30 = icmp eq i32* %29, null
br i1 %30, label %61, label %20
31: ; preds = %14, %56
%32 = phi i64 [ 2, %14 ], [ %59, %56 ]
%33 = phi i32 [ 0, %14 ], [ %57, %56 ]
%34 = getelementptr inbounds i8*, i8** %1, i64 %32
%35 = load i8*, i8** %34
%36 = call i32* @fopen(i8* %35, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i32* %36, null
br i1 %37, label %41, label %38
38: ; preds = %31
%39 = call i32* @fgets(i8* %12, i32 1000, i32* %36)
%40 = icmp eq i32* %39, null
br i1 %40, label %56, label %45
41: ; preds = %31
%42 = load i32, i32* @stderr
%43 = load i8*, i8** %34
%44 = call i32 @fprintf(i32 %42, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.3, i64 0, i64 0), i8* %43)
br label %61
45: ; preds = %38, %53
%46 = phi i32 [ %47, %53 ], [ %33, %38 ]
%47 = add i32 %46, 1
%48 = call i32* @strstr(i8* %12, i8* dereferenceable(1) %11)
%49 = icmp eq i32* %48, null
br i1 %49, label %53, label %50
50: ; preds = %45
%51 = load i8*, i8** %34
%52 = call i32 (i8*, i32, i8*, ...) @printf(i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.4, i64 0, i64 0), i32 %47, i8* %51, i8* %12)
br label %53
53: ; preds = %50, %45
%54 = call i32* @fgets(i8* %12, i32 1000, i32* %36)
%55 = icmp eq i32* %54, null
br i1 %55, label %56, label %45
56: ; preds = %53, %38
%57 = phi i32 [ %33, %38 ], [ %47, %53 ]
%58 = call i32 @fclose(i32* %36)
%59 = add nuw nsw i64 %32, 1
%60 = icmp eq i64 %59, %15
br i1 %60, label %61, label %31
61: ; preds = %56, %27, %16, %41
br label %62
62: ; preds = %61, %5
%63 = phi i32 [ 1, %5 ], [ 0, %61 ]
ret i32 %63
}