#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*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ *strstr(char *, char *);
int is_in_file(const char *filename, char *substr) {
  FILE *f = fopen(filename, "rb");
  fseek(f, 0L, SEEK_END);
  int file_size = ftell(f);
  fseek(f, 0L, SEEK_SET);
  char *str = malloc(file_size * sizeof(char));
  fread(str, sizeof(char), file_size, f);
  fclose(f);
  if (strstr(str, substr) == NULL) {
    free(str);
    return 0;
  } else {
    free(str);
    return 1;
  }
}


x86 assembly (clang, -O0):
<is_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e39(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e07(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
movslq -0x24(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x30(%rbp),%rdi
mov    -0x18(%rbp),%rsi
call   10a0 <strstr@plt>
cmp    $0x0,%rax
jne    1239 <is_in_file+0xb9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    1249 <is_in_file+0xc9>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_in_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe6f(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%rbx
mov    0x2e48(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,%r15d
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15d,%edi
call   1070 <malloc@plt>
mov    %rax,%rbp
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15d,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %rbp,%rdi
mov    %r14,%rsi
call   10a0 <strstr@plt>
xor    %ebx,%ebx
test   %rax,%rax
setne  %bl
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %ebx,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @is_in_file(i8* %0, i8* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = load i32*, i32** %6
%12 = load i32, i32* @SEEK_END
%13 = call i32 @fseek(i32* %11, i64 0, i32 %12)
%14 = load i32*, i32** %6
%15 = call i32 @ftell(i32* %14)
store i32 %15, i32* %7
%16 = load i32*, i32** %6
%17 = load i32, i32* @SEEK_SET
%18 = call i32 @fseek(i32* %16, i64 0, i32 %17)
%19 = load i32, i32* %7
%20 = sext i32 %19 to i64
%21 = mul i64 %20, 1
%22 = trunc i64 %21 to i32
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = load i32, i32* %7
%26 = load i32*, i32** %6
%27 = call i32 @fread(i8* %24, i32 1, i32 %25, i32* %26)
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
%30 = load i8*, i8** %8
%31 = load i8*, i8** %5
%32 = call i32* @strstr(i8* %30, i8* %31)
%33 = icmp eq i32* %32, null
br i1 %33, label %34, label %37
34: ; preds = %2
%35 = load i8*, i8** %8
%36 = call i32 @free(i8* %35)
store i32 0, i32* %3
br label %40
37: ; preds = %2
%38 = load i8*, i8** %8
%39 = call i32 @free(i8* %38)
store i32 1, i32* %3
br label %40
40: ; preds = %37, %34
%41 = load i32, i32* %3
ret i32 %41
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @is_in_file(i8* nocapture %0, i8* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i64 0, i32 %4)
%6 = tail call i32 @ftell(i32* %3)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %3, i64 0, i32 %7)
%9 = tail call i8* @malloc(i32 %6)
%10 = tail call i32 @fread(i8* %9, i32 1, i32 %6, i32* %3)
%11 = tail call i32 @fclose(i32* %3)
%12 = tail call i32* @strstr(i8* dereferenceable(1) %9, i8* dereferenceable(1) %1)
%13 = icmp ne i32* %12, null
%14 = tail call i32 @free(i8* %9)
%15 = zext i1 %13 to i32
ret i32 %15
}