#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int getFileSize(char *);
scalar_t__ malloc(int);
int /*<<< orphan*/ printf(char *);
char *readFile(char *file) {
  int size;
  size = getFileSize(file);
  FILE *fp;
  fp = fopen(file, "rb");
  char *data = (char *)malloc(sizeof(char) * size);
  fread(data, 1, size, fp);
  int i;
  printf("Data read!\n\n");
  fclose(fp);
  return data;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1060 <getFileSize@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe7d(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
movslq -0xc(%rbp),%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
lea    0xe48(%rip),%rdi
call   1050 <printf@plt>
mov    -0x18(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r14
push   %rbx
mov    %rdi,%rbx
call   1060 <getFileSize@plt>
mov    %eax,%ebp
lea    0xe8b(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
mov    %rax,%r14
mov    %ebp,%edi
call   1070 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %ebp,%edx
mov    %r14,%rcx
call   1040 <fread@plt>
lea    0xe60(%rip),%rdi
call   1030 <puts@plt>
mov    %r14,%rdi
call   1050 <fclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [13 x i8] c"Data read!\0A\0A\00"
define i8* @readFile(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i32*
%5 = alloca i8*
%6 = alloca i32
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32 @getFileSize(i8* %7)
store i32 %8, i32* %3
%9 = load i8*, i8** %2
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %4
%11 = load i32, i32* %3
%12 = sext i32 %11 to i64
%13 = mul i64 1, %12
%14 = trunc i64 %13 to i32
%15 = call i64 @malloc(i32 %14)
%16 = inttoptr i64 %15 to i8*
store i8* %16, i8** %5
%17 = load i8*, i8** %5
%18 = load i32, i32* %3
%19 = load i32*, i32** %4
%20 = call i32 @fread(i8* %17, i32 1, i32 %18, i32* %19)
%21 = call i32 @printf(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32*, i32** %4
%23 = call i32 @fclose(i32* %22)
%24 = load i8*, i8** %5
ret i8* %24
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@str = [12 x i8] c"Data read!\0A\00"
define i8* @readFile(i8* %0) {
%2 = tail call i32 @getFileSize(i8* %0)
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = tail call i64 @malloc(i32 %2)
%5 = inttoptr i64 %4 to i8*
%6 = tail call i32 @fread(i8* %5, i32 1, i32 %2, i32* %3)
%7 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([12 x i8], [12 x i8]* @str, i64 0, i64 0))
%8 = tail call i32 @fclose(i32* %3)
ret i8* %5
}