#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*/ loff_t;

/* Variables and functions */
int O_CREAT;
int /*<<< orphan*/ O_RDONLY;
int O_WRONLY;
int /*<<< orphan*/ SEEK_CUR;
int /*<<< orphan*/ SEEK_END;
int /*<<< orphan*/ SEEK_SET;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ lseek(int, int, int /*<<< orphan*/);
int open(char *, int, ...);
int /*<<< orphan*/ pread(int, char *, int, int);
int /*<<< orphan*/ pwrite(int, char *, int, int);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ readv(int, struct iovec *, int);
int /*<<< orphan*/ write(int, char *, int);
int /*<<< orphan*/ writev(int, struct iovec *, int);
int main() {
  int fd;
  struct iovec v[3], x[3];
  loff_t res;
  char buf[64], buf1[32], buf2[32], buf3[32];
  v[0].iov_base = "red";
  v[0].iov_len = sizeof("red");
  v[1].iov_base = "green";
  v[1].iov_len = sizeof("green");
  v[2].iov_base = "blue";
  v[2].iov_len = sizeof("blue");
  fd = open("foobar1", O_WRONLY | O_CREAT, 0666);
  write(fd, "Hello world", 11);
  write(fd, "Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789", 59);
  pwrite(fd, "Hello Again", 11, 12);
  writev(fd, v, 3);
  lseek(fd, 0, SEEK_SET);
  lseek(fd, 1, SEEK_CUR);
  lseek(fd, -1, SEEK_END);
  close(fd);
  fd = open("foobar1", O_RDONLY);
  read(fd, buf, 11);
  read(fd, buf, 50);
  pread(fd, buf, 11, 10);
  x[0].iov_base = buf1;
  x[0].iov_len = sizeof("red");
  x[1].iov_base = buf2;
  x[1].iov_len = sizeof("green");
  x[2].iov_base = buf3;
  x[2].iov_len = sizeof("blue");
  readv(fd, x, 3);
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xe57(%rip),%rax
mov    %rax,-0x40(%rbp)
movl   $0x4,-0x38(%rbp)
lea    0xe49(%rip),%rax
mov    %rax,-0x30(%rbp)
movl   $0x6,-0x28(%rbp)
lea    0xe3d(%rip),%rax
mov    %rax,-0x20(%rbp)
movl   $0x5,-0x18(%rbp)
mov    0x2dd1(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
lea    0xe1e(%rip),%rdi
mov    $0x1b6,%edx
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    0xe0d(%rip),%rsi
mov    $0xb,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe05(%rip),%rsi
mov    $0x3b,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
lea    0xe2d(%rip),%rsi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1080 <pwrite@plt>
mov    -0x8(%rbp),%edi
lea    -0x40(%rbp),%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
mov    -0x8(%rbp),%edi
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1050 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2d69(%rip),%rax
mov    (%rax),%edx
mov    $0x1,%esi
call   1050 <lseek@plt>
mov    -0x8(%rbp),%edi
mov    0x2d5b(%rip),%rax
mov    (%rax),%edx
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
mov    0x2d30(%rip),%rax
mov    (%rax),%esi
lea    0xd66(%rip),%rdi
mov    $0x0,%al
call   10a0 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0xb,%edx
call   1070 <read@plt>
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0x32,%edx
call   1070 <read@plt>
mov    -0x8(%rbp),%edi
lea    -0xc0(%rbp),%rsi
mov    $0xb,%edx
mov    $0xa,%ecx
call   10b0 <pread@plt>
lea    -0xe0(%rbp),%rax
mov    %rax,-0x70(%rbp)
movl   $0x4,-0x68(%rbp)
lea    -0x100(%rbp),%rax
mov    %rax,-0x60(%rbp)
movl   $0x6,-0x58(%rbp)
lea    -0x120(%rbp),%rax
mov    %rax,-0x50(%rbp)
movl   $0x5,-0x48(%rbp)
mov    -0x8(%rbp),%edi
lea    -0x70(%rbp),%rsi
mov    $0x3,%edx
call   1090 <readv@plt>
mov    -0x8(%rbp),%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
lea    0xe60(%rip),%rax
mov    %rax,0x30(%rsp)
movl   $0x4,0x38(%rsp)
lea    0xe50(%rip),%rax
mov    %rax,0x40(%rsp)
movl   $0x6,0x48(%rsp)
lea    0xe42(%rip),%rax
mov    %rax,0x50(%rsp)
movl   $0x5,0x58(%rsp)
mov    0x2dd4(%rip),%rax
mov    0x2e15(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
lea    0xe21(%rip),%rbx
mov    %rbx,%rdi
mov    $0x1b6,%edx
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%ebp
lea    0xe11(%rip),%rsi
mov    %eax,%edi
mov    $0xb,%edx
call   1040 <write@plt>
lea    0xe0a(%rip),%rsi
mov    %ebp,%edi
mov    $0x3b,%edx
call   1040 <write@plt>
lea    0xe33(%rip),%rsi
mov    %ebp,%edi
mov    $0xb,%edx
mov    $0xc,%ecx
call   1080 <pwrite@plt>
lea    0x30(%rsp),%rsi
mov    %ebp,%edi
mov    $0x3,%edx
call   1030 <writev@plt>
mov    0x2d6b(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
xor    %esi,%esi
call   1050 <lseek@plt>
mov    0x2d71(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0x1,%esi
call   1050 <lseek@plt>
mov    0x2d64(%rip),%rax
mov    (%rax),%edx
mov    %ebp,%edi
mov    $0xffffffff,%esi
call   1050 <lseek@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0x2d38(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
xor    %eax,%eax
call   10a0 <open@plt>
mov    %eax,%ebx
lea    0xc0(%rsp),%rbp
mov    %eax,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
call   1070 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x32,%edx
call   1070 <read@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0xb,%edx
mov    $0xa,%ecx
call   10b0 <pread@plt>
lea    0xa0(%rsp),%rax
mov    %rax,(%rsp)
movl   $0x4,0x8(%rsp)
lea    0x80(%rsp),%rax
mov    %rax,0x10(%rsp)
movl   $0x6,0x18(%rsp)
lea    0x60(%rsp),%rax
mov    %rax,0x20(%rsp)
movl   $0x5,0x28(%rsp)
mov    %rsp,%rsi
mov    %ebx,%edi
mov    $0x3,%edx
call   1090 <readv@plt>
mov    %ebx,%edi
call   1060 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

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

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [4 x i8] c"red\00"
@.str.1 = [6 x i8] c"green\00"
@.str.2 = [5 x i8] c"blue\00"
@.str.3 = [8 x i8] c"foobar1\00"
@O_WRONLY = global i32 0
@O_CREAT = global i32 0
@.str.4 = [12 x i8] c"Hello world\00"
@.str.5 = [60 x i8] c"Hello world abcdefghijklmnopqrstuvwxyz 01234567890123456789\00"
@.str.6 = [12 x i8] c"Hello Again\00"
@SEEK_SET = global i32 0
@SEEK_CUR = global i32 0
@SEEK_END = global i32 0
@O_RDONLY = global i32 0
define i32 @main() {
%1 = alloca [3 x %struct.iovec]
%2 = alloca [3 x %struct.iovec]
%3 = alloca [64 x i8]
%4 = alloca [32 x i8]
%5 = alloca [32 x i8]
%6 = alloca [32 x i8]
%7 = bitcast [3 x %struct.iovec]* %1 to i8*
%8 = bitcast [3 x %struct.iovec]* %2 to i8*
%9 = getelementptr inbounds [64 x i8], [64 x i8]* %3, i64 0, i64 0
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %5, i64 0, i64 0
%12 = getelementptr inbounds [32 x i8], [32 x i8]* %6, i64 0, i64 0
%13 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0
%14 = 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, i64 0, i64 0), i8** %14
%15 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store i32 4, i32* %15
%16 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8** %16
%17 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 1, i32 1
store i32 6, i32* %17
%18 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 0
store i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8** %18
%19 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %1, i64 0, i64 2, i32 1
store i32 5, i32* %19
%20 = load i32, i32* @O_WRONLY
%21 = load i32, i32* @O_CREAT
%22 = or i32 %21, %20
%23 = tail call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %22, i32 438)
%24 = tail call i32 @write(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.4, i64 0, i64 0), i32 11)
%25 = tail call i32 @write(i32 %23, i8* getelementptr inbounds ([60 x i8], [60 x i8]* @.str.5, i64 0, i64 0), i32 59)
%26 = tail call i32 @pwrite(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.6, i64 0, i64 0), i32 11, i32 12)
%27 = call i32 @writev(i32 %23, %struct.iovec* %13, i32 3)
%28 = load i32, i32* @SEEK_SET
%29 = call i32 @lseek(i32 %23, i32 0, i32 %28)
%30 = load i32, i32* @SEEK_CUR
%31 = call i32 @lseek(i32 %23, i32 1, i32 %30)
%32 = load i32, i32* @SEEK_END
%33 = call i32 @lseek(i32 %23, i32 -1, i32 %32)
%34 = call i32 @close(i32 %23)
%35 = load i32, i32* @O_RDONLY
%36 = call i32 (i8*, i32, ...) @open(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.3, i64 0, i64 0), i32 %35)
%37 = call i32 @read(i32 %36, i8* %9, i32 11)
%38 = call i32 @read(i32 %36, i8* %9, i32 50)
%39 = call i32 @pread(i32 %36, i8* %9, i32 11, i32 10)
%40 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0
%41 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0, i32 0
store i8* %10, i8** %41
%42 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 0, i32 1
store i32 4, i32* %42
%43 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 1, i32 0
store i8* %11, i8** %43
%44 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 1, i32 1
store i32 6, i32* %44
%45 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 2, i32 0
store i8* %12, i8** %45
%46 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %2, i64 0, i64 2, i32 1
store i32 5, i32* %46
%47 = call i32 @readv(i32 %36, %struct.iovec* %40, i32 3)
%48 = call i32 @close(i32 %36)
ret i32 0
}