#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int main(void) {
  int pfd[2];
  pipe(pfd);
  if (fork() == 0) {
    close(pfd[1]);
    dup2(pfd[0], STDIN_FILENO);
    close(pfd[0]);
    execlp("wc", "wc", NULL);
  } else {
    close(pfd[0]);
    dup2(pfd[1], STDOUT_FILENO);
    close(pfd[1]);
    execlp("ls", "ls", "-hal", NULL);
  }
  exit(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   1080 <fork@plt>
cmp    $0x0,%rax
jne    11c4 <main+0x64>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
mov    0x2e3d(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
lea    0xe4f(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execlp@plt>
jmp    1201 <main+0xa1>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
mov    0x2e1a(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe17(%rip),%rsi
lea    0xe13(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execlp@plt>
xor    %edi,%edi
call   1060 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rax
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
jne    11b1 <main+0x51>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
mov    0x2e50(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
lea    0xe62(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execlp@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
mov    0x2e2c(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
lea    0xe28(%rip),%rdi
lea    0xe24(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <execlp@plt>
xor    %edi,%edi
call   1060 <exit@plt>

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

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@.str = [3 x i8] c"wc\00"
@STDOUT_FILENO = global i32 0
@.str.1 = [3 x i8] c"ls\00"
@.str.2 = [5 x i8] c"-hal\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 i64 (...) @fork()
%6 = icmp eq i64 %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 = call i32 @close(i32 %9)
%11 = load i32, i32* %3
%12 = load i32, i32* @STDIN_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
%16 = 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 %27
17: ; preds = %0
%18 = load i32, i32* %3
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%21 = load i32, i32* %20
%22 = load i32, i32* @STDOUT_FILENO
%23 = call i32 @dup2(i32 %21, i32 %22)
%24 = load i32, i32* %20
%25 = call i32 @close(i32 %24)
%26 = 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 ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %27
27: ; preds = %17, %7
%28 = call i32 @exit(i32 0)
unreachable
}