#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 *member_0;
  int member_1;
};
typedef int off_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int pread(int, char *, int, int const);
int preadv(int, struct iovec *, int, int const);
int pwrite(int, char *, int, int const);
int pwritev(int, struct iovec *, int, int const);
int main(void) {
  const off_t offset = 0xdefaceddeadbeefLL;
  int fd;
  char buf[4];
  struct iovec iov = {buf, sizeof buf};
  assert((fd = open("/dev/zero", O_RDONLY)) >= 0);
  assert(pread(fd, buf, sizeof buf, offset) == 4);
  assert(preadv(fd, &iov, 1, offset) == 4);
  assert(!close(fd));
  assert((fd = open("/dev/null", O_WRONLY)) >= 0);
  assert(pwrite(fd, buf, sizeof buf, offset) == 4);
  assert(pwritev(fd, &iov, 1, offset) == 4);
  assert(!close(fd));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
movl   $0xdeadbeef,-0x8(%rbp)
lea    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x4,-0x18(%rbp)
mov    0x2e4c(%rip),%rax
mov    (%rax),%esi
lea    0xe5b(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0xdeadbeef,%ecx
call   1090 <pread@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
mov    $0xdeadbeef,%ecx
call   1060 <preadv@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    0x2da6(%rip),%rax
mov    (%rax),%esi
lea    0xdd7(%rip),%rdi
call   1080 <open@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
setge  %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x10(%rbp),%rsi
mov    $0x4,%edx
mov    $0xdeadbeef,%ecx
call   1070 <pwrite@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
lea    -0x20(%rbp),%rsi
mov    $0x1,%edx
mov    $0xdeadbeef,%ecx
call   1040 <pwritev@plt>
cmp    $0x4,%eax
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
mov    -0xc(%rbp),%edi
call   1030 <close@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%edi
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x20,%rsp
lea    0xc(%rsp),%rbx
mov    %rbx,0x10(%rsp)
movl   $0x4,0x18(%rsp)
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
lea    0xe66(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
mov    $0xdeadbeef,%ecx
call   1090 <pread@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1050 <assert@plt>
lea    0x10(%rsp),%r14
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0xdeadbeef,%ecx
call   1060 <preadv@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
lea    0xdf0(%rip),%rdi
call   1080 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
not    %edi
shr    $0x1f,%edi
call   1050 <assert@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x4,%edx
mov    $0xdeadbeef,%ecx
call   1070 <pwrite@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x1,%edx
mov    $0xdeadbeef,%ecx
call   1040 <pwritev@plt>
xor    %edi,%edi
cmp    $0x4,%eax
sete   %dil
call   1050 <assert@plt>
mov    %ebp,%edi
call   1030 <close@plt>
xor    %edi,%edi
test   %eax,%eax
sete   %dil
call   1050 <assert@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32
%4 = alloca [4 x i8]
%5 = alloca %struct.iovec
store i32 0, i32* %1
store i32 -559038737, i32* %2
%6 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 0
%7 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
store i8* %7, i8** %6
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %5, i32 0, i32 1
store i32 4, i32* %8
%9 = load i32, i32* @O_RDONLY
%10 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %3
%11 = icmp sge i32 %10, 0
%12 = zext i1 %11 to i32
%13 = call i32 @assert(i32 %12)
%14 = load i32, i32* %3
%15 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%16 = call i32 @pread(i32 %14, i8* %15, i32 4, i32 -559038737)
%17 = icmp eq i32 %16, 4
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = load i32, i32* %3
%21 = call i32 @preadv(i32 %20, %struct.iovec* %5, i32 1, i32 -559038737)
%22 = icmp eq i32 %21, 4
%23 = zext i1 %22 to i32
%24 = call i32 @assert(i32 %23)
%25 = load i32, i32* %3
%26 = call i32 @close(i32 %25)
%27 = icmp ne i32 %26, 0
%28 = xor i1 %27, true
%29 = zext i1 %28 to i32
%30 = call i32 @assert(i32 %29)
%31 = load i32, i32* @O_WRONLY
%32 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %31)
store i32 %32, i32* %3
%33 = icmp sge i32 %32, 0
%34 = zext i1 %33 to i32
%35 = call i32 @assert(i32 %34)
%36 = load i32, i32* %3
%37 = getelementptr inbounds [4 x i8], [4 x i8]* %4, i64 0, i64 0
%38 = call i32 @pwrite(i32 %36, i8* %37, i32 4, i32 -559038737)
%39 = icmp eq i32 %38, 4
%40 = zext i1 %39 to i32
%41 = call i32 @assert(i32 %40)
%42 = load i32, i32* %3
%43 = call i32 @pwritev(i32 %42, %struct.iovec* %5, i32 1, i32 -559038737)
%44 = icmp eq i32 %43, 4
%45 = zext i1 %44 to i32
%46 = call i32 @assert(i32 %45)
%47 = load i32, i32* %3
%48 = call i32 @close(i32 %47)
%49 = icmp ne i32 %48, 0
%50 = xor i1 %49, true
%51 = zext i1 %50 to i32
%52 = call i32 @assert(i32 %51)
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [10 x i8] c"/dev/zero\00"
@O_RDONLY = global i32 0
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
define i32 @main() {
%1 = alloca [4 x i8]
%2 = alloca %struct.iovec
%3 = getelementptr inbounds [4 x i8], [4 x i8]* %1, i64 0, i64 0
%4 = bitcast %struct.iovec* %2 to i8*
%5 = getelementptr inbounds %struct.iovec, %struct.iovec* %2, i64 0, i32 0
store i8* %3, i8** %5
%6 = getelementptr inbounds %struct.iovec, %struct.iovec* %2, i64 0, i32 1
store i32 4, i32* %6
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %7)
%9 = xor i32 %8, -1
%10 = lshr i32 %9, 31
%11 = call i32 @assert(i32 %10)
%12 = call i32 @pread(i32 %8, i8* %3, i32 4, i32 -559038737)
%13 = icmp eq i32 %12, 4
%14 = zext i1 %13 to i32
%15 = call i32 @assert(i32 %14)
%16 = call i32 @preadv(i32 %8, %struct.iovec* %2, i32 1, i32 -559038737)
%17 = icmp eq i32 %16, 4
%18 = zext i1 %17 to i32
%19 = call i32 @assert(i32 %18)
%20 = call i32 @close(i32 %8)
%21 = icmp eq i32 %20, 0
%22 = zext i1 %21 to i32
%23 = call i32 @assert(i32 %22)
%24 = load i32, i32* @O_WRONLY
%25 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %24)
%26 = xor i32 %25, -1
%27 = lshr i32 %26, 31
%28 = call i32 @assert(i32 %27)
%29 = call i32 @pwrite(i32 %25, i8* %3, i32 4, i32 -559038737)
%30 = icmp eq i32 %29, 4
%31 = zext i1 %30 to i32
%32 = call i32 @assert(i32 %31)
%33 = call i32 @pwritev(i32 %25, %struct.iovec* %2, i32 1, i32 -559038737)
%34 = icmp eq i32 %33, 4
%35 = zext i1 %34 to i32
%36 = call i32 @assert(i32 %35)
%37 = call i32 @close(i32 %25)
%38 = icmp eq i32 %37, 0
%39 = zext i1 %38 to i32
%40 = call i32 @assert(i32 %39)
ret i32 0
}