#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;
scalar_t__ calloc(int, int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
int read_file_into_buffer(char *filter_file, char **filter_buffer) {
  FILE *filter_file_fp;
  int filter_file_len;
  filter_file_fp = fopen(filter_file, "r");
  if (!filter_file_fp) {
    return 0;
  }
  fseek(filter_file_fp, 0, SEEK_END);
  filter_file_len = ftell(filter_file_fp);
  fseek(filter_file_fp, 0, SEEK_SET);
  *filter_buffer = (char *)calloc(1, (filter_file_len + 1));
  if (!*filter_buffer) {
    return 0;
  }
  if (fread(*filter_buffer, filter_file_len, 1, filter_file_fp) != 1) {
    free(*filter_buffer);
    return 0;
  }
  fclose(filter_file_fp);
  (*filter_buffer)[filter_file_len] = '\0';
  return filter_file_len;
}


x86 assembly (clang, -O0):
<read_file_into_buffer>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe75(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ab <read_file_into_buffer+0x3b>
movl   $0x0,-0x4(%rbp)
jmp    126a <read_file_into_buffer+0xfa>
mov    -0x20(%rbp),%rdi
mov    0x2e32(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e02(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x24(%rbp),%esi
add    $0x1,%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1213 <read_file_into_buffer+0xa3>
movl   $0x0,-0x4(%rbp)
jmp    126a <read_file_into_buffer+0xfa>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1040 <fread@plt>
cmp    $0x1,%eax
je     124c <read_file_into_buffer+0xdc>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
movl   $0x0,-0x4(%rbp)
jmp    126a <read_file_into_buffer+0xfa>
mov    -0x20(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file_into_buffer>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7f(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1204 <read_file_into_buffer+0x94>
mov    %rax,%rbx
mov    0x2e53(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%ebp
mov    0x2e23(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%rbp),%esi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,(%r14)
test   %rax,%rax
je     1211 <read_file_into_buffer+0xa1>
mov    %rax,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    $0x1,%eax
jne    1209 <read_file_into_buffer+0x99>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    (%r14),%rax
movslq %ebp,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    %ebp,%r15d
jmp    1211 <read_file_into_buffer+0xa1>
xor    %r15d,%r15d
jmp    1211 <read_file_into_buffer+0xa1>
mov    (%r14),%rdi
call   1030 <free@plt>
mov    %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @read_file_into_buffer(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32*
%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** %6
%10 = load i32*, i32** %6
%11 = icmp ne i32* %10, null
br i1 %11, label %13, label %12
12: ; preds = %2
store i32 0, i32* %3
br label %51
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i32, i32* @SEEK_END
%16 = call i32 @fseek(i32* %14, i32 0, i32 %15)
%17 = load i32*, i32** %6
%18 = call i32 @ftell(i32* %17)
store i32 %18, i32* %7
%19 = load i32*, i32** %6
%20 = load i32, i32* @SEEK_SET
%21 = call i32 @fseek(i32* %19, i32 0, i32 %20)
%22 = load i32, i32* %7
%23 = add nsw i32 %22, 1
%24 = call i64 @calloc(i32 1, i32 %23)
%25 = inttoptr i64 %24 to i8*
%26 = load i8**, i8*** %5
store i8* %25, i8** %26
%27 = load i8**, i8*** %5
%28 = load i8*, i8** %27
%29 = icmp ne i8* %28, null
br i1 %29, label %31, label %30
30: ; preds = %13
store i32 0, i32* %3
br label %51
31: ; preds = %13
%32 = load i8**, i8*** %5
%33 = load i8*, i8** %32
%34 = load i32, i32* %7
%35 = load i32*, i32** %6
%36 = call i32 @fread(i8* %33, i32 %34, i32 1, i32* %35)
%37 = icmp ne i32 %36, 1
br i1 %37, label %38, label %42
38: ; preds = %31
%39 = load i8**, i8*** %5
%40 = load i8*, i8** %39
%41 = call i32 @free(i8* %40)
store i32 0, i32* %3
br label %51
42: ; preds = %31
%43 = load i32*, i32** %6
%44 = call i32 @fclose(i32* %43)
%45 = load i8**, i8*** %5
%46 = load i8*, i8** %45
%47 = load i32, i32* %7
%48 = sext i32 %47 to i64
%49 = getelementptr inbounds i8, i8* %46, i64 %48
store i8 0, i8* %49
%50 = load i32, i32* %7
store i32 %50, i32* %3
br label %51
51: ; preds = %42, %38, %30, %12
%52 = load i32, i32* %3
ret i32 %52
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @read_file_into_buffer(i8* nocapture %0, i8** nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %3, i32 0, i32 %6)
%8 = tail call i32 @ftell(i32* %3)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = add nsw i32 %8, 1
%12 = tail call i64 @calloc(i32 1, i32 %11)
%13 = inttoptr i64 %12 to i8*
store i8* %13, i8** %1
%14 = icmp eq i64 %12, 0
br i1 %14, label %26, label %15
15: ; preds = %5
%16 = tail call i32 @fread(i8* %13, i32 %8, i32 1, i32* %3)
%17 = icmp eq i32 %16, 1
br i1 %17, label %21, label %18
18: ; preds = %15
%19 = load i8*, i8** %1
%20 = tail call i32 @free(i8* %19)
br label %26
21: ; preds = %15
%22 = tail call i32 @fclose(i32* %3)
%23 = load i8*, i8** %1
%24 = sext i32 %8 to i64
%25 = getelementptr inbounds i8, i8* %23, i64 %24
store i8 0, i8* %25
br label %26
26: ; preds = %5, %2, %21, %18
%27 = phi i32 [ 0, %18 ], [ %8, %21 ], [ 0, %2 ], [ 0, %5 ]
ret i32 %27
}