#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 {
  int *iov_base;
  int iov_len;
};
typedef int ssize_t;
typedef int /*<<< orphan*/ data;

/* Variables and functions */
int O_CREAT;
int O_RDWR;
int O_TRUNC;
int /*<<< orphan*/ SEEK_SET;
int S_IRUSR;
int S_IWUSR;
int close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int lseek(int, int /*<<< orphan*/, int /*<<< orphan*/);
int open(char *, int, int);
int readv(int, struct iovec *, int);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int writev(int, struct iovec *, int);
int main(int argc, char **argv) {
  if (argc != 2) {
    fprintf(stderr, "Usage: %s file\n", argv[0]);
    return 1;
  }
  int data[] = {0x00010203, 0x04050607, 0x08090a0b, 0x0c0d0e0f};
  int n = sizeof(data) / sizeof(int);
  struct iovec chunks[n];
  for (int i = 0; i < n; i++) {
    chunks[i].iov_base = &data[i];
    chunks[i].iov_len = sizeof(int);
  }
  ssize_t total = 0;
  for (int i = 0; i < n; i++) {
    total += chunks[i].iov_len;
  }
  int fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR);
  if (fd == -1) {
    fprintf(stderr, "open: %s\n", strerror(errno));
    return 1;
  }
  ssize_t write_total = writev(fd, chunks, n);
  if (write_total == -1) {
    fprintf(stderr, "writev: %s\n", strerror(errno));
    return 1;
  }
  if (write_total != total) {
    fprintf(stderr, "writev: Not enough data written\n");
    return 1;
  }
  if (lseek(fd, 0, SEEK_SET) == -1) {
    fprintf(stderr, "lseek: %s\n", strerror(errno));
    return 1;
  }
  ssize_t read_total = readv(fd, chunks, n);
  if (read_total == -1) {
    fprintf(stderr, "readv: %s\n", strerror(errno));
    return 1;
  }
  if (read_total != total) {
    fprintf(stderr, "readv: Not enough data read\n");
    return 1;
  }
  if (close(fd) == -1) {
    fprintf(stderr, "close: %s\n", strerror(errno));
    return 1;
  }
  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   $0x2,-0x8(%rbp)
