#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;
scalar_t__ alchemy_is_empty(char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
long fread(void *, int, long, int /*<<< orphan*/ *);
int /*<<< orphan*/ free(char *);
int fseek(int /*<<< orphan*/ *, int /*<<< orphan*/, int /*<<< orphan*/);
long ftell(int /*<<< orphan*/ *);
scalar_t__ malloc(int);
int /*<<< orphan*/ rewind(int /*<<< orphan*/ *);
int alchemy_load_data(char **data, const char *path) {
  int ret;
  long size;
  FILE *file;
  if (alchemy_is_empty(path))
    return 0;
  file = fopen(path, "rb");
  if (NULL == file)
    return 0;
  if (-1 == fseek(file, 0, SEEK_END) || -1 == (size = ftell(file))) {
    fclose(file);
    return 0;
  }
  rewind(file);
  ret = 0;
  *data = NULL;
  if (size > 0L) {
    *data = (char *)malloc(sizeof(char) * size + 1u);
    if (NULL != *data &&
        fread((void *)*data, sizeof(char), size, file) == size) {
      (*data)[size] = '\0';
      ret = 1;
    }
  }
  if (!ret) {
    free(*data);
    *data = NULL;
  }
  fclose(file);
  return ret;
}


x86 assembly (clang, -O0):
<alchemy_load_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
call   1070 <alchemy_is_empty@plt>
cmp    $0x0,%rax
je     11bf <alchemy_load_data+0x2f>
movl   $0x0,-0x4(%rbp)
jmp    1303 <alchemy_load_data+0x173>
mov    -0x18(%rbp),%rdi
lea    0xe36(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x30(%rbp)
xor    %eax,%eax
cmp    -0x30(%rbp),%rax
jne    11eb <alchemy_load_data+0x5b>
movl   $0x0,-0x4(%rbp)
jmp    1303 <alchemy_load_data+0x173>
mov    -0x30(%rbp),%rdi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   10a0 <fseek@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
je     122e <alchemy_load_data+0x9e>
mov    -0x30(%rbp),%rdi
call   1080 <ftell@plt>
mov    %rax,%rcx
mov    %rcx,-0x28(%rbp)
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    1243 <alchemy_load_data+0xb3>
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    1303 <alchemy_load_data+0x173>
mov    -0x30(%rbp),%rdi
call   1060 <rewind@plt>
movl   $0x0,-0x1c(%rbp)
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
cmpq   $0x0,-0x28(%rbp)
jle    12d3 <alchemy_load_data+0x143>
mov    -0x28(%rbp),%rax
shl    $0x0,%rax
add    $0x1,%rax
mov    %eax,%edi
call   1090 <malloc@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x10(%rbp),%rcx
xor    %eax,%eax
cmp    (%rcx),%rax
je     12ce <alchemy_load_data+0x13e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rdx
mov    -0x30(%rbp),%rcx
mov    $0x1,%esi
call   1040 <fread@plt>
cmp    -0x28(%rbp),%rax
jne    12ce <alchemy_load_data+0x13e>
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    -0x28(%rbp),%rcx
movb   $0x0,(%rax,%rcx,1)
movl   $0x1,-0x1c(%rbp)
jmp    12d3 <alchemy_load_data+0x143>
cmpl   $0x0,-0x1c(%rbp)
jne    12f4 <alchemy_load_data+0x164>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rax
movq   $0x0,(%rax)
mov    -0x30(%rbp),%rdi
call   1050 <fclose@plt>
mov    -0x1c(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<alchemy_load_data>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rsi,%rbx
mov    %rdi,%r14
mov    %rsi,%rdi
call   1070 <alchemy_is_empty@plt>
xor    %r13d,%r13d
test   %rax,%rax
jne    1261 <alchemy_load_data+0xd1>
lea    0xe46(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1261 <alchemy_load_data+0xd1>
mov    %rax,%r15
mov    0x2e13(%rip),%rax
mov    (%rax),%edx
xor    %r13d,%r13d
mov    %r15,%rdi
xor    %esi,%esi
call   10a0 <fseek@plt>
cmp    $0xffffffff,%eax
je     1259 <alchemy_load_data+0xc9>
mov    %r15,%rdi
call   1080 <ftell@plt>
cmp    $0xffffffffffffffff,%rax
je     1259 <alchemy_load_data+0xc9>
mov    %rax,%r12
mov    %r15,%rdi
call   1060 <rewind@plt>
movq   $0x0,(%r14)
xor    %r13d,%r13d
test   %r12,%r12
jle    124b <alchemy_load_data+0xbb>
lea    0x1(%r12),%edi
call   1090 <malloc@plt>
mov    %rax,%rdi
mov    %rax,(%r14)
test   %rax,%rax
je     124d <alchemy_load_data+0xbd>
mov    $0x1,%esi
mov    %r12,%rdx
mov    %r15,%rcx
call   1040 <fread@plt>
mov    (%r14),%rdi
cmp    %r12,%rax
jne    124d <alchemy_load_data+0xbd>
movb   $0x0,(%rdi,%r12,1)
mov    $0x1,%r13d
jmp    1259 <alchemy_load_data+0xc9>
xor    %edi,%edi
call   1030 <free@plt>
movq   $0x0,(%r14)
mov    %r15,%rdi
call   1050 <fclose@plt>
mov    %r13d,%eax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define i32 @alchemy_load_data(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** %5
%10 = call i64 @alchemy_is_empty(i8* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %2
store i32 0, i32* %3
br label %74
13: ; preds = %2
%14 = load i8*, i8** %5
%15 = call i32* @fopen(i8* %14, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %15, i32** %8
%16 = load i32*, i32** %8
%17 = icmp eq i32* null, %16
br i1 %17, label %18, label %19
18: ; preds = %13
store i32 0, i32* %3
br label %74
19: ; preds = %13
%20 = load i32*, i32** %8
%21 = load i32, i32* @SEEK_END
%22 = call i32 @fseek(i32* %20, i32 0, i32 %21)
%23 = icmp eq i32 -1, %22
br i1 %23, label %28, label %24
24: ; preds = %19
%25 = load i32*, i32** %8
%26 = call i64 @ftell(i32* %25)
store i64 %26, i64* %7
%27 = icmp eq i64 -1, %26
br i1 %27, label %28, label %31
28: ; preds = %24, %19
%29 = load i32*, i32** %8
%30 = call i32 @fclose(i32* %29)
store i32 0, i32* %3
br label %74
31: ; preds = %24
%32 = load i32*, i32** %8
%33 = call i32 @rewind(i32* %32)
store i32 0, i32* %6
%34 = load i8**, i8*** %4
store i8* null, i8** %34
%35 = load i64, i64* %7
%36 = icmp sgt i64 %35, 0
br i1 %36, label %37, label %62
37: ; preds = %31
%38 = load i64, i64* %7
%39 = mul i64 1, %38
%40 = add i64 %39, 1
%41 = trunc i64 %40 to i32
%42 = call i64 @malloc(i32 %41)
%43 = inttoptr i64 %42 to i8*
%44 = load i8**, i8*** %4
store i8* %43, i8** %44
%45 = load i8**, i8*** %4
%46 = load i8*, i8** %45
%47 = icmp ne i8* null, %46
br i1 %47, label %48, label %61
48: ; preds = %37
%49 = load i8**, i8*** %4
%50 = load i8*, i8** %49
%51 = load i64, i64* %7
%52 = load i32*, i32** %8
%53 = call i64 @fread(i8* %50, i32 1, i64 %51, i32* %52)
%54 = load i64, i64* %7
%55 = icmp eq i64 %53, %54
br i1 %55, label %56, label %61
56: ; preds = %48
%57 = load i8**, i8*** %4
%58 = load i8*, i8** %57
%59 = load i64, i64* %7
%60 = getelementptr inbounds i8, i8* %58, i64 %59
store i8 0, i8* %60
store i32 1, i32* %6
br label %61
61: ; preds = %56, %48, %37
br label %62
62: ; preds = %61, %31
%63 = load i32, i32* %6
%64 = icmp ne i32 %63, 0
br i1 %64, label %70, label %65
65: ; preds = %62
%66 = load i8**, i8*** %4
%67 = load i8*, i8** %66
%68 = call i32 @free(i8* %67)
%69 = load i8**, i8*** %4
store i8* null, i8** %69
br label %70
70: ; preds = %65, %62
%71 = load i32*, i32** %8
%72 = call i32 @fclose(i32* %71)
%73 = load i32, i32* %6
store i32 %73, i32* %3
br label %74
74: ; preds = %70, %28, %18, %12
%75 = load i32, i32* %3
ret i32 %75
}

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