#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*/ SEEK_CUR;
int feof(int /*<<< orphan*/ *);
int fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ fseek(int /*<<< orphan*/ *, int, int /*<<< orphan*/);
scalar_t__ is_pipe(int /*<<< orphan*/ *);
int eof(FILE *fp) {
  char data[4];
  int beof;
  if (is_pipe(fp))
    return feof(fp);
  else {
    if ((beof = fread(data, 1, 1, fp)) == 1)
      fseek(fp, -1, SEEK_CUR);
    return !beof;
  }
}


x86 assembly (clang, -O0):
<eof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
call   1050 <is_pipe@plt>
cmp    $0x0,%rax
je     1170 <eof+0x30>
mov    -0x10(%rbp),%rdi
call   1040 <feof@plt>
mov    %eax,-0x4(%rbp)
jmp    11b8 <eof+0x78>
lea    -0x14(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
mov    %eax,-0x18(%rbp)
cmp    $0x1,%eax
jne    11a7 <eof+0x67>
mov    -0x10(%rbp),%rdi
mov    0x2e4d(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
cmpl   $0x0,-0x18(%rbp)
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<eof>:
push   %rbp
push   %rbx
push   %rax
mov    %rdi,%rbx
call   1050 <is_pipe@plt>
test   %rax,%rax
je     115e <eof+0x1e>
mov    %rbx,%rdi
add    $0x8,%rsp
pop    %rbx
pop    %rbp
jmp    1040 <feof@plt>
lea    0x4(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rbx,%rcx
call   1030 <fread@plt>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    1192 <eof+0x52>
mov    0x2e65(%rip),%rax
mov    (%rax),%edx
mov    %rbx,%rdi
mov    $0xffffffff,%esi
call   1060 <fseek@plt>
xor    %eax,%eax
test   %ebp,%ebp
sete   %al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@SEEK_CUR = global i32 0
define i32 @eof(i32* %0) {
%2 = alloca i32
%3 = alloca i32*
%4 = alloca [4 x i8]
%5 = alloca i32
store i32* %0, i32** %3
%6 = load i32*, i32** %3
%7 = call i64 @is_pipe(i32* %6)
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %12
9: ; preds = %1
%10 = load i32*, i32** %3
%11 = call i32 @feof(i32* %10)
store i32 %11, i32* %2
br label %26
12: ; preds = %1
%13 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%14 = load i32*, i32** %3
%15 = call i32 @fread(i8* %13, i32 1, i32 1, i32* %14)
store i32 %15, i32* %5
%16 = icmp eq i32 %15, 1
br i1 %16, label %17, label %21
17: ; preds = %12
%18 = load i32*, i32** %3
%19 = load i32, i32* @SEEK_CUR
%20 = call i32 @fseek(i32* %18, i32 -1, i32 %19)
br label %21
21: ; preds = %17, %12
%22 = load i32, i32* %5
%23 = icmp ne i32 %22, 0
%24 = xor i1 %23, true
%25 = zext i1 %24 to i32
store i32 %25, i32* %2
br label %26
26: ; preds = %21, %9
%27 = load i32, i32* %2
ret i32 %27
}

LLVM IR (-O2):
@SEEK_CUR = global i32 0
define i32 @eof(i32* %0) {
%2 = alloca [4 x i8]
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %2, i64 0, i64 0
%4 = tail call i64 @is_pipe(i32* %0)
%5 = icmp eq i64 %4, 0
br i1 %5, label %8, label %6
6: ; preds = %1
%7 = tail call i32 @feof(i32* %0)
br label %17
8: ; preds = %1
%9 = call i32 @fread(i8* %3, i32 1, i32 1, i32* %0)
%10 = icmp eq i32 %9, 1
br i1 %10, label %11, label %14
11: ; preds = %8
%12 = load i32, i32* @SEEK_CUR
%13 = tail call i32 @fseek(i32* %0, i32 -1, i32 %12)
br label %14
14: ; preds = %11, %8
%15 = icmp eq i32 %9, 0
%16 = zext i1 %15 to i32
br label %17
17: ; preds = %14, %6
%18 = phi i32 [ %7, %6 ], [ %16, %14 ]
ret i32 %18
}