#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*/ Die(char *, char *);
int EOF;
int fgetc(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ printf(char *, char *);
FILE *ReadFile(char *filename, char *buff) {
  FILE *file;
  int i, n;
  if ((file = fopen(filename, "r+b")) == NULL)
    Die("Cannot open %s\n", filename);
  printf("Reading %s...\n", filename);
  for (i = 0; i < 16384; i++) {
    if ((n = fgetc(file)) == EOF) {
      buff[i] = 0;
      return file;
    }
    buff[i] = n;
  }
  buff[16384 - 1] = 0;
  return file;
}


x86 assembly (clang, -O0):
<ReadFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmp    $0x0,%rax
jne    117e <ReadFile+0x3e>
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1050 <Die@plt>
mov    -0x10(%rbp),%rsi
lea    0xe8b(%rip),%rdi
call   1030 <printf@plt>
movl   $0x0,-0x24(%rbp)
cmpl   $0x4000,-0x24(%rbp)
jge    11f4 <ReadFile+0xb4>
mov    -0x20(%rbp),%rdi
call   1040 <fgetc@plt>
mov    %eax,-0x28(%rbp)
mov    0x2e33(%rip),%rcx
cmp    (%rcx),%eax
jne    11d6 <ReadFile+0x96>
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x20(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1207 <ReadFile+0xc7>
mov    -0x28(%rbp),%eax
mov    %al,%dl
mov    -0x18(%rbp),%rax
movslq -0x24(%rbp),%rcx
mov    %dl,(%rax,%rcx,1)
mov    -0x24(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x24(%rbp)
jmp    1195 <ReadFile+0x55>
mov    -0x18(%rbp),%rax
movb   $0x0,0x3fff(%rax)
mov    -0x20(%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    %rsi,%r14
mov    %rdi,%r15
lea    0xeab(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%r12
test   %rax,%rax
jne    1171 <ReadFile+0x31>
lea    0xe9b(%rip),%rdi
mov    %r15,%rsi
call   1050 <Die@plt>
lea    0xe9c(%rip),%rdi
mov    %r15,%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
mov    0x2e5f(%rip),%r15
nopl   0x0(%rax)
mov    %r12,%rdi
call   1040 <fgetc@plt>
cmp    (%r15),%eax
je     11b3 <ReadFile+0x73>
mov    %al,(%r14,%rbx,1)
add    $0x1,%rbx
cmp    $0x4000,%rbx
jne    1190 <ReadFile+0x50>
mov    $0x3fff,%ebx
movb   $0x0,(%r14,%rbx,1)
mov    %r12,%rax
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [16 x i8] c"Cannot open %s\0A\00"
@.str.2 = [15 x i8] c"Reading %s...\0A\00"
@EOF = global i32 0
define i32* @ReadFile(i8* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i8*
%6 = alloca i32*
%7 = alloca i32
%8 = alloca i32
store i8* %0, i8** %4
store i8* %1, i8** %5
%9 = load i8*, i8** %4
%10 = call i32* @fopen(i8* %9, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
store i32* %10, i32** %6
%11 = icmp eq i32* %10, null
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = load i8*, i8** %4
%14 = call i32 @Die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %15
15: ; preds = %12, %2
%16 = load i8*, i8** %4
%17 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %16)
store i32 0, i32* %7
br label %18
18: ; preds = %39, %15
%19 = load i32, i32* %7
%20 = icmp slt i32 %19, 16384
br i1 %20, label %21, label %42
21: ; preds = %18
%22 = load i32*, i32** %6
%23 = call i32 @fgetc(i32* %22)
store i32 %23, i32* %8
%24 = load i32, i32* @EOF
%25 = icmp eq i32 %23, %24
br i1 %25, label %26, label %32
26: ; preds = %21
%27 = load i8*, i8** %5
%28 = load i32, i32* %7
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds i8, i8* %27, i64 %29
store i8 0, i8* %30
%31 = load i32*, i32** %6
store i32* %31, i32** %3
br label %46
32: ; preds = %21
%33 = load i32, i32* %8
%34 = trunc i32 %33 to i8
%35 = load i8*, i8** %5
%36 = load i32, i32* %7
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds i8, i8* %35, i64 %37
store i8 %34, i8* %38
br label %39
39: ; preds = %32
%40 = load i32, i32* %7
%41 = add nsw i32 %40, 1
store i32 %41, i32* %7
br label %18
42: ; preds = %18
%43 = load i8*, i8** %5
%44 = getelementptr inbounds i8, i8* %43, i64 16383
store i8 0, i8* %44
%45 = load i32*, i32** %6
store i32* %45, i32** %3
br label %46
46: ; preds = %42, %26
%47 = load i32*, i32** %3
ret i32* %47
}

LLVM IR (-O2):
@.str = [4 x i8] c"r+b\00"
@.str.1 = [16 x i8] c"Cannot open %s\0A\00"
@.str.2 = [15 x i8] c"Reading %s...\0A\00"
@EOF = global i32 0
define noalias i32* @ReadFile(i8* %0, i8* nocapture writeonly %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %7
5: ; preds = %2
%6 = tail call i32 @Die(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %7
7: ; preds = %5, %2
%8 = tail call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %0)
br label %9
9: ; preds = %7, %16
%10 = phi i64 [ 0, %7 ], [ %19, %16 ]
%11 = tail call i32 @fgetc(i32* %3)
%12 = load i32, i32* @EOF
%13 = icmp eq i32 %11, %12
br i1 %13, label %14, label %16
14: ; preds = %9
%15 = and i64 %10, 4294967295
br label %21
16: ; preds = %9
%17 = trunc i32 %11 to i8
%18 = getelementptr inbounds i8, i8* %1, i64 %10
store i8 %17, i8* %18
%19 = add nuw nsw i64 %10, 1
%20 = icmp eq i64 %19, 16384
br i1 %20, label %21, label %9
21: ; preds = %16, %14
%22 = phi i64 [ %15, %14 ], [ 16383, %16 ]
%23 = getelementptr inbounds i8, i8* %1, i64 %22
store i8 0, i8* %23
ret i32* %3
}