#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 EXIT_SUCCESS;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int read(int, char *, int);
int /*<<< orphan*/ write(int, char *, int);
int main(void) {
  int n, fds[2];
  pid_t pid;
  char line[100];
  pipe(fds);
  pid = fork();
  if (pid > 0) {
    close(fds[0]);
    write(fds[1], "hello world\n", 12);
  } else {
    close(fds[1]);
    n = read(fds[0], line, 100);
    write(STDOUT_FILENO, line, n);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x80,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0x10(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jle    11a2 <main+0x52>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
lea    0xe6d(%rip),%rsi
mov    $0xc,%edx
call   1030 <write@plt>
jmp    11d3 <main+0x83>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
lea    -0x80(%rbp),%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    %eax,-0x8(%rbp)
mov    0x2e2b(%rip),%rax
mov    (%rax),%edi
lea    -0x80(%rbp),%rsi
mov    -0x8(%rbp),%edx
call   1030 <write@plt>
mov    0x2dfe(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x80,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jle    1189 <main+0x39>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
lea    0xe7e(%rip),%rsi
mov    $0xc,%edx
jmp    11b6 <main+0x66>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
lea    0x10(%rsp),%rbx
mov    %rbx,%rsi
mov    $0x64,%edx
call   1060 <read@plt>
mov    0x2e41(%rip),%rcx
mov    (%rcx),%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1030 <write@plt>
mov    0x2e16(%rip),%rax
mov    (%rax),%eax
add    $0x80,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
@.str = [13 x i8] c"hello world\0A\00"
@STDOUT_FILENO = global i32 0
@EXIT_SUCCESS = global i32 0
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [100 x i8]
%3 = bitcast [2 x i32]* %1 to i8*
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp sgt i64 %7, 0
br i1 %8, label %9, label %15
9: ; preds = %0
%10 = load i32, i32* %5
%11 = call i32 @close(i32 %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @write(i32 %13, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i32 12)
br label %23
15: ; preds = %0
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = load i32, i32* %5
%20 = call i32 @read(i32 %19, i8* %4, i32 100)
%21 = load i32, i32* @STDOUT_FILENO
%22 = call i32 @write(i32 %21, i8* %4, i32 %20)
br label %23
23: ; preds = %15, %9
%24 = load i32, i32* @EXIT_SUCCESS
ret i32 %24
}