#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fread(void *, int, size_t, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int /*<<< orphan*/,
                         int /*<<< orphan*/);
size_t ftell(int /*<<< orphan*/ *);
void *malloc(size_t);
void *blob(char *filename, size_t *size) {
  void *data;
  FILE *f;
  f = fopen(filename, "rb");
  if (f) {
    fseek(f, 0, SEEK_END);
    *size = ftell(f);
    fseek(f, 0, 0);
    data = malloc(*size);
    if (data)
      fread(data, 1, *size, f);
    fclose(f);
  }
  return data;
}


x86 assembly (clang, -O0):
<blob>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe85(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
je     1200 <blob+0xa0>
mov    -0x20(%rbp),%rdi
mov    0x2e4e(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1070 <fseek@plt>
mov    -0x20(%rbp),%rdi
call   1050 <ftell@plt>
mov    %rax,%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x20(%rbp),%rdi
xor    %edx,%edx
mov    %edx,%esi
call   1070 <fseek@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1060 <malloc@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
je     11f7 <blob+0x97>
mov    -0x18(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
mov    -0x20(%rbp),%rcx
mov    $0x1,%esi
call   1030 <fread@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<blob>:
push   %r15
push   %r14
push   %rbx
mov    %rsi,%r14
lea    0xe91(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     11d6 <blob+0x76>
mov    %rax,%rbx
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
xor    %esi,%esi
call   1070 <fseek@plt>
mov    %rbx,%rdi
call   1050 <ftell@plt>
mov    %rax,(%r14)
mov    %rbx,%rdi
xor    %esi,%esi
xor    %edx,%edx
call   1070 <fseek@plt>
mov    (%r14),%r15
mov    %r15,%rdi
call   1060 <malloc@plt>
mov    %rax,%r14
test   %rax,%rax
je     11cc <blob+0x6c>
mov    %r14,%rdi
mov    $0x1,%esi
mov    %r15,%rdx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
jmp    11d6 <blob+0x76>
mov    %r14,%rax
pop    %rbx
pop    %r14
pop    %r15
ret

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

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@SEEK_END = global i32 0
define noalias i8* @blob(i8* nocapture %0, i64* nocapture %1) {
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %17, label %5
5: ; preds = %2
%6 = load i32, i32* @SEEK_END
%7 = tail call i32 @fseek(i32* %3, i32 0, i32 %6)
%8 = tail call i64 @ftell(i32* %3)
store i64 %8, i64* %1
%9 = tail call i32 @fseek(i32* %3, i32 0, i32 0)
%10 = load i64, i64* %1
%11 = tail call i8* @malloc(i64 %10)
%12 = icmp eq i8* %11, null
br i1 %12, label %15, label %13
13: ; preds = %5
%14 = tail call i32 @fread(i8* %11, i32 1, i64 %10, i32* %3)
br label %15
15: ; preds = %13, %5
%16 = tail call i32 @fclose(i32* %3)
br label %17
17: ; preds = %15, %2
%18 = phi i8* [ %11, %15 ], [ undef, %2 ]
ret i8* %18
}