#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__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
scalar_t__ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
char *malloc(int);
int /*<<< orphan*/ stderr;
char *readFile(char *path) {
  char *source = NULL;
  FILE *fp = fopen(path, "rb");
  if (fp != NULL) {
    if (fseek(fp, 0L, SEEK_END) == 0) {
      size_t bufsize = ftell(fp);
      if (bufsize == -1) {
        fprintf(stderr, "Error reading file %s\n", path);
        return NULL;
      }
      source = malloc(sizeof(char) * (bufsize + 1));
      if (source == NULL) {
        fprintf(stderr, "Error reading file %s\n", path);
        return NULL;
      }
      if (fseek(fp, 0L, SEEK_SET) != 0) {
        fprintf(stderr, "Error reading file %s\n", path);
        free(source);
        return NULL;
      }
      size_t fileLen = fread(source, sizeof(char), bufsize, fp);
      if (ferror(fp) != 0) {
        fprintf(stderr, "Error reading file %s\n", path);
        free(source);
        return NULL;
      } else {
        source[fileLen++] = '\0';
      }
    }
    fclose(fp);
  }
  return source;
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1339 <readFile+0x1a9>
mov    -0x20(%rbp),%rdi
mov    0x2e1a(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
jne    1330 <readFile+0x1a0>
mov    -0x20(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0xffffffffffffffff,-0x28(%rbp)
jne    1221 <readFile+0x91>
mov    0x2dd6(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdf4(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1341 <readFile+0x1b1>
mov    -0x28(%rbp),%rax
add    $0x1,%rax
shl    $0x0,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1269 <readFile+0xd9>
mov    0x2d8e(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdac(%rip),%rsi
call   1070 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1341 <readFile+0x1b1>
mov    -0x20(%rbp),%rdi
mov    0x2d5c(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   10a0 <fseek@plt>
cmp    $0x0,%rax
je     12b8 <readFile+0x128>
mov    0x2d48(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd66(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1341 <readFile+0x1b1>
mov    -0x18(%rbp),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1050 <fread@plt>
mov    %rax,-0x30(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <ferror@plt>
cmp    $0x0,%rax
je     1314 <readFile+0x184>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xd0a(%rip),%rsi
call   1070 <fprintf@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1341 <readFile+0x1b1>
mov    -0x18(%rbp),%rax
mov    -0x30(%rbp),%rcx
mov    %rcx,%rdx
add    $0x1,%rdx
mov    %rdx,-0x30(%rbp)
movb   $0x0,(%rax,%rcx,1)
jmp    1330 <readFile+0x1a0>
mov    -0x20(%rbp),%rdi
call   1060 <fclose@plt>
mov    -0x18(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdi,%r14
lea    0xe5e(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1271 <readFile+0xe1>
mov    %rax,%rbx
mov    0x2e2e(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %rax,%rax
je     11db <readFile+0x4b>
mov    %rbx,%rdi
call   1060 <fclose@plt>
jmp    1274 <readFile+0xe4>
mov    %rbx,%rdi
call   1080 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     1259 <readFile+0xc9>
mov    %rax,%r12
lea    0x1(%rax),%edi
call   1090 <malloc@plt>
test   %rax,%rax
je     1259 <readFile+0xc9>
mov    %rax,%r15
mov    0x2dcd(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
test   %rax,%rax
jne    1237 <readFile+0xa7>
mov    %r15,%rdi
mov    $0x1,%esi
mov    %r12,%rdx
mov    %rbx,%rcx
call   1050 <fread@plt>
mov    %rax,%r12
mov    %rbx,%rdi
call   1040 <ferror@plt>
test   %rax,%rax
je     1283 <readFile+0xf3>
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
lea    0xdbc(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
mov    %r15,%rdi
call   1030 <free@plt>
jmp    1271 <readFile+0xe1>
mov    0x2d78(%rip),%rax
mov    (%rax),%edi
lea    0xd9a(%rip),%rsi
mov    %r14,%rdx
call   1070 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret
movb   $0x0,(%r15,%r12,1)
jmp    11ce <readFile+0x3e>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error reading file %s\0A\00"
@SEEK_SET = global i32 0
define i8* @readFile(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
store i8* null, i8** %4
%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 %72
12: ; preds = %1
%13 = load i32*, i32** %5
%14 = load i32, i32* @SEEK_END
%15 = call i64 @fseek(i32* %13, i64 0, i32 %14)
%16 = icmp eq i64 %15, 0
br i1 %16, label %17, label %69
17: ; preds = %12
%18 = load i32*, i32** %5
%19 = call i64 @ftell(i32* %18)
store i64 %19, i64* %6
%20 = load i64, i64* %6
%21 = icmp eq i64 %20, -1
br i1 %21, label %22, label %26
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %3
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %24)
store i8* null, i8** %2
br label %74
26: ; preds = %17
%27 = load i64, i64* %6
%28 = add i64 %27, 1
%29 = mul i64 1, %28
%30 = trunc i64 %29 to i32
%31 = call i8* @malloc(i32 %30)
store i8* %31, i8** %4
%32 = load i8*, i8** %4
%33 = icmp eq i8* %32, null
br i1 %33, label %34, label %38
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i8*, i8** %3
%37 = call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %36)
store i8* null, i8** %2
br label %74
38: ; preds = %26
%39 = load i32*, i32** %5
%40 = load i32, i32* @SEEK_SET
%41 = call i64 @fseek(i32* %39, i64 0, i32 %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %49
43: ; preds = %38
%44 = load i32, i32* @stderr
%45 = load i8*, i8** %3
%46 = call i32 @fprintf(i32 %44, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %45)
%47 = load i8*, i8** %4
%48 = call i32 @free(i8* %47)
store i8* null, i8** %2
br label %74
49: ; preds = %38
%50 = load i8*, i8** %4
%51 = load i64, i64* %6
%52 = load i32*, i32** %5
%53 = call i64 @fread(i8* %50, i32 1, i64 %51, i32* %52)
store i64 %53, i64* %7
%54 = load i32*, i32** %5
%55 = call i64 @ferror(i32* %54)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %63
57: ; preds = %49
%58 = load i32, i32* @stderr
%59 = load i8*, i8** %3
%60 = call i32 @fprintf(i32 %58, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %59)
%61 = load i8*, i8** %4
%62 = call i32 @free(i8* %61)
store i8* null, i8** %2
br label %74
63: ; preds = %49
%64 = load i8*, i8** %4
%65 = load i64, i64* %7
%66 = add i64 %65, 1
store i64 %66, i64* %7
%67 = getelementptr inbounds i8, i8* %64, i64 %65
store i8 0, i8* %67
br label %68
68: ; preds = %63
br label %69
69: ; preds = %68, %12
%70 = load i32*, i32** %5
%71 = call i32 @fclose(i32* %70)
br label %72
72: ; preds = %69, %1
%73 = load i8*, i8** %4
store i8* %73, i8** %2
br label %74
74: ; preds = %72, %57, %43, %34, %22
%75 = load i8*, i8** %2
ret i8* %75
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@stderr = global i32 0
@.str.1 = [23 x i8] c"Error reading file %s\0A\00"
@SEEK_SET = global i32 0
define noalias i8* @readFile(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 %43, label %4
4: ; preds = %1
%5 = load i32, i32* @SEEK_END
%6 = tail call i64 @fseek(i32* %2, i64 0, i32 %5)
%7 = icmp eq i64 %6, 0
br i1 %7, label %8, label %40
8: ; preds = %4
%9 = tail call i64 @ftell(i32* %2)
%10 = icmp eq i64 %9, -1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = tail call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %43
14: ; preds = %8
%15 = trunc i64 %9 to i32
%16 = add i32 %15, 1
%17 = tail call i8* @malloc(i32 %16)
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %14
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %43
22: ; preds = %14
%23 = load i32, i32* @SEEK_SET
%24 = tail call i64 @fseek(i32* %2, i64 0, i32 %23)
%25 = icmp eq i64 %24, 0
br i1 %25, label %30, label %26
26: ; preds = %22
%27 = load i32, i32* @stderr
%28 = tail call i32 @fprintf(i32 %27, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%29 = tail call i32 @free(i8* %17)
br label %43
30: ; preds = %22
%31 = tail call i64 @fread(i8* %17, i32 1, i64 %9, i32* %2)
%32 = tail call i64 @ferror(i32* %2)
%33 = icmp eq i64 %32, 0
br i1 %33, label %38, label %34
34: ; preds = %30
%35 = load i32, i32* @stderr
%36 = tail call i32 @fprintf(i32 %35, i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%37 = tail call i32 @free(i8* %17)
br label %43
38: ; preds = %30
%39 = getelementptr inbounds i8, i8* %17, i64 %31
store i8 0, i8* %39
br label %40
40: ; preds = %38, %4
%41 = phi i8* [ %17, %38 ], [ null, %4 ]
%42 = tail call i32 @fclose(i32* %2)
br label %43
43: ; preds = %34, %26, %19, %11, %1, %40
%44 = phi i8* [ %41, %40 ], [ null, %1 ], [ null, %11 ], [ null, %19 ], [ null, %26 ], [ null, %34 ]
ret i8* %44
}