#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;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ pread(int, void *, size_t, int /*<<< orphan*/);
ssize_t xpread(int fd, void *buf, size_t count, off_t offset) {
  ssize_t nr;
restart:
  nr = pread(fd, buf, count, offset);
  if ((nr < 0) && ((errno == EAGAIN) || (errno == EINTR)))
    goto restart;
  return nr;
}


x86 assembly (clang, -O0):
<xpread>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %ecx,-0x1c(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x18(%rbp),%rdx
mov    -0x1c(%rbp),%ecx
call   1030 <pread@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    1181 <xpread+0x71>
mov    0x2e91(%rip),%rax
mov    (%rax),%rax
mov    0x2e6f(%rip),%rcx
cmp    (%rcx),%rax
je     117c <xpread+0x6c>
mov    0x2e77(%rip),%rax
mov    (%rax),%rax
mov    0x2e65(%rip),%rcx
cmp    (%rcx),%rax
jne    1181 <xpread+0x71>
jmp    1126 <xpread+0x16>
mov    -0x28(%rbp),%rax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xpread>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %ecx,%r14d
mov    %rdx,%r15
mov    %rsi,%rbp
mov    %edi,%ebx
mov    0x2eb3(%rip),%r12
mov    0x2e94(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
xchg   %ax,%ax
mov    %ebx,%edi
mov    %rbp,%rsi
mov    %r15,%rdx
mov    %r14d,%ecx
call   1030 <pread@plt>
test   %rax,%rax
jns    116b <xpread+0x5b>
mov    (%r12),%rcx
cmp    0x0(%r13),%rcx
je     1140 <xpread+0x30>
mov    0x2e72(%rip),%rdx
cmp    (%rdx),%rcx
je     1140 <xpread+0x30>
add    $0x8,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @xpread(i32 %0, i8* %1, i64 %2, i32 %3) {
%5 = alloca i32
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca i64
store i32 %0, i32* %5
store i8* %1, i8** %6
store i64 %2, i64* %7
store i32 %3, i32* %8
br label %10
10: ; preds = %26, %4
%11 = load i32, i32* %5
%12 = load i8*, i8** %6
%13 = load i64, i64* %7
%14 = load i32, i32* %8
%15 = call i64 @pread(i32 %11, i8* %12, i64 %13, i32 %14)
store i64 %15, i64* %9
%16 = load i64, i64* %9
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %27
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %26, label %22
22: ; preds = %18
%23 = load i64, i64* @errno
%24 = load i64, i64* @EINTR
%25 = icmp eq i64 %23, %24
br i1 %25, label %26, label %27
26: ; preds = %22, %18
br label %10
27: ; preds = %22, %10
%28 = load i64, i64* %9
ret i64 %28
}

LLVM IR (-O2):
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @xpread(i32 %0, i8* nocapture %1, i64 %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i64 @pread(i32 %0, i8* %1, i64 %2, i32 %3)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %15
8: ; preds = %5
%9 = load i64, i64* @errno
%10 = load i64, i64* @EAGAIN
%11 = icmp eq i64 %9, %10
%12 = load i64, i64* @EINTR
%13 = icmp eq i64 %9, %12
%14 = select i1 %11, i1 true, i1 %13
br i1 %14, label %5, label %15
15: ; preds = %8, %5
ret i64 %6
}