#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 *);
size_t fread(unsigned char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
void *getData(char *filename) {
  unsigned char *s;
  FILE *fp;
  size_t size, asize;
  fp = fopen(filename, "rb");
  if (fp != (FILE *)NULL) {
    fseek(fp, 0, SEEK_END);
    size = ftell(fp);
    printf("Size is %lu.\n", size);
    fseek(fp, 0, SEEK_SET);
    s = (unsigned char *)malloc(size);
    if (s != (unsigned char *)NULL) {
      asize = fread(s, 1, size, fp);
      if (asize != size) {
        printf("error: Expecting %lu bytes. Read %lu bytes.\n", size, asize);
      }
      fclose(fp);
      return (void *)s;
    } else {
      printf("error: Unable to allocate buffer of %lu bytes.\n", size);
      fclose(fp);
      return NULL;
    }
  } else {
    printf("error: Unable to open file [%s].\n", filename);
    return NULL;
  }
}


x86 assembly (clang, -O0):
<getData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1276 <getData+0x106>
mov    -0x20(%rbp),%rdi
mov    0x2e42(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rsi
lea    0xe3c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     124e <getData+0xde>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x30(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     1238 <getData+0xc8>
mov    -0x28(%rbp),%rsi
mov    -0x30(%rbp),%rdx
lea    0xde0(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1290 <getData+0x120>
mov    -0x28(%rbp),%rsi
lea    0xde5(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movq   $0x0,-0x8(%rbp)
jmp    1290 <getData+0x120>
mov    -0x10(%rbp),%rsi
lea    0xded(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getData>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%rbx
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     1213 <getData+0xa3>
mov    %rax,%r12
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r12,%rdi
call   1060 <ftell@plt>
mov    %rax,%r15
lea    0xe4b(%rip),%rdi
mov    %rax,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    0x2e0f(%rip),%rax
mov    (%rax),%edx
mov    %r12,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     1229 <getData+0xb9>
mov    %rax,%r14
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %r12,%rcx
call   1030 <fread@plt>
cmp    %r15,%rax
je     123d <getData+0xcd>
lea    0xe0d(%rip),%rdi
mov    %r15,%rsi
mov    %rax,%rdx
xor    %eax,%eax
call   1050 <printf@plt>
jmp    123d <getData+0xcd>
lea    0xe54(%rip),%rdi
xor    %r14d,%r14d
mov    %rbx,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
jmp    1245 <getData+0xd5>
lea    0xe0e(%rip),%rdi
xor    %r14d,%r14d
mov    %r15,%rsi
xor    %eax,%eax
call   1050 <printf@plt>
mov    %r12,%rdi
call   1040 <fclose@plt>
mov    %r14,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [14 x i8] c"Size is %lu.\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [45 x i8] c"error: Expecting %lu bytes. Read %lu bytes.\0A\00"
@.str.3 = [48 x i8] c"error: Unable to allocate buffer of %lu bytes.\0A\00"
@.str.4 = [34 x i8] c"error: Unable to open file [%s].\0A\00"
define i8* @getData(i8* %0) {
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i64
%7 = alloca i64
store i8* %0, i8** %3
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %5
%10 = load i32*, i32** %5
%11 = icmp ne i32* %10, null
br i1 %11, label %12, label %49
12: ; preds = %1
%13 = load i32*, i32** %5
%14 = load i32, i32* @SEEK_END
%15 = call i32 @fseek(i32* %13, i32 0, i32 %14)
%16 = load i32*, i32** %5
%17 = call i64 @ftell(i32* %16)
store i64 %17, i64* %6
%18 = load i64, i64* %6
%19 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %18)
%20 = load i32*, i32** %5
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = load i64, i64* %6
%24 = call i64 @malloc(i64 %23)
%25 = inttoptr i64 %24 to i8*
store i8* %25, i8** %4
%26 = load i8*, i8** %4
%27 = icmp ne i8* %26, null
br i1 %27, label %28, label %44
28: ; preds = %12
%29 = load i8*, i8** %4
%30 = load i64, i64* %6
%31 = load i32*, i32** %5
%32 = call i64 @fread(i8* %29, i32 1, i64 %30, i32* %31)
store i64 %32, i64* %7
%33 = load i64, i64* %7
%34 = load i64, i64* %6
%35 = icmp ne i64 %33, %34
br i1 %35, label %36, label %40
36: ; preds = %28
%37 = load i64, i64* %6
%38 = load i64, i64* %7
%39 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %37, i64 %38)
br label %40
40: ; preds = %36, %28
%41 = load i32*, i32** %5
%42 = call i32 @fclose(i32* %41)
%43 = load i8*, i8** %4
store i8* %43, i8** %2
br label %52
44: ; preds = %12
%45 = load i64, i64* %6
%46 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i64 %45)
%47 = load i32*, i32** %5
%48 = call i32 @fclose(i32* %47)
store i8* null, i8** %2
br label %52
49: ; preds = %1
%50 = load i8*, i8** %3
%51 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %50)
store i8* null, i8** %2
br label %52
52: ; preds = %49, %44, %40
%53 = load i8*, i8** %2
ret i8* %53
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@.str.1 = [14 x i8] c"Size is %lu.\0A\00"
@SEEK_SET = global i32 0
@.str.2 = [45 x i8] c"error: Expecting %lu bytes. Read %lu bytes.\0A\00"
@.str.3 = [48 x i8] c"error: Unable to allocate buffer of %lu bytes.\0A\00"
@.str.4 = [34 x i8] c"error: Unable to open file [%s].\0A\00"
define i8* @getData(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %24, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i32 @fseek(i32* %2, i32 0, i32 %5)
%7 = tail call i64 @ftell(i32* %2)
%8 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @.str.1, i64 0, i64 0), i64 %7)
%9 = load i32, i32* @SEEK_SET
%10 = tail call i32 @fseek(i32* %2, i32 0, i32 %9)
%11 = tail call i64 @malloc(i64 %7)
%12 = inttoptr i64 %11 to i8*
%13 = icmp eq i64 %11, 0
br i1 %13, label %21, label %14
14: ; preds = %4
%15 = tail call i64 @fread(i8* %12, i32 1, i64 %7, i32* %2)
%16 = icmp eq i64 %15, %7
br i1 %16, label %19, label %17
17: ; preds = %14
%18 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0), i64 %7, i64 %15)
br label %19
19: ; preds = %17, %14
%20 = tail call i32 @fclose(i32* %2)
br label %26
21: ; preds = %4
%22 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([48 x i8], [48 x i8]* @.str.3, i64 0, i64 0), i64 %7)
%23 = tail call i32 @fclose(i32* %2)
br label %26
24: ; preds = %1
%25 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.4, i64 0, i64 0), i8* %0)
br label %26
26: ; preds = %24, %21, %19
%27 = phi i8* [ %12, %19 ], [ null, %21 ], [ null, %24 ]
ret i8* %27
}