#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*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int /*<<< orphan*/ search_file(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int argc, char *argv[]) {
  int file_index;
  FILE *fp;
  if (argc < 2) {
    fprintf(stderr, "Usage: %s pattern [file1] [file2] ...\n", argv[0]);
    return 0;
  }
  if (argc == 2) {
    search_file(argv[1], "<STDIN>", stdin);
  } else {
    for (file_index = 2; file_index < argc; file_index++) {
      if ((fp = fopen(argv[file_index], "r")) == NULL) {
        fprintf(stderr, "%s: Could not open file %s\n", argv[0],
                argv[file_index]);
        continue;
      }
      search_file(argv[1], argv[file_index], fp);
      fclose(fp);
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
jge    118a <main+0x4a>
mov    0x2e71(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe89(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0x0,-0x4(%rbp)
jmp    125f <main+0x11f>
cmpl   $0x2,-0x8(%rbp)
jne    11b7 <main+0x77>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e45(%rip),%rax
mov    (%rax),%rdx
lea    0xe7a(%rip),%rsi
call   1060 <search_file@plt>
jmp    1258 <main+0x118>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    1253 <main+0x113>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe52(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    121f <main+0xdf>
mov    0x2de1(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rcx
lea    0xe1e(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
jmp    1245 <main+0x105>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rsi
mov    -0x20(%rbp),%rdx
call   1060 <search_file@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    11be <main+0x7e>
jmp    1258 <main+0x118>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r12
cmp    $0x1,%edi
jg     1170 <main+0x30>
mov    0x2e7e(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
lea    0xe99(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    1190 <main+0x50>
cmp    $0x2,%edi
jne    11a1 <main+0x61>
mov    0x8(%r12),%rdi
mov    0x2e67(%rip),%rax
mov    (%rax),%rdx
lea    0xe9c(%rip),%rsi
call   1060 <search_file@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %edi,%r13d
mov    $0x2,%ebp
lea    0xe7f(%rip),%r14
lea    0xe7a(%rip),%r15
jmp    11e5 <main+0xa5>
nopl   0x0(%rax)
mov    %rax,%rbx
mov    0x8(%r12),%rdi
mov    (%r12,%rbp,8),%rsi
mov    %rax,%rdx
call   1060 <search_file@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
add    $0x1,%rbp
cmp    %rbp,%r13
je     1190 <main+0x50>
mov    (%r12,%rbp,8),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
test   %rax,%rax
jne    11c0 <main+0x80>
mov    0x2ddb(%rip),%rax
mov    (%rax),%edi
mov    (%r12),%rdx
mov    (%r12,%rbp,8),%rcx
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
jmp    11dc <main+0x9c>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s pattern [file1] [file2] ...\0A\00"
@.str.1 = [8 x i8] c"<STDIN>\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"%s: Could not open file %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 2
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = load i8**, i8*** %5
%13 = getelementptr inbounds i8*, i8** %12, i64 0
%14 = load i8*, i8** %13
%15 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %11, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %14)
store i32 0, i32* %3
br label %67
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp eq i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i8**, i8*** %5
%21 = getelementptr inbounds i8*, i8** %20, i64 1
%22 = load i8*, i8** %21
%23 = load i32*, i32** @stdin
%24 = call i32 @search_file(i8* %22, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %23)
br label %66
25: ; preds = %16
store i32 2, i32* %6
br label %26
26: ; preds = %62, %25
%27 = load i32, i32* %6
%28 = load i32, i32* %4
%29 = icmp slt i32 %27, %28
br i1 %29, label %30, label %65
30: ; preds = %26
%31 = load i8**, i8*** %5
%32 = load i32, i32* %6
%33 = sext i32 %32 to i64
%34 = getelementptr inbounds i8*, i8** %31, i64 %33
%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))
store i32* %36, i32** %7
%37 = icmp eq i32* %36, null
br i1 %37, label %38, label %49
38: ; preds = %30
%39 = load i32, i32* @stderr
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 0
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = load i32, i32* %6
%45 = sext i32 %44 to i64
%46 = getelementptr inbounds i8*, i8** %43, i64 %45
%47 = load i8*, i8** %46
%48 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %42, i8* %47)
br label %62
49: ; preds = %30
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 1
%52 = load i8*, i8** %51
%53 = load i8**, i8*** %5
%54 = load i32, i32* %6
%55 = sext i32 %54 to i64
%56 = getelementptr inbounds i8*, i8** %53, i64 %55
%57 = load i8*, i8** %56
%58 = load i32*, i32** %7
%59 = call i32 @search_file(i8* %52, i8* %57, i32* %58)
%60 = load i32*, i32** %7
%61 = call i32 @fclose(i32* %60)
br label %62
62: ; preds = %49, %38
%63 = load i32, i32* %6
%64 = add nsw i32 %63, 1
store i32 %64, i32* %6
br label %26
65: ; preds = %26
br label %66
66: ; preds = %65, %19
store i32 0, i32* %3
br label %67
67: ; preds = %66, %10
%68 = load i32, i32* %3
ret i32 %68
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [39 x i8] c"Usage: %s pattern [file1] [file2] ...\0A\00"
@.str.1 = [8 x i8] c"<STDIN>\00"
@stdin = global i32* null
@.str.2 = [2 x i8] c"r\00"
@.str.3 = [28 x i8] c"%s: Could not open file %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %8
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = load i8*, i8** %1
%7 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %5, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str, i64 0, i64 0), i8* %6)
br label %36
8: ; preds = %2
%9 = icmp eq i32 %0, 2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
br i1 %9, label %13, label %11
11: ; preds = %8
%12 = zext i32 %0 to i64
br label %17
13: ; preds = %8
%14 = load i8*, i8** %10
%15 = load i32*, i32** @stdin
%16 = tail call i32 @search_file(i8* %14, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i32* %15)
br label %36
17: ; preds = %11, %33
%18 = phi i64 [ 2, %11 ], [ %34, %33 ]
%19 = getelementptr inbounds i8*, i8** %1, i64 %18
%20 = load i8*, i8** %19
%21 = tail call i32* @fopen(i8* %20, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.2, i64 0, i64 0))
%22 = icmp eq i32* %21, null
br i1 %22, label %23, label %28
23: ; preds = %17
%24 = load i32, i32* @stderr
%25 = load i8*, i8** %1
%26 = load i8*, i8** %19
%27 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %24, i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.3, i64 0, i64 0), i8* %25, i8* %26)
br label %33
28: ; preds = %17
%29 = load i8*, i8** %10
%30 = load i8*, i8** %19
%31 = tail call i32 @search_file(i8* %29, i8* %30, i32* %21)
%32 = tail call i32 @fclose(i32* %21)
br label %33
33: ; preds = %28, %23
%34 = add nuw nsw i64 %18, 1
%35 = icmp eq i64 %34, %12
br i1 %35, label %36, label %17
36: ; preds = %33, %13, %4
ret i32 0
}