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

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ *fdopen(int, char *);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ reader(int /*<<< orphan*/ *);
int /*<<< orphan*/ writer(char *, int, int /*<<< orphan*/ *);
int main() {
  int fds[2];
  pid_t pid;
  pipe(fds);
  pid = fork();
  if (pid == (pid_t)0) {
    FILE *stream;
    close(fds[1]);
    stream = fdopen(fds[0], "r");
    reader(stream);
    close(fds[0]);
  } else {
    FILE *stream;
    close(fds[0]);
    stream = fdopen(fds[1], "w");
    writer("Hello, world.", 5, stream);
    close(fds[1]);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11bf <main+0x5f>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
lea    0xe60(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x20(%rbp)
mov    -0x20(%rbp),%rdi
call   1030 <reader@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
jmp    11f7 <main+0x97>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
lea    0xe31(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,-0x28(%rbp)
mov    -0x28(%rbp),%rdx
lea    0xe1f(%rip),%rdi
mov    $0x5,%esi
call   1070 <writer@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11a7 <main+0x47>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
lea    0xe7a(%rip),%rsi
call   1060 <fdopen@plt>
lea    0xe70(%rip),%rdi
mov    $0x5,%esi
mov    %rax,%rdx
call   1070 <writer@plt>
mov    0x4(%rsp),%edi
jmp    11ca <main+0x6a>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
lea    0xe46(%rip),%rsi
call   1060 <fdopen@plt>
mov    %rax,%rdi
call   1030 <reader@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"Hello, world.\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca i64
%4 = alloca i32*
%5 = alloca i32*
store i32 0, i32* %1
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i64 (...) @fork()
store i64 %8, i64* %3
%9 = load i64, i64* %3
%10 = icmp eq i64 %9, 0
br i1 %10, label %11, label %23
11: ; preds = %0
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32* @fdopen(i32 %16, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %17, i32** %4
%18 = load i32*, i32** %4
%19 = call i32 @reader(i32* %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
br label %35
23: ; preds = %0
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32* @fdopen(i32 %28, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %29, i32** %5
%30 = load i32*, i32** %5
%31 = call i32 @writer(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 5, i32* %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
br label %35
35: ; preds = %23, %11
ret i32 0
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@.str.1 = [2 x i8] c"w\00"
@.str.2 = [14 x i8] c"Hello, world.\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = bitcast [2 x i32]* %1 to i8*
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i64 (...) @fork()
%6 = icmp eq i64 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%9 = load i32, i32* %8
%10 = call i32 @close(i32 %9)
%11 = load i32, i32* %3
%12 = call i32* @fdopen(i32 %11, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%13 = call i32 @reader(i32* %12)
%14 = load i32, i32* %3
br label %23
15: ; preds = %0
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32* @fdopen(i32 %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%21 = call i32 @writer(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i32 5, i32* %20)
%22 = load i32, i32* %18
br label %23
23: ; preds = %15, %7
%24 = phi i32 [ %22, %15 ], [ %14, %7 ]
%25 = call i32 @close(i32 %24)
ret i32 0
}