#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__ EINTR;
scalar_t__ errno;
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ xerror(char *);
void xread_until_eof(int fd) {
  while (1) {
    char buf[1];
    ssize_t len = read(fd, buf, sizeof buf);
    if (len <= 0) {
      if (len == 0)
        return;
      if (errno == EINTR)
        continue;
      xerror("read");
    }
  }
}


x86 assembly (clang, -O0):
<xread_until_eof>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %edi,-0x4(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x5(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jg     1187 <xread_until_eof+0x67>
cmpq   $0x0,-0x10(%rbp)
jne    115c <xread_until_eof+0x3c>
add    $0x10,%rsp
pop    %rbp
ret
mov    0x2e7d(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    117b <xread_until_eof+0x5b>
jmp    112b <xread_until_eof+0xb>
lea    0xe7e(%rip),%rdi
call   1030 <xerror@plt>
jmp    112b <xread_until_eof+0xb>

x86 assembly (clang, -O2):
<xread_until_eof>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %edi,%ebx
lea    0xf(%rsp),%r14
mov    0x2ea5(%rip),%r12
mov    0x2e96(%rip),%r13
lea    0xeb7(%rip),%r15
nopl   0x0(%rax)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x1,%edx
call   1040 <read@plt>
test   %rax,%rax
jg     1150 <xread_until_eof+0x30>
je     117a <xread_until_eof+0x5a>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
je     1150 <xread_until_eof+0x30>
mov    %r15,%rdi
call   1030 <xerror@plt>
jmp    1150 <xread_until_eof+0x30>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"read\00"
define void @xread_until_eof(i32 %0) {
%2 = alloca i32
%3 = alloca [1 x i8]
%4 = alloca i64
store i32 %0, i32* %2
br label %5
5: ; preds = %1, %19, %22
%6 = load i32, i32* %2
%7 = getelementptr inbounds [1 x i8], [1 x i8]* %3, i64 0, i64 0
%8 = call i64 @read(i32 %6, i8* %7, i32 1)
store i64 %8, i64* %4
%9 = load i64, i64* %4
%10 = icmp sle i64 %9, 0
br i1 %10, label %11, label %22
11: ; preds = %5
%12 = load i64, i64* %4
%13 = icmp eq i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %11
ret void
15: ; preds = %11
%16 = load i64, i64* @errno
%17 = load i64, i64* @EINTR
%18 = icmp eq i64 %16, %17
br i1 %18, label %19, label %20
19: ; preds = %15
br label %5
20: ; preds = %15
%21 = call i32 @xerror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %22
22: ; preds = %20, %5
br label %5
}

LLVM IR (-O2):
@errno = global i64 0
@EINTR = global i64 0
@.str = [5 x i8] c"read\00"
define void @xread_until_eof(i32 %0) {
%2 = alloca [1 x i8]
%3 = getelementptr inbounds [1 x i8], [1 x i8]* %2, i64 0, i64 0
br label %4
4: ; preds = %15, %1
%5 = call i64 @read(i32 %0, i8* %3, i32 1)
%6 = icmp slt i64 %5, 1
br i1 %6, label %7, label %15
7: ; preds = %4
%8 = icmp eq i64 %5, 0
br i1 %8, label %16, label %9
9: ; preds = %7
%10 = load i64, i64* @errno
%11 = load i64, i64* @EINTR
%12 = icmp eq i64 %10, %11
br i1 %12, label %15, label %13
13: ; preds = %9
%14 = tail call i32 @xerror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
br label %15
15: ; preds = %4, %13, %9
br label %4
16: ; preds = %7
ret void
}