#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 */

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ SEEK_END;
size_t lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(size_t);
int open(char const *, int /*<<< orphan*/);
int read(int, char *, size_t);
int readFile(const char *fileName, char **contents) {
  int fd = open(fileName, O_RDONLY);
  size_t size = lseek(fd, 0, SEEK_END);
  lseek(fd, 0, 0);
  *contents = (char *)malloc(size * sizeof(char));
  int bufferSize = read(fd, *contents, size);
  if (bufferSize != size) {
    return 0;
  }
  return bufferSize;
}


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
mov    0x2e85(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
mov    0x2e79(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,-0x28(%rbp)
mov    -0x1c(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   1030 <lseek@plt>
mov    -0x28(%rbp),%rdi
shl    $0x0,%rdi
call   1050 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x1c(%rbp),%edi
mov    -0x18(%rbp),%rax
mov    (%rax),%rsi
mov    -0x28(%rbp),%rdx
call   1040 <read@plt>
mov    %eax,-0x2c(%rbp)
movslq -0x2c(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     11cf <readFile+0x8f>
movl   $0x0,-0x4(%rbp)
jmp    11d5 <readFile+0x95>
mov    -0x2c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFile>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    0x2e8f(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,%ebp
mov    0x2e87(%rip),%rax
mov    (%rax),%edx
xor    %r15d,%r15d
mov    %ebp,%edi
xor    %esi,%esi
call   1030 <lseek@plt>
mov    %rax,%rbx
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1030 <lseek@plt>
mov    %rbx,%rdi
call   1050 <malloc@plt>
mov    %rax,(%r14)
mov    %ebp,%edi
mov    %rax,%rsi
mov    %rbx,%rdx
call   1040 <read@plt>
cltq
cmp    %rax,%rbx
cmovne %r15d,%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
define i32 @readFile(i8* %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i64
%8 = alloca i32
store i8* %0, i8** %4
store i8** %1, i8*** %5
%9 = load i8*, i8** %4
%10 = load i32, i32* @O_RDONLY
%11 = call i32 @open(i8* %9, i32 %10)
store i32 %11, i32* %6
%12 = load i32, i32* %6
%13 = load i32, i32* @SEEK_END
%14 = call i64 @lseek(i32 %12, i32 0, i32 %13)
store i64 %14, i64* %7
%15 = load i32, i32* %6
%16 = call i64 @lseek(i32 %15, i32 0, i32 0)
%17 = load i64, i64* %7
%18 = mul i64 %17, 1
%19 = call i64 @malloc(i64 %18)
%20 = inttoptr i64 %19 to i8*
%21 = load i8**, i8*** %5
store i8* %20, i8** %21
%22 = load i32, i32* %6
%23 = load i8**, i8*** %5
%24 = load i8*, i8** %23
%25 = load i64, i64* %7
%26 = call i32 @read(i32 %22, i8* %24, i64 %25)
store i32 %26, i32* %8
%27 = load i32, i32* %8
%28 = sext i32 %27 to i64
%29 = load i64, i64* %7
%30 = icmp ne i64 %28, %29
br i1 %30, label %31, label %32
31: ; preds = %2
store i32 0, i32* %3
br label %34
32: ; preds = %2
%33 = load i32, i32* %8
store i32 %33, i32* %3
br label %34
34: ; preds = %32, %31
%35 = load i32, i32* %3
ret i32 %35
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@SEEK_END = global i32 0
define i32 @readFile(i8* nocapture %0, i8** nocapture writeonly %1) {
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* %0, i32 %3)
%5 = load i32, i32* @SEEK_END
%6 = tail call i64 @lseek(i32 %4, i32 0, i32 %5)
%7 = tail call i64 @lseek(i32 %4, i32 0, i32 0)
%8 = tail call i64 @malloc(i64 %6)
%9 = inttoptr i64 %8 to i8*
store i8* %9, i8** %1
%10 = tail call i32 @read(i32 %4, i8* %9, i64 %6)
%11 = sext i32 %10 to i64
%12 = icmp eq i64 %6, %11
%13 = select i1 %12, i32 %10, i32 0
ret i32 %13
}