#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 */
struct iovec {
  int dummy;
};
typedef scalar_t__ ssize_t;
typedef int /*<<< orphan*/ off_t;

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ EINTR;
scalar_t__ errno;
scalar_t__ preadv(int, struct iovec const *, int, int /*<<< orphan*/);
ssize_t xpreadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
  ssize_t nr;
restart:
  nr = preadv(fd, iov, iovcnt, offset);
  if ((nr < 0) && ((errno == EAGAIN) || (errno == EINTR)))
    goto restart;
  return nr;
}


x86 assembly (clang, -O0):
<xpreadv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    %ecx,-0x18(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
mov    -0x18(%rbp),%ecx
call   1030 <preadv@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    117f <xpreadv+0x6f>
mov    0x2e93(%rip),%rax
mov    (%rax),%rax
mov    0x2e71(%rip),%rcx
cmp    (%rcx),%rax
je     117a <xpreadv+0x6a>
mov    0x2e79(%rip),%rax
mov    (%rax),%rax
mov    0x2e67(%rip),%rcx
cmp    (%rcx),%rax
jne    117f <xpreadv+0x6f>
jmp    1125 <xpreadv+0x15>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

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

LLVM IR (-O0):
%struct.iovec = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @xpreadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.iovec*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i64
store i32 %0, i32* %5
store %struct.iovec* %1, %struct.iovec** %6
store i32 %2, i32* %7
store i32 %3, i32* %8
br label %10
10: ; preds = %26, %4
%11 = load i32, i32* %5
%12 = load %struct.iovec*, %struct.iovec** %6
%13 = load i32, i32* %7
%14 = load i32, i32* %8
%15 = call i64 @preadv(i32 %11, %struct.iovec* %12, i32 %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):
%struct.iovec = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
@EINTR = global i64 0
define i64 @xpreadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3) {
br label %5
5: ; preds = %8, %4
%6 = tail call i64 @preadv(i32 %0, %struct.iovec* %1, i32 %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
}