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

/* Variables and functions */
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int fds[2];
  char str[] = "hello world!";
  char buf[1024];
  pid_t pid;
  pipe(fds);
  pid = fork();
  if (pid == 0) {
    write(fds[1], str, sizeof(str));
  } else {
    read(fds[0], buf, sizeof(buf));
    printf("[recv] %s\n", buf);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x440,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0xe90(%rip),%rax
mov    %rax,-0x25(%rbp)
mov    0xe8e(%rip),%eax
mov    %eax,-0x1d(%rbp)
mov    0xe89(%rip),%al
mov    %al,-0x19(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x438(%rbp)
cmpq   $0x0,-0x438(%rbp)
jne    11c1 <main+0x71>
mov    -0x14(%rbp),%edi
lea    -0x25(%rbp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
jmp    11e8 <main+0x98>
mov    -0x18(%rbp),%edi
lea    -0x430(%rbp),%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    -0x430(%rbp),%rsi
lea    0xe2a(%rip),%rdi
call   1040 <printf@plt>
xor    %eax,%eax
add    $0x440,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x420,%rsp
movabs $0x21646c726f7720,%rax
mov    %rax,0x15(%rsp)
movabs $0x6f77206f6c6c6568,%rax
20 77 6f
mov    %rax,0x10(%rsp)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11b3 <main+0x63>
mov    0x8(%rsp),%edi
lea    0x20(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1060 <read@plt>
lea    0xe64(%rip),%rdi
mov    %rbx,%rsi
call   1040 <printf@plt>
jmp    11c6 <main+0x76>
mov    0xc(%rsp),%edi
lea    0x10(%rsp),%rsi
mov    $0xd,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x420,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@__const.main.str = [13 x i8] c"hello world!\00"
@.str = [11 x i8] c"[recv] %s\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [13 x i8]
%8 = alloca [1024 x i8]
%9 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%10 = bitcast [13 x i8]* %7 to i8*
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = call i64 (...) @fork()
store i64 %13, i64* %9
%14 = load i64, i64* %9
%15 = icmp eq i64 %14, 0
br i1 %15, label %16, label %21
16: ; preds = %2
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%18 = load i32, i32* %17
%19 = getelementptr inbounds [13 x i8], [13 x i8]* %7, i64 0, i64 0
%20 = call i32 @write(i32 %18, i8* %19, i32 13)
br label %28
21: ; preds = %2
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%23 = load i32, i32* %22
%24 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%25 = call i32 @read(i32 %23, i8* %24, i32 1024)
%26 = getelementptr inbounds [1024 x i8], [1024 x i8]* %8, i64 0, i64 0
%27 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %26)
br label %28
28: ; preds = %21, %16
ret i32 0
}

LLVM IR (-O2):
@__const.main.str = [13 x i8] c"hello world!\00"
@.str = [11 x i8] c"[recv] %s\0A\00"
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = alloca [13 x i8]
%5 = alloca [1024 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = getelementptr inbounds [13 x i8], [13 x i8]* %4, i64 0, i64 0
%8 = getelementptr inbounds [1024 x i8], [1024 x i8]* %5, i64 0, i64 0
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
%11 = call i64 (...) @fork()
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%15 = load i32, i32* %14
%16 = call i32 @write(i32 %15, i8* %7, i32 13)
br label %21
17: ; preds = %2
%18 = load i32, i32* %9
%19 = call i32 @read(i32 %18, i8* %8, i32 1024)
%20 = call i32 @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %21
21: ; preds = %17, %13
ret i32 0
}