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

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int S_IEXEC;
int S_IREAD;
int S_IWRITE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ memset(char *, int, int);
int /*<<< orphan*/ mkdir(char *, int);
int open(char *, int, ...);
int /*<<< orphan*/ preadv(int, struct iovec *, int, int);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int fd;
  struct iovec rd_iovec[3];
  char buf[64];
  fd = open("foobar1", O_WRONLY | O_CREAT, 0666);
  memset(buf, (int)'B', sizeof(buf));
  write(fd, buf, sizeof(buf));
  close(fd);
  fd = open("foobar1", O_RDONLY);
  rd_iovec[0].iov_base = buf;
  rd_iovec[0].iov_len = sizeof(buf);
  rd_iovec[1].iov_base = NULL;
  rd_iovec[1].iov_len = 0;
  rd_iovec[2].iov_base = NULL;
  rd_iovec[2].iov_len = 0;
  preadv(fd, rd_iovec, 0, 0);
  memset(buf, 0x0, sizeof(buf));
  preadv(fd, rd_iovec, 3, 0);
  memset(buf, 0x0, sizeof(buf));
  preadv(fd, rd_iovec, 3, 32);
  rd_iovec[0].iov_len = -1;
  preadv(fd, rd_iovec, 1, 0);
  rd_iovec[0].iov_base = (char *)-1;
  rd_iovec[0].iov_len = sizeof(buf);
  preadv(fd, rd_iovec, 1, 0);
  rd_iovec[0].iov_base = buf;
  rd_iovec[0].iov_len = sizeof(buf);
  preadv(-1, rd_iovec, 1, 0);
  preadv(fd, rd_iovec, -1, 0);
  close(fd);
  mkdir("dir1", S_IREAD | S_IWRITE | S_IEXEC);
  fd = open("dir1", O_RDONLY);
  preadv(fd, rd_iovec, 1, 0);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    0x2e37(%rip),%rax
