#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*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int main(void) {
  int pfds[2];
  pipe(pfds);
  if (!fork()) {
    close(1);
    dup(pfds[1]);
    close(pfds[0]);
    execlp("ls", "ls", NULL);
  } else {
    close(0);
    dup(pfds[0]);
    close(pfds[1]);
    execlp("wc", "wc", "-l", NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%eax
jne    11ac <main+0x5c>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1030 <dup@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
lea    0xe67(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    11df <main+0x8f>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
call   1030 <dup@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe39(%rip),%rsi
lea    0xe35(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
xor    %eax,%eax
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   %eax,%eax
je     1198 <main+0x48>
xor    %edi,%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1030 <dup@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe80(%rip),%rdi
lea    0xe7c(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <execlp@plt>
jmp    11c6 <main+0x76>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1030 <dup@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
lea    0xe46(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execlp@plt>
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
store i32 0, i32* %1
%3 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%4 = call i32 @pipe(i32* %3)
%5 = call i32 (...) @fork()
%6 = icmp ne i32 %5, 0
br i1 %6, label %16, label %7
7: ; preds = %0
%8 = call i32 @close(i32 1)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%10 = load i32, i32* %9
%11 = call i32 @dup(i32 %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%13 = load i32, i32* %12
%14 = call i32 @close(i32 %13)
%15 = 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 %25
16: ; preds = %0
%17 = call i32 @close(i32 0)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%19 = load i32, i32* %18
%20 = call i32 @dup(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%22 = load i32, i32* %21
%23 = call i32 @close(i32 %22)
%24 = call i32 (i8*, i8*, i8*, ...) @execlp(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.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %25
25: ; preds = %16, %7
ret i32 0
}

LLVM IR (-O2):
@.str = [3 x i8] c"ls\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\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 i32 (...) @fork()
%6 = icmp eq i32 %5, 0
br i1 %6, label %7, label %15
7: ; preds = %0
%8 = call i32 @close(i32 1)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%10 = load i32, i32* %9
%11 = call i32 @dup(i32 %10)
%12 = load i32, i32* %3
%13 = call i32 @close(i32 %12)
%14 = 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 %23
15: ; preds = %0
%16 = call i32 @close(i32 0)
%17 = load i32, i32* %3
%18 = call i32 @dup(i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = call i32 (i8*, i8*, i8*, ...) @execlp(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.1, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %23
23: ; preds = %15, %7
ret i32 0
}