#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*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execlp(char *, char *, char *, int /*<<< orphan*/ *);
int fork();
int /*<<< orphan*/ pipe(int *);
void main(int args, char **argv) {
  int fd[2];
  pipe(fd);
  pid_t pid = fork();
  if (pid == -1) {
  } else if (pid == 0) {
    close(fd[0]);
    dup2(fd[1], 1);
    execlp(argv[3], argv[3], argv[4], NULL);
  } else {
    close(fd[1]);
    dup2(fd[0], 0);
    execlp(argv[1], argv[1], argv[2], NULL);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1070 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    1181 <main+0x31>
jmp    11fe <main+0xae>
cmpl   $0x0,-0x1c(%rbp)
jne    11c6 <main+0x76>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%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   1060 <execlp@plt>
jmp    11f9 <main+0xa9>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%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   1060 <execlp@plt>
jmp    11fe <main+0xae>
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>
cmp    $0xffffffff,%eax
je     11b9 <main+0x69>
test   %eax,%eax
jne    1193 <main+0x43>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x18(%rbx),%rdi
mov    0x20(%rbx),%rdx
jmp    11af <main+0x5f>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x8(%rbx),%rdi
mov    0x10(%rbx),%rdx
mov    %rdi,%rsi
xor    %ecx,%ecx
call   1060 <execlp@plt>
add    $0x10,%rsp
pop    %rbx
ret

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

LLVM IR (-O2):
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 = call i32 (...) @fork()
switch i32 %7, label %19 [
i32 -1, label %30
i32 0, label %8
]
8: ; preds = %2
%9 = load i32, i32* %5
%10 = call i32 @close(i32 %9)
%11 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%12 = load i32, i32* %11
%13 = call i32 @dup2(i32 %12, i32 1)
%14 = getelementptr inbounds i8*, i8** %1, i64 3
%15 = load i8*, i8** %14
%16 = getelementptr inbounds i8*, i8** %1, i64 4
%17 = load i8*, i8** %16
%18 = call i32 @execlp(i8* %15, i8* %15, i8* %17, i32* null)
br label %30
19: ; preds = %2
%20 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%21 = load i32, i32* %20
%22 = call i32 @close(i32 %21)
%23 = load i32, i32* %5
%24 = call i32 @dup2(i32 %23, i32 0)
%25 = getelementptr inbounds i8*, i8** %1, i64 1
%26 = load i8*, i8** %25
%27 = getelementptr inbounds i8*, i8** %1, i64 2
%28 = load i8*, i8** %27
%29 = call i32 @execlp(i8* %26, i8* %26, i8* %28, i32* null)
br label %30
30: ; preds = %2, %8, %19
ret void
}