#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 char *ssize_t;
typedef int /*<<< orphan*/ buf2;
typedef int /*<<< orphan*/ buf1;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char *);
char *readv(int /*<<< orphan*/, struct iovec *, int);
int main() {
  char buf1[8] = {0};
  char buf2[8] = {0};
  struct iovec iov[2];
  ssize_t nread;
  iov[0].iov_base = buf1;
  iov[0].iov_len = sizeof(buf1) - 1;
  iov[1].iov_base = buf2;
  iov[1].iov_len = sizeof(buf2) - 1;
  nread = readv(STDIN_FILENO, iov, 2);
  printf("%ld bytes read.\n", nread);
  printf("buf1: %s\n", buf1);
  printf("buf2: %s\n", buf2);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0x14(%rbp),%rdi
xor    %esi,%esi
mov    $0x8,%edx
call   1040 <memset@plt>
lea    -0xc(%rbp),%rax
mov    %rax,-0x40(%rbp)
movl   $0x7,-0x38(%rbp)
lea    -0x14(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x7,-0x28(%rbp)
mov    0x2e44(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2,%edx
call   1050 <readv@plt>
mov    %rax,-0x48(%rbp)
mov    -0x48(%rbp),%rsi
lea    0xe4d(%rip),%rdi
call   1030 <printf@plt>
lea    -0xc(%rbp),%rsi
lea    0xe4e(%rip),%rdi
call   1030 <printf@plt>
lea    -0x14(%rbp),%rsi
lea    0xe48(%rip),%rdi
call   1030 <printf@plt>
mov    0x2e01(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
movq   $0x0,0x8(%rsp)
movq   $0x0,(%rsp)
lea    0x8(%rsp),%rbx
mov    %rbx,0x10(%rsp)
movl   $0x7,0x18(%rsp)
mov    %rsp,%r14
mov    %r14,0x20(%rsp)
movl   $0x7,0x28(%rsp)
mov    0x2e67(%rip),%rax
mov    (%rax),%edi
lea    0x10(%rsp),%rsi
mov    $0x2,%edx
call   1040 <readv@plt>
lea    0xe77(%rip),%rdi
mov    %rax,%rsi
call   1030 <printf@plt>
lea    0xe79(%rip),%rdi
mov    %rbx,%rsi
call   1030 <printf@plt>
lea    0xe74(%rip),%rdi
mov    %r14,%rsi
call   1030 <printf@plt>
mov    0x2e2a(%rip),%rax
mov    (%rax),%edi
call   1050 <exit@plt>

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@STDIN_FILENO = global i32 0
@.str = [17 x i8] c"%ld bytes read.\0A\00"
@.str.1 = [10 x i8] c"buf1: %s\0A\00"
@.str.2 = [10 x i8] c"buf2: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca [8 x i8]
%3 = alloca [8 x i8]
%4 = alloca [2 x %struct.iovec]
%5 = alloca i8*
store i32 0, i32* %1
%6 = bitcast [8 x i8]* %2 to i8*
%7 = bitcast [8 x i8]* %3 to i8*
%8 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%9 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 0
%10 = getelementptr inbounds %struct.iovec, %struct.iovec* %9, i32 0, i32 0
store i8* %8, i8** %10
%11 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 0
%12 = getelementptr inbounds %struct.iovec, %struct.iovec* %11, i32 0, i32 1
store i32 7, i32* %12
%13 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%14 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 1
%15 = getelementptr inbounds %struct.iovec, %struct.iovec* %14, i32 0, i32 0
store i8* %13, i8** %15
%16 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 1
%17 = getelementptr inbounds %struct.iovec, %struct.iovec* %16, i32 0, i32 1
store i32 7, i32* %17
%18 = load i32, i32* @STDIN_FILENO
%19 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 0
%20 = call i8* @readv(i32 %18, %struct.iovec* %19, i32 2)
store i8* %20, i8** %5
%21 = load i8*, i8** %5
%22 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %21)
%23 = getelementptr inbounds [8 x i8], [8 x i8]* %2, i64 0, i64 0
%24 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %23)
%25 = getelementptr inbounds [8 x i8], [8 x i8]* %3, i64 0, i64 0
%26 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %25)
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@STDIN_FILENO = global i32 0
@.str = [17 x i8] c"%ld bytes read.\0A\00"
@.str.1 = [10 x i8] c"buf1: %s\0A\00"
@.str.2 = [10 x i8] c"buf2: %s\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i64
%2 = alloca i64
%3 = alloca [2 x %struct.iovec]
%4 = bitcast i64* %1 to i8*
store i64 0, i64* %1
%5 = bitcast i64* %2 to i8*
store i64 0, i64* %2
%6 = bitcast [2 x %struct.iovec]* %3 to i8*
%7 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0
%8 = bitcast [2 x %struct.iovec]* %3 to i64**
store i64* %1, i64** %8
%9 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0, i32 1
store i32 7, i32* %9
%10 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1
%11 = bitcast %struct.iovec* %10 to i64**
store i64* %2, i64** %11
%12 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1, i32 1
store i32 7, i32* %12
%13 = load i32, i32* @STDIN_FILENO
%14 = call i8* @readv(i32 %13, %struct.iovec* %7, i32 2)
%15 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0), i8* %14)
%16 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i8* %4)
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.2, i64 0, i64 0), i8* %5)
%18 = load i32, i32* @EXIT_SUCCESS
%19 = call i32 @exit(i32 %18)
unreachable
}