#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long fread(unsigned char *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(unsigned char *);
scalar_t__ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(long);
unsigned char *read_file(const char *name, long *size) {
  FILE *f;
  unsigned char *data = NULL;
  *size = 0;
  f = fopen(name, "r");
  if (f != NULL) {
    if (fseek(f, 0, SEEK_END) == 0) {
      *size = ftell(f);
      if (*size != -1) {
        if (fseek(f, 0, SEEK_SET) == 0) {
          data = (unsigned char *)malloc(*size);
          if (data != NULL) {
            if (fread(data, sizeof(char), *size, f) != *size) {
              free(data);
              data = NULL;
            }
          }
        }
      }
    }
    fclose(f);
  }
  return data;
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movq   $0x0,-0x20(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x8(%rbp),%rdi
lea    0xe62(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     127e <read_file+0x10e>
mov    -0x18(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
jne    1275 <read_file+0x105>
mov    -0x18(%rbp),%rdi
call   1060 <ftell@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rax
cmpq   $0xffffffffffffffff,(%rax)
je     1270 <read_file+0x100>
mov    -0x18(%rbp),%rdi
mov    0x2ddc(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1080 <fseek@plt>
cmp    $0x0,%rax
jne    126b <read_file+0xfb>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <malloc@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1266 <read_file+0xf6>
mov    -0x20(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x18(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    -0x10(%rbp),%rcx
cmp    (%rcx),%rax
je     1261 <read_file+0xf1>
mov    -0x20(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x20(%rbp)
jmp    1266 <read_file+0xf6>
jmp    126b <read_file+0xfb>
jmp    1270 <read_file+0x100>
jmp    1275 <read_file+0x105>
mov    -0x18(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r15
movq   $0x0,(%rsi)
lea    0xe7a(%rip),%rsi
call   1090 <fopen@plt>
test   %rax,%rax
je     121b <read_file+0xab>
mov    %rax,%rbx
mov    0x2e4a(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1211 <read_file+0xa1>
mov    %rbx,%rdi
call   1060 <ftell@plt>
mov    %rax,(%r15)
cmp    $0xffffffffffffffff,%rax
je     120e <read_file+0x9e>
mov    0x2e0e(%rip),%rax
mov    (%rax),%edx
xor    %r14d,%r14d
mov    %rbx,%rdi
xor    %esi,%esi
call   1080 <fseek@plt>
test   %rax,%rax
jne    1211 <read_file+0xa1>
mov    (%r15),%rdi
call   1070 <malloc@plt>
test   %rax,%rax
je     120e <read_file+0x9e>
mov    %rax,%r14
mov    (%r15),%rdx
mov    %rax,%rdi
mov    $0x1,%esi
mov    %rbx,%rcx
call   1040 <fread@plt>
cmp    (%r15),%rax
je     1211 <read_file+0xa1>
mov    %r14,%rdi
call   1030 <free@plt>
xor    %r14d,%r14d
mov    %rbx,%rdi
call   1050 <fclose@plt>
jmp    121e <read_file+0xae>
xor    %r14d,%r14d
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@SEEK_END = global i32 0
@SEEK_SET = global i32 0
define i8* @read_file(i8* nocapture %0, i64* nocapture %1) {
store i64 0, i64* %1
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %31, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i64 @fseek(i32* %3, i32 0, i32 %6)
%8 = icmp eq i64 %7, 0
br i1 %8, label %9, label %28
9: ; preds = %5
%10 = tail call i64 @ftell(i32* %3)
store i64 %10, i64* %1
%11 = icmp eq i64 %10, -1
br i1 %11, label %28, label %12
12: ; preds = %9
%13 = load i32, i32* @SEEK_SET
%14 = tail call i64 @fseek(i32* %3, i32 0, i32 %13)
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %28
16: ; preds = %12
%17 = load i64, i64* %1
%18 = tail call i64 @malloc(i64 %17)
%19 = inttoptr i64 %18 to i8*
%20 = icmp eq i64 %18, 0
br i1 %20, label %28, label %21
21: ; preds = %16
%22 = load i64, i64* %1
%23 = tail call i64 @fread(i8* %19, i32 1, i64 %22, i32* %3)
%24 = load i64, i64* %1
%25 = icmp eq i64 %23, %24
br i1 %25, label %28, label %26
26: ; preds = %21
%27 = tail call i32 @free(i8* %19)
br label %28
28: ; preds = %9, %16, %26, %21, %12, %5
%29 = phi i8* [ null, %26 ], [ %19, %21 ], [ null, %16 ], [ null, %12 ], [ null, %9 ], [ null, %5 ]
%30 = tail call i32 @fclose(i32* %3)
br label %31
31: ; preds = %28, %2
%32 = phi i8* [ %29, %28 ], [ null, %2 ]
ret i8* %32
}