#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 STDOUT_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int my_pipe[2];
  pipe(my_pipe);
  pid_t pid = fork();
  if (pid == 0) {
    close(my_pipe[1]);
    char buff[6];
    read(my_pipe[0], buff, 6 * sizeof(char));
    close(my_pipe[0]);
    write(STDOUT_FILENO, buff, 6 * sizeof(char));
  } else if (pid > 0) {
    close(my_pipe[0]);
    char hello[] = "Hello\n";
    write(my_pipe[1], hello, 6 * sizeof(char));
    close(my_pipe[1]);
  } else {
    perror("fork()");
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x20(%rbp)
cmpq   $0x0,-0x20(%rbp)
jne    11d2 <main+0x72>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
lea    -0x26(%rbp),%rsi
mov    $0x6,%edx
call   1060 <read@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0x2e33(%rip),%rax
mov    (%rax),%edi
lea    -0x26(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
jmp    1231 <main+0xd1>
cmpq   $0x0,-0x20(%rbp)
jle    1220 <main+0xc0>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    0xe15(%rip),%eax
mov    %eax,-0x2d(%rbp)
mov    0xe0f(%rip),%ax
mov    %ax,-0x29(%rbp)
mov    0xe07(%rip),%al
mov    %al,-0x27(%rbp)
mov    -0x14(%rbp),%edi
lea    -0x2d(%rbp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
jmp    122c <main+0xcc>
lea    0xde0(%rip),%rdi
call   1070 <perror@plt>
jmp    1231 <main+0xd1>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11b1 <main+0x51>
jle    11f5 <main+0x95>
mov    (%rsp),%edi
call   1040 <close@plt>
movl   $0xa6f6c,0xb(%rsp)
movl   $0x6c6c6548,0x8(%rsp)
6c
mov    0x4(%rsp),%edi
lea    0x8(%rsp),%rsi
mov    $0x6,%edx
call   1030 <write@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
jmp    11ed <main+0x8d>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
lea    0x8(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x6,%edx
call   1060 <read@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x2e12(%rip),%rax
mov    (%rax),%edi
mov    %rbx,%rsi
mov    $0x6,%edx
call   1030 <write@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
lea    0xe0b(%rip),%rdi
call   1070 <perror@plt>
jmp    11ed <main+0x8d>

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

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