#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*/ cleanStr(char *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fgets(char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
char *malloc(int);
scalar_t__ strcmp(int /*<<< orphan*/, char *);
int isInFile(char *targ, char *filename) {
  FILE *fp;
  fp = fopen(filename, "r");
  if (fp == NULL) {
    fp = fopen(filename, "w");
    fclose(fp);
    fp = fopen(filename, "r");
  }
  char *inputLine = malloc(sizeof(char) * 256);
  while (fgets(inputLine, 512, fp) != NULL) {
    if (strcmp(cleanStr(inputLine), targ) == 0) {
      return 1;
    }
  }
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<isInFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11c0 <isInFile+0x60>
mov    -0x18(%rbp),%rdi
lea    0xe68(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x18(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x20(%rbp),%rdx
mov    $0x200,%esi
call   1040 <fgets@plt>
cmp    $0x0,%rax
je     1219 <isInFile+0xb9>
mov    -0x28(%rbp),%rdi
call   1080 <cleanStr@plt>
mov    %eax,%edi
mov    -0x10(%rbp),%rsi
call   1050 <strcmp@plt>
cmp    $0x0,%rax
jne    1214 <isInFile+0xb4>
movl   $0x1,-0x4(%rbp)
jmp    1229 <isInFile+0xc9>
jmp    11ce <isInFile+0x6e>
mov    -0x20(%rbp),%rdi
call   1030 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<isInFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r15
mov    %rdi,%r14
lea    0xe8b(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    11ae <isInFile+0x4e>
lea    0xe76(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%rdi
call   1030 <fclose@plt>
lea    0xe5d(%rip),%rsi
mov    %r15,%rdi
call   1070 <fopen@plt>
mov    %rax,%r12
mov    $0x100,%edi
call   1060 <malloc@plt>
mov    %rax,%rbx
nopl   0x0(%rax,%rax,1)
mov    %rbx,%rdi
mov    $0x200,%esi
mov    %r12,%rdx
call   1040 <fgets@plt>
test   %rax,%rax
je     11f3 <isInFile+0x93>
mov    %rbx,%rdi
call   1080 <cleanStr@plt>
mov    %eax,%edi
mov    %r14,%rsi
call   1050 <strcmp@plt>
test   %rax,%rax
jne    11c0 <isInFile+0x60>
mov    $0x1,%eax
jmp    11fd <isInFile+0x9d>
mov    %r12,%rdi
call   1030 <fclose@plt>
xor    %eax,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
define i32 @isInFile(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%8 = load i8*, i8** %5
%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 %19
12: ; preds = %2
%13 = load i8*, i8** %5
%14 = call i32* @fopen(i8* %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %14, i32** %6
%15 = load i32*, i32** %6
%16 = call i32 @fclose(i32* %15)
%17 = load i8*, i8** %5
%18 = call i32* @fopen(i8* %17, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %18, i32** %6
br label %19
19: ; preds = %12, %2
%20 = call i8* @malloc(i32 256)
store i8* %20, i8** %7
br label %21
21: ; preds = %33, %19
%22 = load i8*, i8** %7
%23 = load i32*, i32** %6
%24 = call i32* @fgets(i8* %22, i32 512, i32* %23)
%25 = icmp ne i32* %24, null
br i1 %25, label %26, label %34
26: ; preds = %21
%27 = load i8*, i8** %7
%28 = call i32 @cleanStr(i8* %27)
%29 = load i8*, i8** %4
%30 = call i64 @strcmp(i32 %28, i8* %29)
%31 = icmp eq i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %26
store i32 1, i32* %3
br label %37
33: ; preds = %26
br label %21
34: ; preds = %21
%35 = load i32*, i32** %6
%36 = call i32 @fclose(i32* %35)
store i32 0, i32* %3
br label %37
37: ; preds = %34, %32
%38 = load i32, i32* %3
ret i32 %38
}

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