#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ EXIT_FAILURE;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int errno;
int /*<<< orphan*/ execlp(char *, char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int pipe(int *);
int /*<<< orphan*/ printf(char *, char *);
char *strerror(int);
void main(int args, char *argv[]) {
  int pipeD[2], en;
  int stat = pipe(pipeD);
  if (stat == -1) {
    en = errno;
    printf("pipe:\t%s\n", strerror(en));
    exit(EXIT_FAILURE);
  }
  pid_t pid = fork();
  if (pid < 0) {
    en = errno;
    printf("fork\t%s\n", strerror(en));
    exit(EXIT_FAILURE);
  } else if (pid == 0) {
    close(pipeD[1]);
    dup2(pipeD[0], 0);
    execlp(argv[3], argv[3], argv[4], (char *)NULL);
  } else {
    close(pipeD[0]);
    dup2(pipeD[1], 1);
    execlp(argv[1], argv[1], argv[2], (char *)NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1060 <pipe@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    11d6 <main+0x56>
mov    0x2e34(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe3d(%rip),%rdi
call   1040 <printf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jge    121d <main+0x9d>
mov    0x2ded(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x1c(%rbp)
mov    -0x1c(%rbp),%edi
call   1090 <strerror@plt>
mov    %rax,%rsi
lea    0xe00(%rip),%rdi
call   1040 <printf@plt>
mov    0x2dc2(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>
cmpq   $0x0,-0x28(%rbp)
jne    1260 <main+0xe0>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@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    %eax,%eax
mov    %eax,%ecx
call   1080 <execlp@plt>
jmp    1296 <main+0x116>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@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    %eax,%eax
mov    %eax,%ecx
call   1080 <execlp@plt>
jmp    129b <main+0x11b>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
call   1060 <pipe@plt>
cmp    $0xffffffff,%eax
je     11f2 <main+0x72>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %rax,%rax
js     1209 <main+0x89>
je     11c6 <main+0x46>
mov    0x8(%rsp),%edi
call   1050 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rdx
jmp    11e2 <main+0x62>
mov    0xc(%rsp),%edi
call   1050 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x18(%rbx),%rdi
mov    0x20(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1080 <execlp@plt>
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2de7(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf9(%rip),%rdi
jmp    121e <main+0x9e>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdec(%rip),%rdi
mov    %rax,%rsi
call   1040 <printf@plt>
mov    0x2dab(%rip),%rax
mov    (%rax),%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@errno = global i32 0
@.str = [10 x i8] c"pipe:\09%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"fork\09%s\0A\00"
define void @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i8**
%5 = alloca [2 x i32]
%6 = alloca i32
%7 = alloca i32
%8 = alloca i64
store i32 %0, i32* %3
store i8** %1, i8*** %4
%9 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%10 = call i32 @pipe(i32* %9)
store i32 %10, i32* %7
%11 = load i32, i32* %7
%12 = icmp eq i32 %11, -1
br i1 %12, label %13, label %20
13: ; preds = %2
%14 = load i32, i32* @errno
store i32 %14, i32* %6
%15 = load i32, i32* %6
%16 = call i8* @strerror(i32 %15)
%17 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %16)
%18 = load i32, i32* @EXIT_FAILURE
%19 = call i32 @exit(i32 %18)
unreachable
20: ; preds = %2
%21 = call i64 (...) @fork()
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp slt i64 %22, 0
br i1 %23, label %24, label %31
24: ; preds = %20
%25 = load i32, i32* @errno
store i32 %25, i32* %6
%26 = load i32, i32* %6
%27 = call i8* @strerror(i32 %26)
%28 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %27)
%29 = load i32, i32* @EXIT_FAILURE
%30 = call i32 @exit(i32 %29)
unreachable
31: ; preds = %20
%32 = load i64, i64* %8
%33 = icmp eq i64 %32, 0
br i1 %33, label %34, label %51
34: ; preds = %31
%35 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%36 = load i32, i32* %35
%37 = call i32 @close(i32 %36)
%38 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%39 = load i32, i32* %38
%40 = call i32 @dup2(i32 %39, i32 0)
%41 = load i8**, i8*** %4
%42 = getelementptr inbounds i8*, i8** %41, i64 3
%43 = load i8*, i8** %42
%44 = load i8**, i8*** %4
%45 = getelementptr inbounds i8*, i8** %44, i64 3
%46 = load i8*, i8** %45
%47 = load i8**, i8*** %4
%48 = getelementptr inbounds i8*, i8** %47, i64 4
%49 = load i8*, i8** %48
%50 = call i32 @execlp(i8* %43, i8* %46, i8* %49, i8* null)
br label %68
51: ; preds = %31
%52 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 0
%53 = load i32, i32* %52
%54 = call i32 @close(i32 %53)
%55 = getelementptr inbounds [2 x i32], [2 x i32]* %5, i64 0, i64 1
%56 = load i32, i32* %55
%57 = call i32 @dup2(i32 %56, i32 1)
%58 = load i8**, i8*** %4
%59 = getelementptr inbounds i8*, i8** %58, i64 1
%60 = load i8*, i8** %59
%61 = load i8**, i8*** %4
%62 = getelementptr inbounds i8*, i8** %61, i64 1
%63 = load i8*, i8** %62
%64 = load i8**, i8*** %4
%65 = getelementptr inbounds i8*, i8** %64, i64 2
%66 = load i8*, i8** %65
%67 = call i32 @execlp(i8* %60, i8* %63, i8* %66, i8* null)
br label %68
68: ; preds = %51, %34
br label %69
69: ; preds = %68
ret void
}

LLVM IR (-O2):
@errno = global i32 0
@.str = [10 x i8] c"pipe:\09%s\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [9 x i8] c"fork\09%s\0A\00"
define void @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 %14
8: ; preds = %2
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @printf(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i8* %10)
%12 = load i32, i32* @EXIT_FAILURE
%13 = call i32 @exit(i32 %12)
unreachable
14: ; preds = %2
%15 = call i64 (...) @fork()
%16 = icmp slt i64 %15, 0
br i1 %16, label %17, label %23
17: ; preds = %14
%18 = load i32, i32* @errno
%19 = call i8* @strerror(i32 %18)
%20 = call i32 @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str.1, i64 0, i64 0), i8* %19)
%21 = load i32, i32* @EXIT_FAILURE
%22 = call i32 @exit(i32 %21)
unreachable
23: ; preds = %14
%24 = icmp eq i64 %15, 0
br i1 %24, label %25, label %36
25: ; preds = %23
%26 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%27 = load i32, i32* %26
%28 = call i32 @close(i32 %27)
%29 = load i32, i32* %5
%30 = call i32 @dup2(i32 %29, i32 0)
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8*, i8** %1, i64 4
%34 = load i8*, i8** %33
%35 = call i32 @execlp(i8* %32, i8* %32, i8* %34, i8* null)
br label %47
36: ; preds = %23
%37 = load i32, i32* %5
%38 = call i32 @close(i32 %37)
%39 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%40 = load i32, i32* %39
%41 = call i32 @dup2(i32 %40, i32 1)
%42 = getelementptr inbounds i8*, i8** %1, i64 1
%43 = load i8*, i8** %42
%44 = getelementptr inbounds i8*, i8** %1, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @execlp(i8* %43, i8* %43, i8* %45, i8* null)
br label %47
47: ; preds = %25, %36
ret void
}