#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*/ execlp(char *, char *, char *, ...);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int main() {
  int fd[2];
  pipe(fd);
  if (fork() != 0) {
    close(fd[0]);
    dup2(fd[1], 1);
    execlp("grep", "grep", "-v", "^#", "/etc/passwd", NULL);
  } else {
    close(fd[1]);
    dup2(fd[0], 0);
    int fd2[2];
    pipe(fd2);
    if (fork() != 0) {
      close(fd2[0]);
      dup2(fd2[1], 1);
      execlp("cut", "cut", "-f7", "-d:", NULL);
    } else {
      close(fd2[1]);
      dup2(fd2[0], 0);
      int fd3[2];
      pipe(fd3);
      if (fork() != 0) {
        close(fd3[0]);
        dup2(fd3[1], 1);
        execlp("uniq", "uniq", NULL);
      } else {
        close(fd3[1]);
        dup2(fd3[0], 0);
        execlp("wc", "wc", "-l", NULL);
      }
    }
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
lea    -0xc(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11be <main+0x6e>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xe6b(%rip),%rsi
lea    0xe69(%rip),%rdx
lea    0xe65(%rip),%rcx
lea    0xe61(%rip),%r8
xor    %eax,%eax
mov    %eax,%r9d
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    12bb <main+0x16b>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    -0x14(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1228 <main+0xd8>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xe11(%rip),%rsi
lea    0xe0e(%rip),%rdx
lea    0xe0b(%rip),%rcx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    12b6 <main+0x166>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    -0x1c(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     1283 <main+0x133>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xdb3(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    12b1 <main+0x161>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xd8c(%rip),%rsi
lea    0xd88(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1060 <execlp@plt>
jmp    12b6 <main+0x166>
jmp    12bb <main+0x16b>
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
sub    $0x18,%rsp
lea    0x10(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     11af <main+0x5f>
mov    0x10(%rsp),%edi
call   1040 <close@plt>
mov    0x14(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xe78(%rip),%rdi
lea    0xe76(%rip),%rdx
lea    0xe72(%rip),%rcx
lea    0xe6e(%rip),%r8
mov    %rdi,%rsi
xor    %r9d,%r9d
xor    %eax,%eax
call   1060 <execlp@plt>
jmp    1297 <main+0x147>
mov    0x14(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1217 <main+0xc7>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xe20(%rip),%rdi
lea    0xe1d(%rip),%rdx
lea    0xe1a(%rip),%rcx
mov    %rdi,%rsi
xor    %r8d,%r8d
xor    %eax,%eax
call   1060 <execlp@plt>
jmp    1297 <main+0x147>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     126a <main+0x11a>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xdc7(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1060 <execlp@plt>
jmp    1297 <main+0x147>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xda4(%rip),%rdi
lea    0xda0(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1060 <execlp@plt>
xor    %eax,%eax
add    $0x18,%rsp
ret

LLVM IR (-O0):
@.str = [5 x i8] c"grep\00"
@.str.1 = [3 x i8] c"-v\00"
@.str.2 = [3 x i8] c"^#\00"
@.str.3 = [12 x i8] c"/etc/passwd\00"
@.str.4 = [4 x i8] c"cut\00"
@.str.5 = [4 x i8] c"-f7\00"
@.str.6 = [4 x i8] c"-d:\00"
@.str.7 = [5 x i8] c"uniq\00"
@.str.8 = [3 x i8] c"wc\00"
@.str.9 = [3 x i8] c"-l\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
store i32 0, i32* %1
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp ne i64 %7, 0
br i1 %8, label %9, label %17
9: ; preds = %0
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%11 = load i32, i32* %10
%12 = call i32 @close(i32 %11)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @dup2(i32 %14, i32 1)
%16 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 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* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null)
br label %65
17: ; preds = %0
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%19 = load i32, i32* %18
%20 = call i32 @close(i32 %19)
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @dup2(i32 %22, i32 0)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%25 = call i32 @pipe(i32* %24)
%26 = call i64 (...) @fork()
%27 = icmp ne i64 %26, 0
br i1 %27, label %28, label %36
28: ; preds = %17
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%33 = load i32, i32* %32
%34 = call i32 @dup2(i32 %33, i32 1)
%35 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
br label %64
36: ; preds = %17
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%41 = load i32, i32* %40
%42 = call i32 @dup2(i32 %41, i32 0)
%43 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%44 = call i32 @pipe(i32* %43)
%45 = call i64 (...) @fork()
%46 = icmp ne i64 %45, 0
br i1 %46, label %47, label %55
47: ; preds = %36
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%49 = load i32, i32* %48
%50 = call i32 @close(i32 %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @dup2(i32 %52, i32 1)
%54 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* null)
br label %63
55: ; preds = %36
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%60 = load i32, i32* %59
%61 = call i32 @dup2(i32 %60, i32 0)
%62 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* null)
br label %63
63: ; preds = %55, %47
br label %64
64: ; preds = %63, %28
br label %65
65: ; preds = %64, %9
%66 = load i32, i32* %1
ret i32 %66
}

LLVM IR (-O2):
@.str = [5 x i8] c"grep\00"
@.str.1 = [3 x i8] c"-v\00"
@.str.2 = [3 x i8] c"^#\00"
@.str.3 = [12 x i8] c"/etc/passwd\00"
@.str.4 = [4 x i8] c"cut\00"
@.str.5 = [4 x i8] c"-f7\00"
@.str.6 = [4 x i8] c"-d:\00"
@.str.7 = [5 x i8] c"uniq\00"
@.str.8 = [3 x i8] c"wc\00"
@.str.9 = [3 x i8] c"-l\00"
define i32 @main() {
%1 = alloca [2 x i32]
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %1 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %0
%10 = load i32, i32* %5
%11 = call i32 @close(i32 %10)
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%13 = load i32, i32* %12
%14 = call i32 @dup2(i32 %13, i32 1)
%15 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 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* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* null)
br label %61
16: ; preds = %0
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %1, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = load i32, i32* %5
%21 = call i32 @dup2(i32 %20, i32 0)
%22 = bitcast [2 x i32]* %2 to i8*
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%24 = call i32 @pipe(i32* %23)
%25 = call i64 (...) @fork()
%26 = icmp eq i64 %25, 0
br i1 %26, label %34, label %27
27: ; preds = %16
%28 = load i32, i32* %23
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @dup2(i32 %31, i32 1)
%33 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.6, i64 0, i64 0), i8* null)
br label %60
34: ; preds = %16
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = load i32, i32* %23
%39 = call i32 @dup2(i32 %38, i32 0)
%40 = bitcast [2 x i32]* %3 to i8*
%41 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%42 = call i32 @pipe(i32* %41)
%43 = call i64 (...) @fork()
%44 = icmp eq i64 %43, 0
br i1 %44, label %52, label %45
45: ; preds = %34
%46 = load i32, i32* %41
%47 = call i32 @close(i32 %46)
%48 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%49 = load i32, i32* %48
%50 = call i32 @dup2(i32 %49, i32 1)
%51 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.7, i64 0, i64 0), i8* null)
br label %59
52: ; preds = %34
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @close(i32 %54)
%56 = load i32, i32* %41
%57 = call i32 @dup2(i32 %56, i32 0)
%58 = call i32 (i8*, i8*, i8*, ...) @execlp(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.8, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.9, i64 0, i64 0), i8* null)
br label %59
59: ; preds = %52, %45
br label %60
60: ; preds = %59, %27
br label %61
61: ; preds = %60, %9
ret i32 0
}