#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 */
scalar_t__ OS_WordMatch(char *, char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ memset(char *, char, int);
int dogrep(char *file, char *str) {
  char line[1024 + 1];
  FILE *fp;
  fp = fopen(file, "r");
  if (!fp) {
    return (0);
  }
  memset(line, '\0', 1024 + 1);
  while (fgets(line, 1024, fp) != NULL) {
    if (OS_WordMatch(str, line)) {
      fclose(fp);
      return (1);
    }
  }
  fclose(fp);
  return (0);
}


x86 assembly (clang, -O0):
<dogrep>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe92(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x428(%rbp)
cmpq   $0x0,-0x428(%rbp)
jne    1194 <dogrep+0x44>
movl   $0x0,-0x4(%rbp)
jmp    1213 <dogrep+0xc3>
lea    -0x420(%rbp),%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
lea    -0x420(%rbp),%rdi
mov    -0x428(%rbp),%rdx
mov    $0x400,%esi
call   1060 <fgets@plt>
cmp    $0x0,%rax
je     1200 <dogrep+0xb0>
mov    -0x18(%rbp),%rdi
lea    -0x420(%rbp),%rsi
call   1040 <OS_WordMatch@plt>
cmp    $0x0,%rax
je     11fb <dogrep+0xab>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x1,-0x4(%rbp)
jmp    1213 <dogrep+0xc3>
jmp    11a7 <dogrep+0x57>
mov    -0x428(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<dogrep>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x408,%rsp
mov    %rsi,%r15
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c5 <dogrep+0x75>
mov    %rax,%rbx
mov    %rsp,%rbp
xor    %r14d,%r14d
mov    %rbp,%rdi
xor    %esi,%esi
mov    $0x401,%edx
call   1050 <memset@plt>
nopl   0x0(%rax)
mov    %rbp,%rdi
mov    $0x400,%esi
mov    %rbx,%rdx
call   1060 <fgets@plt>
test   %rax,%rax
je     11bb <dogrep+0x6b>
mov    %r15,%rdi
mov    %rbp,%rsi
call   1040 <OS_WordMatch@plt>
test   %rax,%rax
je     1190 <dogrep+0x40>
mov    $0x1,%r14d
mov    %rbx,%rdi
call   1030 <fclose@plt>
jmp    11c8 <dogrep+0x78>
xor    %r14d,%r14d
mov    %r14d,%eax
add    $0x408,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
define i32 @dogrep(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca [1025 x i8]
%7 = alloca i32*
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** %7
%10 = load i32*, i32** %7
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %33
13: ; preds = %2
%14 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%15 = call i32 @memset(i8* %14, i8 signext 0, i32 1025)
br label %16
16: ; preds = %29, %13
%17 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%18 = load i32*, i32** %7
%19 = call i32* @fgets(i8* %17, i32 1024, i32* %18)
%20 = icmp ne i32* %19, null
br i1 %20, label %21, label %30
21: ; preds = %16
%22 = load i8*, i8** %5
%23 = getelementptr inbounds [1025 x i8], [1025 x i8]* %6, i64 0, i64 0
%24 = call i64 @OS_WordMatch(i8* %22, i8* %23)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %21
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
store i32 1, i32* %3
br label %33
29: ; preds = %21
br label %16
30: ; preds = %16
%31 = load i32*, i32** %7
%32 = call i32 @fclose(i32* %31)
store i32 0, i32* %3
br label %33
33: ; preds = %30, %26, %12
%34 = load i32, i32* %3
ret i32 %34
}

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