#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 */

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
void main() {
  int p[2];
  pipe(p);
  if (fork() == 0) {
    dup2(p[1], 1);
    close(p[0]);
    execlp("ls", "ls", (char *)0);
  }
  dup2(p[0], 0);
  close(p[1]);
  execlp("sort", "sort", "-r", (char *)0);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
jne    119c <main+0x4c>
mov    -0x4(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe72(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
mov    -0x8(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe4e(%rip),%rsi
lea    0xe4c(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
jne    118e <main+0x3e>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
lea    0xe7e(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execlp@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe5b(%rip),%rdi
lea    0xe59(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <execlp@plt>
pop    %rax
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [5 x i8] c"sort\00"
@.str.2 = [3 x i8] c"-r\00"
define void @main() {
%1 = alloca [2 x i32]
%2 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%3 = call i32 @pipe(i32* %2)
%4 = call i64 (...) @fork()
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %14
6: ; preds = %0
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%8 = load i32, i32* %7
%9 = call i32 @dup2(i32 %8, i32 1)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* null)
br label %14
14: ; preds = %6, %0
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%16 = load i32, i32* %15
%17 = call i32 @dup2(i32 %16, i32 0)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
ret void
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [5 x i8] c"sort\00"
@.str.2 = [3 x i8] c"-r\00"
define void @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 %14
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 @dup2(i32 %9, i32 1)
%11 = load i32, i32* %3
%12 = call i32 @close(i32 %11)
%13 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str, i64 0, i64 0), i8* null)
br label %14
14: ; preds = %7, %0
%15 = load i32, i32* %3
%16 = call i32 @dup2(i32 %15, i32 0)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
ret void
}