#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*/ line;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ *strstr(char *, char *);
int grep(char *name, char *world) {
  FILE *in = fopen(name, "r");
  if (in == NULL)
    return 0;
  char line[1024];
  while (!feof(in)) {
    if (NULL != fgets(line, sizeof(line), in)) {
      if (NULL != strstr(line, world))
        return 1;
    }
  }
  fclose(in);
  return 0;
}


x86 assembly (clang, -O0):
<grep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    118e <grep+0x3e>
movl   $0x0,-0x4(%rbp)
jmp    1218 <grep+0xc8>
jmp    1193 <grep+0x43>
mov    -0x20(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    11b1 <grep+0x61>
jmp    1208 <grep+0xb8>
lea    -0x420(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x400,%esi
call   1040 <fgets@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1203 <grep+0xb3>
lea    -0x420(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   1070 <strstr@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     11fe <grep+0xae>
movl   $0x1,-0x4(%rbp)
jmp    1218 <grep+0xc8>
jmp    1203 <grep+0xb3>
jmp    1193 <grep+0x43>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x420,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<grep>:
push   %r15
push   %r14
push   %rbx
sub    $0x400,%rsp
mov    %rsi,%r14
lea    0xe9a(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1187 <grep+0x37>
mov    %rax,%rbx
mov    %rax,%rdi
call   1050 <feof@plt>
test   %eax,%eax
je     1196 <grep+0x46>
mov    %rbx,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x400,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
mov    %rsp,%r15
jmp    11ac <grep+0x5c>
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
call   1050 <feof@plt>
test   %eax,%eax
jne    117f <grep+0x2f>
mov    %r15,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11a0 <grep+0x50>
mov    %r15,%rdi
mov    %r14,%rsi
call   1070 <strstr@plt>
test   %rax,%rax
je     11a0 <grep+0x50>
mov    $0x1,%eax
jmp    1189 <grep+0x39>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @grep(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca [1024 x i8]
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %6
%10 = load i32*, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %35
13: ; preds = %2
br label %14
14: ; preds = %31, %13
%15 = load i32*, i32** %6
%16 = call i32 @feof(i32* %15)
%17 = icmp ne i32 %16, 0
%18 = xor i1 %17, true
br i1 %18, label %19, label %32
19: ; preds = %14
%20 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%21 = load i32*, i32** %6
%22 = call i32* @fgets(i8* %20, i32 1024, i32* %21)
%23 = icmp ne i32* null, %22
br i1 %23, label %24, label %31
24: ; preds = %19
%25 = getelementptr inbounds [1024 x i8], [1024 x i8]* %7, i64 0, i64 0
%26 = load i8*, i8** %5
%27 = call i32* @strstr(i8* %25, i8* %26)
%28 = icmp ne i32* null, %27
br i1 %28, label %29, label %30
29: ; preds = %24
store i32 1, i32* %3
br label %35
30: ; preds = %24
br label %31
31: ; preds = %30, %19
br label %14
32: ; preds = %14
%33 = load i32*, i32** %6
%34 = call i32 @fclose(i32* %33)
store i32 0, i32* %3
br label %35
35: ; preds = %32, %29, %12
%36 = load i32, i32* %3
ret i32 %36
}

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