#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*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
int ftell(int /*<<< orphan*/ *);
char *malloc(int);
int internalize(char *srcfilename, char **srcbuf) {
  int fsize, rsize;
  FILE *srcfile = fopen(srcfilename, "rb");
  fseek(srcfile, 0L, SEEK_END);
  fsize = ftell(srcfile);
  fseek(srcfile, 0L, SEEK_SET);
  *srcbuf = malloc(fsize + 1);
  rsize = fread(*srcbuf, fsize, 1, srcfile);
  fclose(srcfile);
  return rsize;
}


x86 assembly (clang, -O0):
<internalize>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e59(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %eax,-0x14(%rbp)
mov    -0x20(%rbp),%rdi
mov    0x2e27(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1070 <fseek@plt>
mov    -0x14(%rbp),%edi
add    $0x1,%edi
call   1060 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x14(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<internalize>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
lea    0xe8f(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,%rbx
mov    0x2e68(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %eax,%r15d
mov    0x2e3a(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
lea    0x1(%r15),%edi
call   1060 <malloc@plt>
mov    %rax,(%r14)
mov    %rax,%rdi
mov    %r15d,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %ebp,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @internalize(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca i32*
store i8* %0, i8** %3
store i8** %1, 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** %7
%10 = load i32*, i32** %7
%11 = load i32, i32* @SEEK_END
%12 = call i32 @fseek(i32* %10, i64 0, i32 %11)
%13 = load i32*, i32** %7
%14 = call i32 @ftell(i32* %13)
store i32 %14, i32* %5
%15 = load i32*, i32** %7
%16 = load i32, i32* @SEEK_SET
%17 = call i32 @fseek(i32* %15, i64 0, i32 %16)
%18 = load i32, i32* %5
%19 = add nsw i32 %18, 1
%20 = call i8* @malloc(i32 %19)
%21 = load i8**, i8*** %4
store i8* %20, i8** %21
%22 = load i8**, i8*** %4
%23 = load i8*, i8** %22
%24 = load i32, i32* %5
%25 = load i32*, i32** %7
%26 = call i32 @fread(i8* %23, i32 %24, i32 1, i32* %25)
store i32 %26, i32* %6
%27 = load i32*, i32** %7
%28 = call i32 @fclose(i32* %27)
%29 = load i32, i32* %6
ret i32 %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i32 @internalize(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = load i32, i32* @SEEK_END
%5 = tail call i32 @fseek(i32* %3, i64 0, i32 %4)
%6 = tail call i32 @ftell(i32* %3)
%7 = load i32, i32* @SEEK_SET
%8 = tail call i32 @fseek(i32* %3, i64 0, i32 %7)
%9 = add nsw i32 %6, 1
%10 = tail call i8* @malloc(i32 %9)
store i8* %10, i8** %1
%11 = tail call i32 @fread(i8* %10, i32 %6, i32 1, i32* %3)
%12 = tail call i32 @fclose(i32* %3)
ret i32 %11
}