#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;
  void *iov_len;
};
typedef int ssize_t;

/* Variables and functions */
int /*<<< orphan*/ STDOUT_FILENO;
void *strlen(char *);
int writev(int /*<<< orphan*/, struct iovec *, int);
int writev2() {
  char *str0 = "hello ";
  char *str1 = "world\n";
  struct iovec iov[2];
  ssize_t nwritten;
  iov[0].iov_base = str0;
  iov[0].iov_len = strlen(str0);
  iov[1].iov_base = str1;
  iov[1].iov_len = strlen(str1);
  nwritten = writev(STDOUT_FILENO, iov, 2);
  return nwritten;
}


x86 assembly (clang, -O0):
<writev2>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
lea    0xed1(%rip),%rax
mov    %rax,-0x8(%rbp)
lea    0xecd(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x8(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x8(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x20(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x18(%rbp)
mov    0x2e81(%rip),%rax
mov    (%rax),%edi
lea    -0x30(%rbp),%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    %eax,-0x34(%rbp)
mov    -0x34(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<writev2>:
sub    $0x28,%rsp
lea    0xed5(%rip),%rdi
mov    %rdi,(%rsp)
call   1040 <strlen@plt>
mov    %rax,0x8(%rsp)
lea    0xec7(%rip),%rdi
mov    %rdi,0x10(%rsp)
call   1040 <strlen@plt>
mov    %rax,0x18(%rsp)
mov    0x2e9a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
add    $0x28,%rsp
ret

LLVM IR (-O0):
%struct.iovec = type { i8*, i8* }
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @writev2() {
%1 = alloca i8*
%2 = alloca i8*
%3 = alloca [2 x %struct.iovec]
%4 = alloca i32
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %1
%6 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0
%7 = getelementptr inbounds %struct.iovec, %struct.iovec* %6, i32 0, i32 0
store i8* %5, i8** %7
%8 = load i8*, i8** %1
%9 = call i8* @strlen(i8* %8)
%10 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0
%11 = getelementptr inbounds %struct.iovec, %struct.iovec* %10, i32 0, i32 1
store i8* %9, i8** %11
%12 = load i8*, i8** %2
%13 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1
%14 = getelementptr inbounds %struct.iovec, %struct.iovec* %13, i32 0, i32 0
store i8* %12, i8** %14
%15 = load i8*, i8** %2
%16 = call i8* @strlen(i8* %15)
%17 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 1
%18 = getelementptr inbounds %struct.iovec, %struct.iovec* %17, i32 0, i32 1
store i8* %16, i8** %18
%19 = load i32, i32* @STDOUT_FILENO
%20 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %3, i64 0, i64 0
%21 = call i32 @writev(i32 %19, %struct.iovec* %20, i32 2)
store i32 %21, i32* %4
%22 = load i32, i32* %4
ret i32 %22
}

LLVM IR (-O2):
%struct.iovec = type { i8*, i8* }
@.str = [7 x i8] c"hello \00"
@.str.1 = [7 x i8] c"world\0A\00"
@STDOUT_FILENO = global i32 0
define i32 @writev2() {
%1 = alloca [2 x %struct.iovec]
%2 = bitcast [2 x %struct.iovec]* %1 to i8*
%3 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %1, i64 0, i64 0
%4 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %1, i64 0, i64 0, i32 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %4
%5 = tail call i8* @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%6 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %1, i64 0, i64 0, i32 1
store i8* %5, i8** %6
%7 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %1, i64 0, i64 1, i32 0
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %7
%8 = tail call i8* @strlen(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%9 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %1, i64 0, i64 1, i32 1
store i8* %8, i8** %9
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @writev(i32 %10, %struct.iovec* %3, i32 2)
ret i32 %11
}