#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 STDIN_FILENO;
int STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, ...);
int /*<<< orphan*/ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
void who_wc() {
  int pfd[2];
  pipe(pfd);
  if (!fork()) {
    close(STDOUT_FILENO);
    dup2(pfd[1], STDOUT_FILENO);
    close(pfd[1]);
    close(pfd[0]);
    execlp("who", "who", NULL);
  } else {
    close(STDIN_FILENO);
    dup2(pfd[0], STDIN_FILENO);
    close(pfd[1]);
    close(pfd[0]);
    execlp("wc", "wc", "-l", NULL);
  }
  close(pfd[0]);
  close(pfd[1]);
  wait(NULL);
  wait(NULL);
}


x86 assembly (clang, -O0):
<who_wc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
lea    -0x8(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
cmp    $0x0,%eax
jne    11ca <who_wc+0x6a>
mov    0x2e68(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
mov    0x2e57(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe49(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    1215 <who_wc+0xb5>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
mov    0x2df6(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
lea    0xe04(%rip),%rsi
lea    0xe00(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x4(%rbp),%edi
call   1040 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
xor    %eax,%eax
mov    %eax,%edi
call   1070 <wait@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<who_wc>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11c1 <who_wc+0x61>
mov    0x2e57(%rip),%rbx
mov    (%rbx),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
mov    (%rbx),%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
lea    0xe58(%rip),%rdi
lea    0xe54(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <execlp@plt>
jmp    11ff <who_wc+0x9f>
mov    0x2e28(%rip),%rbx
mov    (%rbx),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
mov    (%rbx),%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
lea    0xe0d(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execlp@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1070 <wait@plt>
xor    %edi,%edi
call   1070 <wait@plt>
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"who\00"
@STDIN_FILENO = global i32 0
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
define void @who_wc() {
%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 i32 (...) @fork()
%5 = icmp ne i32 %4, 0
br i1 %5, label %20, label %6
6: ; preds = %0
%7 = load i32, i32* @STDOUT_FILENO
%8 = call i32 @close(i32 %7)
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%10 = load i32, i32* %9
%11 = load i32, i32* @STDOUT_FILENO
%12 = call i32 @dup2(i32 %10, i32 %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @close(i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* null)
br label %34
20: ; preds = %0
%21 = load i32, i32* @STDIN_FILENO
%22 = call i32 @close(i32 %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%24 = load i32, i32* %23
%25 = load i32, i32* @STDIN_FILENO
%26 = call i32 @dup2(i32 %24, i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = 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 %34
34: ; preds = %20, %6
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @close(i32 %39)
%41 = call i32 @wait(i32* null)
%42 = call i32 @wait(i32* null)
ret void
}

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@.str = [4 x i8] c"who\00"
@STDIN_FILENO = global i32 0
@.str.1 = [3 x i8] c"wc\00"
@.str.2 = [3 x i8] c"-l\00"
define void @who_wc() {
%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 %19
7: ; preds = %0
%8 = load i32, i32* @STDOUT_FILENO
%9 = call i32 @close(i32 %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%11 = load i32, i32* %10
%12 = load i32, i32* @STDOUT_FILENO
%13 = call i32 @dup2(i32 %11, i32 %12)
%14 = load i32, i32* %10
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %3
%17 = call i32 @close(i32 %16)
%18 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i8* null)
br label %31
19: ; preds = %0
%20 = load i32, i32* @STDIN_FILENO
%21 = call i32 @close(i32 %20)
%22 = load i32, i32* %3
%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 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %3
%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 ([3 x i8], [3 x i8]* @.str.2, i64 0, i64 0), i8* null)
br label %31
31: ; preds = %19, %7
%32 = load i32, i32* %3
%33 = call i32 @close(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = call i32 @wait(i32* null)
%38 = call i32 @wait(i32* null)
ret void
}