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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int /*<<< orphan*/ *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
bool read_raw(const char *filename, uint8_t buffer[40960]) {
  FILE *file = fopen(filename, "rb");
  if (file == NULL) {
    perror("Could not open file for reading");
    return false;
  }
  if (fread(buffer, 40960, 1, file) != 1) {
    perror("Could not read all input data");
    fclose(file);
    return false;
  }
  fclose(file);
  return true;
}


x86 assembly (clang, -O0):
<read_raw>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %rsi,-0x18(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xea5(%rip),%rsi
call   1050 <fopen@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    1187 <read_raw+0x47>
lea    0xe8d(%rip),%rdi
call   1060 <perror@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <read_raw+0x98>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rcx
mov    $0xa000,%esi
mov    $0x1,%edx
call   1030 <fread@plt>
cmp    $0x1,%eax
je     11c8 <read_raw+0x88>
lea    0xe75(%rip),%rdi
call   1060 <perror@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x0,-0x4(%rbp)
jmp    11d8 <read_raw+0x98>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_raw>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%rbp
lea    0xeb2(%rip),%rsi
call   1050 <fopen@plt>
test   %rax,%rax
je     118b <read_raw+0x4b>
mov    %rax,%rbx
mov    $0x1,%r14d
mov    %rbp,%rdi
mov    $0xa000,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
cmp    $0x1,%eax
jne    119c <read_raw+0x5c>
mov    %rbx,%rdi
call   1040 <fclose@plt>
mov    %r14d,%eax
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xe71(%rip),%rdi
call   1060 <perror@plt>
xor    %r14d,%r14d
jmp    1183 <read_raw+0x43>
lea    0xe80(%rip),%rdi
call   1060 <perror@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
xor    %r14d,%r14d
jmp    1183 <read_raw+0x43>

LLVM IR (-O0):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Could not open file for reading\00"
@.str.2 = [30 x i8] c"Could not read all input data\00"
define i32 @read_raw(i8* %0, i32* %1) {
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i32*
%6 = alloca i32*
store i8* %0, i8** %4
store i32* %1, i32** %5
%7 = load i8*, i8** %4
%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 eq i32* %9, null
br i1 %10, label %11, label %13
11: ; preds = %2
%12 = call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
store i32 0, i32* %3
br label %25
13: ; preds = %2
%14 = load i32*, i32** %5
%15 = load i32*, i32** %6
%16 = call i32 @fread(i32* %14, i32 40960, i32 1, i32* %15)
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %22
18: ; preds = %13
%19 = call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%20 = load i32*, i32** %6
%21 = call i32 @fclose(i32* %20)
store i32 0, i32* %3
br label %25
22: ; preds = %13
%23 = load i32*, i32** %6
%24 = call i32 @fclose(i32* %23)
store i32 1, i32* %3
br label %25
25: ; preds = %22, %18, %11
%26 = load i32, i32* %3
ret i32 %26
}

LLVM IR (-O2):
@.str = [3 x i8] c"rb\00"
@.str.1 = [32 x i8] c"Could not open file for reading\00"
@.str.2 = [30 x i8] c"Could not read all input data\00"
define i32 @read_raw(i8* nocapture %0, i32* 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 %5, label %7
5: ; preds = %2
%6 = tail call i32 @perror(i8* getelementptr inbounds ([32 x i8], [32 x i8]* @.str.1, i64 0, i64 0))
br label %15
7: ; preds = %2
%8 = tail call i32 @fread(i32* %1, i32 40960, i32 1, i32* %3)
%9 = icmp eq i32 %8, 1
br i1 %9, label %13, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str.2, i64 0, i64 0))
%12 = tail call i32 @fclose(i32* %3)
br label %15
13: ; preds = %7
%14 = tail call i32 @fclose(i32* %3)
br label %15
15: ; preds = %13, %10, %5
%16 = phi i32 [ 0, %5 ], [ 0, %10 ], [ 1, %13 ]
ret i32 %16
}