#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*/ SEEK_SET;
int S_IRWXU;
int S_IWOTH;
int /*<<< orphan*/ close(int);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ malloc(int);
int open(char *, int, int);
int /*<<< orphan*/ printf(char *, ...);
int readv(int, struct iovec *, int);
void *strlen(char *);
int /*<<< orphan*/ sync();
int writev(int, struct iovec *, int);
int main(int argc, char **argv) {
  int fd, ret;
  struct iovec iov[3];
  struct iovec iov_r[3];
  if (argc != 5) {
    printf("Usage: ./xxx path/to/file string0 string1 string2\n");
    return -1;
  }
  fd = open(argv[1], O_RDWR | O_CREAT, S_IRWXU | S_IWOTH);
  if (fd == -1) {
    printf("open %s failed\n", argv[1]);
    return -1;
  }
  iov[0].iov_base = argv[2];
  iov[0].iov_len = strlen(argv[2]);
  iov[1].iov_base = argv[3];
  iov[1].iov_len = strlen(argv[3]);
  iov[2].iov_base = argv[4];
  iov[2].iov_len = strlen(argv[4]);
  ret = writev(fd, iov, 3);
  if (ret == -1) {
    printf("writev failed\n");
    close(fd);
    return -1;
  }
  sync();
  ret = lseek(fd, 0, SEEK_SET);
  if (ret == -1) {
    printf("lseek failed\n");
    close(fd);
    return -1;
  }
  iov_r[0].iov_len = 1;
  iov_r[0].iov_base = (char *)malloc(1);
  iov_r[1].iov_len = 2;
  iov_r[1].iov_base = (char *)malloc(2);
  iov_r[2].iov_len = 3;
  iov_r[2].iov_base = (char *)malloc(3);
  ret = readv(fd, iov_r, 3);
  if (ret == -1) {
    printf("readv failed\n");
    close(fd);
    return -1;
  } else {
    printf("v0 %s\n", iov_r[0].iov_base);
    printf("v1 %s\n", iov_r[1].iov_base);
    printf("v2 %s\n", iov_r[2].iov_base);
    printf("argv2 %s\n", argv[2]);
    printf("argv3 %s\n", argv[3]);
    printf("argv4 %s\n", argv[4]);
  }
  ret = lseek(fd, 0, SEEK_SET);
  if (ret == -1) {
    printf("lseek failed\n");
    close(fd);
    return -1;
  }
  iov[0].iov_base = argv[2];
  iov[0].iov_len = strlen(argv[4]);
  iov[1].iov_base = argv[3];
  iov[1].iov_len = strlen(argv[2]);
  iov[2].iov_base = argv[4];
  iov[2].iov_len = strlen(argv[3]);
  ret = readv(fd, iov, 3);
  if (ret == -1) {
    printf("readv failed\n");
    close(fd);
    return -1;
  } else {
    printf("v0 %s\n", iov[0].iov_base);
    printf("v1 %s\n", iov[1].iov_base);
    printf("v2 %s\n", iov[2].iov_base);
    printf("argv2 %s\n", argv[2]);
    printf("argv3 %s\n", argv[3]);
    printf("argv4 %s\n", argv[4]);
  }
  close(fd);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x5,-0x8(%rbp)
je     11cd <main+0x3d>
lea    0xe46(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dfc(%rip),%rax
mov    (%rax),%esi
mov    0x2e13(%rip),%rax
or     (%rax),%esi
mov    0x2df2(%rip),%rax
mov    (%rax),%edx
mov    0x2dc1(%rip),%rax
or     (%rax),%edx
call   10b0 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    122d <main+0x9d>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
lea    0xe19(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x3,%edx
call   1030 <writev@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    12c1 <main+0x131>
lea    0xd9d(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    $0x0,%al
call   1080 <sync@plt>
mov    -0x14(%rbp),%edi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    130a <main+0x17a>
lea    0xd63(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
movl   $0x1,-0x78(%rbp)
mov    $0x1,%edi
call   1090 <malloc@plt>
mov    %rax,-0x80(%rbp)
movl   $0x2,-0x68(%rbp)
mov    $0x2,%edi
call   1090 <malloc@plt>
mov    %rax,-0x70(%rbp)
movl   $0x3,-0x58(%rbp)
mov    $0x3,%edi
call   1090 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x3,%edx
call   10a0 <readv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1389 <main+0x1f9>
lea    0xcf2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    -0x80(%rbp),%rsi
lea    0xcda(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x70(%rbp),%rsi
lea    0xccf(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x60(%rbp),%rsi
lea    0xcc7(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xcae(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xca2(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0xc96(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
mov    0x2bbd(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1060 <lseek@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    1443 <main+0x2b3>
lea    0xc2a(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x38(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x28(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x3,%edx
call   10a0 <readv@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0xffffffff,-0x18(%rbp)
jne    14d7 <main+0x347>
lea    0xba4(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    155e <main+0x3ce>
mov    -0x50(%rbp),%rsi
lea    0xb8c(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x40(%rbp),%rsi
lea    0xb81(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x30(%rbp),%rsi
lea    0xb79(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
lea    0xb60(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
lea    0xb54(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rsi
lea    0xb48(%rip),%rdi
mov    $0x0,%al
call   1050 <printf@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x60,%rsp
cmp    $0x5,%edi
jne    1418 <main+0x278>
mov    %rsi,%rbx
mov    0x8(%rsi),%rdi
mov    0x2e19(%rip),%rax
mov    0x2e32(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2e0f(%rip),%rax
mov    0x2de0(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   10c0 <open@plt>
cmp    $0xffffffff,%eax
je     1426 <main+0x286>
mov    %eax,%r14d
mov    0x10(%rbx),%rdi
mov    %rdi,(%rsp)
call   1050 <strlen@plt>
mov    %eax,0x8(%rsp)
mov    0x18(%rbx),%rdi
mov    %rdi,0x10(%rsp)
call   1050 <strlen@plt>
mov    %eax,0x18(%rsp)
mov    0x20(%rbx),%rdi
mov    %rdi,0x20(%rsp)
call   1050 <strlen@plt>
mov    %eax,0x28(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x3,%edx
call   1030 <writev@plt>
cmp    $0xffffffff,%eax
je     143a <main+0x29a>
xor    %eax,%eax
call   1090 <sync@plt>
mov    0x2d7f(%rip),%rbp
mov    0x0(%rbp),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x2a3>
movl   $0x1,0x38(%rsp)
mov    $0x1,%edi
call   10a0 <malloc@plt>
mov    %rax,0x30(%rsp)
movl   $0x2,0x48(%rsp)
mov    $0x2,%edi
call   10a0 <malloc@plt>
mov    %rax,0x40(%rsp)
movl   $0x3,0x58(%rsp)
mov    $0x3,%edi
call   10a0 <malloc@plt>
mov    %rax,0x50(%rsp)
lea    0x30(%rsp),%rsi
mov    %r14d,%edi
mov    $0x3,%edx
call   10b0 <readv@plt>
cmp    $0xffffffff,%eax
je     144c <main+0x2ac>
mov    0x30(%rsp),%rsi
lea    0xd45(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x40(%rsp),%rsi
lea    0xd39(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x50(%rsp),%rsi
lea    0xd30(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xd1b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%rsi
lea    0xd13(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rbx),%rsi
lea    0xd0b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x0(%rbp),%edx
mov    %r14d,%edi
xor    %esi,%esi
call   1070 <lseek@plt>
cmp    $0xffffffff,%eax
je     1443 <main+0x2a3>
mov    0x10(%rbx),%rax
mov    %rax,(%rsp)
mov    0x20(%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,0x8(%rsp)
mov    0x18(%rbx),%rax
mov    %rax,0x10(%rsp)
mov    0x10(%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,0x18(%rsp)
mov    0x20(%rbx),%rax
mov    %rax,0x20(%rsp)
mov    0x18(%rbx),%rdi
call   1050 <strlen@plt>
mov    %eax,0x28(%rsp)
mov    %rsp,%rsi
mov    %r14d,%edi
mov    $0x3,%edx
call   10b0 <readv@plt>
cmp    $0xffffffff,%eax
je     144c <main+0x2ac>
mov    (%rsp),%rsi
lea    0xc67(%rip),%rdi
xor    %ebp,%ebp
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rsp),%rsi
lea    0xc59(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rsp),%rsi
lea    0xc50(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x10(%rbx),%rsi
lea    0xc3b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x18(%rbx),%rsi
lea    0xc33(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    0x20(%rbx),%rsi
lea    0xc2b(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
mov    %r14d,%edi
call   1080 <close@plt>
jmp    1465 <main+0x2c5>
lea    0xc45(%rip),%rdi
call   1040 <puts@plt>
jmp    1460 <main+0x2c0>
mov    0x8(%rbx),%rsi
lea    0xbcf(%rip),%rdi
xor    %eax,%eax
call   1060 <printf@plt>
jmp    1460 <main+0x2c0>
lea    0xc15(%rip),%rdi
jmp    1453 <main+0x2b3>
lea    0xbff(%rip),%rdi
jmp    1453 <main+0x2b3>
lea    0xbe9(%rip),%rdi
call   1040 <puts@plt>
mov    %r14d,%edi
call   1080 <close@plt>
mov    $0xffffffff,%ebp
mov    %ebp,%eax
add    $0x60,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [51 x i8] c"Usage: ./xxx path/to/file string0 string1 string2\0A\00"
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [16 x i8] c"open %s failed\0A\00"
@.str.2 = [15 x i8] c"writev failed\0A\00"
@SEEK_SET = global i32 0
@.str.3 = [14 x i8] c"lseek failed\0A\00"
@.str.4 = [14 x i8] c"readv failed\0A\00"
@.str.5 = [7 x i8] c"v0 %s\0A\00"
@.str.6 = [7 x i8] c"v1 %s\0A\00"
@.str.7 = [7 x i8] c"v2 %s\0A\00"
@.str.8 = [10 x i8] c"argv2 %s\0A\00"
@.str.9 = [10 x i8] c"argv3 %s\0A\00"
@.str.10 = [10 x i8] c"argv4 %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca [3 x %struct.iovec]
%9 = alloca [3 x %struct.iovec]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = load i32, i32* %4
%11 = icmp ne i32 %10, 5
br i1 %11, label %12, label %14
12: ; preds = %2
%13 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
br label %226
14: ; preds = %2
%15 = load i8**, i8*** %5
%16 = getelementptr inbounds i8*, i8** %15, i64 1
%17 = load i8*, i8** %16
%18 = load i32, i32* @O_RDWR
%19 = load i32, i32* @O_CREAT
%20 = or i32 %18, %19
%21 = load i32, i32* @S_IRWXU
%22 = load i32, i32* @S_IWOTH
%23 = or i32 %21, %22
%24 = call i32 @open(i8* %17, i32 %20, i32 %23)
store i32 %24, i32* %6
%25 = load i32, i32* %6
%26 = icmp eq i32 %25, -1
br i1 %26, label %27, label %32
27: ; preds = %14
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 1
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %30)
store i32 -1, i32* %3
br label %226
32: ; preds = %14
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%37 = getelementptr inbounds %struct.iovec, %struct.iovec* %36, i32 0, i32 0
store i8* %35, i8** %37
%38 = load i8**, i8*** %5
%39 = getelementptr inbounds i8*, i8** %38, i64 2
%40 = load i8*, i8** %39
%41 = call i8* @strlen(i8* %40)
%42 = ptrtoint i8* %41 to i32
%43 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%44 = getelementptr inbounds %struct.iovec, %struct.iovec* %43, i32 0, i32 1
store i32 %42, i32* %44
%45 = load i8**, i8*** %5
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%49 = getelementptr inbounds %struct.iovec, %struct.iovec* %48, i32 0, i32 0
store i8* %47, i8** %49
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 3
%52 = load i8*, i8** %51
%53 = call i8* @strlen(i8* %52)
%54 = ptrtoint i8* %53 to i32
%55 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%56 = getelementptr inbounds %struct.iovec, %struct.iovec* %55, i32 0, i32 1
store i32 %54, i32* %56
%57 = load i8**, i8*** %5
%58 = getelementptr inbounds i8*, i8** %57, i64 4
%59 = load i8*, i8** %58
%60 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%61 = getelementptr inbounds %struct.iovec, %struct.iovec* %60, i32 0, i32 0
store i8* %59, i8** %61
%62 = load i8**, i8*** %5
%63 = getelementptr inbounds i8*, i8** %62, i64 4
%64 = load i8*, i8** %63
%65 = call i8* @strlen(i8* %64)
%66 = ptrtoint i8* %65 to i32
%67 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%68 = getelementptr inbounds %struct.iovec, %struct.iovec* %67, i32 0, i32 1
store i32 %66, i32* %68
%69 = load i32, i32* %6
%70 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%71 = call i32 @writev(i32 %69, %struct.iovec* %70, i32 3)
store i32 %71, i32* %7
%72 = load i32, i32* %7
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %78
74: ; preds = %32
%75 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0))
%76 = load i32, i32* %6
%77 = call i32 @close(i32 %76)
store i32 -1, i32* %3
br label %226
78: ; preds = %32
%79 = call i32 (...) @sync()
%80 = load i32, i32* %6
%81 = load i32, i32* @SEEK_SET
%82 = call i32 @lseek(i32 %80, i32 0, i32 %81)
store i32 %82, i32* %7
%83 = load i32, i32* %7
%84 = icmp eq i32 %83, -1
br i1 %84, label %85, label %89
85: ; preds = %78
%86 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%87 = load i32, i32* %6
%88 = call i32 @close(i32 %87)
store i32 -1, i32* %3
br label %226
89: ; preds = %78
%90 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 0
%91 = getelementptr inbounds %struct.iovec, %struct.iovec* %90, i32 0, i32 1
store i32 1, i32* %91
%92 = call i64 @malloc(i32 1)
%93 = inttoptr i64 %92 to i8*
%94 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 0
%95 = getelementptr inbounds %struct.iovec, %struct.iovec* %94, i32 0, i32 0
store i8* %93, i8** %95
%96 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 1
%97 = getelementptr inbounds %struct.iovec, %struct.iovec* %96, i32 0, i32 1
store i32 2, i32* %97
%98 = call i64 @malloc(i32 2)
%99 = inttoptr i64 %98 to i8*
%100 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 1
%101 = getelementptr inbounds %struct.iovec, %struct.iovec* %100, i32 0, i32 0
store i8* %99, i8** %101
%102 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 2
%103 = getelementptr inbounds %struct.iovec, %struct.iovec* %102, i32 0, i32 1
store i32 3, i32* %103
%104 = call i64 @malloc(i32 3)
%105 = inttoptr i64 %104 to i8*
%106 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 2
%107 = getelementptr inbounds %struct.iovec, %struct.iovec* %106, i32 0, i32 0
store i8* %105, i8** %107
%108 = load i32, i32* %6
%109 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 0
%110 = call i32 @readv(i32 %108, %struct.iovec* %109, i32 3)
store i32 %110, i32* %7
%111 = load i32, i32* %7
%112 = icmp eq i32 %111, -1
br i1 %112, label %113, label %117
113: ; preds = %89
%114 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%115 = load i32, i32* %6
%116 = call i32 @close(i32 %115)
store i32 -1, i32* %3
br label %226
117: ; preds = %89
%118 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 0
%119 = getelementptr inbounds %struct.iovec, %struct.iovec* %118, i32 0, i32 0
%120 = load i8*, i8** %119
%121 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %120)
%122 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 1
%123 = getelementptr inbounds %struct.iovec, %struct.iovec* %122, i32 0, i32 0
%124 = load i8*, i8** %123
%125 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %124)
%126 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %9, i64 0, i64 2
%127 = getelementptr inbounds %struct.iovec, %struct.iovec* %126, i32 0, i32 0
%128 = load i8*, i8** %127
%129 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %128)
%130 = load i8**, i8*** %5
%131 = getelementptr inbounds i8*, i8** %130, i64 2
%132 = load i8*, i8** %131
%133 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %132)
%134 = load i8**, i8*** %5
%135 = getelementptr inbounds i8*, i8** %134, i64 3
%136 = load i8*, i8** %135
%137 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %136)
%138 = load i8**, i8*** %5
%139 = getelementptr inbounds i8*, i8** %138, i64 4
%140 = load i8*, i8** %139
%141 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %140)
br label %142
142: ; preds = %117
%143 = load i32, i32* %6
%144 = load i32, i32* @SEEK_SET
%145 = call i32 @lseek(i32 %143, i32 0, i32 %144)
store i32 %145, i32* %7
%146 = load i32, i32* %7
%147 = icmp eq i32 %146, -1
br i1 %147, label %148, label %152
148: ; preds = %142
%149 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.3, i64 0, i64 0))
%150 = load i32, i32* %6
%151 = call i32 @close(i32 %150)
store i32 -1, i32* %3
br label %226
152: ; preds = %142
%153 = load i8**, i8*** %5
%154 = getelementptr inbounds i8*, i8** %153, i64 2
%155 = load i8*, i8** %154
%156 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%157 = getelementptr inbounds %struct.iovec, %struct.iovec* %156, i32 0, i32 0
store i8* %155, i8** %157
%158 = load i8**, i8*** %5
%159 = getelementptr inbounds i8*, i8** %158, i64 4
%160 = load i8*, i8** %159
%161 = call i8* @strlen(i8* %160)
%162 = ptrtoint i8* %161 to i32
%163 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%164 = getelementptr inbounds %struct.iovec, %struct.iovec* %163, i32 0, i32 1
store i32 %162, i32* %164
%165 = load i8**, i8*** %5
%166 = getelementptr inbounds i8*, i8** %165, i64 3
%167 = load i8*, i8** %166
%168 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%169 = getelementptr inbounds %struct.iovec, %struct.iovec* %168, i32 0, i32 0
store i8* %167, i8** %169
%170 = load i8**, i8*** %5
%171 = getelementptr inbounds i8*, i8** %170, i64 2
%172 = load i8*, i8** %171
%173 = call i8* @strlen(i8* %172)
%174 = ptrtoint i8* %173 to i32
%175 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%176 = getelementptr inbounds %struct.iovec, %struct.iovec* %175, i32 0, i32 1
store i32 %174, i32* %176
%177 = load i8**, i8*** %5
%178 = getelementptr inbounds i8*, i8** %177, i64 4
%179 = load i8*, i8** %178
%180 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%181 = getelementptr inbounds %struct.iovec, %struct.iovec* %180, i32 0, i32 0
store i8* %179, i8** %181
%182 = load i8**, i8*** %5
%183 = getelementptr inbounds i8*, i8** %182, i64 3
%184 = load i8*, i8** %183
%185 = call i8* @strlen(i8* %184)
%186 = ptrtoint i8* %185 to i32
%187 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%188 = getelementptr inbounds %struct.iovec, %struct.iovec* %187, i32 0, i32 1
store i32 %186, i32* %188
%189 = load i32, i32* %6
%190 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%191 = call i32 @readv(i32 %189, %struct.iovec* %190, i32 3)
store i32 %191, i32* %7
%192 = load i32, i32* %7
%193 = icmp eq i32 %192, -1
br i1 %193, label %194, label %198
194: ; preds = %152
%195 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0))
%196 = load i32, i32* %6
%197 = call i32 @close(i32 %196)
store i32 -1, i32* %3
br label %226
198: ; preds = %152
%199 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 0
%200 = getelementptr inbounds %struct.iovec, %struct.iovec* %199, i32 0, i32 0
%201 = load i8*, i8** %200
%202 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %201)
%203 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 1
%204 = getelementptr inbounds %struct.iovec, %struct.iovec* %203, i32 0, i32 0
%205 = load i8*, i8** %204
%206 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %205)
%207 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %8, i64 0, i64 2
%208 = getelementptr inbounds %struct.iovec, %struct.iovec* %207, i32 0, i32 0
%209 = load i8*, i8** %208
%210 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %209)
%211 = load i8**, i8*** %5
%212 = getelementptr inbounds i8*, i8** %211, i64 2
%213 = load i8*, i8** %212
%214 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %213)
%215 = load i8**, i8*** %5
%216 = getelementptr inbounds i8*, i8** %215, i64 3
%217 = load i8*, i8** %216
%218 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %217)
%219 = load i8**, i8*** %5
%220 = getelementptr inbounds i8*, i8** %219, i64 4
%221 = load i8*, i8** %220
%222 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %221)
br label %223
223: ; preds = %198
%224 = load i32, i32* %6
%225 = call i32 @close(i32 %224)
store i32 0, i32* %3
br label %226
226: ; preds = %223, %194, %148, %113, %85, %74, %27, %12
%227 = load i32, i32* %3
ret i32 %227
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@S_IRWXU = global i32 0
@S_IWOTH = global i32 0
@.str.1 = [16 x i8] c"open %s failed\0A\00"
@SEEK_SET = global i32 0
@.str.5 = [7 x i8] c"v0 %s\0A\00"
@.str.6 = [7 x i8] c"v1 %s\0A\00"
@.str.7 = [7 x i8] c"v2 %s\0A\00"
@.str.8 = [10 x i8] c"argv2 %s\0A\00"
@.str.9 = [10 x i8] c"argv3 %s\0A\00"
@.str.10 = [10 x i8] c"argv4 %s\0A\00"
@str.12 = [13 x i8] c"readv failed\00"
@str.13 = [13 x i8] c"lseek failed\00"
@str.14 = [14 x i8] c"writev failed\00"
@str.15 = [50 x i8] c"Usage: ./xxx path/to/file string0 string1 string2\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x %struct.iovec]
%4 = alloca [3 x %struct.iovec]
%5 = bitcast [3 x %struct.iovec]* %3 to i8*
%6 = bitcast [3 x %struct.iovec]* %4 to i8*
%7 = icmp eq i32 %0, 5
br i1 %7, label %10, label %8
8: ; preds = %2
%9 = tail call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([50 x i8], [50 x i8]* @str.15, i64 0, i64 0))
br label %133
10: ; preds = %2
%11 = getelementptr inbounds i8*, i8** %1, i64 1
%12 = load i8*, i8** %11
%13 = load i32, i32* @O_RDWR
%14 = load i32, i32* @O_CREAT
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IRWXU
%17 = load i32, i32* @S_IWOTH
%18 = or i32 %17, %16
%19 = tail call i32 @open(i8* %12, i32 %15, i32 %18)
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %10
%22 = load i8*, i8** %11
%23 = tail call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.1, i64 0, i64 0), i8* %22)
br label %133
24: ; preds = %10
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0
%28 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0, i32 0
store i8* %26, i8** %28
%29 = tail call i8* @strlen(i8* %26)
%30 = ptrtoint i8* %29 to i64
%31 = trunc i64 %30 to i32
%32 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 0, i32 1
store i32 %31, i32* %32
%33 = getelementptr inbounds i8*, i8** %1, i64 3
%34 = load i8*, i8** %33
%35 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 1, i32 0
store i8* %34, i8** %35
%36 = tail call i8* @strlen(i8* %34)
%37 = ptrtoint i8* %36 to i64
%38 = trunc i64 %37 to i32
%39 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 1, i32 1
store i32 %38, i32* %39
%40 = getelementptr inbounds i8*, i8** %1, i64 4
%41 = load i8*, i8** %40
%42 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 2, i32 0
store i8* %41, i8** %42
%43 = tail call i8* @strlen(i8* %41)
%44 = ptrtoint i8* %43 to i64
%45 = trunc i64 %44 to i32
%46 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %3, i64 0, i64 2, i32 1
store i32 %45, i32* %46
%47 = call i32 @writev(i32 %19, %struct.iovec* %27, i32 3)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %52
49: ; preds = %24
%50 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([14 x i8], [14 x i8]* @str.14, i64 0, i64 0))
%51 = call i32 @close(i32 %19)
br label %133
52: ; preds = %24
%53 = call i32 (...) @sync()
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %19, i32 0, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %52
%58 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.13, i64 0, i64 0))
%59 = call i32 @close(i32 %19)
br label %133
60: ; preds = %52
%61 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0
%62 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0, i32 1
store i32 1, i32* %62
%63 = call i64 @malloc(i32 1)
%64 = inttoptr i64 %63 to i8*
%65 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 0, i32 0
store i8* %64, i8** %65
%66 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 1, i32 1
store i32 2, i32* %66
%67 = call i64 @malloc(i32 2)
%68 = inttoptr i64 %67 to i8*
%69 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 1, i32 0
store i8* %68, i8** %69
%70 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 2, i32 1
store i32 3, i32* %70
%71 = call i64 @malloc(i32 3)
%72 = inttoptr i64 %71 to i8*
%73 = getelementptr inbounds [3 x %struct.iovec], [3 x %struct.iovec]* %4, i64 0, i64 2, i32 0
store i8* %72, i8** %73
%74 = call i32 @readv(i32 %19, %struct.iovec* %61, i32 3)
%75 = icmp eq i32 %74, -1
br i1 %75, label %76, label %79
76: ; preds = %60
%77 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%78 = call i32 @close(i32 %19)
br label %133
79: ; preds = %60
%80 = load i8*, i8** %65
%81 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %80)
%82 = load i8*, i8** %69
%83 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %82)
%84 = load i8*, i8** %73
%85 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %84)
%86 = load i8*, i8** %25
%87 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %86)
%88 = load i8*, i8** %33
%89 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %88)
%90 = load i8*, i8** %40
%91 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %90)
%92 = load i32, i32* @SEEK_SET
%93 = call i32 @lseek(i32 %19, i32 0, i32 %92)
%94 = icmp eq i32 %93, -1
br i1 %94, label %95, label %98
95: ; preds = %79
%96 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.13, i64 0, i64 0))
%97 = call i32 @close(i32 %19)
br label %133
98: ; preds = %79
%99 = load i8*, i8** %25
store i8* %99, i8** %28
%100 = load i8*, i8** %40
%101 = call i8* @strlen(i8* %100)
%102 = ptrtoint i8* %101 to i64
%103 = trunc i64 %102 to i32
store i32 %103, i32* %32
%104 = load i8*, i8** %33
store i8* %104, i8** %35
%105 = load i8*, i8** %25
%106 = call i8* @strlen(i8* %105)
%107 = ptrtoint i8* %106 to i64
%108 = trunc i64 %107 to i32
store i32 %108, i32* %39
%109 = load i8*, i8** %40
store i8* %109, i8** %42
%110 = load i8*, i8** %33
%111 = call i8* @strlen(i8* %110)
%112 = ptrtoint i8* %111 to i64
%113 = trunc i64 %112 to i32
store i32 %113, i32* %46
%114 = call i32 @readv(i32 %19, %struct.iovec* %27, i32 3)
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %119
116: ; preds = %98
%117 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([13 x i8], [13 x i8]* @str.12, i64 0, i64 0))
%118 = call i32 @close(i32 %19)
br label %133
119: ; preds = %98
%120 = load i8*, i8** %28
%121 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0), i8* %120)
%122 = load i8*, i8** %35
%123 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.6, i64 0, i64 0), i8* %122)
%124 = load i8*, i8** %42
%125 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([7 x i8], [7 x i8]* @.str.7, i64 0, i64 0), i8* %124)
%126 = load i8*, i8** %25
%127 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.8, i64 0, i64 0), i8* %126)
%128 = load i8*, i8** %33
%129 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.9, i64 0, i64 0), i8* %128)
%130 = load i8*, i8** %40
%131 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([10 x i8], [10 x i8]* @.str.10, i64 0, i64 0), i8* %130)
%132 = call i32 @close(i32 %19)
br label %133
133: ; preds = %119, %116, %95, %76, %57, %49, %21, %8
%134 = phi i32 [ -1, %8 ], [ -1, %21 ], [ -1, %49 ], [ -1, %57 ], [ -1, %76 ], [ -1, %95 ], [ -1, %116 ], [ 0, %119 ]
ret i32 %134
}