#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 */
struct stat {
  size_t st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
size_t fread(char *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(size_t);
int stat(char *, struct stat *);
int readFileData(char *sFileName, char **psData, long *pnDataLen) {
  struct stat fstat;
  *psData = NULL;
  *pnDataLen = 0;
  if (stat(sFileName, &fstat) == -1) {
    return 1;
  } else {
    FILE *file = fopen(sFileName, "r");
    if (file == NULL) {
      return 2;
    } else {
      *psData = malloc(fstat.st_size);
      if (*psData == NULL) {
        return 3;
      } else {
        size_t len = fread(*psData, 1, fstat.st_size, file);
        fclose(file);
        if (len != fstat.st_size) {
          free(*psData);
          *psData = NULL;
          return 4;
        }
        *pnDataLen = len;
        return 0;
      }
    }
  }
}


x86 assembly (clang, -O0):
<readFileData>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    %rdx,-0x20(%rbp)
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x20(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x10(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
jne    11ac <readFileData+0x4c>
movl   $0x1,-0x4(%rbp)
jmp    126d <readFileData+0x10d>
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11d7 <readFileData+0x77>
movl   $0x2,-0x4(%rbp)
jmp    126d <readFileData+0x10d>
mov    -0x28(%rbp),%rdi
call   1070 <malloc@plt>
mov    %rax,%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x18(%rbp),%rax
cmpq   $0x0,(%rax)
jne    1204 <readFileData+0xa4>
movl   $0x3,-0x4(%rbp)
jmp    126d <readFileData+0x10d>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %rax,-0x38(%rbp)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rax
cmp    -0x28(%rbp),%rax
je     125b <readFileData+0xfb>
mov    -0x18(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rax
movq   $0x0,(%rax)
movl   $0x4,-0x4(%rbp)
jmp    126d <readFileData+0x10d>
mov    -0x38(%rbp),%rcx
mov    -0x20(%rbp),%rax
mov    %rcx,(%rax)
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readFileData>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdx,%r14
mov    %rsi,%r12
mov    %rdi,%rbx
movq   $0x0,(%rsi)
movq   $0x0,(%rdx)
lea    0x8(%rsp),%rsi
call   1060 <stat@plt>
cmp    $0xffffffff,%eax
je     11ea <readFileData+0x8a>
lea    0xe66(%rip),%rsi
mov    %rbx,%rdi
call   1080 <fopen@plt>
test   %rax,%rax
je     11f1 <readFileData+0x91>
mov    %rax,%rbx
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1070 <malloc@plt>
mov    %rax,(%r12)
test   %rax,%rax
je     11f8 <readFileData+0x98>
mov    %rax,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1040 <fread@plt>
mov    %rax,%r13
mov    %rbx,%rdi
call   1050 <fclose@plt>
cmp    %r15,%r13
jne    11ff <readFileData+0x9f>
mov    %r15,(%r14)
xor    %eax,%eax
jmp    1215 <readFileData+0xb5>
mov    $0x1,%eax
jmp    1215 <readFileData+0xb5>
mov    $0x2,%eax
jmp    1215 <readFileData+0xb5>
mov    $0x3,%eax
jmp    1215 <readFileData+0xb5>
mov    (%r12),%rdi
call   1030 <free@plt>
movq   $0x0,(%r12)
mov    $0x4,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
define i32 @readFileData(i8* %0, i8** %1, i64* %2) {
%4 = alloca i32
%5 = alloca i8*
%6 = alloca i8**
%7 = alloca i64*
%8 = alloca %struct.stat
%9 = alloca i32*
%10 = alloca i64
store i8* %0, i8** %5
store i8** %1, i8*** %6
store i64* %2, i64** %7
%11 = load i8**, i8*** %6
store i8* null, i8** %11
%12 = load i64*, i64** %7
store i64 0, i64* %12
%13 = load i8*, i8** %5
%14 = call i32 @stat(i8* %13, %struct.stat* %8)
%15 = icmp eq i32 %14, -1
br i1 %15, label %16, label %17
16: ; preds = %3
store i32 1, i32* %4
br label %53
17: ; preds = %3
%18 = load i8*, i8** %5
%19 = call i32* @fopen(i8* %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %19, i32** %9
%20 = load i32*, i32** %9
%21 = icmp eq i32* %20, null
br i1 %21, label %22, label %23
22: ; preds = %17
store i32 2, i32* %4
br label %53
23: ; preds = %17
%24 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%25 = load i64, i64* %24
%26 = call i8* @malloc(i64 %25)
%27 = load i8**, i8*** %6
store i8* %26, i8** %27
%28 = load i8**, i8*** %6
%29 = load i8*, i8** %28
%30 = icmp eq i8* %29, null
br i1 %30, label %31, label %32
31: ; preds = %23
store i32 3, i32* %4
br label %53
32: ; preds = %23
%33 = load i8**, i8*** %6
%34 = load i8*, i8** %33
%35 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%36 = load i64, i64* %35
%37 = load i32*, i32** %9
%38 = call i64 @fread(i8* %34, i32 1, i64 %36, i32* %37)
store i64 %38, i64* %10
%39 = load i32*, i32** %9
%40 = call i32 @fclose(i32* %39)
%41 = load i64, i64* %10
%42 = getelementptr inbounds %struct.stat, %struct.stat* %8, i32 0, i32 0
%43 = load i64, i64* %42
%44 = icmp ne i64 %41, %43
br i1 %44, label %45, label %50
45: ; preds = %32
%46 = load i8**, i8*** %6
%47 = load i8*, i8** %46
%48 = call i32 @free(i8* %47)
%49 = load i8**, i8*** %6
store i8* null, i8** %49
store i32 4, i32* %4
br label %53
50: ; preds = %32
%51 = load i64, i64* %10
%52 = load i64*, i64** %7
store i64 %51, i64* %52
store i32 0, i32* %4
br label %53
53: ; preds = %50, %45, %31, %22, %16
%54 = load i32, i32* %4
ret i32 %54
}

LLVM IR (-O2):
%struct.stat = type { i64 }
@.str = [2 x i8] c"r\00"
define i32 @readFileData(i8* nocapture %0, i8** nocapture %1, i64* nocapture writeonly %2) {
%4 = alloca %struct.stat
%5 = bitcast %struct.stat* %4 to i8*
store i8* null, i8** %1
store i64 0, i64* %2
%6 = call i32 @stat(i8* %0, %struct.stat* %4)
%7 = icmp eq i32 %6, -1
br i1 %7, label %24, label %8
8: ; preds = %3
%9 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%10 = icmp eq i32* %9, null
br i1 %10, label %24, label %11
11: ; preds = %8
%12 = getelementptr inbounds %struct.stat, %struct.stat* %4, i64 0, i32 0
%13 = load i64, i64* %12
%14 = tail call i8* @malloc(i64 %13)
store i8* %14, i8** %1
%15 = icmp eq i8* %14, null
br i1 %15, label %24, label %16
16: ; preds = %11
%17 = tail call i64 @fread(i8* %14, i32 1, i64 %13, i32* %9)
%18 = tail call i32 @fclose(i32* %9)
%19 = icmp eq i64 %17, %13
br i1 %19, label %23, label %20
20: ; preds = %16
%21 = load i8*, i8** %1
%22 = tail call i32 @free(i8* %21)
store i8* null, i8** %1
br label %24
23: ; preds = %16
store i64 %13, i64* %2
br label %24
24: ; preds = %8, %11, %23, %20, %3
%25 = phi i32 [ 1, %3 ], [ 2, %8 ], [ 3, %11 ], [ 4, %20 ], [ 0, %23 ]
ret i32 %25
}