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

/* Variables and functions */
int /*<<< orphan*/ syscall_dup(int, int);
int /*<<< orphan*/ syscall_pipe(int *);
int /*<<< orphan*/ syscall_read(int, char *, int);
int /*<<< orphan*/ syscall_write(int, char *, int);
int main() {
  char buf[143];
  int ofds[2];
  (void)syscall_pipe(ofds);
  syscall_dup(ofds[1], 1);
  syscall_dup(ofds[0], 0);
  syscall_write(ofds[1], "Hello World\n", sizeof("Hello World") + 1);
  syscall_read(ofds[0], buf, sizeof(buf));
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0xb0,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xa8(%rbp),%rdi
call   1040 <syscall_pipe@plt>
mov    -0xa4(%rbp),%edi
mov    $0x1,%esi
call   1050 <syscall_dup@plt>
mov    -0xa8(%rbp),%edi
xor    %esi,%esi
call   1050 <syscall_dup@plt>
mov    -0xa4(%rbp),%edi
lea    0xe78(%rip),%rsi
mov    $0xd,%edx
call   1030 <syscall_write@plt>
mov    -0xa8(%rbp),%edi
lea    -0xa0(%rbp),%rsi
mov    $0x8f,%edx
call   1060 <syscall_read@plt>
xor    %eax,%eax
add    $0xb0,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0xa8,%rsp
lea    0x8(%rsp),%rdi
call   1040 <syscall_pipe@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1050 <syscall_dup@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1050 <syscall_dup@plt>
mov    0xc(%rsp),%edi
lea    0xe8b(%rip),%rsi
mov    $0xd,%edx
call   1030 <syscall_write@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0x8f,%edx
call   1060 <syscall_read@plt>
xor    %eax,%eax
add    $0xa8,%rsp
ret

LLVM IR (-O0):
@.str = [13 x i8] c"Hello World\0A\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [143 x i8]
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%5 = call i32 @syscall_pipe(i32* %4)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%7 = load i32, i32* %6
%8 = call i32 @syscall_dup(i32 %7, i32 1)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = load i32, i32* %9
%11 = call i32 @syscall_dup(i32 %10, i32 0)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @syscall_write(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%16 = load i32, i32* %15
%17 = getelementptr inbounds [143 x i8], [143 x i8]* %2, i64 0, i64 0
%18 = call i32 @syscall_read(i32 %16, i8* %17, i32 143)
ret i32 0
}

LLVM IR (-O2):
@.str = [13 x i8] c"Hello World\0A\00"
define i32 @main() {
%1 = alloca [143 x i8]
%2 = alloca [2 x i32]
%3 = getelementptr inbounds [143 x i8], [143 x i8]* %1, i64 0, i64 0
%4 = bitcast [2 x i32]* %2 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @syscall_pipe(i32* %5)
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%8 = load i32, i32* %7
%9 = call i32 @syscall_dup(i32 %8, i32 1)
%10 = load i32, i32* %5
%11 = call i32 @syscall_dup(i32 %10, i32 0)
%12 = load i32, i32* %7
%13 = call i32 @syscall_write(i32 %12, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 13)
%14 = load i32, i32* %5
%15 = call i32 @syscall_read(i32 %14, i8* %3, i32 143)
ret i32 0
}