#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*/ off_t;
typedef int /*<<< orphan*/ FILE;

/* Variables and functions */
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(void *, int /*<<< orphan*/, int, int /*<<< orphan*/ *);
void *get_file_data(const char *fname, off_t fsz, void *buf) {
  FILE *f = fopen(fname, "rb");
  assert(buf);
  assert(f);
  assert(fread(buf, fsz, 1, f) == 1);
  fclose(f);
  return buf;
}


x86 assembly (clang, -O0):
<get_file_data>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x18(%rbp),%rax
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rax
mov    %eax,%edi
call   1050 <assert@plt>
mov    -0x18(%rbp),%rdi
mov    -0xc(%rbp),%esi
mov    -0x20(%rbp),%rcx
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
mov    -0x18(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_file_data>:
push   %rbp
push   %r14
push   %rbx
mov    %rdx,%rbx
mov    %esi,%r14d
lea    0xeaf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rbp
mov    %ebx,%edi
call   1050 <assert@plt>
mov    %ebp,%edi
call   1050 <assert@plt>
mov    %rbx,%rdi
mov    %r14d,%esi
mov    $0x1,%edx
mov    %rbp,%rcx
call   1030 <fread@plt>
xor    %edi,%edi
cmp    $0x1,%eax
sete   %dil
call   1050 <assert@plt>
mov    %rbp,%rdi
call   1040 <fclose@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
define i8* @get_file_data(i8* %0, i32 %1, i8* %2) {
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i8* %0, i8** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %4
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = load i8*, i8** %6
%11 = ptrtoint i8* %10 to i32
%12 = call i32 @assert(i32 %11)
%13 = load i32*, i32** %7
%14 = ptrtoint i32* %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = load i8*, i8** %6
%17 = load i32, i32* %5
%18 = load i32*, i32** %7
%19 = call i32 @fread(i8* %16, i32 %17, i32 1, i32* %18)
%20 = icmp eq i32 %19, 1
%21 = zext i1 %20 to i32
%22 = call i32 @assert(i32 %21)
%23 = load i32*, i32** %7
%24 = call i32 @fclose(i32* %23)
%25 = load i8*, i8** %6
ret i8* %25
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
define i8* @get_file_data(i8* nocapture %0, i32 %1, i8* returned %2) {
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = ptrtoint i8* %2 to i64
%6 = trunc i64 %5 to i32
%7 = tail call i32 @assert(i32 %6)
%8 = ptrtoint i32* %4 to i64
%9 = trunc i64 %8 to i32
%10 = tail call i32 @assert(i32 %9)
%11 = tail call i32 @fread(i8* %2, i32 %1, i32 1, i32* %4)
%12 = icmp eq i32 %11, 1
%13 = zext i1 %12 to i32
%14 = tail call i32 @assert(i32 %13)
%15 = tail call i32 @fclose(i32* %4)
ret i8* %2
}