#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 const *, char *);
int /*<<< orphan*/ grep(char const *, int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
int main(int argc, const char *argv[]) {
  if (2 == argc) {
    grep(argv[1], stdin);
  } else {
    for (int i = 2; i < argc; ++i) {
      FILE *file = fopen(argv[i], "r");
      grep(argv[1], file);
      fclose(file);
    }
  }
  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)
mov    $0x2,%eax
cmp    -0x8(%rbp),%eax
jne    1170 <main+0x40>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2e85(%rip),%rax
mov    (%rax),%rsi
call   1040 <grep@plt>
jmp    11cc <main+0x9c>
movl   $0x2,-0x14(%rbp)
mov    -0x14(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    11c7 <main+0x97>
mov    -0x10(%rbp),%rax
movslq -0x14(%rbp),%rcx
mov    (%rax,%rcx,8),%rdi
lea    0xe6a(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x20(%rbp),%rsi
call   1040 <grep@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    1177 <main+0x47>
jmp    11cc <main+0x9c>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%r15
cmp    $0x2,%edi
jne    1156 <main+0x26>
mov    0x8(%r15),%rdi
mov    0x2e9c(%rip),%rax
mov    (%rax),%rsi
call   1040 <grep@plt>
jmp    119c <main+0x6c>
jle    119c <main+0x6c>
mov    %edi,%r12d
mov    $0x2,%ebx
lea    0xe99(%rip),%r14
nopw   0x0(%rax,%rax,1)
mov    (%r15,%rbx,8),%rdi
mov    %r14,%rsi
call   1050 <fopen@plt>
mov    %rax,%r13
mov    0x8(%r15),%rdi
mov    %rax,%rsi
call   1040 <grep@plt>
mov    %r13,%rdi
call   1030 <fclose@plt>
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1170 <main+0x40>
xor    %eax,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@stdin = global i32* null
@.str = [2 x i8] c"r\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 eq i32 2, %8
br i1 %9, label %10, label %16
10: ; preds = %2
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
%14 = load i32*, i32** @stdin
%15 = call i32 @grep(i8* %13, i32* %14)
br label %39
16: ; preds = %2
store i32 2, i32* %6
br label %17
17: ; preds = %35, %16
%18 = load i32, i32* %6
%19 = load i32, i32* %4
%20 = icmp slt i32 %18, %19
br i1 %20, label %21, label %38
21: ; preds = %17
%22 = load i8**, i8*** %5
%23 = load i32, i32* %6
%24 = sext i32 %23 to i64
%25 = getelementptr inbounds i8*, i8** %22, i64 %24
%26 = load i8*, i8** %25
%27 = call i32* @fopen(i8* %26, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %27, i32** %7
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = load i32*, i32** %7
%32 = call i32 @grep(i8* %30, i32* %31)
%33 = load i32*, i32** %7
%34 = call i32 @fclose(i32* %33)
br label %35
35: ; preds = %21
%36 = load i32, i32* %6
%37 = add nsw i32 %36, 1
store i32 %37, i32* %6
br label %17
38: ; preds = %17
br label %39
39: ; preds = %38, %10
ret i32 0
}

LLVM IR (-O2):
@stdin = global i32* null
@.str = [2 x i8] c"r\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp eq i32 %0, 2
br i1 %3, label %9, label %4
4: ; preds = %2
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %24
6: ; preds = %4
%7 = getelementptr inbounds i8*, i8** %1, i64 1
%8 = zext i32 %0 to i64
br label %14
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = load i32*, i32** @stdin
%13 = tail call i32 @grep(i8* %11, i32* %12)
br label %24
14: ; preds = %6, %14
%15 = phi i64 [ 2, %6 ], [ %22, %14 ]
%16 = getelementptr inbounds i8*, i8** %1, i64 %15
%17 = load i8*, i8** %16
%18 = tail call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%19 = load i8*, i8** %7
%20 = tail call i32 @grep(i8* %19, i32* %18)
%21 = tail call i32 @fclose(i32* %18)
%22 = add nuw nsw i64 %15, 1
%23 = icmp eq i64 %22, %8
br i1 %23, label %24, label %14
24: ; preds = %14, %4, %9
ret i32 0
}