je     11bd <main+0x4d>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe56(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
jmp    14fa <main+0x38a>
movaps 0xecc(%rip),%xmm0
movaps %xmm0,-0x20(%rbp)
movl   $0x4,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rdx
shl    $0x4,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x60(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x38(%rbp)
movl   $0x0,-0x3c(%rbp)
mov    -0x3c(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1248 <main+0xd8>
mov    -0x60(%rbp),%rax
movslq -0x3c(%rbp),%rcx
lea    -0x20(%rbp),%rdx
shl    $0x2,%rcx
add    %rcx,%rdx
movslq -0x3c(%rbp),%rsi
shl    $0x4,%rsi
mov    %rax,%rcx
add    %rsi,%rcx
mov    %rdx,(%rcx)
movslq -0x3c(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
movl   $0x4,0x8(%rax)
mov    -0x3c(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x3c(%rbp)
jmp    11f8 <main+0x88>
movl   $0x0,-0x40(%rbp)
movl   $0x0,-0x44(%rbp)
mov    -0x44(%rbp),%eax
cmp    -0x24(%rbp),%eax
jge    1288 <main+0x118>
mov    -0x60(%rbp),%rax
movslq -0x44(%rbp),%rcx
shl    $0x4,%rcx
add    %rcx,%rax
mov    0x8(%rax),%eax
add    -0x40(%rbp),%eax
mov    %eax,-0x40(%rbp)
mov    -0x44(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x44(%rbp)
jmp    1256 <main+0xe6>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2d41(%rip),%rax
mov    (%rax),%esi
mov    0x2d58(%rip),%rax
or     (%rax),%esi
mov    0x2d47(%rip),%rax
or     (%rax),%esi
mov    0x2cf6(%rip),%rax
mov    (%rax),%edx
mov    0x2d15(%rip),%rax
or     (%rax),%edx
call   1080 <open@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1310 <main+0x1a0>
mov    0x2cea(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    0x2cd6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    %rax,%rdx
lea    0xd1a(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x60(%rbp),%rsi
mov    -0x48(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1030 <writev@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0xffffffff,-0x50(%rbp)
jne    136d <main+0x1fd>
mov    0x2c8d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2c79(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    %rax,%rdx
lea    0xcc7(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x50(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     13a3 <main+0x233>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
lea    0xc9d(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x48(%rbp),%edi
mov    0x2c03(%rip),%rax
mov    (%rax),%edx
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
jne    1400 <main+0x290>
mov    0x2bfa(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x6c(%rbp)
mov    0x2be6(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x6c(%rbp),%edi
mov    %rax,%rdx
lea    0xc61(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x60(%rbp),%rsi
mov    -0x48(%rbp),%edi
mov    -0x24(%rbp),%edx
call   1070 <readv@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0xffffffff,-0x54(%rbp)
jne    145d <main+0x2ed>
mov    0x2b9d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x70(%rbp)
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x70(%rbp),%edi
mov    %rax,%rdx
lea    0xc0f(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x54(%rbp),%eax
cmp    -0x40(%rbp),%eax
je     1493 <main+0x323>
mov    0x2b50(%rip),%rax
mov    (%rax),%edi
lea    0xbe4(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
mov    -0x48(%rbp),%edi
call   1050 <close@plt>
cmp    $0xffffffff,%eax
jne    14e5 <main+0x375>
mov    0x2b15(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x74(%rbp)
mov    0x2b01(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x74(%rbp),%edi
mov    %rax,%rdx
lea    0xbaf(%rip),%rsi
mov    $0x0,%al
call   1060 <fprintf@plt>
movl   $0x1,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
jmp    14f3 <main+0x383>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x4c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %rbx
sub    $0x18,%rsp
cmp    $0x2,%edi
jne    1254 <main+0xe4>
mov    %rsp,%r15
movaps 0xf00(%rip),%xmm0
movaps %xmm0,-0x30(%rbp)
mov    %rsp,%rax
lea    -0x40(%rax),%r14
mov    %r14,%rsp
lea    -0x30(%rbp),%rcx
mov    %rcx,-0x40(%rax)
movl   $0x4,-0x38(%rax)
lea    -0x2c(%rbp),%rcx
mov    %rcx,-0x30(%rax)
movl   $0x4,-0x28(%rax)
lea    -0x28(%rbp),%rcx
mov    %rcx,-0x20(%rax)
movl   $0x4,-0x18(%rax)
lea    -0x24(%rbp),%rcx
mov    %rcx,-0x10(%rax)
movl   $0x4,-0x8(%rax)
mov    0x8(%rsi),%rdi
mov    0x2df3(%rip),%rax
mov    0x2e0c(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2df9(%rip),%rax
or     (%rax),%esi
mov    0x2da8(%rip),%rax
mov    0x2dc9(%rip),%rcx
mov    (%rcx),%edx
or     (%rax),%edx
call   1080 <open@plt>
cmp    $0xffffffff,%eax
je     1278 <main+0x108>
mov    %eax,%ebx
mov    %eax,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1030 <writev@plt>
cmp    $0x10,%eax
je     12a4 <main+0x134>
cmp    $0xffffffff,%eax
jne    12f8 <main+0x188>
mov    0x2d85(%rip),%rax
mov    (%rax),%ebx
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdc8(%rip),%rsi
jmp    1296 <main+0x126>
mov    0x2d65(%rip),%rax
mov    (%rax),%edi
mov    (%rsi),%rdx
lea    0xd99(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
jmp    1317 <main+0x1a7>
mov    0x2d41(%rip),%rax
mov    (%rax),%ebx
mov    0x2d30(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd7a(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
xor    %eax,%eax
call   1060 <fprintf@plt>
jmp    130f <main+0x19f>
mov    0x2d05(%rip),%rax
mov    (%rax),%edx
mov    %ebx,%edi
xor    %esi,%esi
call   1040 <lseek@plt>
cmp    $0xffffffff,%eax
je     1322 <main+0x1b2>
mov    %ebx,%edi
mov    %r14,%rsi
mov    $0x4,%edx
call   1070 <readv@plt>
cmp    $0x10,%eax
je     1345 <main+0x1d5>
cmp    $0xffffffff,%eax
jne    1378 <main+0x208>
mov    0x2ce1(%rip),%rax
mov    (%rax),%ebx
mov    0x2cd0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd5c(%rip),%rsi
jmp    1296 <main+0x126>
mov    0x2cc1(%rip),%rax
mov    (%rax),%edi
lea    0xd1e(%rip),%rsi
xor    %eax,%eax
call   1060 <fprintf@plt>
mov    $0x1,%eax
mov    %r15,%rsp
lea    -0x18(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2c97(%rip),%rax
mov    (%rax),%ebx
mov    0x2c86(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd07(%rip),%rsi
jmp    1296 <main+0x126>
mov    %ebx,%edi
call   1050 <close@plt>
mov    %eax,%ecx
xor    %eax,%eax
cmp    $0xffffffff,%ecx
jne    1314 <main+0x1a4>
mov    0x2c64(%rip),%rax
mov    (%rax),%ebx
mov    0x2c53(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xd07(%rip),%rsi
jmp    1296 <main+0x126>
mov    0x2c41(%rip),%rax
mov    (%rax),%edi
lea    0xcd5(%rip),%rsi
jmp    1308 <main+0x198>

LLVM IR (-O0):
%struct.iovec = type { i32*, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s file\0A\00"
@__const.main.data = [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159]
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [10 x i8] c"open: %s\0A\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"writev: %s\0A\00"
@.str.3 = [33 x i8] c"writev: Not enough data written\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [11 x i8] c"lseek: %s\0A\00"
@.str.5 = [11 x i8] c"readv: %s\0A\00"
@.str.6 = [29 x i8] c"readv: Not enough data read\0A\00"
@.str.7 = [11 x i8] c"close: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [4 x i32]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i64
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
%14 = alloca i32
%15 = alloca i32
%16 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%17 = load i32, i32* %4
%18 = icmp ne i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %2
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %23)
store i32 1, i32* %3
br label %144
25: ; preds = %2
%26 = bitcast [4 x i32]* %6 to i8*
store i32 4, i32* %7
%27 = load i32, i32* %7
%28 = zext i32 %27 to i64
%29 = call i8* @llvm.stacksave()
store i8* %29, i8** %8
%30 = alloca %struct.iovec, i64 %28
store i64 %28, i64* %9
store i32 0, i32* %10
br label %31
31: ; preds = %47, %25
%32 = load i32, i32* %10
%33 = load i32, i32* %7
%34 = icmp slt i32 %32, %33
br i1 %34, label %35, label %50
35: ; preds = %31
%36 = load i32, i32* %10
%37 = sext i32 %36 to i64
%38 = getelementptr inbounds [4 x i32], [4 x i32]* %6, i64 0, i64 %37
%39 = load i32, i32* %10
%40 = sext i32 %39 to i64
%41 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i64 %40
%42 = getelementptr inbounds %struct.iovec, %struct.iovec* %41, i32 0, i32 0
store i32* %38, i32** %42
%43 = load i32, i32* %10
%44 = sext i32 %43 to i64
%45 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i64 %44
%46 = getelementptr inbounds %struct.iovec, %struct.iovec* %45, i32 0, i32 1
store i32 4, i32* %46
br label %47
47: ; preds = %35
%48 = load i32, i32* %10
%49 = add nsw i32 %48, 1
store i32 %49, i32* %10
br label %31
50: ; preds = %31
store i32 0, i32* %11
store i32 0, i32* %12
br label %51
51: ; preds = %63, %50
%52 = load i32, i32* %12
%53 = load i32, i32* %7
%54 = icmp slt i32 %52, %53
br i1 %54, label %55, label %66
55: ; preds = %51
%56 = load i32, i32* %12
%57 = sext i32 %56 to i64
%58 = getelementptr inbounds %struct.iovec, %struct.iovec* %30, i64 %57
%59 = getelementptr inbounds %struct.iovec, %struct.iovec* %58, i32 0, i32 1
%60 = load i32, i32* %59
%61 = load i32, i32* %11
%62 = add nsw i32 %61, %60
store i32 %62, i32* %11
br label %63
63: ; preds = %55
%64 = load i32, i32* %12
%65 = add nsw i32 %64, 1
store i32 %65, i32* %12
br label %51
66: ; preds = %51
%67 = load i8**, i8*** %5
%68 = getelementptr inbounds i8*, i8** %67, i64 1
%69 = load i8*, i8** %68
%70 = load i32, i32* @O_RDWR
%71 = load i32, i32* @O_CREAT
%72 = or i32 %70, %71
%73 = load i32, i32* @O_TRUNC
%74 = or i32 %72, %73
%75 = load i32, i32* @S_IRUSR
%76 = load i32, i32* @S_IWUSR
%77 = or i32 %75, %76
%78 = call i32 @open(i8* %69, i32 %74, i32 %77)
store i32 %78, i32* %13
%79 = load i32, i32* %13
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %86
81: ; preds = %66
%82 = load i32, i32* @stderr
%83 = load i32, i32* @errno
%84 = call i8* @strerror(i32 %83)
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %82, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %84)
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
86: ; preds = %66
%87 = load i32, i32* %13
%88 = load i32, i32* %7
%89 = call i32 @writev(i32 %87, %struct.iovec* %30, i32 %88)
store i32 %89, i32* %15
%90 = load i32, i32* %15
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %97
92: ; preds = %86
%93 = load i32, i32* @stderr
%94 = load i32, i32* @errno
%95 = call i8* @strerror(i32 %94)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %95)
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
97: ; preds = %86
%98 = load i32, i32* %15
%99 = load i32, i32* %11
%100 = icmp ne i32 %98, %99
br i1 %100, label %101, label %104
101: ; preds = %97
%102 = load i32, i32* @stderr
%103 = call i32 (i32, i8*, ...) @fprintf(i32 %102, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
104: ; preds = %97
%105 = load i32, i32* %13
%106 = load i32, i32* @SEEK_SET
%107 = call i32 @lseek(i32 %105, i32 0, i32 %106)
%108 = icmp eq i32 %107, -1
br i1 %108, label %109, label %114
109: ; preds = %104
%110 = load i32, i32* @stderr
%111 = load i32, i32* @errno
%112 = call i8* @strerror(i32 %111)
%113 = call i32 (i32, i8*, ...) @fprintf(i32 %110, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %112)
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
114: ; preds = %104
%115 = load i32, i32* %13
%116 = load i32, i32* %7
%117 = call i32 @readv(i32 %115, %struct.iovec* %30, i32 %116)
store i32 %117, i32* %16
%118 = load i32, i32* %16
%119 = icmp eq i32 %118, -1
br i1 %119, label %120, label %125
120: ; preds = %114
%121 = load i32, i32* @stderr
%122 = load i32, i32* @errno
%123 = call i8* @strerror(i32 %122)
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %121, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %123)
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
125: ; preds = %114
%126 = load i32, i32* %16
%127 = load i32, i32* %11
%128 = icmp ne i32 %126, %127
br i1 %128, label %129, label %132
129: ; preds = %125
%130 = load i32, i32* @stderr
%131 = call i32 (i32, i8*, ...) @fprintf(i32 %130, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
132: ; preds = %125
%133 = load i32, i32* %13
%134 = call i32 @close(i32 %133)
%135 = icmp eq i32 %134, -1
br i1 %135, label %136, label %141
136: ; preds = %132
%137 = load i32, i32* @stderr
%138 = load i32, i32* @errno
%139 = call i8* @strerror(i32 %138)
%140 = call i32 (i32, i8*, ...) @fprintf(i32 %137, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %139)
store i32 1, i32* %3
store i32 1, i32* %14
br label %142
141: ; preds = %132
store i32 0, i32* %3
store i32 1, i32* %14
br label %142
142: ; preds = %141, %136, %129, %120, %109, %101, %92, %81
%143 = load i8*, i8** %8
br label %144
144: ; preds = %142, %19
%145 = load i32, i32* %3
ret i32 %145
}

LLVM IR (-O2):
%struct.iovec = type { i32*, i32 }
@stderr = global i32 0
@.str = [16 x i8] c"Usage: %s file\0A\00"
@__const.main.data = [4 x i32] [i32 66051, i32 67438087, i32 134810123, i32 202182159]
@O_RDWR = global i32 0
@O_CREAT = global i32 0
@O_TRUNC = global i32 0
@S_IRUSR = global i32 0
@S_IWUSR = global i32 0
@.str.1 = [10 x i8] c"open: %s\0A\00"
@errno = global i32 0
@.str.2 = [12 x i8] c"writev: %s\0A\00"
@.str.3 = [33 x i8] c"writev: Not enough data written\0A\00"
@SEEK_SET = global i32 0
@.str.4 = [11 x i8] c"lseek: %s\0A\00"
@.str.5 = [11 x i8] c"readv: %s\0A\00"
@.str.6 = [29 x i8] c"readv: Not enough data read\0A\00"
@.str.7 = [11 x i8] c"close: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [4 x i32]
%4 = icmp eq i32 %0, 2
br i1 %4, label %9, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = load i8*, i8** %1
%8 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i8* %7)
br label %82
9: ; preds = %2
%10 = bitcast [4 x i32]* %3 to i8*
%11 = tail call i8* @llvm.stacksave()
%12 = alloca [4 x %struct.iovec]
%13 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 0
%14 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 0, i32 0
store i32* %13, i32** %14
%15 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 0, i32 1
store i32 4, i32* %15
%16 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 1
%17 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 1, i32 0
store i32* %16, i32** %17
%18 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 1, i32 1
store i32 4, i32* %18
%19 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 2
%20 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 2, i32 0
store i32* %19, i32** %20
%21 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 2, i32 1
store i32 4, i32* %21
%22 = getelementptr inbounds [4 x i32], [4 x i32]* %3, i64 0, i64 3
%23 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 3, i32 0
store i32* %22, i32** %23
%24 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 3, i32 1
store i32 4, i32* %24
%25 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %12, i64 0, i64 0
%26 = getelementptr inbounds i8*, i8** %1, i64 1
%27 = load i8*, i8** %26
%28 = load i32, i32* @O_RDWR
%29 = load i32, i32* @O_CREAT
%30 = or i32 %29, %28
%31 = load i32, i32* @O_TRUNC
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IRUSR
%34 = load i32, i32* @S_IWUSR
%35 = or i32 %34, %33
%36 = call i32 @open(i8* %27, i32 %32, i32 %35)
%37 = icmp eq i32 %36, -1
br i1 %37, label %38, label %43
38: ; preds = %9
%39 = load i32, i32* @stderr
%40 = load i32, i32* @errno
%41 = call i8* @strerror(i32 %40)
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %39, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %41)
br label %80
43: ; preds = %9
%44 = call i32 @writev(i32 %36, %struct.iovec* %25, i32 4)
switch i32 %44, label %50 [
i32 -1, label %45
i32 16, label %53
]
45: ; preds = %43
%46 = load i32, i32* @stderr
%47 = load i32, i32* @errno
%48 = call i8* @strerror(i32 %47)
%49 = call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %48)
br label %80
50: ; preds = %43
%51 = load i32, i32* @stderr
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %51, i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.3, i64 0, i64 0))
br label %80
53: ; preds = %43
%54 = load i32, i32* @SEEK_SET
%55 = call i32 @lseek(i32 %36, i32 0, i32 %54)
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i32, i32* @errno
%60 = call i8* @strerror(i32 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.4, i64 0, i64 0), i8* %60)
br label %80
62: ; preds = %53
%63 = call i32 @readv(i32 %36, %struct.iovec* %25, i32 4)
switch i32 %63, label %69 [
i32 -1, label %64
i32 16, label %72
]
64: ; preds = %62
%65 = load i32, i32* @stderr
%66 = load i32, i32* @errno
%67 = call i8* @strerror(i32 %66)
%68 = call i32 (i32, i8*, ...) @fprintf(i32 %65, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.5, i64 0, i64 0), i8* %67)
br label %80
69: ; preds = %62
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.6, i64 0, i64 0))
br label %80
72: ; preds = %62
%73 = call i32 @close(i32 %36)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %80
75: ; preds = %72
%76 = load i32, i32* @stderr
%77 = load i32, i32* @errno
%78 = call i8* @strerror(i32 %77)
%79 = call i32 (i32, i8*, ...) @fprintf(i32 %76, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %78)
br label %80
80: ; preds = %45, %50, %57, %72, %75, %69, %64, %38
%81 = phi i32 [ 1, %38 ], [ 1, %45 ], [ 1, %50 ], [ 1, %57 ], [ 1, %64 ], [ 1, %69 ], [ 1, %75 ], [ 0, %72 ]
br label %82
82: ; preds = %80, %5
%83 = phi i32 [ 1, %5 ], [ %81, %80 ]
ret i32 %83
}