#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 *, ...);
unsigned long 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) != (unsigned long)*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
movslq (%rcx),%rcx
cmp    %rcx,%rax
je     130d <readFile+0x18d>
mov    0x2cee(%rip),%rax
mov    (%rax),%edi
lea    0xd78(%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,%rbx
mov    %rdi,%r12
lea    0xe68(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     123b <readFile+0xbb>
mov    %rax,%r14
mov    0x2e38(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    %r14,%rdi
call   1060 <ftell@plt>
mov    %eax,(%rbx)
test   %eax,%eax
js     1229 <readFile+0xa9>
mov    %r14,%rdi
call   1060 <ftell@plt>
movslq (%rbx),%rcx
cmp    %rcx,%rax
jg     1229 <readFile+0xa9>
mov    0x2def(%rip),%rax
mov    (%rax),%edx
mov    %r14,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
mov    (%rbx),%edi
call   1070 <malloc@plt>
mov    %rax,(%r15)
test   %rax,%rax
je     125f <readFile+0xdf>
mov    (%rbx),%edx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r14,%rcx
call   1030 <fread@plt>
movslq (%rbx),%rcx
cmp    %rcx,%rax
jne    127a <readFile+0xfa>
mov    %r14,%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    128a <readFile+0x10a>
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    (%rbx),%edx
lea    0xdcd(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
jmp    1291 <readFile+0x111>
mov    0x2d57(%rip),%rax
mov    (%rax),%edi
lea    0xde1(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    %r14,%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 i64 @fread(i8* %63, i32 1, i32 %65, i32* %66)
%68 = load i32*, i32** %5
%69 = load i32, i32* %68
%70 = sext i32 %69 to i64
%71 = icmp ne i64 %67, %70
br i1 %71, label %72, label %78
72: ; preds = %61
%73 = load i32, i32* @stderr
%74 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%75 = load i32*, i32** %7
%76 = call i32 @fclose(i32* %75)
%77 = call i32 @exit(i32 1)
unreachable
78: ; preds = %61
%79 = load i32*, i32** %7
%80 = call i32 @fclose(i32* %79)
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 i64 @fread(i8* %31, i32 1, i32 %40, i32* %4)
%42 = load i32, i32* %1
%43 = sext i32 %42 to i64
%44 = icmp eq i64 %41, %43
br i1 %44, label %50, label %45
45: ; preds = %39
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.4, i64 0, i64 0))
%48 = tail call i32 @fclose(i32* %4)
%49 = tail call i32 @exit(i32 1)
unreachable
50: ; preds = %39
%51 = tail call i32 @fclose(i32* %4)
ret void
}