#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_FAILURE;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ fputs(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ stderr;
void io_error(FILE *file) {
  if (feof(file)) {
    fputs("file closed", stderr);
  } else if (ferror(file)) {
    perror("file error");
  } else {
    fputs("unknown error", stderr);
  }
  exit(EXIT_FAILURE);
}


x86 assembly (clang, -O0):
<io_error>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1050 <feof@plt>
cmp    $0x0,%rax
je     1189 <io_error+0x39>
mov    0x2e6a(%rip),%rax
mov    (%rax),%esi
lea    0xe81(%rip),%rdi
call   1040 <fputs@plt>
jmp    11c7 <io_error+0x77>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ad <io_error+0x5d>
lea    0xe69(%rip),%rdi
call   1060 <perror@plt>
jmp    11c2 <io_error+0x72>
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
lea    0xe5a(%rip),%rdi
call   1040 <fputs@plt>
jmp    11c7 <io_error+0x77>
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<io_error>:
push   %rbx
mov    %rdi,%rbx
call   1050 <feof@plt>
test   %rax,%rax
jne    1185 <io_error+0x35>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1197 <io_error+0x47>
lea    0xe9a(%rip),%rdi
call   1060 <perror@plt>
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    0x2e54(%rip),%rax
mov    (%rax),%esi
lea    0xe6b(%rip),%rdi
jmp    11a7 <io_error+0x57>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
lea    0xe70(%rip),%rdi
call   1040 <fputs@plt>
jmp    1177 <io_error+0x27>

LLVM IR (-O0):
@.str = [12 x i8] c"file closed\00"
@stderr = global i32 0
@.str.1 = [11 x i8] c"file error\00"
@.str.2 = [14 x i8] c"unknown error\00"
@EXIT_FAILURE = global i32 0
define void @io_error(i32* %0) {
%2 = alloca i32*
store i32* %0, i32** %2
%3 = load i32*, i32** %2
%4 = call i64 @feof(i32* %3)
%5 = icmp ne i64 %4, 0
br i1 %5, label %6, label %9
6: ; preds = %1
%7 = load i32, i32* @stderr
%8 = call i32 @fputs(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %7)
br label %19
9: ; preds = %1
%10 = load i32*, i32** %2
%11 = call i64 @ferror(i32* %10)
%12 = icmp ne i64 %11, 0
br i1 %12, label %13, label %15
13: ; preds = %9
%14 = call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %18
15: ; preds = %9
%16 = load i32, i32* @stderr
%17 = call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %16)
br label %18
18: ; preds = %15, %13
br label %19
19: ; preds = %18, %6
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
}

LLVM IR (-O2):
@.str = [12 x i8] c"file closed\00"
@stderr = global i32 0
@.str.1 = [11 x i8] c"file error\00"
@.str.2 = [14 x i8] c"unknown error\00"
@EXIT_FAILURE = global i32 0
define void @io_error(i32* nocapture %0) {
%2 = tail call i64 @feof(i32* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %7, label %4
4: ; preds = %1
%5 = load i32, i32* @stderr
%6 = tail call i32 @fputs(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i32 %5)
br label %15
7: ; preds = %1
%8 = tail call i64 @ferror(i32* %0)
%9 = icmp eq i64 %8, 0
br i1 %9, label %12, label %10
10: ; preds = %7
%11 = tail call i32 @perror(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0))
br label %15
12: ; preds = %7
%13 = load i32, i32* @stderr
%14 = tail call i32 @fputs(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 %13)
br label %15
15: ; preds = %10, %12, %4
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
}