#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*/ exit_error(char *, char const *);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int fread(int *, int, int, int /*<<< orphan*/ *);
void read_int(int *data, int size, const char *filename) {
  FILE *file;
  if (NULL == (file = fopen(filename, "r")))
    exit_error("failed to open %s", filename);
  if (size != fread(data, sizeof(int), size, file))
    exit_error("failed reading %s", filename);
  fclose(file);
}


x86 assembly (clang, -O0):
<read_int>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %esi,-0xc(%rbp)
mov    %rdx,-0x18(%rbp)
mov    -0x18(%rbp),%rdi
lea    0xea2(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,%rcx
mov    %rcx,-0x20(%rbp)
xor    %eax,%eax
cmp    %rcx,%rax
jne    1185 <read_int+0x45>
mov    -0x18(%rbp),%rsi
lea    0xe82(%rip),%rdi
call   1050 <exit_error@plt>
mov    -0xc(%rbp),%eax
mov    %eax,-0x24(%rbp)
mov    -0x8(%rbp),%rdi
mov    -0xc(%rbp),%edx
mov    -0x20(%rbp),%rcx
mov    $0x4,%esi
call   1030 <fread@plt>
mov    %eax,%ecx
mov    -0x24(%rbp),%eax
cmp    %ecx,%eax
je     11bd <read_int+0x7d>
mov    -0x18(%rbp),%rsi
lea    0xe5c(%rip),%rdi
call   1050 <exit_error@plt>
mov    -0x20(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_int>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rdx,%r14
mov    %esi,%ebp
mov    %rdi,%r15
lea    0xeaa(%rip),%rsi
mov    %rdx,%rdi
call   1060 <fopen@plt>
mov    %rax,%rbx
test   %rax,%rax
jne    1175 <read_int+0x35>
lea    0xe95(%rip),%rdi
mov    %r14,%rsi
call   1050 <exit_error@plt>
mov    %r15,%rdi
mov    $0x4,%esi
mov    %ebp,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
cmp    %ebp,%eax
je     119a <read_int+0x5a>
lea    0xe82(%rip),%rdi
mov    %r14,%rsi
call   1050 <exit_error@plt>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <fclose@plt>

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"failed to open %s\00"
@.str.2 = [18 x i8] c"failed reading %s\00"
define void @read_int(i32* %0, i32 %1, i8* %2) {
%4 = alloca i32*
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i32*
store i32* %0, i32** %4
store i32 %1, i32* %5
store i8* %2, i8** %6
%8 = load i8*, i8** %6
%9 = call i32* @fopen(i8* %8, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %9, i32** %7
%10 = icmp eq i32* null, %9
br i1 %10, label %11, label %14
11: ; preds = %3
%12 = load i8*, i8** %6
%13 = call i32 @exit_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %11, %3
%15 = load i32, i32* %5
%16 = load i32*, i32** %4
%17 = load i32, i32* %5
%18 = load i32*, i32** %7
%19 = call i32 @fread(i32* %16, i32 4, i32 %17, i32* %18)
%20 = icmp ne i32 %15, %19
br i1 %20, label %21, label %24
21: ; preds = %14
%22 = load i8*, i8** %6
%23 = call i32 @exit_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %22)
br label %24
24: ; preds = %21, %14
%25 = load i32*, i32** %7
%26 = call i32 @fclose(i32* %25)
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [18 x i8] c"failed to open %s\00"
@.str.2 = [18 x i8] c"failed reading %s\00"
define void @read_int(i32* nocapture %0, i32 %1, i8* %2) {
%4 = tail call i32* @fopen(i8* %2, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%5 = icmp eq i32* %4, null
br i1 %5, label %6, label %8
6: ; preds = %3
%7 = tail call i32 @exit_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.1, i64 0, i64 0), i8* %2)
br label %8
8: ; preds = %6, %3
%9 = tail call i32 @fread(i32* %0, i32 4, i32 %1, i32* %4)
%10 = icmp eq i32 %9, %1
br i1 %10, label %13, label %11
11: ; preds = %8
%12 = tail call i32 @exit_error(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.2, i64 0, i64 0), i8* %2)
br label %13
13: ; preds = %11, %8
%14 = tail call i32 @fclose(i32* %4)
ret void
}