mov    (%rax),%esi
mov    0x2e76(%rip),%rax
or     (%rax),%esi
lea    0xe75(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x80(%rbp),%rdi
mov    $0x42,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x40,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2e13(%rip),%rax
mov    (%rax),%esi
lea    0xe2a(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
lea    -0x80(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x40,-0x38(%rbp)
movq   $0x0,-0x30(%rbp)
movl   $0x0,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
movl   $0x0,-0x18(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
xor    %ecx,%ecx
mov    %ecx,%edx
call   1070 <preadv@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
lea    -0x80(%rbp),%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
mov    $0x20,%ecx
call   1070 <preadv@plt>
movl   $0xffffffff,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    $0xffffffffffffffff,%rax
mov    %rax,-0x40(%rbp)
movl   $0x40,-0x38(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
lea    -0x80(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x40,-0x38(%rbp)
lea    -0x40(%rbp),%rsi
mov    $0xffffffff,%edi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2cd5(%rip),%rax
mov    (%rax),%esi
mov    0x2ce4(%rip),%rax
or     (%rax),%esi
mov    0x2ccb(%rip),%rax
or     (%rax),%esi
lea    0xd02(%rip),%rdi
call   1030 <mkdir@plt>
mov    0x2cce(%rip),%rax
mov    (%rax),%esi
lea    0xced(%rip),%rdi
mov    $0x0,%al
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %rbx
sub    $0x78,%rsp
mov    0x2e3f(%rip),%rax
mov    0x2e80(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe7d(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
lea    0x30(%rsp),%r14
mov    %r14,%rdi
mov    $0x42,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %r14,%rsi
mov    $0x40,%edx
call   1040 <write@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2e18(%rip),%r15
mov    (%r15),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
mov    %r14,(%rsp)
movl   $0x40,0x8(%rsp)
movq   $0x0,0x10(%rsp)
movl   $0x0,0x18(%rsp)
movq   $0x0,0x20(%rsp)
movl   $0x0,0x28(%rsp)
mov    %rsp,%rbx
mov    %eax,%edi
mov    %rbx,%rsi
xor    %edx,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %r14,%rdi
xor    %esi,%esi
mov    $0x40,%edx
call   1050 <memset@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x3,%edx
mov    $0x20,%ecx
call   1070 <preadv@plt>
movl   $0xffffffff,0x8(%rsp)
ff
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
movq   $0xffffffffffffffff,(%rsp)
ff
movl   $0x40,0x8(%rsp)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %r14,(%rsp)
movl   $0x40,0x8(%rsp)
mov    $0xffffffff,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    $0xffffffff,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2cee(%rip),%rax
mov    0x2cff(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2ce4(%rip),%rax
or     (%rax),%esi
lea    0xd1b(%rip),%rbp
mov    %rbp,%rdi
call   1030 <mkdir@plt>
mov    (%r15),%esi
mov    %rbp,%rdi
xor    %eax,%eax
call   1080 <open@plt>
mov    %eax,%ebp
mov    %eax,%edi
mov    %rbx,%rsi
mov    $0x1,%edx
xor    %ecx,%ecx
call   1070 <preadv@plt>
mov    %ebp,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x78,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"dir1\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@S_IEXEC = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [3 x %struct.iovec]
%4 = alloca [64 x i8]
store i32 0, i32* %1
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %5, %6
%8 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7, i32 438)
store i32 %8, i32* %2
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%10 = call i32 @memset(i8* %9, i32 66, i32 64)
%11 = load i32, i32* %2
%12 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%13 = call i32 @write(i32 %11, i8* %12, i32 64)
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* @O_RDONLY
%17 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %16)
store i32 %17, i32* %2
%18 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%20 = getelementptr inbounds %struct.iovec, %struct.iovec* %19, i32 0, i32 0
store i8* %18, i8** %20
%21 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i32 0, i32 1
store i32 64, i32* %22
%23 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 1
%24 = getelementptr inbounds %struct.iovec, %struct.iovec* %23, i32 0, i32 0
store i8* null, i8** %24
%25 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 1
%26 = getelementptr inbounds %struct.iovec, %struct.iovec* %25, i32 0, i32 1
store i32 0, i32* %26
%27 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 2
%28 = getelementptr inbounds %struct.iovec, %struct.iovec* %27, i32 0, i32 0
store i8* null, i8** %28
%29 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 2
%30 = getelementptr inbounds %struct.iovec, %struct.iovec* %29, i32 0, i32 1
store i32 0, i32* %30
%31 = load i32, i32* %2
%32 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%33 = call i32 @preadv(i32 %31, %struct.iovec* %32, i32 0, i32 0)
%34 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%35 = call i32 @memset(i8* %34, i32 0, i32 64)
%36 = load i32, i32* %2
%37 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%38 = call i32 @preadv(i32 %36, %struct.iovec* %37, i32 3, i32 0)
%39 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%40 = call i32 @memset(i8* %39, i32 0, i32 64)
%41 = load i32, i32* %2
%42 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%43 = call i32 @preadv(i32 %41, %struct.iovec* %42, i32 3, i32 32)
%44 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %44, i32 0, i32 1
store i32 -1, i32* %45
%46 = load i32, i32* %2
%47 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%48 = call i32 @preadv(i32 %46, %struct.iovec* %47, i32 1, i32 0)
%49 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%50 = getelementptr inbounds %struct.iovec, %struct.iovec* %49, i32 0, i32 0
store i8* inttoptr (i64 -1 to i8*), i8** %50
%51 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%52 = getelementptr inbounds %struct.iovec, %struct.iovec* %51, i32 0, i32 1
store i32 64, i32* %52
%53 = load i32, i32* %2
%54 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%55 = call i32 @preadv(i32 %53, %struct.iovec* %54, i32 1, i32 0)
%56 = getelementptr inbounds [64 x i8], [64 x i8]* %4, i64 0, i64 0
%57 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%58 = getelementptr inbounds %struct.iovec, %struct.iovec* %57, i32 0, i32 0
store i8* %56, i8** %58
%59 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%60 = getelementptr inbounds %struct.iovec, %struct.iovec* %59, i32 0, i32 1
store i32 64, i32* %60
%61 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%62 = call i32 @preadv(i32 -1, %struct.iovec* %61, i32 1, i32 0)
%63 = load i32, i32* %2
%64 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%65 = call i32 @preadv(i32 %63, %struct.iovec* %64, i32 -1, i32 0)
%66 = load i32, i32* %2
%67 = call i32 @close(i32 %66)
%68 = load i32, i32* @S_IREAD
%69 = load i32, i32* @S_IWRITE
%70 = or i32 %68, %69
%71 = load i32, i32* @S_IEXEC
%72 = or i32 %70, %71
%73 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %72)
%74 = load i32, i32* @O_RDONLY
%75 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %74)
store i32 %75, i32* %2
%76 = load i32, i32* %2
%77 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%78 = call i32 @preadv(i32 %76, %struct.iovec* %77, i32 1, i32 0)
%79 = load i32, i32* %2
%80 = call i32 @close(i32 %79)
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"dir1\00"
@S_IREAD = global i32 0
@S_IWRITE = global i32 0
@S_IEXEC = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.iovec]
%2 = alloca [64 x i8]
%3 = bitcast [3 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_WRONLY
%6 = load i32, i32* @O_CREAT
%7 = or i32 %6, %5
%8 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %7, i32 438)
%9 = call i32 @memset(i8* %4, i32 66, i32 64)
%10 = call i32 @write(i32 %8, i8* %4, i32 64)
%11 = call i32 @close(i32 %8)
%12 = load i32, i32* @O_RDONLY
%13 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str, i64 0, i64 0), i32 %12)
%14 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0, i32 0
store i8* %4, i8** %15
%16 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store i32 64, i32* %16
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 0
store i8* null, i8** %17
%18 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 1
store i32 0, i32* %18
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 0
store i8* null, i8** %19
%20 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 1
store i32 0, i32* %20
%21 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 0, i32 0)
%22 = call i32 @memset(i8* %4, i32 0, i32 64)
%23 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 3, i32 0)
%24 = call i32 @memset(i8* %4, i32 0, i32 64)
%25 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 3, i32 32)
store i32 -1, i32* %16
%26 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 1, i32 0)
store i8* inttoptr (i64 -1 to i8*), i8** %15
store i32 64, i32* %16
%27 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 1, i32 0)
store i8* %4, i8** %15
store i32 64, i32* %16
%28 = call i32 @preadv(i32 -1, %struct.iovec* %14, i32 1, i32 0)
%29 = call i32 @preadv(i32 %13, %struct.iovec* %14, i32 -1, i32 0)
%30 = call i32 @close(i32 %13)
%31 = load i32, i32* @S_IREAD
%32 = load i32, i32* @S_IWRITE
%33 = or i32 %32, %31
%34 = load i32, i32* @S_IEXEC
%35 = or i32 %33, %34
%36 = call i32 @mkdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %35)
%37 = load i32, i32* @O_RDONLY
%38 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i32 %37)
%39 = call i32 @preadv(i32 %38, %struct.iovec* %14, i32 1, i32 0)
%40 = call i32 @close(i32 %38)
ret i32 0
}