#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
scalar_t__ pipe(int *);
int /*<<< orphan*/ puts(char *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main() {
  int pfd[2];
  char buf[1024];
  pid_t pid;
  if (pipe(pfd) < 0) {
    perror("pipe()");
    exit(1);
  }
  pid = fork();
  if (pid < 0) {
    perror("fork()");
    exit(1);
  }
  if (pid == 0) {
    close(pfd[1]);
    read(pfd[0], buf, 1024);
    puts(buf);
    close(pfd[0]);
    exit(0);
  } else {
    close(pfd[0]);
    write(pfd[1], "Hello!", 6);
    close(pfd[1]);
    wait(NULL);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x420,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1060 <pipe@plt>
cmp    $0x0,%rax
jge    11cb <main+0x3b>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jge    11fd <main+0x6d>
lea    0xe19(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
cmpq   $0x0,-0x418(%rbp)
jne    1242 <main+0xb2>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
mov    -0xc(%rbp),%edi
lea    -0x410(%rbp),%rsi
mov    $0x400,%edx
call   1070 <read@plt>
lea    -0x410(%rbp),%rdi
call   1030 <puts@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
mov    -0x8(%rbp),%edi
lea    0xdba(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
xor    %edi,%edi
call   1090 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x410,%rsp
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
test   %rax,%rax
jns    11b0 <main+0x20>
lea    0xe52(%rip),%rdi
jmp    11c3 <main+0x33>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %rax,%rax
jns    11d2 <main+0x42>
lea    0xe44(%rip),%rdi
call   1080 <perror@plt>
mov    $0x1,%edi
call   1090 <exit@plt>
jne    120b <main+0x7b>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x400,%edx
call   1070 <read@plt>
mov    %rbx,%rdi
call   1030 <puts@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   1090 <exit@plt>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
lea    0xdef(%rip),%rsi
mov    $0x6,%edx
call   1040 <write@plt>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
xor    %edi,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [7 x i8] c"fork()\00"
@.str.2 = [7 x i8] c"Hello!\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [1024 x i8]
%4 = alloca i64
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i64 (...) @fork()
store i64 %12, i64* %4
%13 = load i64, i64* %4
%14 = icmp slt i64 %13, 0
br i1 %14, label %15, label %18
15: ; preds = %11
%16 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%17 = call i32 @exit(i32 1)
unreachable
18: ; preds = %11
%19 = load i64, i64* %4
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %35
21: ; preds = %18
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%26 = load i32, i32* %25
%27 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%28 = call i32 @read(i32 %26, i8* %27, i32 1024)
%29 = getelementptr inbounds [1024 x i8], [1024 x i8]* %3, i64 0, i64 0
%30 = call i32 @puts(i8* %29)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
%34 = call i32 @exit(i32 0)
unreachable
35: ; preds = %18
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @write(i32 %40, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%42 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%43 = load i32, i32* %42
%44 = call i32 @close(i32 %43)
%45 = call i32 @wait(i32* null)
%46 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@.str = [7 x i8] c"pipe()\00"
@.str.1 = [7 x i8] c"fork()\00"
@.str.2 = [7 x i8] c"Hello!\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [1024 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [1024 x i8], [1024 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i64 @pipe(i32* %5)
%7 = icmp slt i64 %6, 0
br i1 %7, label %8, label %11
8: ; preds = %0
%9 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 1)
unreachable
11: ; preds = %0
%12 = call i64 (...) @fork()
%13 = icmp slt i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %11
%15 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.1, i64 0, i64 0))
%16 = call i32 @exit(i32 1)
unreachable
17: ; preds = %11
%18 = icmp eq i64 %12, 0
br i1 %18, label %19, label %29
19: ; preds = %17
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %5
%24 = call i32 @read(i32 %23, i8* %4, i32 1024)
%25 = call i32 @puts(i8* %4)
%26 = load i32, i32* %5
%27 = call i32 @close(i32 %26)
%28 = call i32 @exit(i32 0)
unreachable
29: ; preds = %17
%30 = load i32, i32* %5
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @write(i32 %33, i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.2, i64 0, i64 0), i32 6)
%35 = load i32, i32* %32
%36 = call i32 @close(i32 %35)
%37 = call i32 @wait(i32* null)
%38 = call i32 @exit(i32 0)
unreachable
}