#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 _read_file(int /*<<< orphan*/ *, char const *, void **, size_t *);
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
int /*<<< orphan*/ stderr;
char *read_file(const char *input, size_t *size) {
  FILE *in = fopen(input, "rb");
  if (!in) {
    fprintf(stderr, "cannot open file '%s' for reading\n", input);
    exit(-3);
  }
  {
    void *mem;
    int r = _read_file(in, input, &mem, size);
    fclose(in);
    if (!r)
      exit(-3);
    return (char *)mem;
  }
}


x86 assembly (clang, -O0):
<read_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe95(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11a2 <read_file+0x52>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe70(%rip),%rsi
call   1040 <fprintf@plt>
mov    $0xfffffffd,%edi
call   1070 <exit@plt>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
mov    -0x10(%rbp),%rcx
lea    -0x20(%rbp),%rdx
call   1050 <_read_file@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%rdi
call   1030 <fclose@plt>
cmpl   $0x0,-0x24(%rbp)
jne    11d7 <read_file+0x87>
mov    $0xfffffffd,%edi
call   1070 <exit@plt>
mov    -0x20(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_file>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%r15
lea    0xe9c(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     119f <read_file+0x4f>
mov    %rax,%rbx
mov    %rsp,%rdx
mov    %rax,%rdi
mov    %r15,%rsi
mov    %r14,%rcx
call   1050 <_read_file@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <fclose@plt>
test   %ebp,%ebp
je     11b7 <read_file+0x67>
mov    (%rsp),%rax
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e3a(%rip),%rax
mov    (%rax),%edi
lea    0xe54(%rip),%rsi
mov    %r15,%rdx
call   1040 <fprintf@plt>
mov    $0xfffffffd,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"cannot open file '%s' for reading\0A\00"
define i8* @read_file(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = alloca i64*
%5 = alloca i32*
%6 = alloca i8*
%7 = alloca i32
store i8* %0, i8** %3
store i64* %1, i64** %4
%8 = load i8*, i8** %3
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([3 x i8], [3 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 %17, label %12
12: ; preds = %2
%13 = load i32, i32* @stderr
%14 = load i8*, i8** %3
%15 = call i32 @fprintf(i32 %13, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %14)
%16 = call i32 @exit(i32 -3)
unreachable
17: ; preds = %2
%18 = load i32*, i32** %5
%19 = load i8*, i8** %3
%20 = load i64*, i64** %4
%21 = call i32 @_read_file(i32* %18, i8* %19, i8** %6, i64* %20)
store i32 %21, i32* %7
%22 = load i32*, i32** %5
%23 = call i32 @fclose(i32* %22)
%24 = load i32, i32* %7
%25 = icmp ne i32 %24, 0
br i1 %25, label %28, label %26
26: ; preds = %17
%27 = call i32 @exit(i32 -3)
unreachable
28: ; preds = %17
%29 = load i8*, i8** %6
ret i8* %29
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@stderr = global i32 0
@.str.1 = [35 x i8] c"cannot open file '%s' for reading\0A\00"
define i8* @read_file(i8* %0, i64* %1) {
%3 = alloca i8*
%4 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%9 = tail call i32 @exit(i32 -3)
unreachable
10: ; preds = %2
%11 = bitcast i8** %3 to i8*
%12 = call i32 @_read_file(i32* %4, i8* %0, i8** %3, i64* %1)
%13 = call i32 @fclose(i32* %4)
%14 = icmp eq i32 %12, 0
br i1 %14, label %15, label %17
15: ; preds = %10
%16 = call i32 @exit(i32 -3)
unreachable
17: ; preds = %10
%18 = load i8*, i8** %3
ret i8* %18
}