#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 scalar_t__ ssize_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ EWOULDBLOCK;
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
int test_at_eof(int nfds, int *fds, char **names) {
  int i;
  ssize_t bytes;
  char byte;
  for (i = 0; i < nfds; i++) {
    if (fds[i] < 0)
      continue;
    do {
      bytes = read(fds[i], &byte, 1);
    } while (bytes < 0 &&
             (EINTR == errno || EAGAIN == errno || EWOULDBLOCK == errno));
    if (bytes < 0) {
      fprintf(stderr, "(Looking for EOF) : error reading from %s : %s\n",
              names[i], strerror(errno));
      return -1;
    }
    if (bytes != 0) {
      fprintf(stderr, "Read past expected end of data on %s\n", names[i]);
      return -1;
    }
  }
  return 0;
}


x86 assembly (clang, -O0):
<test_at_eof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
movl   $0x0,-0x1c(%rbp)
mov    -0x1c(%rbp),%eax
cmp    -0x8(%rbp),%eax
jge    12af <test_at_eof+0x17f>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
cmpl   $0x0,(%rax,%rcx,4)
jge    116d <test_at_eof+0x3d>
jmp    12a1 <test_at_eof+0x171>
jmp    1172 <test_at_eof+0x42>
mov    -0x10(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,4),%edi
lea    -0x29(%rbp),%rsi
mov    $0x1,%edx
call   1030 <read@plt>
mov    %rax,-0x28(%rbp)
xor    %eax,%eax
cmpq   $0x0,-0x28(%rbp)
mov    %al,-0x2a(%rbp)
jge    11fd <test_at_eof+0xcd>
mov    0x2e22(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e26(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x2b(%rbp)
je     11f7 <test_at_eof+0xc7>
mov    0x2df3(%rip),%rax
mov    (%rax),%rcx
mov    $0x1,%al
mov    0x2e07(%rip),%rdx
cmp    (%rdx),%rcx
mov    %al,-0x2b(%rbp)
je     11f7 <test_at_eof+0xc7>
mov    0x2dec(%rip),%rax
mov    (%rax),%rax
mov    0x2dea(%rip),%rcx
cmp    (%rcx),%rax
sete   %al
mov    %al,-0x2b(%rbp)
mov    -0x2b(%rbp),%al
mov    %al,-0x2a(%rbp)
mov    -0x2a(%rbp),%al
test   $0x1,%al
jne    1172 <test_at_eof+0x42>
cmpq   $0x0,-0x28(%rbp)
jge    1262 <test_at_eof+0x132>
mov    0x2dc6(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x3c(%rbp)
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rax
mov    %rax,-0x38(%rbp)
mov    0x2da2(%rip),%rax
mov    (%rax),%rdi
call   1050 <strerror@plt>
mov    -0x3c(%rbp),%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
lea    0xdb1(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b6 <test_at_eof+0x186>
cmpq   $0x0,-0x28(%rbp)
je     129c <test_at_eof+0x16c>
mov    0x2d6c(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rax
movslq -0x1c(%rbp),%rcx
mov    (%rax,%rcx,8),%rdx
lea    0xda7(%rip),%rsi
mov    $0x0,%al
call   1040 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    12b6 <test_at_eof+0x186>
jmp    12a1 <test_at_eof+0x171>
mov    -0x1c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x1c(%rbp)
jmp    114a <test_at_eof+0x1a>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<test_at_eof>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
test   %edi,%edi
jle    1207 <test_at_eof+0xd7>
mov    %rsi,%r12
mov    %rdx,0x8(%rsp)
mov    %edi,%eax
mov    %rax,0x10(%rsp)
xor    %ebx,%ebx
lea    0x7(%rsp),%r15
mov    0x2e65(%rip),%rbp
mov    0x2e6e(%rip),%r14
mov    0x2e47(%rip),%r13
jmp    1194 <test_at_eof+0x64>
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
test   %rax,%rax
jne    1218 <test_at_eof+0xe8>
add    $0x1,%rbx
cmp    0x10(%rsp),%rbx
je     1207 <test_at_eof+0xd7>
mov    (%r12,%rbx,4),%edi
test   %edi,%edi
jns    11a4 <test_at_eof+0x74>
jmp    1189 <test_at_eof+0x59>
xchg   %ax,%ax
mov    (%r12,%rbx,4),%edi
mov    %r15,%rsi
mov    $0x1,%edx
call   1030 <read@plt>
test   %rax,%rax
jns    1180 <test_at_eof+0x50>
mov    (%r14),%rdi
cmp    %rdi,0x0(%rbp)
je     11a0 <test_at_eof+0x70>
cmp    %rdi,0x0(%r13)
je     11a0 <test_at_eof+0x70>
mov    0x2e04(%rip),%rax
cmp    %rdi,(%rax)
je     11a0 <test_at_eof+0x70>
mov    %ebx,%eax
mov    0x2e06(%rip),%rcx
mov    (%rcx),%ebx
mov    0x8(%rsp),%rcx
mov    (%rcx,%rax,8),%r14
call   1050 <strerror@plt>
lea    0xe0f(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1209 <test_at_eof+0xd9>
xor    %eax,%eax
add    $0x18,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %ebx,%eax
mov    0x2dbf(%rip),%rcx
mov    (%rcx),%edi
mov    0x8(%rsp),%rcx
mov    (%rcx,%rax,8),%rdx
lea    0xdfd(%rip),%rsi
xor    %eax,%eax
call   1040 <fprintf@plt>
mov    $0xffffffff,%eax
jmp    1209 <test_at_eof+0xd9>

LLVM IR (-O0):
@EINTR = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"(Looking for EOF) : error reading from %s : %s\0A\00"
@.str.1 = [38 x i8] c"Read past expected end of data on %s\0A\00"
define i32 @test_at_eof(i32 %0, i32* %1, i8** %2) {
%4 = alloca i32
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8**
%8 = alloca i32
%9 = alloca i64
%10 = alloca i8
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8** %2, i8*** %7
store i32 0, i32* %8
br label %11
11: ; preds = %75, %3
%12 = load i32, i32* %8
%13 = load i32, i32* %5
%14 = icmp slt i32 %12, %13
br i1 %14, label %15, label %78
15: ; preds = %11
%16 = load i32*, i32** %6
%17 = load i32, i32* %8
%18 = sext i32 %17 to i64
%19 = getelementptr inbounds i32, i32* %16, i64 %18
%20 = load i32, i32* %19
%21 = icmp slt i32 %20, 0
br i1 %21, label %22, label %23
22: ; preds = %15
br label %75
23: ; preds = %15
br label %24
24: ; preds = %48, %23
%25 = load i32*, i32** %6
%26 = load i32, i32* %8
%27 = sext i32 %26 to i64
%28 = getelementptr inbounds i32, i32* %25, i64 %27
%29 = load i32, i32* %28
%30 = call i64 @read(i32 %29, i8* %10, i32 1)
store i64 %30, i64* %9
br label %31
31: ; preds = %24
%32 = load i64, i64* %9
%33 = icmp slt i64 %32, 0
br i1 %33, label %34, label %48
34: ; preds = %31
%35 = load i64, i64* @EINTR
%36 = load i64, i64* @errno
%37 = icmp eq i64 %35, %36
br i1 %37, label %46, label %38
38: ; preds = %34
%39 = load i64, i64* @EAGAIN
%40 = load i64, i64* @errno
%41 = icmp eq i64 %39, %40
br i1 %41, label %46, label %42
42: ; preds = %38
%43 = load i64, i64* @EWOULDBLOCK
%44 = load i64, i64* @errno
%45 = icmp eq i64 %43, %44
br label %46
46: ; preds = %42, %38, %34
%47 = phi i1 [ true, %38 ], [ true, %34 ], [ %45, %42 ]
br label %48
48: ; preds = %46, %31
%49 = phi i1 [ false, %31 ], [ %47, %46 ]
br i1 %49, label %24, label %50
50: ; preds = %48
%51 = load i64, i64* %9
%52 = icmp slt i64 %51, 0
br i1 %52, label %53, label %63
53: ; preds = %50
%54 = load i32, i32* @stderr
%55 = load i8**, i8*** %7
%56 = load i32, i32* %8
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds i8*, i8** %55, i64 %57
%59 = load i8*, i8** %58
%60 = load i64, i64* @errno
%61 = call i8* @strerror(i64 %60)
%62 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %59, i8* %61)
store i32 -1, i32* %4
br label %79
63: ; preds = %50
%64 = load i64, i64* %9
%65 = icmp ne i64 %64, 0
br i1 %65, label %66, label %74
66: ; preds = %63
%67 = load i32, i32* @stderr
%68 = load i8**, i8*** %7
%69 = load i32, i32* %8
%70 = sext i32 %69 to i64
%71 = getelementptr inbounds i8*, i8** %68, i64 %70
%72 = load i8*, i8** %71
%73 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %67, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %72)
store i32 -1, i32* %4
br label %79
74: ; preds = %63
br label %75
75: ; preds = %74, %22
%76 = load i32, i32* %8
%77 = add nsw i32 %76, 1
store i32 %77, i32* %8
br label %11
78: ; preds = %11
store i32 0, i32* %4
br label %79
79: ; preds = %78, %66, %53
%80 = load i32, i32* %4
ret i32 %80
}

LLVM IR (-O2):
@EINTR = global i64 0
@errno = global i64 0
@EAGAIN = global i64 0
@EWOULDBLOCK = global i64 0
@stderr = global i32 0
@.str = [48 x i8] c"(Looking for EOF) : error reading from %s : %s\0A\00"
@.str.1 = [38 x i8] c"Read past expected end of data on %s\0A\00"
define i32 @test_at_eof(i32 %0, i32* nocapture %1, i8** nocapture %2) {
%4 = alloca i8
%5 = icmp sgt i32 %0, 0
br i1 %5, label %6, label %49
6: ; preds = %3
%7 = zext i32 %0 to i64
br label %8
8: ; preds = %6, %46
%9 = phi i64 [ 0, %6 ], [ %47, %46 ]
%10 = getelementptr inbounds i32, i32* %1, i64 %9
%11 = load i32, i32* %10
%12 = icmp slt i32 %11, 0
br i1 %12, label %46, label %13
13: ; preds = %8
%14 = call i64 @read(i32 %11, i8* %4, i32 1)
%15 = icmp slt i64 %14, 0
br i1 %15, label %16, label %37
16: ; preds = %13, %26
%17 = load i64, i64* @EINTR
%18 = load i64, i64* @errno
%19 = icmp eq i64 %17, %18
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %20, %18
%22 = select i1 %19, i1 true, i1 %21
%23 = load i64, i64* @EWOULDBLOCK
%24 = icmp eq i64 %23, %18
%25 = select i1 %22, i1 true, i1 %24
br i1 %25, label %26, label %30
26: ; preds = %16
%27 = load i32, i32* %10
%28 = call i64 @read(i32 %27, i8* %4, i32 1)
%29 = icmp slt i64 %28, 0
br i1 %29, label %16, label %37
30: ; preds = %16
%31 = and i64 %9, 4294967295
%32 = load i32, i32* @stderr
%33 = getelementptr inbounds i8*, i8** %2, i64 %31
%34 = load i8*, i8** %33
%35 = tail call i8* @strerror(i64 %18)
%36 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %32, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str, i64 0, i64 0), i8* %34, i8* %35)
br label %49
37: ; preds = %26, %13
%38 = phi i64 [ %14, %13 ], [ %28, %26 ]
%39 = icmp eq i64 %38, 0
br i1 %39, label %46, label %40
40: ; preds = %37
%41 = and i64 %9, 4294967295
%42 = load i32, i32* @stderr
%43 = getelementptr inbounds i8*, i8** %2, i64 %41
%44 = load i8*, i8** %43
%45 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %42, i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str.1, i64 0, i64 0), i8* %44)
br label %49
46: ; preds = %37, %8
%47 = add nuw nsw i64 %9, 1
%48 = icmp eq i64 %47, %7
br i1 %48, label %49, label %8
49: ; preds = %46, %3, %40, %30
%50 = phi i32 [ -1, %30 ], [ -1, %40 ], [ 0, %3 ], [ 0, %46 ]
ret i32 %50
}