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

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


x86 assembly (clang, -O0):
<xwritev>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
mov    -0x4(%rbp),%edi
mov    -0x10(%rbp),%rsi
mov    -0x14(%rbp),%edx
call   1030 <writev@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jge    1179 <xwritev+0x69>
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
mov    0x2e77(%rip),%rcx
cmp    (%rcx),%rax
je     1174 <xwritev+0x64>
mov    0x2e7f(%rip),%rax
mov    (%rax),%rax
mov    0x2e6d(%rip),%rcx
cmp    (%rcx),%rax
jne    1179 <xwritev+0x69>
jmp    1122 <xwritev+0x12>
mov    -0x20(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<xwritev>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %edx,%r14d
mov    %rsi,%rbx
mov    %edi,%ebp
mov    0x2eb6(%rip),%r15
mov    0x2e97(%rip),%r12
mov    0x2ea0(%rip),%r13
nopl   0x0(%rax,%rax,1)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14d,%edx
call   1030 <writev@plt>
test   %rax,%rax
jns    1161 <xwritev+0x51>
mov    (%r15),%rcx
cmp    (%r12),%rcx
je     1140 <xwritev+0x30>
cmp    0x0(%r13),%rcx
je     1140 <xwritev+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 @xwritev(i32 %0, %struct.iovec* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.iovec*
%6 = alloca i32
%7 = alloca i64
store i32 %0, i32* %4
store %struct.iovec* %1, %struct.iovec** %5
store i32 %2, i32* %6
br label %8
8: ; preds = %23, %3
%9 = load i32, i32* %4
%10 = load %struct.iovec*, %struct.iovec** %5
%11 = load i32, i32* %6
%12 = call i64 @writev(i32 %9, %struct.iovec* %10, i32 %11)
store i64 %12, i64* %7
%13 = load i64, i64* %7
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %24
15: ; preds = %8
%16 = load i64, i64* @errno
%17 = load i64, i64* @EAGAIN
%18 = icmp eq i64 %16, %17
br i1 %18, label %23, label %19
19: ; preds = %15
%20 = load i64, i64* @errno
%21 = load i64, i64* @EINTR
%22 = icmp eq i64 %20, %21
br i1 %22, label %23, label %24
23: ; preds = %19, %15
br label %8
24: ; preds = %19, %8
%25 = load i64, i64* %7
ret i64 %25
}

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