#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 */
typedef int pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int STDOUT_FILENO;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ assert(int);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getpid();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
scalar_t__ read(int, char *, int);
int /*<<< orphan*/ sleep(int);
int /*<<< orphan*/ sprintf(char *, char *, int);
int strlen(char *);
int /*<<< orphan*/ wait(int /*<<< orphan*/ *);
int /*<<< orphan*/ write(int, char *, int);
int main(int argc, char *argv[]) {
  int i;
  int pfd[2];
  pid_t cpid[10];
  char buf;
  assert(argc == 2);
  if (pipe(pfd) == -1) {
    perror("pipe");
    exit(EXIT_FAILURE);
  }
  for (i = 0; i < 10; i++) {
    cpid[i] = fork();
    if (cpid[i] == -1) {
      perror("fork");
      exit(EXIT_FAILURE);
    }
    if (cpid[i] == 0) {
      char space[128];
      close(pfd[1]);
      while (read(pfd[0], &buf, 1) > 0)
        write(STDOUT_FILENO, &buf, 1);
      sprintf(space, "pid=%d the end\n", getpid());
      write(STDOUT_FILENO, space, strlen(space));
      close(pfd[0]);
      _exit(EXIT_SUCCESS);
    }
  }
  close(pfd[0]);
  sleep(3);
  write(pfd[1], argv[1], strlen(argv[1]));
  sleep(30);
  close(pfd[1]);
  wait(NULL);
  exit(EXIT_SUCCESS);
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x110,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x2,-0x8(%rbp)
sete   %al
and    $0x1,%al
movzbl %al,%edi
call   10a0 <assert@plt>
lea    -0x1c(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1236 <main+0x56>
lea    0xddd(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2da9(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movl   $0x0,-0x14(%rbp)
cmpl   $0xa,-0x14(%rbp)
jge    135f <main+0x17f>
mov    $0x0,%al
call   1100 <fork@plt>
mov    %eax,%ecx
movslq -0x14(%rbp),%rax
mov    %ecx,-0x50(%rbp,%rax,4)
movslq -0x14(%rbp),%rax
cmpl   $0xffffffff,-0x50(%rbp,%rax,4)
jne    1281 <main+0xa1>
lea    0xd97(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2d5e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
movslq -0x14(%rbp),%rax
cmpl   $0x0,-0x50(%rbp,%rax,4)
jne    134c <main+0x16c>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x1c(%rbp),%edi
lea    -0x51(%rbp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
cmp    $0x0,%rax
jle    12cf <main+0xef>
mov    0x2d36(%rip),%rax
mov    (%rax),%edi
lea    -0x51(%rbp),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
jmp    1298 <main+0xb8>
lea    -0xe0(%rbp),%rax
mov    %rax,-0xf8(%rbp)
mov    $0x0,%al
call   1050 <getpid@plt>
mov    -0xf8(%rbp),%rdi
mov    %eax,%edx
lea    0xd16(%rip),%rsi
call   10c0 <sprintf@plt>
mov    0x2cf0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0xec(%rbp)
lea    -0xe0(%rbp),%rax
mov    %rax,-0xe8(%rbp)
lea    -0xe0(%rbp),%rdi
call   1060 <strlen@plt>
mov    -0xec(%rbp),%edi
mov    -0xe8(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    0x2c8b(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
jmp    1351 <main+0x171>
mov    -0x14(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x14(%rbp)
jmp    123d <main+0x5d>
mov    -0x1c(%rbp),%edi
call   1070 <close@plt>
mov    $0x3,%edi
call   10e0 <sleep@plt>
mov    -0x18(%rbp),%eax
mov    %eax,-0x104(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x100(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
call   1060 <strlen@plt>
mov    -0x104(%rbp),%edi
mov    -0x100(%rbp),%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1e,%edi
call   10e0 <sleep@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10f0 <wait@plt>
mov    0x2c04(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
sub    $0x98,%rsp
mov    %rsi,%rbx
xor    %eax,%eax
cmp    $0x2,%edi
sete   %al
mov    %eax,%edi
call   10a0 <assert@plt>
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
cmp    $0xffffffff,%eax
jne    1216 <main+0x36>
lea    0xdef(%rip),%rdi
jmp    139e <main+0x1be>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
je     12ee <main+0x10e>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1397 <main+0x1b7>
test   %eax,%eax
jne    13b1 <main+0x1d1>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
lea    0x7(%rsp),%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
jle    1346 <main+0x166>
mov    0x2cda(%rip),%rbp
lea    0x7(%rsp),%rbx
nopl   0x0(%rax,%rax,1)
mov    0x0(%rbp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1040 <write@plt>
mov    0x8(%rsp),%edi
mov    %rbx,%rsi
mov    $0x1,%edx
call   1090 <read@plt>
test   %rax,%rax
jg     1320 <main+0x140>
xor    %eax,%eax
call   1050 <getpid@plt>
lea    0xcb6(%rip),%rsi
lea    0x10(%rsp),%rbx
mov    %rbx,%rdi
mov    %eax,%edx
call   10c0 <sprintf@plt>
mov    0x2c86(%rip),%rax
mov    (%rax),%ebp
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0x2c40(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
lea    0xc67(%rip),%rdi
call   10b0 <perror@plt>
mov    0x2c2e(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    $0x3,%edi
call   10e0 <sleep@plt>
mov    0xc(%rsp),%ebp
mov    0x8(%rbx),%rbx
mov    %rbx,%rdi
call   1060 <strlen@plt>
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %eax,%edx
call   1040 <write@plt>
mov    $0x1e,%edi
call   10e0 <sleep@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
xor    %edi,%edi
call   10f0 <wait@plt>
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
call   10d0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [16 x i8] c"pid=%d the end\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca [10 x i32]
%9 = alloca i8
%10 = alloca [128 x i8]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%11 = load i32, i32* %4
%12 = icmp eq i32 %11, 2
%13 = zext i1 %12 to i32
%14 = call i32 @assert(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %22
18: ; preds = %2
%19 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%20 = load i32, i32* @EXIT_FAILURE
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
store i32 0, i32* %6
br label %23
23: ; preds = %73, %22
%24 = load i32, i32* %6
%25 = icmp slt i32 %24, 10
br i1 %25, label %26, label %76
26: ; preds = %23
%27 = call i32 (...) @fork()
%28 = load i32, i32* %6
%29 = sext i32 %28 to i64
%30 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %29
store i32 %27, i32* %30
%31 = load i32, i32* %6
%32 = sext i32 %31 to i64
%33 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %32
%34 = load i32, i32* %33
%35 = icmp eq i32 %34, -1
br i1 %35, label %36, label %40
36: ; preds = %26
%37 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %26
%41 = load i32, i32* %6
%42 = sext i32 %41 to i64
%43 = getelementptr inbounds [10 x i32], [10 x i32]* %8, i64 0, i64 %42
%44 = load i32, i32* %43
%45 = icmp eq i32 %44, 0
br i1 %45, label %46, label %72
46: ; preds = %40
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @close(i32 %48)
br label %50
50: ; preds = %55, %46
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%52 = load i32, i32* %51
%53 = call i64 @read(i32 %52, i8* %9, i32 1)
%54 = icmp sgt i64 %53, 0
br i1 %54, label %55, label %58
55: ; preds = %50
%56 = load i32, i32* @STDOUT_FILENO
%57 = call i32 @write(i32 %56, i8* %9, i32 1)
br label %50
58: ; preds = %50
%59 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%60 = call i32 (...) @getpid()
%61 = call i32 @sprintf(i8* %59, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %60)
%62 = load i32, i32* @STDOUT_FILENO
%63 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%64 = getelementptr inbounds [128 x i8], [128 x i8]* %10, i64 0, i64 0
%65 = call i32 @strlen(i8* %64)
%66 = call i32 @write(i32 %62, i8* %63, i32 %65)
%67 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%68 = load i32, i32* %67
%69 = call i32 @close(i32 %68)
%70 = load i32, i32* @EXIT_SUCCESS
%71 = call i32 @_exit(i32 %70)
unreachable
72: ; preds = %40
br label %73
73: ; preds = %72
%74 = load i32, i32* %6
%75 = add nsw i32 %74, 1
store i32 %75, i32* %6
br label %23
76: ; preds = %23
%77 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%78 = load i32, i32* %77
%79 = call i32 @close(i32 %78)
%80 = call i32 @sleep(i32 3)
%81 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%82 = load i32, i32* %81
%83 = load i8**, i8*** %5
%84 = getelementptr inbounds i8*, i8** %83, i64 1
%85 = load i8*, i8** %84
%86 = load i8**, i8*** %5
%87 = getelementptr inbounds i8*, i8** %86, i64 1
%88 = load i8*, i8** %87
%89 = call i32 @strlen(i8* %88)
%90 = call i32 @write(i32 %82, i8* %85, i32 %89)
%91 = call i32 @sleep(i32 30)
%92 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%93 = load i32, i32* %92
%94 = call i32 @close(i32 %93)
%95 = call i32 @wait(i32* null)
%96 = load i32, i32* @EXIT_SUCCESS
%97 = call i32 @exit(i32 %96)
unreachable
}

LLVM IR (-O2):
@.str = [5 x i8] c"pipe\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [5 x i8] c"fork\00"
@STDOUT_FILENO = global i32 0
@.str.2 = [16 x i8] c"pid=%d the end\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca i8
%5 = alloca [128 x i8]
%6 = bitcast [2 x i32]* %3 to i8*
%7 = icmp eq i32 %0, 2
%8 = zext i1 %7 to i32
%9 = tail call i32 @assert(i32 %8)
%10 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%11 = call i32 @pipe(i32* %10)
%12 = icmp eq i32 %11, -1
br i1 %12, label %15, label %13
13: ; preds = %2
%14 = call i32 (...) @fork()
switch i32 %14, label %47 [
i32 -1, label %19
i32 0, label %23
]
15: ; preds = %2
%16 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%17 = load i32, i32* @EXIT_FAILURE
%18 = call i32 @exit(i32 %17)
unreachable
19: ; preds = %63, %61, %59, %57, %55, %53, %51, %49, %47, %13
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %63, %61, %59, %57, %55, %53, %51, %49, %47, %13
%24 = getelementptr inbounds [128 x i8], [128 x i8]* %5, i64 0, i64 0
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %10
%29 = call i64 @read(i32 %28, i8* %4, i32 1)
%30 = icmp sgt i64 %29, 0
br i1 %30, label %31, label %37
31: ; preds = %23, %31
%32 = load i32, i32* @STDOUT_FILENO
%33 = call i32 @write(i32 %32, i8* %4, i32 1)
%34 = load i32, i32* %10
%35 = call i64 @read(i32 %34, i8* %4, i32 1)
%36 = icmp sgt i64 %35, 0
br i1 %36, label %31, label %37
37: ; preds = %31, %23
%38 = call i32 (...) @getpid()
%39 = call i32 @sprintf(i8* %24, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str.2, i64 0, i64 0), i32 %38)
%40 = load i32, i32* @STDOUT_FILENO
%41 = call i32 @strlen(i8* %24)
%42 = call i32 @write(i32 %40, i8* %24, i32 %41)
%43 = load i32, i32* %10
%44 = call i32 @close(i32 %43)
%45 = load i32, i32* @EXIT_SUCCESS
%46 = call i32 @_exit(i32 %45)
unreachable
47: ; preds = %13
%48 = call i32 (...) @fork()
switch i32 %48, label %49 [
i32 -1, label %19
i32 0, label %23
]
49: ; preds = %47
%50 = call i32 (...) @fork()
switch i32 %50, label %51 [
i32 -1, label %19
i32 0, label %23
]
51: ; preds = %49
%52 = call i32 (...) @fork()
switch i32 %52, label %53 [
i32 -1, label %19
i32 0, label %23
]
53: ; preds = %51
%54 = call i32 (...) @fork()
switch i32 %54, label %55 [
i32 -1, label %19
i32 0, label %23
]
55: ; preds = %53
%56 = call i32 (...) @fork()
switch i32 %56, label %57 [
i32 -1, label %19
i32 0, label %23
]
57: ; preds = %55
%58 = call i32 (...) @fork()
switch i32 %58, label %59 [
i32 -1, label %19
i32 0, label %23
]
59: ; preds = %57
%60 = call i32 (...) @fork()
switch i32 %60, label %61 [
i32 -1, label %19
i32 0, label %23
]
61: ; preds = %59
%62 = call i32 (...) @fork()
switch i32 %62, label %63 [
i32 -1, label %19
i32 0, label %23
]
63: ; preds = %61
%64 = call i32 (...) @fork()
switch i32 %64, label %65 [
i32 -1, label %19
i32 0, label %23
]
65: ; preds = %63
%66 = load i32, i32* %10
%67 = call i32 @close(i32 %66)
%68 = call i32 @sleep(i32 3)
%69 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%70 = load i32, i32* %69
%71 = getelementptr inbounds i8*, i8** %1, i64 1
%72 = load i8*, i8** %71
%73 = call i32 @strlen(i8* %72)
%74 = call i32 @write(i32 %70, i8* %72, i32 %73)
%75 = call i32 @sleep(i32 30)
%76 = load i32, i32* %69
%77 = call i32 @close(i32 %76)
%78 = call i32 @wait(i32* null)
%79 = load i32, i32* @EXIT_SUCCESS
%80 = call i32 @exit(i32 %79)
unreachable
}