#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 */
char EOF;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
char fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
char *getFile(char *s) {
  FILE *fp = fopen(s, "r");
  if (fp != NULL) {
    fseek(fp, 0, SEEK_END);
    long length = ftell(fp);
    fseek(fp, 0, SEEK_SET);
    char *buffer = malloc((length + 1) * sizeof(char));
    long offset = 0;
    char c;
    while ((c = fgetc(fp)) != EOF) {
      buffer[offset++] = c;
    }
    buffer[offset] = '\0';
    fclose(fp);
    return buffer;
  }
  return "";
}


x86 assembly (clang, -O0):
<getFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe89(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     123e <getFile+0xde>
mov    -0x18(%rbp),%rdi
mov    0x2e52(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x18(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rdi
mov    0x2e19(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
add    $0x1,%rdi
shl    $0x0,%rdi
call   1060 <malloc@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %al,-0x31(%rbp)
movsbl %al,%eax
mov    0x2ded(%rip),%rcx
movsbl (%rcx),%ecx
cmp    %ecx,%eax
je     121c <getFile+0xbc>
mov    -0x31(%rbp),%dl
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rsi
add    $0x1,%rsi
mov    %rsi,-0x30(%rbp)
mov    %dl,(%rax,%rcx,1)
jmp    11dd <getFile+0x7d>
mov    -0x28(%rbp),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1249 <getFile+0xe9>
lea    0xdbc(%rip),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<getFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     1205 <getFile+0xa5>
mov    %rax,%r14
mov    0x2e61(%rip),%rax
mov    (%rax),%edx
xor    %ebx,%ebx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %r14,%rdi
call   1050 <ftell@plt>
mov    %rax,%r15
mov    0x2e29(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
add    $0x1,%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%r15
mov    %r14,%rdi
call   1040 <fgetc@plt>
mov    0x2e0f(%rip),%r12
cmp    (%r12),%al
je     11f6 <getFile+0x96>
xor    %ebx,%ebx
nopl   0x0(%rax)
mov    %al,(%r15,%rbx,1)
add    $0x1,%rbx
mov    %r14,%rdi
call   1040 <fgetc@plt>
cmp    (%r12),%al
jne    11e0 <getFile+0x80>
movb   $0x0,(%r15,%rbx,1)
mov    %r14,%rdi
call   1030 <fclose@plt>
jmp    120c <getFile+0xac>
lea    0xdf5(%rip),%r15
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@EOF = global i8 0
@.str.1 = [1 x i8] zeroinitializer
define i8* @getFile(i8* nocapture %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 %27, 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 = load i32, i32* @SEEK_SET
%9 = tail call i32 @fseek(i32* %2, i32 0, i32 %8)
%10 = add nsw i64 %7, 1
%11 = tail call i8* @malloc(i64 %10)
%12 = tail call signext i8 @fgetc(i32* %2)
%13 = load i8, i8* @EOF
%14 = icmp eq i8 %12, %13
br i1 %14, label %23, label %15
15: ; preds = %4, %15
%16 = phi i8 [ %20, %15 ], [ %12, %4 ]
%17 = phi i64 [ %18, %15 ], [ 0, %4 ]
%18 = add nuw nsw i64 %17, 1
%19 = getelementptr inbounds i8, i8* %11, i64 %17
store i8 %16, i8* %19
%20 = tail call signext i8 @fgetc(i32* %2)
%21 = load i8, i8* @EOF
%22 = icmp eq i8 %20, %21
br i1 %22, label %23, label %15
23: ; preds = %15, %4
%24 = phi i64 [ 0, %4 ], [ %18, %15 ]
%25 = getelementptr inbounds i8, i8* %11, i64 %24
store i8 0, i8* %25
%26 = tail call i32 @fclose(i32* %2)
br label %27
27: ; preds = %1, %23
%28 = phi i8* [ %11, %23 ], [ getelementptr inbounds ([1 x i8], [1 x i8]* @.str.1, i64 0, i64 0), %1 ]
ret i8* %28
}