#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*/ execl(char *, char *, char *, ...);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int /*<<< orphan*/);
int main() {
  int su[2], uw[2];
  pipe(su);
  pipe(uw);
  if (fork() == 0) {
    close(su[0]);
    close(uw[0]);
    close(uw[1]);
    dup2(su[1], 1);
    execl("/usr/bin/sort", "/usr/bin/sort", "a.txt", NULL);
    exit(0);
  }
  if (fork() == 0) {
    close(su[1]);
    close(uw[0]);
    dup2(su[0], 0);
    dup2(uw[1], 1);
    execl("/usr/bin/uniq", "/usr/bin/uniq", NULL);
    exit(0);
  }
  if (fork() == 0) {
    close(su[0]);
    close(su[1]);
    close(uw[1]);
    dup2(uw[0], 0);
    execl("/usr/bin/wc", "/usr/bin/wc", "-l", NULL);
    exit(0);
  }
  close(su[0]);
  close(su[1]);
  close(uw[0]);
  close(uw[1]);
  wait(0);
  wait(0);
  wait(0);
  return 0;
}


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>
lea    -0x14(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    11ea <main+0x7a>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xe32(%rip),%rsi
lea    0xe39(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    123e <main+0xce>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x10(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xdeb(%rip),%rsi
xor    %eax,%eax
mov    %eax,%edx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    $0x0,%al
call   1090 <fork@plt>
cmp    $0x0,%rax
jne    1294 <main+0x124>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xdaa(%rip),%rsi
lea    0xdaf(%rip),%rdx
xor    %eax,%eax
mov    %eax,%ecx
mov    %rsi,%rdi
mov    $0x0,%al
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    -0xc(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11f6 <main+0x86>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     122e <main+0xbe>
xor    %eax,%eax
call   1090 <fork@plt>
mov    %rax,%rbx
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
test   %rbx,%rbx
je     1272 <main+0x102>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %edi,%edi
call   1080 <wait@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xddb(%rip),%rdi
lea    0xde2(%rip),%rdx
jmp    1293 <main+0x123>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
lea    0xdb5(%rip),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
xor    %eax,%eax
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
lea    0xd96(%rip),%rdi
lea    0xd9b(%rip),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
xor    %eax,%eax
call   1070 <execl@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [14 x i8] c"/usr/bin/sort\00"
@.str.1 = [6 x i8] c"a.txt\00"
@.str.2 = [14 x i8] c"/usr/bin/uniq\00"
@.str.3 = [12 x i8] c"/usr/bin/wc\00"
@.str.4 = [3 x i8] c"-l\00"
define i32 @main() {
%1 = alloca i32
%2 = alloca [2 x i32]
%3 = alloca [2 x i32]
store i32 0, i32* %1
%4 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%5 = call i32 @pipe(i32* %4)
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i64 (...) @fork()
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %25
10: ; preds = %0
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%12 = load i32, i32* %11
%13 = call i32 @close(i32 %12)
%14 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%18 = load i32, i32* %17
%19 = call i32 @close(i32 %18)
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @dup2(i32 %21, i32 1)
%23 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* null)
%24 = call i32 @exit(i32 0)
unreachable
25: ; preds = %0
%26 = call i64 (...) @fork()
%27 = icmp eq i64 %26, 0
br i1 %27, label %28, label %43
28: ; preds = %25
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%30 = load i32, i32* %29
%31 = call i32 @close(i32 %30)
%32 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%33 = load i32, i32* %32
%34 = call i32 @close(i32 %33)
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%36 = load i32, i32* %35
%37 = call i32 @dup2(i32 %36, i32 0)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%39 = load i32, i32* %38
%40 = call i32 @dup2(i32 %39, i32 1)
%41 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str.2, i64 0, i64 0), i8* null)
%42 = call i32 @exit(i32 0)
unreachable
43: ; preds = %25
%44 = call i64 (...) @fork()
%45 = icmp eq i64 %44, 0
br i1 %45, label %46, label %61
46: ; preds = %43
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%51 = load i32, i32* %50
%52 = call i32 @close(i32 %51)
%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 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @dup2(i32 %57, i32 0)
%59 = call i32 (i8*, i8*, i8*, ...) @execl(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.4, i64 0, i64 0), i8* null)
%60 = call i32 @exit(i32 0)
unreachable
61: ; preds = %43
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %2, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 @close(i32 %66)
%68 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%69 = load i32, i32* %68
%70 = call i32 @close(i32 %69)
%71 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%72 = load i32, i32* %71
%73 = call i32 @close(i32 %72)
%74 = call i32 @wait(i32 0)
%75 = call i32 @wait(i32 0)
%76 = call i32 @wait(i32 0)
ret i32 0
}

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