#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 /*<<< orphan*/ ssize_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, int /*<<< orphan*/);
void *strlen(char *);
int /*<<< orphan*/ writev(int /*<<< orphan*/, struct iovec *, int);
int main() {
  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);
  printf("%ld bytes written.\n", nwritten);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
movl   $0x0,-0x4(%rbp)
lea    0xeaa(%rip),%rax
mov    %rax,-0x10(%rbp)
lea    0xea6(%rip),%rax
mov    %rax,-0x18(%rbp)
mov    -0x10(%rbp),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x38(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x30(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    %rax,-0x28(%rbp)
mov    0x2e5a(%rip),%rax
mov    (%rax),%edi
lea    -0x40(%rbp),%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
mov    %eax,-0x44(%rbp)
mov    -0x44(%rbp),%esi
lea    0xe5b(%rip),%rdi
call   1050 <printf@plt>
mov    0x2e19(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
sub    $0x28,%rsp
lea    0xeb5(%rip),%rdi
mov    %rdi,(%rsp)
call   1040 <strlen@plt>
mov    %rax,0x8(%rsp)
lea    0xea7(%rip),%rdi
mov    %rdi,0x10(%rsp)
call   1040 <strlen@plt>
mov    %rax,0x18(%rsp)
mov    0x2e7a(%rip),%rax
mov    (%rax),%edi
mov    %rsp,%rsi
mov    $0x2,%edx
call   1030 <writev@plt>
lea    0xe82(%rip),%rdi
mov    %eax,%esi
call   1050 <printf@plt>
mov    0x2e3e(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

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
@.str.2 = [20 x i8] c"%ld bytes written.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i8*
%4 = alloca [2 x %struct.iovec]
%5 = alloca i32
store i32 0, i32* %1
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0), i8** %2
store i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0), i8** %3
%6 = load i8*, i8** %2
%7 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 0
%8 = getelementptr inbounds %struct.iovec, %struct.iovec* %7, i32 0, i32 0
store i8* %6, i8** %8
%9 = load i8*, i8** %2
%10 = call i8* @strlen(i8* %9)
%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 i8* %10, i8** %12
%13 = load i8*, i8** %3
%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 = load i8*, i8** %3
%17 = call i8* @strlen(i8* %16)
%18 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 1
%19 = getelementptr inbounds %struct.iovec, %struct.iovec* %18, i32 0, i32 1
store i8* %17, i8** %19
%20 = load i32, i32* @STDOUT_FILENO
%21 = getelementptr inbounds [2 x %struct.iovec], [2 x %struct.iovec]* %4, i64 0, i64 0
%22 = call i32 @writev(i32 %20, %struct.iovec* %21, i32 2)
store i32 %22, i32* %5
%23 = load i32, i32* %5
%24 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %23)
%25 = load i32, i32* @EXIT_SUCCESS
%26 = call i32 @exit(i32 %25)
unreachable
}

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
@.str.2 = [20 x i8] c"%ld bytes written.\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%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)
%12 = call i32 @printf(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str.2, i64 0, i64 0), i32 %11)
%13 = load i32, i32* @EXIT_SUCCESS
%14 = call i32 @exit(i32 %13)
unreachable
}