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

/* Variables and functions */
int /*<<< orphan*/ memset(char *, int /*<<< orphan*/, int);
int /*<<< orphan*/ printf(char *, ...);
int readv(int /*<<< orphan*/, struct iovec *, int);
int main(int argc, char *argv[]) {
  struct iovec vec[2];
  char buf1[10];
  char buf2[10];
  int str_len;
  memset(buf1, 0, sizeof(buf1));
  memset(buf2, 0, sizeof(buf2));
  vec[0].iov_base = buf1;
  vec[0].iov_len = 3;
  vec[1].iov_base = buf2;
  vec[1].iov_len = 4;
  str_len = readv(0, vec, 2);
  printf("Read bytes: %d\n", str_len);
  printf("First msg: %s\n", buf1);
  printf("Second msg: %s\n", buf2);
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x3a(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    -0x44(%rbp),%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    -0x3a(%rbp),%rax
mov    %rax,-0x30(%rbp)
movl   $0x3,-0x28(%rbp)
lea    -0x44(%rbp),%rax
mov    %rax,-0x20(%rbp)
movl   $0x4,-0x18(%rbp)
lea    -0x30(%rbp),%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1050 <readv@plt>
mov    %eax,-0x48(%rbp)
mov    -0x48(%rbp),%esi
lea    0xe5f(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x3a(%rbp),%rsi
lea    0xe5d(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
lea    -0x44(%rbp),%rsi
lea    0xe5a(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x50,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
sub    $0x38,%rsp
lea    0x2e(%rsp),%r14
mov    %r14,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
lea    0x24(%rsp),%rbx
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <memset@plt>
mov    %r14,(%rsp)
movl   $0x3,0x8(%rsp)
mov    %rbx,0x10(%rsp)
movl   $0x4,0x18(%rsp)
mov    %rsp,%rsi
xor    %edi,%edi
mov    $0x2,%edx
call   1050 <readv@plt>
lea    0xe72(%rip),%rdi
mov    %eax,%esi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe72(%rip),%rdi
mov    %r14,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
lea    0xe70(%rip),%rdi
mov    %rbx,%rsi
xor    %eax,%eax
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x38,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i32 }
@.str = [16 x i8] c"Read bytes: %d\0A\00"
@.str.1 = [15 x i8] c"First msg: %s\0A\00"
@.str.2 = [16 x i8] c"Second msg: %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x %struct.iovec]
%7 = alloca [10 x i8]
%8 = alloca [10 x i8]
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%11 = call i32 @memset(i8* %10, i32 0, i32 10)
%12 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%13 = call i32 @memset(i8* %12, i32 0, i32 10)
%14 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%15 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0
%16 = getelementptr inbounds %struct.iovec, %struct.iovec* %15, i32 0, i32 0
store i8* %14, i8** %16
%17 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 1
store i32 3, i32* %18
%19 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%20 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 1
%21 = getelementptr inbounds %struct.iovec, %struct.iovec* %20, i32 0, i32 0
store i8* %19, i8** %21
%22 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 1
%23 = getelementptr inbounds %struct.iovec, %struct.iovec* %22, i32 0, i32 1
store i32 4, i32* %23
%24 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %6, i64 0, i64 0
%25 = call i32 @readv(i32 0, %struct.iovec* %24, i32 2)
store i32 %25, i32* %9
%26 = load i32, i32* %9
%27 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %26)
%28 = getelementptr inbounds [10 x i8], [10 x i8]* %7, i64 0, i64 0
%29 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %28)
%30 = getelementptr inbounds [10 x i8], [10 x i8]* %8, i64 0, i64 0
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %30)
ret i32 0
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i32 }
@.str = [16 x i8] c"Read bytes: %d\0A\00"
@.str.1 = [15 x i8] c"First msg: %s\0A\00"
@.str.2 = [16 x i8] c"Second msg: %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x %struct.iovec]
%4 = alloca [10 x i8]
%5 = alloca [10 x i8]
%6 = bitcast [2 x %struct.iovec]* %3 to i8*
%7 = getelementptr inbounds [10 x i8], [10 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [10 x i8], [10 x i8]* %5, i64 0, i64 0
%9 = call i32 @memset(i8* %7, i32 0, i32 10)
%10 = call i32 @memset(i8* %8, i32 0, i32 10)
%11 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0
%12 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0, i32 0
store i8* %7, i8** %12
%13 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0, i32 1
store i32 3, i32* %13
%14 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1, i32 0
store i8* %8, i8** %14
%15 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1, i32 1
store i32 4, i32* %15
%16 = call i32 @readv(i32 0, %struct.iovec* %11, i32 2)
%17 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %16)
%18 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %7)
%19 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i8* %8)
ret i32 0
}