#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 *);
scalar_t__ fork();
int /*<<< orphan*/ pipe(int *);
int main(int argc, char *argv[]) {
  int pd[2];
  pipe(pd);
  if (fork()) {
    close(1);
    dup(pd[1]);
    close(pd[0]);
    close(pd[1]);
    execlp(argv[1], argv[1], (char *)NULL);
  } else {
    close(0);
    dup(pd[0]);
    close(pd[0]);
    close(pd[1]);
    execlp(argv[2], argv[2], (char *)NULL);
  }
  return 0;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
cmp    $0x0,%rax
je     11c0 <main+0x70>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1030 <dup@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
jmp    11f8 <main+0xa8>
xor    %edi,%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1030 <dup@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1070 <fork@plt>
test   %rax,%rax
je     1199 <main+0x49>
mov    $0x1,%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1030 <dup@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rbx),%rdi
jmp    11bf <main+0x6f>
xor    %edi,%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
call   1030 <dup@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x10(%rbx),%rdi
mov    %rdi,%rsi
xor    %edx,%edx
call   1060 <execlp@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%8 = call i32 @pipe(i32* %7)
%9 = call i64 (...) @fork()
%10 = icmp ne i64 %9, 0
br i1 %10, label %11, label %29
11: ; preds = %2
%12 = call i32 @close(i32 1)
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%14 = load i32, i32* %13
%15 = call i32 @dup(i32 %14)
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = load i32, i32* %16
%18 = call i32 @close(i32 %17)
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @close(i32 %20)
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 1
%24 = load i8*, i8** %23
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = call i32 @execlp(i8* %24, i8* %27, i8* null)
br label %47
29: ; preds = %2
%30 = call i32 @close(i32 0)
%31 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%32 = load i32, i32* %31
%33 = call i32 @dup(i32 %32)
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @close(i32 %35)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%38 = load i32, i32* %37
%39 = call i32 @close(i32 %38)
%40 = load i8**, i8*** %5
%41 = getelementptr inbounds i8*, i8** %40, i64 2
%42 = load i8*, i8** %41
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 2
%45 = load i8*, i8** %44
%46 = call i32 @execlp(i8* %42, i8* %45, i8* null)
br label %47
47: ; preds = %29, %11
ret i32 0
}

LLVM IR (-O2):
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 = call i64 (...) @fork()
%8 = icmp eq i64 %7, 0
br i1 %8, label %21, label %9
9: ; preds = %2
%10 = call i32 @close(i32 1)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @dup(i32 %12)
%14 = load i32, i32* %5
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %11
%17 = call i32 @close(i32 %16)
%18 = getelementptr inbounds i8*, i8** %1, i64 1
%19 = load i8*, i8** %18
%20 = call i32 @execlp(i8* %19, i8* %19, i8* null)
br label %33
21: ; preds = %2
%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 = getelementptr inbounds i8*, i8** %1, i64 2
%31 = load i8*, i8** %30
%32 = call i32 @execlp(i8* %31, i8* %31, i8* null)
br label %33
33: ; preds = %21, %9
ret i32 0
}