#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*/ execvp(char *, char *const *);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  char *const cat_args[] = {"cat", argv[1], NULL};
  char *const wc_args[] = {"wc", "-l", NULL};
  if (fork() == 0) {
    int pipefd[2];
    pipe(pipefd);
    if (fork() == 0) {
      dup2(pipefd[0], 0);
      close(pipefd[1]);
      execvp("wc", wc_args);
    } else {
      dup2(pipefd[1], 1);
      close(pipefd[0]);
      execvp("cat", cat_args);
    }
  } else {
    wait(NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    0xe83(%rip),%rax
mov    %rax,-0x30(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x20(%rbp)
mov    0x2c64(%rip),%rax
mov    %rax,-0x50(%rbp)
mov    0x2c61(%rip),%rax
mov    %rax,-0x48(%rbp)
mov    0x2c5e(%rip),%rax
mov    %rax,-0x40(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    1232 <main+0xd2>
lea    -0x58(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%rax
jne    1208 <main+0xa8>
mov    -0x58(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x54(%rbp),%edi
call   1040 <close@plt>
lea    -0x50(%rbp),%rsi
lea    0xe06(%rip),%rdi
call   1060 <execvp@plt>
jmp    122d <main+0xcd>
mov    -0x54(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x58(%rbp),%edi
call   1040 <close@plt>
lea    -0x30(%rbp),%rsi
lea    0xdd8(%rip),%rdi
call   1060 <execvp@plt>
jmp    123b <main+0xdb>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x48,%rsp
lea    0xe95(%rip),%rax
mov    %rax,0x10(%rsp)
mov    0x8(%rsi),%rax
mov    %rax,0x18(%rsp)
movq   $0x0,0x20(%rsp)
mov    0x2c87(%rip),%rax
mov    %rax,0x40(%rsp)
movaps 0x2c6b(%rip),%xmm0
movaps %xmm0,0x30(%rsp)
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11af <main+0x4f>
xor    %edi,%edi
call   1070 <wait@plt>
jmp    120f <main+0xaf>
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     11ea <main+0x8a>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
lea    0xe1d(%rip),%rdi
lea    0x10(%rsp),%rsi
jmp    120a <main+0xaa>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
lea    0xdff(%rip),%rdi
lea    0x30(%rsp),%rsi
call   1060 <execvp@plt>
xor    %eax,%eax
add    $0x48,%rsp
ret

LLVM IR (-O0):
@.str = [4 x i8] c"cat\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
@__const.main.wc_args = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* null]
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [3 x i8*]
%7 = alloca [3 x i8*]
%8 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %9
%10 = getelementptr inbounds i8*, i8** %9, i64 1
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 1
%13 = load i8*, i8** %12
store i8* %13, i8** %10
%14 = getelementptr inbounds i8*, i8** %10, i64 1
store i8* null, i8** %14
%15 = bitcast [3 x i8*]* %7 to i8*
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %42
18: ; preds = %2
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%20 = call i32 @pipe(i32* %19)
%21 = call i64 (...) @fork()
%22 = icmp eq i64 %21, 0
br i1 %22, label %23, label %32
23: ; preds = %18
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%25 = load i32, i32* %24
%26 = call i32 @dup2(i32 %25, i32 0)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [3 x i8*], [3 x i8*]* %7, i64 0, i64 0
%31 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %30)
br label %41
32: ; preds = %18
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 1
%34 = load i32, i32* %33
%35 = call i32 @dup2(i32 %34, i32 1)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %8, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [3 x i8*], [3 x i8*]* %6, i64 0, i64 0
%40 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %39)
br label %41
41: ; preds = %32, %23
br label %44
42: ; preds = %2
%43 = call i32 @wait(i32* null)
br label %44
44: ; preds = %42, %41
%45 = load i32, i32* %3
ret i32 %45
}

LLVM IR (-O2):
@.str = [4 x i8] c"cat\00"
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
@__const.main.wc_args = [3 x i8*] [i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i32 0, i32 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.2, i32 0, i32 0), i8* null]
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [3 x i8*]
%4 = alloca [3 x i8*]
%5 = alloca [2 x i32]
%6 = bitcast [3 x i8*]* %3 to i8*
%7 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7
%8 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 1
%9 = getelementptr inbounds i8*, i8** %1, i64 1
%10 = load i8*, i8** %9
store i8* %10, i8** %8
%11 = getelementptr inbounds [3 x i8*], [3 x i8*]* %3, i64 0, i64 2
store i8* null, i8** %11
%12 = bitcast [3 x i8*]* %4 to i8*
%13 = tail call i64 (...) @fork()
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %37
15: ; preds = %2
%16 = bitcast [2 x i32]* %5 to i8*
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%18 = call i32 @pipe(i32* %17)
%19 = call i64 (...) @fork()
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %29
21: ; preds = %15
%22 = load i32, i32* %17
%23 = call i32 @dup2(i32 %22, i32 0)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [3 x i8*], [3 x i8*]* %4, i64 0, i64 0
%28 = call i32 @execvp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.1, i64 0, i64 0), i8** %27)
br label %36
29: ; preds = %15
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @dup2(i32 %31, i32 1)
%33 = load i32, i32* %17
%34 = call i32 @close(i32 %33)
%35 = call i32 @execvp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8** %7)
br label %36
36: ; preds = %29, %21
br label %39
37: ; preds = %2
%38 = tail call i32 @wait(i32* null)
br label %39
39: ; preds = %37, %36
ret i32 0
}