#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 {
  char *iov_base;
  size_t iov_len;
};

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int preadv2(int, struct iovec *, int, int, int /*<<< orphan*/);
int main(void) {
  struct iovec iov[1];
  char data[(64)];
  int fd, rc;
  fd = open("/dev/zero", O_RDONLY);
  if (fd < 0)
    return -1;
  iov[0].iov_base = data;
  iov[0].iov_len = (size_t)(64);
  rc = preadv2(fd, iov, 1, -1, 0);
  (void)close(fd);
  return rc;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2ea2(%rip),%rax
mov    (%rax),%esi
lea    0xeb1(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x64(%rbp)
cmpl   $0x0,-0x64(%rbp)
jge    116d <main+0x3d>
movl   $0xffffffff,-0x4(%rbp)
jmp    11a7 <main+0x77>
lea    -0x60(%rbp),%rax
mov    %rax,-0x20(%rbp)
movq   $0x40,-0x18(%rbp)
mov    -0x64(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <preadv2@plt>
mov    %eax,-0x68(%rbp)
mov    -0x64(%rbp),%edi
call   1030 <close@plt>
mov    -0x68(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x58,%rsp
mov    0x2eab(%rip),%rax
mov    (%rax),%esi
lea    0xeba(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1185 <main+0x55>
mov    %eax,%ebx
lea    0x10(%rsp),%rax
mov    %rax,(%rsp)
movq   $0x40,0x8(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x1,%edx
mov    $0xffffffff,%ecx
xor    %r8d,%r8d
call   1040 <preadv2@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
jmp    118a <main+0x5a>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x58,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i64 }
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [1 x %struct.iovec]
%3 = alloca [64 x i8]
%4 = alloca i32
%5 = alloca i32
store i32 0, i32* %1
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
store i32 %7, i32* %4
%8 = load i32, i32* %4
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 -1, i32* %1
br label %23
11: ; preds = %0
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%13 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %2, i64 0, i64 0
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i32 0, i32 0
store i8* %12, i8** %14
%15 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %2, i64 0, i64 0
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 1
store i64 64, i64* %16
%17 = load i32, i32* %4
%18 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %2, i64 0, i64 0
%19 = call i32 @preadv2(i32 %17, %struct.iovec* %18, i32 1, i32 -1, i32 0)
store i32 %19, i32* %5
%20 = load i32, i32* %4
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %5
store i32 %22, i32* %1
br label %23
23: ; preds = %11, %10
%24 = load i32, i32* %1
ret i32 %24
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i64 }
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca [1 x %struct.iovec]
%2 = alloca [64 x i8]
%3 = bitcast [1 x %struct.iovec]* %1 to i8*
%4 = getelementptr inbounds [64 x i8], [64 x i8]* %2, i64 0, i64 0
%5 = load i32, i32* @O_RDONLY
%6 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp slt i32 %6, 0
br i1 %7, label %14, label %8
8: ; preds = %0
%9 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %1, i64 0, i64 0
%10 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %1, i64 0, i64 0, i32 0
store i8* %4, i8** %10
%11 = getelementptr inbounds [1 x %struct.iovec], [1 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store i64 64, i64* %11
%12 = call i32 @preadv2(i32 %6, %struct.iovec* %9, i32 1, i32 -1, i32 0)
%13 = call i32 @close(i32 %6)
br label %14
14: ; preds = %0, %8
%15 = phi i32 [ %12, %8 ], [ -1, %0 ]
ret i32 %15
}