#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, long, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ stderr;
void readFile(char *name, int *size, char **buffer) {
  FILE *file;
  file = fopen(name, "rb");
  if (file == NULL) {
    fprintf(stderr, "Error: Can not open \"%s\" file.\n", name);
    exit(1);
  }
  fseek(file, 0L, SEEK_END);
  *size = (int)ftell(file);
  if ((*size < 0) || (ftell(file) > (long)*size)) {
    fprintf(stderr, "Error: File is too large.\n");
    fclose(file);
    exit(1);
  }
  fseek(file, 0L, SEEK_SET);
  *buffer = (char *)malloc(*size);
  if (*buffer == NULL) {
    fprintf(stderr, "Error: Can not allocate %d bytes of memory.\n", *size);
    fclose(file);
    exit(1);
  }
  if (fread(*buffer, 1, *size, file) != *size) {
    fprintf(stderr, "Error: Can not read input file.\n");
    fclose(file);
    exit(1);
  }
  fclose(file);
}


x86 assembly (clang, -O0):
<readFile>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe61(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d8 <readFile+0x58>
mov    0x2e1e(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe3c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2e05(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    %eax,%ecx
mov    -0x10(%rbp),%rax
mov    %ecx,(%rax)
mov    -0x10(%rbp),%rax
cmpl   $0x0,(%rax)
jl     1225 <readFile+0xa5>
mov    -0x20(%rbp),%rdi
call   1060 <ftell@plt>
mov    -0x10(%rbp),%rcx
movslq (%rcx),%rcx
cmp    %rcx,%rax
jle    124f <readFile+0xcf>
mov    0x2dac(%rip),%rax
mov    (%rax),%edi
lea    0xdee(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
mov    0x2d76(%rip),%rax
mov    (%rax),%edx
xor    %eax,%eax
mov    %eax,%esi
call   1080 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    12b8 <readFile+0x138>
mov    0x2d49(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
lea    0xda0(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%edx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%eax
je     1309 <readFile+0x189>
mov    0x2cf2(%rip),%rax
mov    (%rax),%edi
lea    0xd7c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %r15
push   %r14
push   %r12
push   %rbx
push   %rax
mov    %rdx,%r15
mov    %rsi,%r14
mov    %rdi,%r12
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123b <readFile+0xbb>
mov    %rax,%rbx
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %eax,(%r14)
test   %eax,%eax
js     1229 <readFile+0xa9>
mov    %rbx,%rdi
call   1060 <ftell@plt>
movslq (%r14),%rcx
cmp    %rcx,%rax
jg     1229 <readFile+0xa9>
mov    0x2dee(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    (%r14),%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     125f <readFile+0xdf>
mov    (%r14),%edx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    (%r14),%eax
jne    127b <readFile+0xfb>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
jmp    1040 <fclose@plt>
mov    0x2da8(%rip),%rax
mov    (%rax),%edi
lea    0xdea(%rip),%rsi
jmp    128b <readFile+0x10b>
mov    0x2d96(%rip),%rax
mov    (%rax),%edi
lea    0xdb8(%rip),%rsi
mov    %r12,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    0x2d72(%rip),%rax
mov    (%rax),%edi
mov    (%r14),%edx
lea    0xdcc(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1292 <readFile+0x112>
mov    0x2d56(%rip),%rax
mov    (%rax),%edi
lea    0xde0(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Error: Can not open \22%s\22 file.\0A\00"
@SEEK_END = global i32 0
@.str.2 = [27 x i8] c"Error: File is too large.\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [45 x i8] c"Error: Can not allocate %d bytes of memory.\0A\00"
@.str.4 = [33 x i8] c"Error: Can not read input file.\0A\00"
define void @readFile(i8* %0, i32* %1, i8** %2) {
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i8**
%7 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
store i8** %2, i8*** %6
%8 = load i8*, i8** %4
%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 = icmp eq i32* %10, null
br i1 %11, label %12, label %17
12: ; preds = %3
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %4
%15 = call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %3
%18 = load i32*, i32** %7
%19 = load i32, i32* @SEEK_END
%20 = call i32 @fseek(i32* %18, i64 0, i32 %19)
%21 = load i32*, i32** %7
%22 = call i64 @ftell(i32* %21)
%23 = trunc i64 %22 to i32
%24 = load i32*, i32** %5
store i32 %23, i32* %24
%25 = load i32*, i32** %5
%26 = load i32, i32* %25
%27 = icmp slt i32 %26, 0
br i1 %27, label %35, label %28
28: ; preds = %17
%29 = load i32*, i32** %7
%30 = call i64 @ftell(i32* %29)
%31 = load i32*, i32** %5
%32 = load i32, i32* %31
%33 = sext i32 %32 to i64
%34 = icmp sgt i64 %30, %33
br i1 %34, label %35, label %41
35: ; preds = %28, %17
%36 = load i32, i32* @stderr
%37 = call i32 (i32, i8*, ...) @fprintf(i32 %36, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%38 = load i32*, i32** %7
%39 = call i32 @fclose(i32* %38)
%40 = call i32 @exit(i32 1)
unreachable
41: ; preds = %28
%42 = load i32*, i32** %7
%43 = load i32, i32* @SEEK_SET
%44 = call i32 @fseek(i32* %42, i64 0, i32 %43)
%45 = load i32*, i32** %5
%46 = load i32, i32* %45
%47 = call i64 @malloc(i32 %46)
%48 = inttoptr i64 %47 to i8*
%49 = load i8**, i8*** %6
store i8* %48, i8** %49
%50 = load i8**, i8*** %6
%51 = load i8*, i8** %50
%52 = icmp eq i8* %51, null
br i1 %52, label %53, label %61
53: ; preds = %41
%54 = load i32, i32* @stderr
%55 = load i32*, i32** %5
%56 = load i32, i32* %55
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %56)
%58 = load i32*, i32** %7
%59 = call i32 @fclose(i32* %58)
%60 = call i32 @exit(i32 1)
unreachable
61: ; preds = %41
%62 = load i8**, i8*** %6
%63 = load i8*, i8** %62
%64 = load i32*, i32** %5
%65 = load i32, i32* %64
%66 = load i32*, i32** %7
%67 = call i32 @fread(i8* %63, i32 1, i32 %65, i32* %66)
%68 = load i32*, i32** %5
%69 = load i32, i32* %68
%70 = icmp ne i32 %67, %69
br i1 %70, label %71, label %77
71: ; preds = %61
%72 = load i32, i32* @stderr
%73 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%74 = load i32*, i32** %7
%75 = call i32 @fclose(i32* %74)
%76 = call i32 @exit(i32 1)
unreachable
77: ; preds = %61
%78 = load i32*, i32** %7
%79 = call i32 @fclose(i32* %78)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [32 x i8] c"Error: Can not open \22%s\22 file.\0A\00"
@SEEK_END = global i32 0
@.str.2 = [27 x i8] c"Error: File is too large.\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [45 x i8] c"Error: Can not allocate %d bytes of memory.\0A\00"
@.str.4 = [33 x i8] c"Error: Can not read input file.\0A\00"
define void @readFile(i8* %0, i32* nocapture %1, i8** 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 %10
6: ; preds = %3
%7 = load i32, i32* @stderr
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %7, i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %3
%11 = load i32, i32* @SEEK_END
%12 = tail call i32 @fseek(i32* %4, i64 0, i32 %11)
%13 = tail call i64 @ftell(i32* %4)
%14 = trunc i64 %13 to i32
store i32 %14, i32* %1
%15 = icmp slt i32 %14, 0
br i1 %15, label %21, label %16
16: ; preds = %10
%17 = tail call i64 @ftell(i32* %4)
%18 = load i32, i32* %1
%19 = sext i32 %18 to i64
%20 = icmp sgt i64 %17, %19
br i1 %20, label %21, label %26
21: ; preds = %16, %10
%22 = load i32, i32* @stderr
%23 = tail call i32 (i32, i8*, ...) @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.2, i64 0, i64 0))
%24 = tail call i32 @fclose(i32* %4)
%25 = tail call i32 @exit(i32 1)
unreachable
26: ; preds = %16
%27 = load i32, i32* @SEEK_SET
%28 = tail call i32 @fseek(i32* %4, i64 0, i32 %27)
%29 = load i32, i32* %1
%30 = tail call i64 @malloc(i32 %29)
%31 = inttoptr i64 %30 to i8*
store i8* %31, i8** %2
%32 = icmp eq i64 %30, 0
br i1 %32, label %33, label %39
33: ; preds = %26
%34 = load i32, i32* @stderr
%35 = load i32, i32* %1
%36 = tail call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = tail call i32 @fclose(i32* %4)
%38 = tail call i32 @exit(i32 1)
unreachable
39: ; preds = %26
%40 = load i32, i32* %1
%41 = tail call i32 @fread(i8* %31, i32 1, i32 %40, i32* %4)
%42 = load i32, i32* %1
%43 = icmp eq i32 %41, %42
br i1 %43, label %49, label %44
44: ; preds = %39
%45 = load i32, i32* @stderr
%46 = tail call i32 (i32, i8*, ...) @fprintf(i32 %45, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%47 = tail call i32 @fclose(i32* %4)
%48 = tail call i32 @exit(i32 1)
unreachable
49: ; preds = %39
%50 = tail call i32 @fclose(i32* %4)
ret void
}