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

/* Variables and functions */
scalar_t__ EAGAIN;
scalar_t__ errno;
int preadv(int, struct iovec const *, int, int /*<<< orphan*/);
int /*<<< orphan*/ task_yield();
ssize_t sys_preadv(int fd, const struct iovec *iov, int iovcnt, off_t offset) {
  ssize_t ret;
RETRY:
  ret = preadv(fd, iov, iovcnt, offset);
  if (ret == -1 && errno == EAGAIN) {
    task_yield();
    goto RETRY;
  }
  return ret;
}


x86 assembly (clang, -O0):
<sys_preadv>:
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   1040 <preadv@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    117a <sys_preadv+0x5a>
mov    0x2e85(%rip),%rax
mov    (%rax),%rax
mov    0x2e6b(%rip),%rcx
cmp    (%rcx),%rax
jne    117a <sys_preadv+0x5a>
mov    $0x0,%al
call   1030 <task_yield@plt>
jmp    1135 <sys_preadv+0x15>
mov    -0x1c(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<sys_preadv>:
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
call   1040 <preadv@plt>
cmp    $0xffffffff,%eax
jne    117d <sys_preadv+0x5d>
mov    0x2e99(%rip),%r12
mov    0x2e82(%rip),%r13
xchg   %ax,%ax
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    1178 <sys_preadv+0x58>
xor    %eax,%eax
call   1030 <task_yield@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r15d,%edx
mov    %r14d,%ecx
call   1040 <preadv@plt>
cmp    $0xffffffff,%eax
je     1150 <sys_preadv+0x30>
jmp    117d <sys_preadv+0x5d>
mov    $0xffffffff,%eax
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
define i32 @sys_preadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3) {
%5 = alloca i32
%6 = alloca %struct.iovec*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
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 = %22, %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 i32 @preadv(i32 %11, %struct.iovec* %12, i32 %13, i32 %14)
store i32 %15, i32* %9
%16 = load i32, i32* %9
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %24
18: ; preds = %10
%19 = load i64, i64* @errno
%20 = load i64, i64* @EAGAIN
%21 = icmp eq i64 %19, %20
br i1 %21, label %22, label %24
22: ; preds = %18
%23 = call i32 (...) @task_yield()
br label %10
24: ; preds = %18, %10
%25 = load i32, i32* %9
ret i32 %25
}

LLVM IR (-O2):
%struct.iovec = type { i32 }
@errno = global i64 0
@EAGAIN = global i64 0
define i32 @sys_preadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3) {
%5 = tail call i32 @preadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3)
%6 = icmp eq i32 %5, -1
br i1 %6, label %7, label %15
7: ; preds = %4, %11
%8 = load i64, i64* @errno
%9 = load i64, i64* @EAGAIN
%10 = icmp eq i64 %8, %9
br i1 %10, label %11, label %15
11: ; preds = %7
%12 = tail call i32 (...) @task_yield()
%13 = tail call i32 @preadv(i32 %0, %struct.iovec* %1, i32 %2, i32 %3)
%14 = icmp eq i32 %13, -1
br i1 %14, label %7, label %15
15: ; preds = %11, %7, %4
%16 = phi i32 [ %5, %4 ], [ -1, %7 ], [ %13, %11 ]
ret i32 %16
}