#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 *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
char *probe_file_data(char *file_name, int *file_len) {
  FILE *pfile;
  int len;
  char *buffer;
  pfile = fopen(file_name, "rb");
  if (pfile == NULL) {
    printf("file %s cant be opened\n", file_name);
    return NULL;
  }
  fseek(pfile, 0, SEEK_END);
  len = ftell(pfile);
  buffer = malloc(len);
  if (buffer == NULL) {
    printf("buffer cant be malloc\n");
    fclose(pfile);
    return NULL;
  }
  memset(buffer, 0, len);
  fseek(pfile, 0, SEEK_SET);
  fread(buffer, len, 1, pfile);
  fclose(pfile);
  *file_len = len;
  return buffer;
}


x86 assembly (clang, -O0):
<probe_file_data>:
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   10a0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11ce <probe_file_data+0x4e>
mov    -0x10(%rbp),%rsi
lea    0xe49(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <probe_file_data+0xfa>
mov    -0x20(%rbp),%rdi
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%edi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    1229 <probe_file_data+0xa9>
lea    0xe0f(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    127a <probe_file_data+0xfa>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%edx
xor    %esi,%esi
call   1060 <memset@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d96(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
mov    -0x24(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x24(%rbp),%ecx
mov    -0x18(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<probe_file_data>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbp
lea    0xe5c(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     121b <probe_file_data+0x8b>
mov    %rax,%rbx
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %rbx,%rdi
call   1080 <ftell@plt>
mov    %eax,%ebp
mov    %eax,%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1231 <probe_file_data+0xa1>
mov    %rax,%r15
mov    %rax,%rdi
xor    %esi,%esi
mov    %ebp,%edx
call   1070 <memset@plt>
mov    0x2de8(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %r15,%rdi
mov    %ebp,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
mov    %ebp,(%r14)
jmp    1248 <probe_file_data+0xb8>
lea    0xde1(%rip),%rdi
xor    %r15d,%r15d
mov    %rbp,%rsi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1248 <probe_file_data+0xb8>
lea    0xde3(%rip),%rdi
call   1030 <puts@plt>
mov    %rbx,%rdi
call   1050 <fclose@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"file %s cant be opened\0A\00"
@SEEK_END = global i32 0
@.str.2 = [23 x i8] c"buffer cant be malloc\0A\00"
@SEEK_SET = global i32 0
define i8* @probe_file_data(i8* %0, i32* %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i8*
store i8* %0, i8** %4
store i32* %1, i32** %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 = icmp eq i32* %11, null
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %14)
store i8* null, i8** %3
br label %46
16: ; preds = %2
%17 = load i32*, i32** %6
%18 = load i32, i32* @SEEK_END
%19 = call i32 @fseek(i32* %17, i32 0, i32 %18)
%20 = load i32*, i32** %6
%21 = call i32 @ftell(i32* %20)
store i32 %21, i32* %7
%22 = load i32, i32* %7
%23 = call i8* @malloc(i32 %22)
store i8* %23, i8** %8
%24 = load i8*, i8** %8
%25 = icmp eq i8* %24, null
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.2, i64 0, i64 0))
%28 = load i32*, i32** %6
%29 = call i32 @fclose(i32* %28)
store i8* null, i8** %3
br label %46
30: ; preds = %16
%31 = load i8*, i8** %8
%32 = load i32, i32* %7
%33 = call i32 @memset(i8* %31, i32 0, i32 %32)
%34 = load i32*, i32** %6
%35 = load i32, i32* @SEEK_SET
%36 = call i32 @fseek(i32* %34, i32 0, i32 %35)
%37 = load i8*, i8** %8
%38 = load i32, i32* %7
%39 = load i32*, i32** %6
%40 = call i32 @fread(i8* %37, i32 %38, i32 1, i32* %39)
%41 = load i32*, i32** %6
%42 = call i32 @fclose(i32* %41)
%43 = load i32, i32* %7
%44 = load i32*, i32** %5
store i32 %43, i32* %44
%45 = load i8*, i8** %8
store i8* %45, i8** %3
br label %46
46: ; preds = %30, %26, %13
%47 = load i8*, i8** %3
ret i8* %47
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [24 x i8] c"file %s cant be opened\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@str = [22 x i8] c"buffer cant be malloc\00"
define i8* @probe_file_data(i8* %0, i32* nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
7: ; preds = %2
%8 = load i32, i32* @SEEK_END
%9 = tail call i32 @fseek(i32* %3, i32 0, i32 %8)
%10 = tail call i32 @ftell(i32* %3)
%11 = tail call i8* @malloc(i32 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %13, label %16
13: ; preds = %7
%14 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
%15 = tail call i32 @fclose(i32* %3)
br label %22
16: ; preds = %7
%17 = tail call i32 @memset(i8* %11, i32 0, i32 %10)
%18 = load i32, i32* @SEEK_SET
%19 = tail call i32 @fseek(i32* %3, i32 0, i32 %18)
%20 = tail call i32 @fread(i8* %11, i32 %10, i32 1, i32* %3)
%21 = tail call i32 @fclose(i32* %3)
store i32 %10, i32* %1
br label %22
22: ; preds = %16, %13, %5
%23 = phi i8* [ null, %5 ], [ null, %13 ], [ %11, %16 ]
ret i8* %23
}