#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 dummy;
};
typedef int /*<<< orphan*/ read_buf4;
typedef int /*<<< orphan*/ read_buf3;
typedef int /*<<< orphan*/ read_buf2;
typedef int /*<<< orphan*/ read_buf1;

/* Variables and functions */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ populate_iovec(struct iovec *, char *, int);
int /*<<< orphan*/ printf(char *, ...);
int readv(int, struct iovec *, int);
int main() {
  int fd, rbytes;
  char read_buf1[50];
  char read_buf2[50];
  char read_buf3[50];
  char read_buf4[50];
  ;
  struct iovec iovec[4];
  fd = open("Write.txt", O_RDONLY);
  populate_iovec(iovec, read_buf1, sizeof(read_buf1));
  populate_iovec(iovec + 1, read_buf2, sizeof(read_buf2));
  populate_iovec(iovec + 2, read_buf3, sizeof(read_buf3));
  populate_iovec(iovec + 3, read_buf4, sizeof(read_buf4));
  rbytes = readv(fd, iovec, 4);
  printf("\n Total number of bytes read from file : %d \n", rbytes);
  printf(" %s", read_buf1);
  printf(" %s", read_buf2);
  printf(" %s", read_buf3);
  printf(" %s\n", read_buf4);
  close(fd);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1070 <open@plt>
mov    %eax,-0x4(%rbp)
lea    -0x110(%rbp),%rdi
lea    -0x40(%rbp),%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    -0x110(%rbp),%rdi
add    $0x4,%rdi
lea    -0x80(%rbp),%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    -0x110(%rbp),%rdi
add    $0x8,%rdi
lea    -0xc0(%rbp),%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    -0x110(%rbp),%rdi
add    $0xc,%rdi
lea    -0x100(%rbp),%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x4,%edx
call   1060 <readv@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%esi
lea    0xe10(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x40(%rbp),%rsi
lea    0xe2c(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x80(%rbp),%rsi
lea    0xe1a(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0xc0(%rbp),%rsi
lea    0xe05(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
lea    -0x100(%rbp),%rsi
lea    0xdf4(%rip),%rdi
mov    $0x0,%al
call   1040 <printf@plt>
mov    -0x4(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x110,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x108,%rsp
mov    0x2e80(%rip),%rax
mov    (%rax),%esi
lea    0xe8f(%rip),%rdi
call   1070 <open@plt>
mov    %eax,%ebx
mov    %rsp,%rbp
lea    0xd0(%rsp),%r14
mov    %rbp,%rdi
mov    %r14,%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    0x4(%rsp),%rdi
lea    0x90(%rsp),%r15
mov    %r15,%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    0x8(%rsp),%rdi
lea    0x50(%rsp),%r12
mov    %r12,%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
lea    0xc(%rsp),%rdi
lea    0x10(%rsp),%r13
mov    %r13,%rsi
mov    $0x32,%edx
call   1030 <populate_iovec@plt>
mov    %ebx,%edi
mov    %rbp,%rsi
mov    $0x4,%edx
call   1060 <readv@plt>
lea    0xe19(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe37(%rip),%rbp
mov    %rbp,%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r15,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %rbp,%rdi
mov    %r12,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
lea    0xe0d(%rip),%rdi
mov    %r13,%rsi
xor    %eax,%eax
call   1040 <printf@plt>
mov    %ebx,%edi
call   1050 <close@plt>
xor    %eax,%eax
add    $0x108,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.iovec = type { i32 }
@.str = [10 x i8] c"Write.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [46 x i8] c"\0A Total number of bytes read from file : %d \0A\00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [5 x i8] c" %s\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = alloca [50 x i8]
%6 = alloca [50 x i8]
%7 = alloca [4 x %struct.iovec]
%8 = load i32, i32* @O_RDONLY
%9 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %8)
store i32 %9, i32* %1
%10 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %7, i64 0, i64 0
%11 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%12 = call i32 @populate_iovec(%struct.iovec* %10, i8* %11, i32 50)
%13 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %7, i64 0, i64 0
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i64 1
%15 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%16 = call i32 @populate_iovec(%struct.iovec* %14, i8* %15, i32 50)
%17 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %7, i64 0, i64 0
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i64 2
%19 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%20 = call i32 @populate_iovec(%struct.iovec* %18, i8* %19, i32 50)
%21 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %7, i64 0, i64 0
%22 = getelementptr inbounds %struct.iovec, %struct.iovec* %21, i64 3
%23 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%24 = call i32 @populate_iovec(%struct.iovec* %22, i8* %23, i32 50)
%25 = load i32, i32* %1
%26 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %7, i64 0, i64 0
%27 = call i32 @readv(i32 %25, %struct.iovec* %26, i32 4)
store i32 %27, i32* %2
%28 = load i32, i32* %2
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %30)
%32 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%33 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %32)
%34 = getelementptr inbounds [50 x i8], [50 x i8]* %5, i64 0, i64 0
%35 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %34)
%36 = getelementptr inbounds [50 x i8], [50 x i8]* %6, i64 0, i64 0
%37 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %36)
%38 = load i32, i32* %1
%39 = call i32 @close(i32 %38)
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i32 }
@.str = [10 x i8] c"Write.txt\00"
@O_RDONLY = global i32 0
@.str.1 = [46 x i8] c"\0A Total number of bytes read from file : %d \0A\00"
@.str.2 = [4 x i8] c" %s\00"
@.str.3 = [5 x i8] c" %s\0A\00"
define i32 @main() {
%1 = alloca [50 x i8]
%2 = alloca [50 x i8]
%3 = alloca [50 x i8]
%4 = alloca [50 x i8]
%5 = alloca [4 x %struct.iovec]
%6 = getelementptr inbounds [50 x i8], [50 x i8]* %1, i64 0, i64 0
%7 = getelementptr inbounds [50 x i8], [50 x i8]* %2, i64 0, i64 0
%8 = getelementptr inbounds [50 x i8], [50 x i8]* %3, i64 0, i64 0
%9 = getelementptr inbounds [50 x i8], [50 x i8]* %4, i64 0, i64 0
%10 = bitcast [4 x %struct.iovec]* %5 to i8*
%11 = load i32, i32* @O_RDONLY
%12 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %5, i64 0, i64 0
%14 = call i32 @populate_iovec(%struct.iovec* %13, i8* %6, i32 50)
%15 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %5, i64 0, i64 1
%16 = call i32 @populate_iovec(%struct.iovec* %15, i8* %7, i32 50)
%17 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %5, i64 0, i64 2
%18 = call i32 @populate_iovec(%struct.iovec* %17, i8* %8, i32 50)
%19 = getelementptr inbounds [4 x %struct.iovec], [4 x %struct.iovec]* %5, i64 0, i64 3
%20 = call i32 @populate_iovec(%struct.iovec* %19, i8* %9, i32 50)
%21 = call i32 @readv(i32 %12, %struct.iovec* %13, i32 4)
%22 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([46 x i8], [46 x i8]* @.str.1, i64 0, i64 0), i32 %21)
%23 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %6)
%24 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %7)
%25 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i8* %8)
%26 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0), i8* %9)
%27 = call i32 @close(i32 %12)
ret i32 0
}