#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*/ assert(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *, ...);
size_t fread(char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
char *malloc(long);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int read_in_file(const char *filename, char **data, size_t *size) {
  FILE *fp = fopen(filename, "rb");
  if (!fp) {
    fprintf(stderr, "%s: %s\n", filename, strerror(errno));
    return -1;
  }
  fseek(fp, 0, SEEK_END);
  long off = ftell(fp);
  fseek(fp, 0, SEEK_SET);
  if (!off) {
    fprintf(stderr, "%s: Warning: file has no content\n", filename);
  }
  *data = malloc(off + 1);
  size_t r = fread(*data, 1, off, fp);
  assert((long)r == off);
  (*data)[off] = '\0';
  *size = off;
  fclose(fp);
  return 0;
}


x86 assembly (clang, -O0):
<read_in_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xe51(%rip),%rsi
call   10a0 <fopen@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jne    1209 <read_in_file+0x79>
mov    0x2e0e(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    0x2df2(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xe0d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12d7 <read_in_file+0x147>
mov    -0x28(%rbp),%rdi
mov    0x2dd4(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
mov    -0x28(%rbp),%rdi
call   1070 <ftell@plt>
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
mov    0x2d93(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1090 <fseek@plt>
cmpq   $0x0,-0x30(%rbp)
jne    1264 <read_in_file+0xd4>
mov    0x2d88(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rdx
lea    0xdae(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
mov    -0x30(%rbp),%rdi
add    $0x1,%rdi
call   1080 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x30(%rbp),%rdx
mov    -0x28(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rax
cmp    -0x30(%rbp),%rax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rax
mov    -0x30(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x30(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x28(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_in_file>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %rsi,%r15
mov    %rdi,%r13
lea    0xe55(%rip),%rsi
call   10a0 <fopen@plt>
test   %rax,%rax
je     1250 <read_in_file+0xc0>
mov    %rax,%rbx
mov    0x2e25(%rip),%rax
mov    (%rax),%edx
xor    %r12d,%r12d
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
mov    %rbx,%rdi
call   1070 <ftell@plt>
mov    %rax,%rbp
mov    0x2de4(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1090 <fseek@plt>
test   %rbp,%rbp
jne    120f <read_in_file+0x7f>
mov    0x2ddc(%rip),%rax
mov    (%rax),%edi
lea    0xe06(%rip),%rsi
mov    %r13,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
lea    0x1(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,(%r15)
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbp,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
cmp    %rbp,%rax
sete   %dil
call   1050 <assert@plt>
mov    (%r15),%rax
movb   $0x0,(%rax,%rbp,1)
mov    %rbp,(%r14)
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    1283 <read_in_file+0xf3>
mov    0x2d81(%rip),%rax
mov    (%rax),%ebx
mov    0x2d70(%rip),%rax
mov    (%rax),%edi
call   10b0 <strerror@plt>
lea    0xd95(%rip),%rsi
mov    %ebx,%edi
mov    %r13,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0xffffffff,%r12d
mov    %r12d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [34 x i8] c"%s: Warning: file has no content\0A\00"
define i32 @read_in_file(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca i32*
%9 = alloca i64
%10 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%11 = load i8*, i8** %5
%12 = call i32* @fopen(i8* %11, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %12, i32** %8
%13 = load i32*, i32** %8
%14 = icmp ne i32* %13, null
br i1 %14, label %21, label %15
15: ; preds = %3
%16 = load i32, i32* @stderr
%17 = load i8*, i8** %5
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %17, i8* %19)
store i32 -1, i32* %4
br label %59
21: ; preds = %3
%22 = load i32*, i32** %8
%23 = load i32, i32* @SEEK_END
%24 = call i32 @fseek(i32* %22, i32 0, i32 %23)
%25 = load i32*, i32** %8
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %9
%27 = load i32*, i32** %8
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @fseek(i32* %27, i32 0, i32 %28)
%30 = load i64, i64* %9
%31 = icmp ne i64 %30, 0
br i1 %31, label %36, label %32
32: ; preds = %21
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %5
%35 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %36
36: ; preds = %32, %21
%37 = load i64, i64* %9
%38 = add nsw i64 %37, 1
%39 = call i8* @malloc(i64 %38)
%40 = load i8**, i8*** %6
store i8* %39, i8** %40
%41 = load i8**, i8*** %6
%42 = load i8*, i8** %41
%43 = load i64, i64* %9
%44 = load i32*, i32** %8
%45 = call i64 @fread(i8* %42, i32 1, i64 %43, i32* %44)
store i64 %45, i64* %10
%46 = load i64, i64* %10
%47 = load i64, i64* %9
%48 = icmp eq i64 %46, %47
%49 = zext i1 %48 to i32
%50 = call i32 @assert(i32 %49)
%51 = load i8**, i8*** %6
%52 = load i8*, i8** %51
%53 = load i64, i64* %9
%54 = getelementptr inbounds i8, i8* %52, i64 %53
store i8 0, i8* %54
%55 = load i64, i64* %9
%56 = load i64*, i64** %7
store i64 %55, i64* %56
%57 = load i32*, i32** %8
%58 = call i32 @fclose(i32* %57)
store i32 0, i32* %4
br label %59
59: ; preds = %36, %15
%60 = load i32, i32* %4
ret i32 %60
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [8 x i8] c"%s: %s\0A\00"
@errno = global i32 0
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
@.str.2 = [34 x i8] c"%s: Warning: file has no content\0A\00"
define i32 @read_in_file(i8* %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %11
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = load i32, i32* @errno
%9 = tail call i8* @strerror(i32 %8)
%10 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.1, i64 0, i64 0), i8* %0, i8* %9)
br label %31
11: ; preds = %3
%12 = load i32, i32* @SEEK_END
%13 = tail call i32 @fseek(i32* %4, i32 0, i32 %12)
%14 = tail call i64 @ftell(i32* %4)
%15 = load i32, i32* @SEEK_SET
%16 = tail call i32 @fseek(i32* %4, i32 0, i32 %15)
%17 = icmp eq i64 %14, 0
br i1 %17, label %18, label %21
18: ; preds = %11
%19 = load i32, i32* @stderr
%20 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %21
21: ; preds = %18, %11
%22 = add nsw i64 %14, 1
%23 = tail call i8* @malloc(i64 %22)
store i8* %23, i8** %1
%24 = tail call i64 @fread(i8* %23, i32 1, i64 %14, i32* %4)
%25 = icmp eq i64 %24, %14
%26 = zext i1 %25 to i32
%27 = tail call i32 @assert(i32 %26)
%28 = load i8*, i8** %1
%29 = getelementptr inbounds i8, i8* %28, i64 %14
store i8 0, i8* %29
store i64 %14, i64* %2
%30 = tail call i32 @fclose(i32* %4)
br label %31
31: ; preds = %21, %6
%32 = phi i32 [ 0, %21 ], [ -1, %6 ]
ret i32 %32
}