#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
char *read_file(char *path, size_t *srcLen) {
  int fsize;
  char *contents;
  FILE *f;
  f = fopen(path, "rb");
  if (!f) {
    fprintf(stderr, "FXML: Could not open file \"%s\"\n", path);
    return NULL;
  }
  fseek(f, 0, SEEK_END);
  fsize = ftell(f);
  rewind(f);
  contents = (char *)malloc(fsize + 1);
  fread(contents, sizeof(char), fsize, f);
  contents[fsize] = 0;
  fclose(f);
  if (srcLen)
    *srcLen = fsize;
  return contents;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe65(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d5 <read_file+0x55>
mov    0x2e22(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xe40(%rip),%rsi
call   1060 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1255 <read_file+0xd5>
mov    -0x30(%rbp),%rdi
mov    0x2e08(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x30(%rbp),%rdi
call   1070 <ftell@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <rewind@plt>
mov    -0x1c(%rbp),%edi
add    $0x1,%edi
call   1080 <malloc@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdi
mov    -0x1c(%rbp),%edx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x28(%rbp),%rax
movslq -0x1c(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rdi
call   1040 <fclose@plt>
cmpq   $0x0,-0x18(%rbp)
je     124d <read_file+0xcd>
movslq -0x1c(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe6b(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1202 <read_file+0x82>
mov    %rax,%rbx
mov    0x2e3f(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %eax,%r12d
mov    %rbx,%rdi
call   1050 <rewind@plt>
lea    0x1(%r12),%edi
call   1080 <malloc@plt>
mov    %rax,%r15
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r12d,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
movslq %r12d,%r12
movb   $0x0,(%r15,%r12,1)
mov    %rbx,%rdi
call   1040 <fclose@plt>
test   %r14,%r14
je     121d <read_file+0x9d>
mov    %r12,(%r14)
jmp    121d <read_file+0x9d>
mov    0x2dcf(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
mov    %r15,%rdx
call   1060 <fprintf@plt>
xor    %r15d,%r15d
mov    %r15,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"FXML: Could not open file \22%s\22\0A\00"
@SEEK_END = global i32 0
define i8* @read_file(i8* %0, i64* writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %8
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %22
8: ; preds = %2
%9 = load i32, i32* @SEEK_END
%10 = tail call i32 @fseek(i32* %3, i32 0, i32 %9)
%11 = tail call i32 @ftell(i32* %3)
%12 = tail call i32 @rewind(i32* %3)
%13 = add nsw i32 %11, 1
%14 = tail call i64 @malloc(i32 %13)
%15 = inttoptr i64 %14 to i8*
%16 = tail call i32 @fread(i8* %15, i32 1, i32 %11, i32* %3)
%17 = sext i32 %11 to i64
%18 = getelementptr inbounds i8, i8* %15, i64 %17
store i8 0, i8* %18
%19 = tail call i32 @fclose(i32* %3)
%20 = icmp eq i64* %1, null
br i1 %20, label %22, label %21
21: ; preds = %8
store i64 %17, i64* %1
br label %22
22: ; preds = %8, %21, %5
%23 = phi i8* [ null, %5 ], [ %15, %21 ], [ %15, %8 ]
ret i8* %23
}