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

/* Variables and functions */
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execl(char *, char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
void main(void) {
  int fd[2];
  pid_t childpid;
  pipe(fd);
  if ((childpid = fork()) == 0) {
    dup2(fd[1], STDOUT_FILENO);
    close(fd[0]);
    close(fd[1]);
    execl("/usr/bin/ls", "ls", "-l", NULL);
    perror("execution of ls failed");
  } else {
    dup2(fd[0], STDIN_FILENO);
    close(fd[0]);
    close(fd[1]);
    execl("/usr/bin/sort", "sort", "-n", "+4", NULL);
    perror("execution of sort failed");
  }
  exit(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   1090 <fork@plt>
mov    %eax,-0xc(%rbp)
cmp    $0x0,%eax
jne    11e6 <main+0x76>
mov    -0x4(%rbp),%edi
mov    0x2e52(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe44(%rip),%rdi
lea    0xe46(%rip),%rsi
lea    0xe42(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    $0x0,%al
call   1080 <execl@plt>
lea    0xe33(%rip),%rdi
call   1060 <perror@plt>
jmp    123b <main+0xcb>
mov    -0x8(%rbp),%edi
mov    0x2de8(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
lea    0xe18(%rip),%rdi
lea    0xe1a(%rip),%rsi
lea    0xe18(%rip),%rdx
lea    0xe14(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    $0x0,%al
call   1080 <execl@plt>
lea    0xe04(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %eax,%eax
jne    11ce <main+0x5e>
mov    0x4(%rsp),%edi
mov    0x2e61(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe52(%rip),%rdi
lea    0xe54(%rip),%rsi
lea    0xe50(%rip),%rdx
xor    %ecx,%ecx
xor    %eax,%eax
call   1080 <execl@plt>
lea    0xe43(%rip),%rdi
jmp    121d <main+0xad>
mov    (%rsp),%edi
mov    0x2e00(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe2f(%rip),%rdi
lea    0xe31(%rip),%rsi
lea    0xe2f(%rip),%rdx
lea    0xe2b(%rip),%rcx
xor    %r8d,%r8d
xor    %eax,%eax
call   1080 <execl@plt>
lea    0xe1d(%rip),%rdi
call   1060 <perror@plt>
xor    %edi,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"/usr/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [23 x i8] c"execution of ls failed\00"
@STDIN_FILENO = global i32 0
@.str.4 = [14 x i8] c"/usr/bin/sort\00"
@.str.5 = [5 x i8] c"sort\00"
@.str.6 = [3 x i8] c"-n\00"
@.str.7 = [3 x i8] c"+4\00"
@.str.8 = [25 x i8] c"execution of sort failed\00"
define void @main() {
%1 = alloca [2 x i32]
%2 = alloca i32
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i32 (...) @fork()
store i32 %5, i32* %2
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %20
7: ; preds = %0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%9 = load i32, i32* %8
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @dup2(i32 %9, i32 %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%16 = load i32, i32* %15
%17 = call i32 @close(i32 %16)
%18 = call i32 (i8*, i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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)
%19 = call i32 @perror(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0))
br label %33
20: ; preds = %0
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%22 = load i32, i32* %21
%23 = load i32, i32* @STDIN_FILENO
%24 = call i32 @dup2(i32 %22, i32 %23)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = call i32 (i8*, i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* null)
%32 = call i32 @perror(i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0))
br label %33
33: ; preds = %20, %7
%34 = call i32 @exit(i32 0)
unreachable
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [12 x i8] c"/usr/bin/ls\00"
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [3 x i8] c"-l\00"
@.str.3 = [23 x i8] c"execution of ls failed\00"
@STDIN_FILENO = global i32 0
@.str.4 = [14 x i8] c"/usr/bin/sort\00"
@.str.5 = [5 x i8] c"sort\00"
@.str.6 = [3 x i8] c"-n\00"
@.str.7 = [3 x i8] c"+4\00"
@.str.8 = [25 x i8] c"execution of sort failed\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 i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %17
7: ; preds = %0
%8 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%9 = load i32, i32* %8
%10 = load i32, i32* @STDOUT_FILENO
%11 = call i32 @dup2(i32 %9, i32 %10)
%12 = load i32, i32* %3
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %8
%15 = call i32 @close(i32 %14)
%16 = call i32 (i8*, i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 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)
br label %27
17: ; preds = %0
%18 = load i32, i32* %3
%19 = load i32, i32* @STDIN_FILENO
%20 = call i32 @dup2(i32 %18, i32 %19)
%21 = load i32, i32* %3
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = call i32 (i8*, i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.7, i64 0, i64 0), i8* null)
br label %27
27: ; preds = %17, %7
%28 = phi i8* [ getelementptr inbounds ([25 x i8], [25 x i8]* @.str.8, i64 0, i64 0), %17 ], [ getelementptr inbounds ([23 x i8], [23 x i8]* @.str.3, i64 0, i64 0), %7 ]
%29 = call i32 @perror(i8* %28)
%30 = call i32 @exit(i32 0)
unreachable
}