#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;
  int iov_len;
};

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int /*<<< orphan*/ assert(int);
int open(char *, int, int);
int /*<<< orphan*/ pwrite(int, char *, int, int);
int /*<<< orphan*/ pwritev(int, struct iovec *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int /*<<< orphan*/ writev(int, struct iovec *, int);
int main() {
  int fd = open("/tmp/x", O_CREAT | O_RDWR, 0666);
  assert(fd > 0);
  write(fd, "hello", 5);
  pwrite(fd, "world", 5, 4);
  struct iovec x[3];
  x[0].iov_base = "aaa";
  x[0].iov_len = 3;
  x[1].iov_base = "bbb";
  x[1].iov_len = 3;
  x[2].iov_base = "ccc";
  x[2].iov_len = 3;
  writev(fd, x, 3);
  x[0].iov_base = "xxx";
  x[1].iov_base = "yyy";
  x[2].iov_base = "zzz";
  pwritev(fd, x, 3, 10);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2e89(%rip),%rax
mov    (%rax),%esi
mov    0x2e68(%rip),%rax
or     (%rax),%esi
lea    0xe7f(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
setg   %al
and    $0x1,%al
movzbl %al,%edi
call   1060 <assert@plt>
mov    -0x4(%rbp),%edi
lea    0xe5e(%rip),%rsi
mov    $0x5,%edx
call   1040 <write@plt>
mov    -0x4(%rbp),%edi
lea    0xe50(%rip),%rsi
mov    $0x5,%edx
mov    $0x4,%ecx
call   1070 <pwrite@plt>
lea    0xe40(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x3,-0x38(%rbp)
lea    0xe32(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x3,-0x28(%rbp)
lea    0xe24(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x3,-0x18(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
lea    0xe05(%rip),%rax
mov    %rax,-0x40(%rbp)
lea    0xdfe(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xdf7(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    -0x4(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
mov    $0xa,%ecx
call   1050 <pwritev@plt>
xor    %eax,%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
mov    0x2e8a(%rip),%rax
mov    0x2e6b(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe80(%rip),%rdi
mov    $0x1b6,%edx
call   1080 <open@plt>
mov    %eax,%ebx
xor    %edi,%edi
test   %eax,%eax
setg   %dil
call   1060 <assert@plt>
lea    0xe67(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
call   1040 <write@plt>
lea    0xe5a(%rip),%rsi
mov    %ebx,%edi
mov    $0x5,%edx
mov    $0x4,%ecx
call   1070 <pwrite@plt>
lea    0xe48(%rip),%rax
mov    %rax,(%rsp)
movl   $0x3,0x8(%rsp)
lea    0xe39(%rip),%rax
mov    %rax,0x10(%rsp)
movl   $0x3,0x18(%rsp)
lea    0xe29(%rip),%rax
mov    %rax,0x20(%rsp)
movl   $0x3,0x28(%rsp)
mov    %rsp,%r14
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
lea    0xe07(%rip),%rax
mov    %rax,(%rsp)
lea    0xe00(%rip),%rax
mov    %rax,0x10(%rsp)
lea    0xdf8(%rip),%rax
mov    %rax,0x20(%rsp)
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x3,%edx
mov    $0xa,%ecx
call   1050 <pwritev@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [7 x i8] c"/tmp/x\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [6 x i8] c"world\00"
@.str.3 = [4 x i8] c"aaa\00"
@.str.4 = [4 x i8] c"bbb\00"
@.str.5 = [4 x i8] c"ccc\00"
@.str.6 = [4 x i8] c"xxx\00"
@.str.7 = [4 x i8] c"yyy\00"
@.str.8 = [4 x i8] c"zzz\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [3 x %struct.iovec]
%3 = load i32, i32* @O_CREAT
%4 = load i32, i32* @O_RDWR
%5 = or i32 %3, %4
%6 = call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %5, i32 438)
store i32 %6, i32* %1
%7 = load i32, i32* %1
%8 = icmp sgt i32 %7, 0
%9 = zext i1 %8 to i32
%10 = call i32 @assert(i32 %9)
%11 = load i32, i32* %1
%12 = call i32 @write(i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%13 = load i32, i32* %1
%14 = call i32 @pwrite(i32 %13, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 4)
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 1
store i32 3, i32* %18
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 1
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %20
%21 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 1
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 1
store i32 3, i32* %22
%23 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 2
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %23, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %24
%25 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 2
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 1
store i32 3, i32* %26
%27 = load i32, i32* %1
%28 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%29 = call i32 @writev(i32 %27, %struct.iovec* %28, i32 3)
%30 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%31 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %31
%32 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 1
%33 = getelementptr inbounds %struct.iovec, %struct.iovec* %32, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %33
%34 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 2
%35 = getelementptr inbounds %struct.iovec, %struct.iovec* %34, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8** %35
%36 = load i32, i32* %1
%37 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%38 = call i32 @pwritev(i32 %36, %struct.iovec* %37, i32 3, i32 10)
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [7 x i8] c"/tmp/x\00"
@O_CREAT = global i32 0
@O_RDWR = global i32 0
@.str.1 = [6 x i8] c"hello\00"
@.str.2 = [6 x i8] c"world\00"
@.str.3 = [4 x i8] c"aaa\00"
@.str.4 = [4 x i8] c"bbb\00"
@.str.5 = [4 x i8] c"ccc\00"
@.str.6 = [4 x i8] c"xxx\00"
@.str.7 = [4 x i8] c"yyy\00"
@.str.8 = [4 x i8] c"zzz\00"
define i32 @main() {
%1 = alloca [3 x %struct.iovec]
%2 = load i32, i32* @O_CREAT
%3 = load i32, i32* @O_RDWR
%4 = or i32 %3, %2
%5 = tail call i32 @open(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i32 %4, i32 438)
%6 = icmp sgt i32 %5, 0
%7 = zext i1 %6 to i32
%8 = tail call i32 @assert(i32 %7)
%9 = tail call i32 @write(i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i32 5)
%10 = tail call i32 @pwrite(i32 %5, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0), i32 5, i32 4)
%11 = bitcast [3 x %struct.iovec]* %1 to i8*
%12 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0
%13 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i8** %13
%14 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store i32 3, i32* %14
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8** %15
%16 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 1
store i32 3, i32* %16
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8** %17
%18 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 1
store i32 3, i32* %18
%19 = call i32 @writev(i32 %5, %struct.iovec* %12, i32 3)
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8** %13
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.7, i64 0, i64 0), i8** %15
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.8, i64 0, i64 0), i8** %17
%20 = call i32 @pwritev(i32 %5, %struct.iovec* %12, i32 3, i32 10)
ret i32 0
}