#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;
char *calloc(int, long);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *get_file_contents(const char *filename, long *outpSize) {
  char *source = NULL;
  FILE *fp = fopen(filename, "r");
  if (fp != NULL) {
    if (fseek(fp, 0L, SEEK_END) == 0) {
      long bufsize = ftell(fp);
      if (bufsize == -1) {
      }
      source = calloc(sizeof(char), (bufsize + 1));
      if (fseek(fp, 0L, SEEK_SET) != 0) {
      }
      size_t newLen = fread(source, sizeof(char), bufsize, fp);
      if (newLen == 0) {
        fputs("Error reading file", stderr);
      } else {
      }
      if (outpSize != NULL) {
        *outpSize = bufsize;
      }
    }
    fclose(fp);
  }
  return (source);
}


x86 assembly (clang, -O0):
<get_file_contents>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe6d(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1287 <get_file_contents+0x117>
mov    -0x20(%rbp),%rdi
mov    0x2e36(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
jne    127e <get_file_contents+0x10e>
mov    -0x20(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    11e4 <get_file_contents+0x74>
jmp    11e4 <get_file_contents+0x74>
mov    -0x28(%rbp),%rsi
add    $0x1,%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2dcb(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
je     121f <get_file_contents+0xaf>
jmp    121f <get_file_contents+0xaf>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    125e <get_file_contents+0xee>
mov    0x2d8d(%rip),%rax
mov    (%rax),%esi
lea    0xdae(%rip),%rdi
call   1050 <fputs@plt>
jmp    1263 <get_file_contents+0xf3>
jmp    1263 <get_file_contents+0xf3>
cmpq   $0x0,-0x10(%rbp)
je     1279 <get_file_contents+0x109>
mov    -0x28(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
jmp    127e <get_file_contents+0x10e>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_contents>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe7e(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121c <get_file_contents+0xac>
mov    %rax,%rbx
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1212 <get_file_contents+0xa2>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%r12
lea    0x1(%rax),%rsi
mov    $0x1,%edi
call   1060 <calloc@plt>
mov    %rax,%r15
mov    0x2dff(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
test   %rax,%rax
jne    120a <get_file_contents+0x9a>
mov    0x2ddc(%rip),%rax
mov    (%rax),%esi
lea    0xdfd(%rip),%rdi
call   1050 <fputs@plt>
test   %r14,%r14
je     1212 <get_file_contents+0xa2>
mov    %r12,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    121f <get_file_contents+0xaf>
xor    %r15d,%r15d
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
@.str.1 = [19 x i8] c"Error reading file\00"
@stderr = global i32 0
define i8* @get_file_contents(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i64
%8 = alloca i64
store i8* %0, i8** %3
store i64* %1, i64** %4
store i8* null, i8** %5
%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** %6
%11 = load i32*, i32** %6
%12 = icmp ne i32* %11, null
br i1 %12, label %13, label %54
13: ; preds = %2
%14 = load i32*, i32** %6
%15 = load i32, i32* @SEEK_END
%16 = call i64 @fseek(i32* %14, i64 0, i32 %15)
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %51
18: ; preds = %13
%19 = load i32*, i32** %6
%20 = call i64 @ftell(i32* %19)
store i64 %20, i64* %7
%21 = load i64, i64* %7
%22 = icmp eq i64 %21, -1
br i1 %22, label %23, label %24
23: ; preds = %18
br label %24
24: ; preds = %23, %18
%25 = load i64, i64* %7
%26 = add nsw i64 %25, 1
%27 = call i8* @calloc(i32 1, i64 %26)
store i8* %27, i8** %5
%28 = load i32*, i32** %6
%29 = load i32, i32* @SEEK_SET
%30 = call i64 @fseek(i32* %28, i64 0, i32 %29)
%31 = icmp ne i64 %30, 0
br i1 %31, label %32, label %33
32: ; preds = %24
br label %33
33: ; preds = %32, %24
%34 = load i8*, i8** %5
%35 = load i64, i64* %7
%36 = load i32*, i32** %6
%37 = call i64 @fread(i8* %34, i32 1, i64 %35, i32* %36)
store i64 %37, i64* %8
%38 = load i64, i64* %8
%39 = icmp eq i64 %38, 0
br i1 %39, label %40, label %43
40: ; preds = %33
%41 = load i32, i32* @stderr
%42 = call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %41)
br label %44
43: ; preds = %33
br label %44
44: ; preds = %43, %40
%45 = load i64*, i64** %4
%46 = icmp ne i64* %45, null
br i1 %46, label %47, label %50
47: ; preds = %44
%48 = load i64, i64* %7
%49 = load i64*, i64** %4
store i64 %48, i64* %49
br label %50
50: ; preds = %47, %44
br label %51
51: ; preds = %50, %13
%52 = load i32*, i32** %6
%53 = call i32 @fclose(i32* %52)
br label %54
54: ; preds = %51, %2
%55 = load i8*, i8** %5
ret i8* %55
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.1 = [19 x i8] c"Error reading file\00"
@stderr = global i32 0
define i8* @get_file_contents(i8* nocapture %0, i64* writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %26, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i64 @fseek(i32* %3, i64 0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %23
9: ; preds = %5
%10 = tail call i64 @ftell(i32* %3)
%11 = add nsw i64 %10, 1
%12 = tail call i8* @calloc(i32 1, i64 %11)
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @fseek(i32* %3, i64 0, i32 %13)
%15 = tail call i64 @fread(i8* %12, i32 1, i64 %10, i32* %3)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %20
17: ; preds = %9
%18 = load i32, i32* @stderr
%19 = tail call i32 @fputs(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.1, i64 0, i64 0), i32 %18)
br label %20
20: ; preds = %9, %17
%21 = icmp eq i64* %1, null
br i1 %21, label %23, label %22
22: ; preds = %20
store i64 %10, i64* %1
br label %23
23: ; preds = %20, %22, %5
%24 = phi i8* [ null, %5 ], [ %12, %22 ], [ %12, %20 ]
%25 = tail call i32 @fclose(i32* %3)
br label %26
26: ; preds = %23, %2
%27 = phi i8* [ %24, %23 ], [ null, %2 ]
ret i8* %27
}