#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*/ readBuffer;
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, int /*<<< orphan*/ *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
int /*<<< orphan*/ read(int, char *, int);
scalar_t__ strlen(char *);
int /*<<< orphan*/ write(int, char *, scalar_t__);
int main(int argc, char *argv[]) {
  char *hw = "Hello World!\n";
  char readBuffer[50];
  int placeHolder;
  int fd[2];
  pipe(fd);
  pid_t pid;
  if (pid = fork() == -1) {
    perror("fork");
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    close(fd[0]);
    dup(fd[0]);
    execlp("sort", "sort", NULL);
    write(fd[1], hw, (strlen(hw) + 1));
    exit(EXIT_SUCCESS);
  } else {
    close(fd[1]);
    read(fd[0], readBuffer, sizeof(readBuffer));
    printf("Recieved string %s", readBuffer);
  }
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe33(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x5c(%rbp),%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
cmp    $0xffffffff,%eax
sete   %al
mov    %al,%cl
and    $0x1,%cl
movzbl %cl,%ecx
mov    %ecx,-0x60(%rbp)
test   $0x1,%al
jne    11ff <main+0x4f>
jmp    1219 <main+0x69>
lea    0xe08(%rip),%rdi
call   10a0 <perror@plt>
mov    0x2dce(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
cmpl   $0x0,-0x60(%rbp)
jne    127e <main+0xce>
mov    -0x5c(%rbp),%edi
call   1070 <close@plt>
mov    -0x5c(%rbp),%edi
call   1060 <dup@plt>
lea    0xdd9(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
call   10c0 <execlp@plt>
mov    -0x58(%rbp),%eax
mov    %eax,-0x6c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,-0x68(%rbp)
mov    -0x18(%rbp),%rdi
call   1040 <strlen@plt>
mov    -0x6c(%rbp),%edi
mov    -0x68(%rbp),%rsi
mov    %rax,%rdx
add    $0x1,%rdx
call   1030 <write@plt>
mov    0x2d61(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>
mov    -0x58(%rbp),%edi
call   1070 <close@plt>
mov    -0x5c(%rbp),%edi
lea    -0x50(%rbp),%rsi
mov    $0x32,%edx
call   1090 <read@plt>
lea    -0x50(%rbp),%rsi
lea    0xd76(%rip),%rdi
call   1050 <printf@plt>
jmp    12ac <main+0xfc>
mov    0x2d25(%rip),%rax
mov    (%rax),%edi
call   10b0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1060 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
cmp    $0xffffffff,%eax
jne    11af <main+0x2f>
lea    0xe72(%rip),%rdi
call   1070 <perror@plt>
mov    0x2e38(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    (%rsp),%edi
call   1040 <dup@plt>
lea    0xe4d(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1090 <execlp@plt>
mov    0x4(%rsp),%edi
lea    0xe25(%rip),%rsi
mov    $0xe,%edx
call   1030 <write@plt>
mov    0x2dec(%rip),%rax
mov    (%rax),%edi
call   1080 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"sort\00"
@EXIT_SUCCESS = global i32 0
@.str.3 = [19 x i8] c"Recieved string %s\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca [50 x i8]
%8 = alloca i32
%9 = alloca [2 x i32]
%10 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8** %6
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%12 = call i32 @pipe(i32* %11)
%13 = call i32 (...) @fork()
%14 = icmp eq i32 %13, -1
%15 = zext i1 %14 to i32
store i32 %15, i32* %10
br i1 %14, label %16, label %20
16: ; preds = %2
%17 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = load i32, i32* %10
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %40
23: ; preds = %20
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @dup(i32 %28)
%30 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* null)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%32 = load i32, i32* %31
%33 = load i8*, i8** %6
%34 = load i8*, i8** %6
%35 = call i64 @strlen(i8* %34)
%36 = add nsw i64 %35, 1
%37 = call i32 @write(i32 %32, i8* %33, i64 %36)
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %20
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 1
%42 = load i32, i32* %41
%43 = call i32 @close(i32 %42)
%44 = getelementptr inbounds [2 x i32], [2 x i32]* %9, i64 0, i64 0
%45 = load i32, i32* %44
%46 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%47 = call i32 @read(i32 %45, i8* %46, i32 50)
%48 = getelementptr inbounds [50 x i8], [50 x i8]* %7, i64 0, i64 0
%49 = call i32 @printf(i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str.3, i64 0, i64 0), i8* %48)
br label %50
50: ; preds = %40
br label %51
51: ; preds = %50
%52 = load i32, i32* @EXIT_SUCCESS
%53 = call i32 @exit(i32 %52)
unreachable
}

LLVM IR (-O2):
@.str = [14 x i8] c"Hello World!\0A\00"
@.str.1 = [5 x i8] c"fork\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [5 x i8] c"sort\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture readnone %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i32 (...) @fork()
%8 = icmp eq i32 %7, -1
br i1 %8, label %9, label %13
9: ; preds = %2
%10 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%11 = load i32, i32* @EXIT_FAILURE
%12 = call i32 @exit(i32 %11)
unreachable
13: ; preds = %2
%14 = load i32, i32* %5
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %5
%17 = call i32 @dup(i32 %16)
%18 = call i32 @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i32* null)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @write(i32 %20, i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i64 14)
%22 = load i32, i32* @EXIT_SUCCESS
%23 = call i32 @exit(i32 %22)
unreachable
}