#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*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ perror(char *);
int pipe(int *);
int /*<<< orphan*/ printf(char *, ...);
int /*<<< orphan*/ wait(int, int /*<<< orphan*/, int /*<<< orphan*/);
main(int argc, char *argv[]) {
  int pid1, pid2;
  int pipeID[2];
  int status;
  if ((status = pipe(pipeID)) == -1) {
    perror("Bad pipe");
    exit(-1);
  }
  if ((pid1 = fork()) == -1) {
    perror("Bad fork");
    exit(-1);
  }
  if (pid1 == 0) {
    printf("The first child is starting: %s %s\n", argv[3], argv[4]);
    close(0);
    dup(pipeID[0]);
    close(pipeID[0]);
    close(pipeID[1]);
    execlp(argv[3], argv[3], argv[4], 0);
    perror("Execl returned");
    exit(-1);
  }
  if ((pid2 = fork()) == -1) {
    perror("Bad fork");
    exit(-1);
  }
  if (pid2 == 0) {
    printf("The second child is starting: %s %s\n", argv[1], argv[2]);
    close(1);
    dup(pipeID[1]);
    close(pipeID[0]);
    close(pipeID[1]);
    execlp(argv[1], argv[1], argv[2], 0);
    perror("Execl returned");
    exit(-1);
  }
  close(pipeID[0]);
  close(pipeID[1]);
  wait(pid1, 0, 0);
  wait(pid2, 0, 0);
  printf("The parent is exiting\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x20(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x24(%rbp)
cmp    $0xffffffff,%eax
jne    11ca <main+0x3a>
lea    0xe45(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
jne    11f3 <main+0x63>
lea    0xe25(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x14(%rbp)
jne    126f <main+0xdf>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
lea    0xdfe(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %edi,%edi
call   1050 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <dup@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rdx
xor    %ecx,%ecx
call   1090 <execlp@plt>
lea    0xdd6(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
jne    1298 <main+0x108>
lea    0xd80(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
cmpl   $0x0,-0x18(%rbp)
jne    1317 <main+0x187>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
lea    0xd8c(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
mov    $0x1,%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1040 <dup@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdx
xor    %ecx,%ecx
call   1090 <execlp@plt>
lea    0xd2e(%rip),%rdi
call   1070 <perror@plt>
mov    $0xffffffff,%edi
call   1080 <exit@plt>
mov    -0x20(%rbp),%edi
call   1050 <close@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <wait@plt>
mov    -0x18(%rbp),%edi
xor    %edx,%edx
mov    %edx,%esi
call   10a0 <wait@plt>
lea    0xd24(%rip),%rdi
mov    $0x0,%al
call   1030 <printf@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
lea    0x8(%rsp),%rdi
call   1070 <pipe@plt>
cmp    $0xffffffff,%eax
je     122d <main+0x8d>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     1239 <main+0x99>
mov    %eax,%ebp
cmp    $0xffffffff,%eax
je     1221 <main+0x81>
xor    %eax,%eax
call   10c0 <fork@plt>
test   %eax,%eax
je     127b <main+0xdb>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     1221 <main+0x81>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    %ebp,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <wait@plt>
mov    %ebx,%edi
xor    %esi,%esi
xor    %edx,%edx
call   10b0 <wait@plt>
lea    0xe59(%rip),%rdi
call   1030 <puts@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
lea    0xde1(%rip),%rdi
jmp    12cf <main+0x12f>
lea    0xdcc(%rip),%rdi
jmp    12cf <main+0x12f>
mov    0x18(%r14),%rsi
mov    0x20(%r14),%rdx
lea    0xdca(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
xor    %edi,%edi
call   1060 <close@plt>
mov    0x8(%rsp),%edi
call   1050 <dup@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x18(%r14),%rdi
mov    0x20(%r14),%rdx
jmp    12be <main+0x11e>
mov    0x8(%r14),%rsi
mov    0x10(%r14),%rdx
lea    0xdbb(%rip),%rdi
xor    %eax,%eax
call   1040 <printf@plt>
mov    $0x1,%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1050 <dup@plt>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
mov    0xc(%rsp),%edi
call   1060 <close@plt>
mov    0x8(%r14),%rdi
mov    0x10(%r14),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   10a0 <execlp@plt>
lea    0xd67(%rip),%rdi
call   1080 <perror@plt>
mov    $0xffffffff,%edi
call   1090 <exit@plt>

LLVM IR (-O0):
@.str = [9 x i8] c"Bad pipe\00"
@.str.1 = [9 x i8] c"Bad fork\00"
@.str.2 = [36 x i8] c"The first child is starting: %s %s\0A\00"
@.str.3 = [15 x i8] c"Execl returned\00"
@.str.4 = [37 x i8] c"The second child is starting: %s %s\0A\00"
@.str.5 = [23 x i8] c"The parent is exiting\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca i32
%6 = alloca i32
%7 = alloca [2 x i32]
%8 = alloca i32
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
store i32 %10, i32* %8
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %15
12: ; preds = %2
%13 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 -1)
unreachable
15: ; preds = %2
%16 = call i32 (...) @fork()
store i32 %16, i32* %5
%17 = icmp eq i32 %16, -1
br i1 %17, label %18, label %21
18: ; preds = %15
%19 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%20 = call i32 @exit(i32 -1)
unreachable
21: ; preds = %15
%22 = load i32, i32* %5
%23 = icmp eq i32 %22, 0
br i1 %23, label %24, label %54
24: ; preds = %21
%25 = load i8**, i8*** %4
%26 = getelementptr inbounds i8*, i8** %25, i64 3
%27 = load i8*, i8** %26
%28 = load i8**, i8*** %4
%29 = getelementptr inbounds i8*, i8** %28, i64 4
%30 = load i8*, i8** %29
%31 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %27, i8* %30)
%32 = call i32 @close(i32 0)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @dup(i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @close(i32 %40)
%42 = load i8**, i8*** %4
%43 = getelementptr inbounds i8*, i8** %42, i64 3
%44 = load i8*, i8** %43
%45 = load i8**, i8*** %4
%46 = getelementptr inbounds i8*, i8** %45, i64 3
%47 = load i8*, i8** %46
%48 = load i8**, i8*** %4
%49 = getelementptr inbounds i8*, i8** %48, i64 4
%50 = load i8*, i8** %49
%51 = call i32 @execlp(i8* %44, i8* %47, i8* %50, i32 0)
%52 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%53 = call i32 @exit(i32 -1)
unreachable
54: ; preds = %21
%55 = call i32 (...) @fork()
store i32 %55, i32* %6
%56 = icmp eq i32 %55, -1
br i1 %56, label %57, label %60
57: ; preds = %54
%58 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%59 = call i32 @exit(i32 -1)
unreachable
60: ; preds = %54
%61 = load i32, i32* %6
%62 = icmp eq i32 %61, 0
br i1 %62, label %63, label %93
63: ; preds = %60
%64 = load i8**, i8*** %4
%65 = getelementptr inbounds i8*, i8** %64, i64 1
%66 = load i8*, i8** %65
%67 = load i8**, i8*** %4
%68 = getelementptr inbounds i8*, i8** %67, i64 2
%69 = load i8*, i8** %68
%70 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %66, i8* %69)
%71 = call i32 @close(i32 1)
%72 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%73 = load i32, i32* %72
%74 = call i32 @dup(i32 %73)
%75 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%76 = load i32, i32* %75
%77 = call i32 @close(i32 %76)
%78 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%79 = load i32, i32* %78
%80 = call i32 @close(i32 %79)
%81 = load i8**, i8*** %4
%82 = getelementptr inbounds i8*, i8** %81, i64 1
%83 = load i8*, i8** %82
%84 = load i8**, i8*** %4
%85 = getelementptr inbounds i8*, i8** %84, i64 1
%86 = load i8*, i8** %85
%87 = load i8**, i8*** %4
%88 = getelementptr inbounds i8*, i8** %87, i64 2
%89 = load i8*, i8** %88
%90 = call i32 @execlp(i8* %83, i8* %86, i8* %89, i32 0)
%91 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%92 = call i32 @exit(i32 -1)
unreachable
93: ; preds = %60
%94 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%95 = load i32, i32* %94
%96 = call i32 @close(i32 %95)
%97 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%98 = load i32, i32* %97
%99 = call i32 @close(i32 %98)
%100 = load i32, i32* %5
%101 = call i32 @wait(i32 %100, i32 0, i32 0)
%102 = load i32, i32* %6
%103 = call i32 @wait(i32 %102, i32 0, i32 0)
%104 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.5, i64 0, i64 0))
ret i32 0
}

LLVM IR (-O2):
@.str = [9 x i8] c"Bad pipe\00"
@.str.1 = [9 x i8] c"Bad fork\00"
@.str.2 = [36 x i8] c"The first child is starting: %s %s\0A\00"
@.str.3 = [15 x i8] c"Execl returned\00"
@.str.4 = [37 x i8] c"The second child is starting: %s %s\0A\00"
@str = [22 x i8] c"The parent is exiting\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = bitcast [2 x i32]* %3 to i8*
%5 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%6 = call i32 @pipe(i32* %5)
%7 = icmp eq i32 %6, -1
br i1 %7, label %8, label %11
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = call i32 (...) @fork()
switch i32 %12, label %35 [
i32 -1, label %13
i32 0, label %16
]
13: ; preds = %11
%14 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%15 = call i32 @exit(i32 -1)
unreachable
16: ; preds = %11
%17 = getelementptr inbounds i8*, i8** %1, i64 3
%18 = load i8*, i8** %17
%19 = getelementptr inbounds i8*, i8** %1, i64 4
%20 = load i8*, i8** %19
%21 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([36 x i8], [36 x i8]* @.str.2, i64 0, i64 0), i8* %18, i8* %20)
%22 = call i32 @close(i32 0)
%23 = load i32, i32* %5
%24 = call i32 @dup(i32 %23)
%25 = load i32, i32* %5
%26 = call i32 @close(i32 %25)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = load i8*, i8** %17
%31 = load i8*, i8** %19
%32 = call i32 @execlp(i8* %30, i8* %30, i8* %31, i32 0)
%33 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%34 = call i32 @exit(i32 -1)
unreachable
35: ; preds = %11
%36 = call i32 (...) @fork()
switch i32 %36, label %59 [
i32 -1, label %37
i32 0, label %40
]
37: ; preds = %35
%38 = call i32 @perror(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0))
%39 = call i32 @exit(i32 -1)
unreachable
40: ; preds = %35
%41 = getelementptr inbounds i8*, i8** %1, i64 1
%42 = load i8*, i8** %41
%43 = getelementptr inbounds i8*, i8** %1, i64 2
%44 = load i8*, i8** %43
%45 = call i32 (i8*, ...) @printf(i8* dereferenceable(1) getelementptr inbounds ([37 x i8], [37 x i8]* @.str.4, i64 0, i64 0), i8* %42, i8* %44)
%46 = call i32 @close(i32 1)
%47 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%48 = load i32, i32* %47
%49 = call i32 @dup(i32 %48)
%50 = load i32, i32* %5
%51 = call i32 @close(i32 %50)
%52 = load i32, i32* %47
%53 = call i32 @close(i32 %52)
%54 = load i8*, i8** %41
%55 = load i8*, i8** %43
%56 = call i32 @execlp(i8* %54, i8* %54, i8* %55, i32 0)
%57 = call i32 @perror(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.3, i64 0, i64 0))
%58 = call i32 @exit(i32 -1)
unreachable
59: ; preds = %35
%60 = load i32, i32* %5
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = call i32 @wait(i32 %12, i32 0, i32 0)
%66 = call i32 @wait(i32 %36, i32 0, i32 0)
%67 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([22 x i8], [22 x i8]* @str, i64 0, i64 0))
ret i32 0
}