#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*/ *);
scalar_t__ fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(size_t);
int /*<<< orphan*/ printf(char *, ...);
char *getFilecontent(char *name) {
  FILE *file = fopen(name, "r");
  if (file == NULL) {
    printf("Error opening file: %s\n", name);
  }
  fseek(file, 0L, SEEK_END);
  size_t fsize = ftell(file);
  fseek(file, 0L, SEEK_SET);
  char *content = malloc((fsize + 1) * sizeof(char));
  if (content == NULL)
    printf("Not enough memory for new vector of dimension %zu\n", (fsize));
  size_t cnt = 0;
  while (cnt < fsize) {
    content[cnt] = (char)fgetc(file);
    cnt++;
  }
  content[fsize] = -1;
  fclose(file);
  printf("File '%s' loaded: %zu, %zu bytes\n", name, cnt, fsize);
  return content;
}


x86 assembly (clang, -O0):
<getFilecontent>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe79(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ad <getFilecontent+0x3d>
mov    -0x8(%rbp),%rsi
lea    0xe5c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e30(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2dfd(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x18(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1218 <getFilecontent+0xa8>
mov    -0x18(%rbp),%rsi
lea    0xe09(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
movq   $0x0,-0x28(%rbp)
mov    -0x28(%rbp),%rax
cmp    -0x18(%rbp),%rax
jae    1255 <getFilecontent+0xe5>
mov    -0x10(%rbp),%rdi
call   1050 <fgetc@plt>
mov    %al,%dl
mov    -0x20(%rbp),%rax
mov    -0x28(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x28(%rbp),%rax
add    $0x1,%rax
mov    %rax,-0x28(%rbp)
jmp    1220 <getFilecontent+0xb0>
mov    -0x20(%rbp),%rax
mov    -0x18(%rbp),%rcx
movb   $0xff,(%rax,%rcx,1)
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%rsi
mov    -0x28(%rbp),%rdx
mov    -0x18(%rbp),%rcx
lea    0xdd0(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFilecontent>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%r14
lea    0xe7d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,%r15
test   %rax,%rax
jne    11a1 <getFilecontent+0x31>
lea    0xe6b(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    0x2e40(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
call   1060 <ftell@plt>
mov    %rax,%r12
mov    0x2e12(%rip),%rax
mov    (%rax),%edx
mov    %r15,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
lea    0x1(%r12),%rdi
call   1070 <malloc@plt>
mov    %rax,%r13
test   %rax,%rax
je     11eb <getFilecontent+0x7b>
test   %r12,%r12
jne    1201 <getFilecontent+0x91>
jmp    1226 <getFilecontent+0xb6>
lea    0xe28(%rip),%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
test   %r12,%r12
je     1226 <getFilecontent+0xb6>
xor    %ebx,%ebx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %r15,%rdi
call   1050 <fgetc@plt>
mov    %al,0x0(%r13,%rbx,1)
add    $0x1,%rbx
cmp    %rbx,%r12
jne    1210 <getFilecontent+0xa0>
movb   $0xff,0x0(%r13,%r12,1)
mov    %r15,%rdi
call   1030 <fclose@plt>
lea    0xe12(%rip),%rdi
mov    %r14,%rsi
mov    %r12,%rdx
mov    %r12,%rcx
xor    %eax,%eax
call   1040 <printf@plt>
mov    %r13,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [51 x i8] c"Not enough memory for new vector of dimension %zu\0A\00"
@.str.3 = [34 x i8] c"File '%s' loaded: %zu, %zu bytes\0A\00"
define i8* @getFilecontent(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i64
%5 = alloca i8*
%6 = alloca i64
store i8* %0, i8** %2
%7 = load i8*, i8** %2
%8 = call i32* @fopen(i8* %7, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %8, i32** %3
%9 = load i32*, i32** %3
%10 = icmp eq i32* %9, null
br i1 %10, label %11, label %14
11: ; preds = %1
%12 = load i8*, i8** %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %1
%15 = load i32*, i32** %3
%16 = load i32, i32* @SEEK_END
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32*, i32** %3
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %4
%20 = load i32*, i32** %3
%21 = load i32, i32* @SEEK_SET
%22 = call i32 @fseek(i32* %20, i64 0, i32 %21)
%23 = load i64, i64* %4
%24 = add i64 %23, 1
%25 = mul i64 %24, 1
%26 = call i8* @malloc(i64 %25)
store i8* %26, i8** %5
%27 = load i8*, i8** %5
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %14
%30 = load i64, i64* %4
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i64 %30)
br label %32
32: ; preds = %29, %14
store i64 0, i64* %6
br label %33
33: ; preds = %37, %32
%34 = load i64, i64* %6
%35 = load i64, i64* %4
%36 = icmp ult i64 %34, %35
br i1 %36, label %37, label %46
37: ; preds = %33
%38 = load i32*, i32** %3
%39 = call i64 @fgetc(i32* %38)
%40 = trunc i64 %39 to i8
%41 = load i8*, i8** %5
%42 = load i64, i64* %6
%43 = getelementptr inbounds i8, i8* %41, i64 %42
store i8 %40, i8* %43
%44 = load i64, i64* %6
%45 = add i64 %44, 1
store i64 %45, i64* %6
br label %33
46: ; preds = %33
%47 = load i8*, i8** %5
%48 = load i64, i64* %4
%49 = getelementptr inbounds i8, i8* %47, i64 %48
store i8 -1, i8* %49
%50 = load i32*, i32** %3
%51 = call i32 @fclose(i32* %50)
%52 = load i8*, i8** %2
%53 = load i64, i64* %6
%54 = load i64, i64* %4
%55 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %52, i64 %53, i64 %54)
%56 = load i8*, i8** %5
ret i8* %56
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [24 x i8] c"Error opening file: %s\0A\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [51 x i8] c"Not enough memory for new vector of dimension %zu\0A\00"
@.str.3 = [34 x i8] c"File '%s' loaded: %zu, %zu bytes\0A\00"
define noalias i8* @getFilecontent(i8* %0) {
%2 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %4, label %6
4: ; preds = %1
%5 = 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 %6
6: ; preds = %4, %1
%7 = load i32, i32* @SEEK_END
%8 = tail call i32 @fseek(i32* %2, i64 0, i32 %7)
%9 = tail call i64 @ftell(i32* %2)
%10 = load i32, i32* @SEEK_SET
%11 = tail call i32 @fseek(i32* %2, i64 0, i32 %10)
%12 = add i64 %9, 1
%13 = tail call i8* @malloc(i64 %12)
%14 = icmp eq i8* %13, null
br i1 %14, label %15, label %17
15: ; preds = %6
%16 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([51 x i8], [51 x i8]* @.str.2, i64 0, i64 0), i64 %9)
br label %17
17: ; preds = %15, %6
%18 = icmp eq i64 %9, 0
br i1 %18, label %26, label %19
19: ; preds = %17, %19
%20 = phi i64 [ %24, %19 ], [ 0, %17 ]
%21 = tail call i64 @fgetc(i32* %2)
%22 = trunc i64 %21 to i8
%23 = getelementptr inbounds i8, i8* %13, i64 %20
store i8 %22, i8* %23
%24 = add nuw i64 %20, 1
%25 = icmp eq i64 %24, %9
br i1 %25, label %26, label %19
26: ; preds = %19, %17
%27 = getelementptr inbounds i8, i8* %13, i64 %9
store i8 -1, i8* %27
%28 = tail call i32 @fclose(i32* %2)
%29 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([34 x i8], [34 x i8]* @.str.3, i64 0, i64 0), i8* %0, i64 %9, i64 %9)
ret i8* %13
}