#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 {
  unsigned long st_size;
};
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int fread(char *, int, unsigned long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
char *malloc(unsigned long);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ stat(char *, struct stat *);
char *mem_load(char *name, unsigned long *isize) {
  struct stat fstat;
  int ret;
  char *mem = NULL;
  unsigned long size;
  if (stat(name, &fstat) != 0) {
    printf("No snapshot : %s\n", name);
    exit(1);
  }
  size = fstat.st_size;
  mem = malloc(size);
  if (mem == NULL)
    return NULL;
  FILE *f = fopen(name, "r");
  ret = fread(mem, 1, size, f);
  fclose(f);
  *isize = size;
  if (ret == size) {
  } else {
    free(mem);
    return NULL;
  }
  return mem;
}


x86 assembly (clang, -O0):
<mem_load>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
movq   $0x0,-0x30(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1070 <stat@plt>
cmp    $0x0,%rax
je     11c9 <mem_load+0x49>
mov    -0x10(%rbp),%rsi
lea    0xe46(%rip),%rdi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>
mov    -0x20(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1080 <malloc@plt>
mov    %rax,-0x30(%rbp)
cmpq   $0x0,-0x30(%rbp)
jne    11f6 <mem_load+0x76>
movq   $0x0,-0x8(%rbp)
jmp    1268 <mem_load+0xe8>
mov    -0x10(%rbp),%rdi
lea    0xe11(%rip),%rsi
call   1090 <fopen@plt>
mov    %rax,-0x40(%rbp)
mov    -0x30(%rbp),%rdi
mov    -0x38(%rbp),%rdx
mov    -0x40(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
mov    %eax,-0x24(%rbp)
mov    -0x40(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x38(%rbp),%rcx
mov    -0x18(%rbp),%rax
mov    %rcx,(%rax)
movslq -0x24(%rbp),%rax
cmp    -0x38(%rbp),%rax
jne    124a <mem_load+0xca>
jmp    1260 <mem_load+0xe0>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
movq   $0x0,-0x8(%rbp)
jmp    1268 <mem_load+0xe8>
mov    -0x30(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<mem_load>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r12
lea    0x8(%rsp),%rsi
call   1070 <stat@plt>
test   %rax,%rax
jne    120a <mem_load+0x8a>
mov    0x8(%rsp),%r15
mov    %r15,%rdi
call   1080 <malloc@plt>
test   %rax,%rax
je     11f8 <mem_load+0x78>
mov    %rax,%rbx
lea    0xe55(%rip),%rsi
mov    %r12,%rdi
call   1090 <fopen@plt>
mov    %rax,%r12
mov    %rbx,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rax,%rcx
call   1040 <fread@plt>
mov    %eax,%ebp
mov    %r12,%rdi
call   1050 <fclose@plt>
mov    %r15,(%r14)
movslq %ebp,%rax
cmp    %rax,%r15
je     11fa <mem_load+0x7a>
mov    %rbx,%rdi
call   1030 <free@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
ret
lea    0xdef(%rip),%rdi
mov    %r12,%rsi
call   1060 <printf@plt>
mov    $0x1,%edi
call   10a0 <exit@plt>

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

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