#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ search(char *, int /*<<< orphan*/ *, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ *stdin;
int main(int ac, char **av) {
  char *string;
  if (ac <= 1) {
    fprintf(stderr, "Usage: fgrep string file ...\n");
    exit(EXIT_FAILURE);
  }
  string = *++av;
  if (ac <= 2)
    search(NULL, stdin, string);
  else {
    while (*++av != NULL) {
      FILE *stream;
      stream = fopen(*av, "r");
      if (stream == NULL)
        perror(*av);
      else {
        search(*av, stream, string);
        fclose(stream);
      }
    }
  }
  return EXIT_SUCCESS;
}


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   $0x1,-0x8(%rbp)
jg     11a3 <main+0x43>
mov    0x2e51(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e34(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
mov    0x8(%rax),%rax
mov    %rax,-0x18(%rbp)
cmpl   $0x2,-0x8(%rbp)
jg     11e0 <main+0x80>
mov    0x2e1d(%rip),%rax
mov    (%rax),%rsi
mov    -0x18(%rbp),%rdx
xor    %eax,%eax
mov    %eax,%edi
call   1040 <search@plt>
jmp    1259 <main+0xf9>
jmp    11e5 <main+0x85>
mov    -0x10(%rbp),%rax
mov    %rax,%rcx
add    $0x8,%rcx
mov    %rcx,-0x10(%rbp)
cmpq   $0x0,0x8(%rax)
je     1254 <main+0xf4>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
lea    0xe11(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1232 <main+0xd2>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
jmp    124f <main+0xef>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x20(%rbp),%rsi
mov    -0x18(%rbp),%rdx
call   1040 <search@plt>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
jmp    11e5 <main+0x85>
jmp    1259 <main+0xf9>
mov    0x2d68(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
cmp    $0x1,%edi
jle    1203 <main+0xa3>
mov    %rsi,%r12
mov    0x8(%rsi),%r14
cmp    $0x2,%edi
jne    1193 <main+0x33>
mov    0x2e64(%rip),%rax
mov    (%rax),%rsi
xor    %edi,%edi
mov    %r14,%rdx
call   1040 <search@plt>
jmp    11ee <main+0x8e>
mov    0x10(%r12),%rdi
test   %rdi,%rdi
je     11ee <main+0x8e>
add    $0x18,%r12
lea    0xe76(%rip),%r15
nopl   0x0(%rax,%rax,1)
mov    %r15,%rsi
call   1060 <fopen@plt>
mov    -0x8(%r12),%rdi
test   %rax,%rax
je     11e7 <main+0x87>
mov    %rax,%rbx
mov    %rax,%rsi
mov    %r14,%rdx
call   1040 <search@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    (%r12),%rdi
add    $0x8,%r12
test   %rdi,%rdi
jne    11b0 <main+0x50>
jmp    11ee <main+0x8e>
call   1070 <perror@plt>
jmp    11d8 <main+0x78>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
lea    0xded(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db1(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: fgrep string file ...\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%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 sle i32 %8, 1
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @exit(i32 %13)
unreachable
15: ; preds = %2
%16 = load i8**, i8*** %5
%17 = getelementptr inbounds i8*, i8** %16, i32 1
store i8** %17, i8*** %5
%18 = load i8*, i8** %17
store i8* %18, i8** %6
%19 = load i32, i32* %4
%20 = icmp sle i32 %19, 2
br i1 %20, label %21, label %25
21: ; preds = %15
%22 = load i32*, i32** @stdin
%23 = load i8*, i8** %6
%24 = call i32 @search(i8* null, i32* %22, i8* %23)
br label %51
25: ; preds = %15
br label %26
26: ; preds = %49, %25
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i32 1
store i8** %28, i8*** %5
%29 = load i8*, i8** %28
%30 = icmp ne i8* %29, null
br i1 %30, label %31, label %50
31: ; preds = %26
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = call i32* @fopen(i8* %33, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %34, i32** %7
%35 = load i32*, i32** %7
%36 = icmp eq i32* %35, null
br i1 %36, label %37, label %41
37: ; preds = %31
%38 = load i8**, i8*** %5
%39 = load i8*, i8** %38
%40 = call i32 @perror(i8* %39)
br label %49
41: ; preds = %31
%42 = load i8**, i8*** %5
%43 = load i8*, i8** %42
%44 = load i32*, i32** %7
%45 = load i8*, i8** %6
%46 = call i32 @search(i8* %43, i32* %44, i8* %45)
%47 = load i32*, i32** %7
%48 = call i32 @fclose(i32* %47)
br label %49
49: ; preds = %41, %37
br label %26
50: ; preds = %26
br label %51
51: ; preds = %50, %21
%52 = load i32, i32* @EXIT_SUCCESS
ret i32 %52
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Usage: fgrep string file ...\0A\00"
@EXIT_FAILURE = global i32 0
@stdin = global i32* null
@.str.1 = [2 x i8] c"r\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %9
4: ; preds = %2
%5 = load i32, i32* @stderr
%6 = tail call i32 @fprintf(i32 %5, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%7 = load i32, i32* @EXIT_FAILURE
%8 = tail call i32 @exit(i32 %7)
unreachable
9: ; preds = %2
%10 = getelementptr inbounds i8*, i8** %1, i64 1
%11 = load i8*, i8** %10
%12 = icmp eq i32 %0, 2
br i1 %12, label %17, label %13
13: ; preds = %9
%14 = getelementptr inbounds i8*, i8** %1, i64 2
%15 = load i8*, i8** %14
%16 = icmp eq i8* %15, null
br i1 %16, label %35, label %20
17: ; preds = %9
%18 = load i32*, i32** @stdin
%19 = tail call i32 @search(i8* null, i32* %18, i8* %11)
br label %35
20: ; preds = %13, %31
%21 = phi i8* [ %33, %31 ], [ %15, %13 ]
%22 = phi i8** [ %32, %31 ], [ %14, %13 ]
%23 = tail call i32* @fopen(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = icmp eq i32* %23, null
%25 = load i8*, i8** %22
br i1 %24, label %26, label %28
26: ; preds = %20
%27 = tail call i32 @perror(i8* %25)
br label %31
28: ; preds = %20
%29 = tail call i32 @search(i8* %25, i32* %23, i8* %11)
%30 = tail call i32 @fclose(i32* %23)
br label %31
31: ; preds = %28, %26
%32 = getelementptr inbounds i8*, i8** %22, i64 1
%33 = load i8*, i8** %32
%34 = icmp eq i8* %33, null
br i1 %34, label %35, label %20
35: ; preds = %31, %13, %17
%36 = load i32, i32* @EXIT_SUCCESS
ret i32 %36
}