#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*/ *);
char *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
scalar_t__ strstr(char *, char const *);
int find_string(const char *file, const char *tofind) {
  int ret = 0;
  FILE *f = fopen(file, "r");
  if (f) {
    char line[256], *str;
    while ((str = fgets(line, sizeof(line), f)) != NULL) {
      if (strstr(str, tofind)) {
        ret = 1;
        break;
      }
    }
    fclose(f);
  }
  return ret;
}


x86 assembly (clang, -O0):
<find_string>:
push   %rbp
mov    %rsp,%rbp
sub    $0x130,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x14(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe9b(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     11d8 <find_string+0x98>
jmp    117e <find_string+0x3e>
lea    -0x120(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x100,%esi
call   1040 <fgets@plt>
mov    %rax,-0x128(%rbp)
cmp    $0x0,%rax
je     11cf <find_string+0x8f>
mov    -0x128(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <strstr@plt>
cmp    $0x0,%rax
je     11ca <find_string+0x8a>
movl   $0x1,-0x14(%rbp)
jmp    11cf <find_string+0x8f>
jmp    117e <find_string+0x3e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x14(%rbp),%eax
add    $0x130,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_string>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x108,%rsp
mov    %rsi,%r14
lea    0xea9(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     119c <find_string+0x5c>
mov    %rax,%rbx
mov    %rsp,%r15
nopw   0x0(%rax,%rax,1)
mov    %r15,%rdi
mov    $0x100,%esi
mov    %rbx,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11a0 <find_string+0x60>
mov    %rax,%rdi
mov    %r14,%rsi
call   1060 <strstr@plt>
test   %rax,%rax
je     1170 <find_string+0x30>
mov    $0x1,%ebp
jmp    11a2 <find_string+0x62>
xor    %ebp,%ebp
jmp    11aa <find_string+0x6a>
xor    %ebp,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    %ebp,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
define i32 @find_string(i8* nocapture %0, i8* %1) {
%3 = alloca [256 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 %17, label %6
6: ; preds = %2
%7 = getelementptr inbounds [256 x i8], [256 x i8]* %3, i64 0, i64 0
br label %8
8: ; preds = %11, %6
%9 = call i8* @fgets(i8* %7, i32 256, i32* %4)
%10 = icmp eq i8* %9, null
br i1 %10, label %14, label %11
11: ; preds = %8
%12 = call i64 @strstr(i8* %9, i8* %1)
%13 = icmp eq i64 %12, 0
br i1 %13, label %8, label %14
14: ; preds = %11, %8
%15 = phi i32 [ 0, %8 ], [ 1, %11 ]
%16 = call i32 @fclose(i32* %4)
br label %17
17: ; preds = %14, %2
%18 = phi i32 [ %15, %14 ], [ 0, %2 ]
ret i32 %18
}