#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*/ err(int, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ feof(int /*<<< orphan*/ *);
scalar_t__ ferror(int /*<<< orphan*/ *);
int /*<<< orphan*/ *stdin;
void check(FILE *stream) {
  if (feof(stream))
    exit(0);
  if (ferror(stream))
    err(1, "%s", stream == stdin ? "stdin" : "stdout");
}


x86 assembly (clang, -O0):
<check>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <feof@plt>
cmp    $0x0,%rax
je     1166 <check+0x26>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0x8(%rbp),%rdi
call   1030 <ferror@plt>
cmp    $0x0,%rax
je     11ad <check+0x6d>
mov    -0x8(%rbp),%rcx
mov    0x2e64(%rip),%rax
mov    (%rax),%rsi
lea    0xe7b(%rip),%rdx
lea    0xe6e(%rip),%rax
cmp    %rsi,%rcx
cmove  %rax,%rdx
mov    $0x1,%edi
lea    0xe58(%rip),%rsi
call   1050 <err@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check>:
push   %rbx
mov    %rdi,%rbx
call   1040 <feof@plt>
test   %rax,%rax
jne    118b <check+0x4b>
mov    %rbx,%rdi
call   1030 <ferror@plt>
test   %rax,%rax
je     1189 <check+0x49>
mov    0x2e86(%rip),%rax
cmp    %rbx,(%rax)
lea    0xe97(%rip),%rax
lea    0xe96(%rip),%rdx
cmove  %rax,%rdx
lea    0xe82(%rip),%rsi
mov    $0x1,%edi
pop    %rbx
jmp    1050 <err@plt>
pop    %rbx
ret
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [3 x i8] c"%s\00"
@stdin = global i32* null
@.str.1 = [6 x i8] c"stdin\00"
@.str.2 = [7 x i8] c"stdout\00"
define void @check(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 %8
6: ; preds = %1
%7 = call i32 @exit(i32 0)
unreachable
8: ; preds = %1
%9 = load i32*, i32** %2
%10 = call i64 @ferror(i32* %9)
%11 = icmp ne i64 %10, 0
br i1 %11, label %12, label %19
12: ; preds = %8
%13 = load i32*, i32** %2
%14 = load i32*, i32** @stdin
%15 = icmp eq i32* %13, %14
%16 = zext i1 %15 to i64
%17 = select i1 %15, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%18 = call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %17)
br label %19
19: ; preds = %12, %8
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"%s\00"
@stdin = global i32* null
@.str.1 = [6 x i8] c"stdin\00"
@.str.2 = [7 x i8] c"stdout\00"
define void @check(i32* nocapture %0) {
%2 = tail call i64 @feof(i32* %0)
%3 = icmp eq i64 %2, 0
br i1 %3, label %6, label %4
4: ; preds = %1
%5 = tail call i32 @exit(i32 0)
unreachable
6: ; preds = %1
%7 = tail call i64 @ferror(i32* %0)
%8 = icmp eq i64 %7, 0
br i1 %8, label %14, label %9
9: ; preds = %6
%10 = load i32*, i32** @stdin
%11 = icmp eq i32* %10, %0
%12 = select i1 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0)
%13 = tail call i32 @err(i32 1, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* %12)
br label %14
14: ; preds = %9, %6
ret void
}