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

/* Variables and functions */
int /*<<< orphan*/ SYS_readv;
int /*<<< orphan*/ memset(int /*<<< orphan*/, int /*<<< orphan*/,
                          int /*<<< orphan*/);
int /*<<< orphan*/ syscall(int /*<<< orphan*/, int, struct iovec const *, int);
ssize_t readv(int fd, const struct iovec *iov, int iovcnt) {
  int i;
  for (i = 0; i < iovcnt; i++)
    memset(iov[i].iov_base, 0, iov[i].iov_len);
  return syscall(SYS_readv, fd, iov, iovcnt);
}


x86 assembly (clang, -O0):
<readv>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %edx,-0x14(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x18(%rbp),%eax
cmp    -0x14(%rbp),%eax
jge    1171 <readv+0x51>
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    0x4(%rax,%rcx,8),%edi
mov    -0x10(%rbp),%rax
movslq -0x18(%rbp),%rcx
mov    (%rax,%rcx,8),%edx
xor    %esi,%esi
call   1030 <memset@plt>
mov    -0x18(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x18(%rbp)
jmp    1139 <readv+0x19>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
mov    -0x4(%rbp),%esi
mov    -0x10(%rbp),%rdx
mov    -0x14(%rbp),%ecx
call   1040 <syscall@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<readv>:
push   %rbp
push   %r15
push   %r14
push   %r12
push   %rbx
mov    %edx,%r15d
mov    %rsi,%rbx
mov    %edi,%r14d
test   %edx,%edx
jle    1157 <readv+0x37>
mov    %r15d,%r12d
xor    %ebp,%ebp
nopw   0x0(%rax,%rax,1)
mov    (%rbx,%rbp,8),%edx
mov    0x4(%rbx,%rbp,8),%edi
xor    %esi,%esi
call   1030 <memset@plt>
add    $0x1,%rbp
cmp    %rbp,%r12
jne    1140 <readv+0x20>
mov    0x2e82(%rip),%rax
mov    (%rax),%edi
mov    %r14d,%esi
mov    %rbx,%rdx
mov    %r15d,%ecx
pop    %rbx
pop    %r12
pop    %r14
pop    %r15
pop    %rbp
jmp    1040 <syscall@plt>

LLVM IR (-O0):
%struct.iovec = type { i32, i32 }
@SYS_readv = global i32 0
define i32 @readv(i32 %0, %struct.iovec* %1, i32 %2) {
%4 = alloca i32
%5 = alloca %struct.iovec*
%6 = alloca i32
%7 = alloca i32
store i32 %0, i32* %4
store %struct.iovec* %1, %struct.iovec** %5
store i32 %2, i32* %6
store i32 0, i32* %7
br label %8
8: ; preds = %26, %3
%9 = load i32, i32* %7
%10 = load i32, i32* %6
%11 = icmp slt i32 %9, %10
br i1 %11, label %12, label %29
12: ; preds = %8
%13 = load %struct.iovec*, %struct.iovec** %5
%14 = load i32, i32* %7
%15 = sext i32 %14 to i64
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i64 %15
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 1
%18 = load i32, i32* %17
%19 = load %struct.iovec*, %struct.iovec** %5
%20 = load i32, i32* %7
%21 = sext i32 %20 to i64
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i64 %21
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 0, i32 0
%24 = load i32, i32* %23
%25 = call i32 @memset(i32 %18, i32 0, i32 %24)
br label %26
26: ; preds = %12
%27 = load i32, i32* %7
%28 = add nsw i32 %27, 1
store i32 %28, i32* %7
br label %8
29: ; preds = %8
%30 = load i32, i32* @SYS_readv
%31 = load i32, i32* %4
%32 = load %struct.iovec*, %struct.iovec** %5
%33 = load i32, i32* %6
%34 = call i32 @syscall(i32 %30, i32 %31, %struct.iovec* %32, i32 %33)
ret i32 %34
}

LLVM IR (-O2):
%struct.iovec = type { i32, i32 }
@SYS_readv = global i32 0
define i32 @readv(i32 %0, %struct.iovec* %1, i32 %2) {
%4 = icmp sgt i32 %2, 0
br i1 %4, label %5, label %16
5: ; preds = %3
%6 = zext i32 %2 to i64
br label %7
7: ; preds = %5, %7
%8 = phi i64 [ 0, %5 ], [ %14, %7 ]
%9 = getelementptr inbounds %struct.iovec, %struct.iovec* %1, i64 %8, i32 1
%10 = load i32, i32* %9
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %1, i64 %8, i32 0
%12 = load i32, i32* %11
%13 = tail call i32 @memset(i32 %10, i32 0, i32 %12)
%14 = add nuw nsw i64 %8, 1
%15 = icmp eq i64 %14, %6
br i1 %15, label %16, label %7
16: ; preds = %7, %3
%17 = load i32, i32* @SYS_readv
%18 = tail call i32 @syscall(i32 %17, i32 %0, %struct.iovec* %1, i32 %2)
ret i32 %18
}