#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*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ close(int);
int dup(int /*<<< orphan*/);
int /*<<< orphan*/ dup2(int, int /*<<< orphan*/);
int /*<<< orphan*/ execute(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ wait(int *);
int pipe_of_wish(char *command1[], char *command2[]) {
  int fds[2];
  pipe(fds);
  int pid;
  int stdout_cpy, stdin_cpy;
  if (!(pid = fork())) {
    close(fds[0]);
    stdout_cpy = dup(STDOUT_FILENO);
    dup2(fds[1], STDOUT_FILENO);
    exit(execute(command1[0], command1));
  } else {
    close(fds[1]);
    int status;
    wait(&status);
    stdin_cpy = dup(STDIN_FILENO);
    dup2(fds[0], STDIN_FILENO);
    execute(command2[0], command2);
    close(fds[0]);
    dup2(stdin_cpy, STDIN_FILENO);
    close(stdin_cpy);
    return status;
  }
}


x86 assembly (clang, -O0):
<pipe_of_wish>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1070 <pipe@plt>
mov    $0x0,%al
call   10a0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmp    $0x0,%eax
jne    11ed <pipe_of_wish+0x6d>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    0x2e35(%rip),%rax
mov    (%rax),%edi
call   1040 <dup@plt>
mov    %eax,-0x20(%rbp)
mov    -0x14(%rbp),%edi
mov    0x2e21(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%rdi
mov    -0x8(%rbp),%rsi
call   1050 <execute@plt>
mov    %eax,%edi
call   1080 <exit@plt>
mov    -0x14(%rbp),%edi
call   1060 <close@plt>
lea    -0x28(%rbp),%rdi
call   1090 <wait@plt>
mov    0x2dd3(%rip),%rax
mov    (%rax),%edi
call   1040 <dup@plt>
mov    %eax,-0x24(%rbp)
mov    -0x18(%rbp),%edi
mov    0x2dbf(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
mov    -0x10(%rbp),%rsi
call   1050 <execute@plt>
mov    -0x18(%rbp),%edi
call   1060 <close@plt>
mov    -0x24(%rbp),%edi
mov    0x2d96(%rip),%rax
mov    (%rax),%esi
call   1030 <dup2@plt>
mov    -0x24(%rbp),%edi
call   1060 <close@plt>
mov    -0x28(%rbp),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<pipe_of_wish>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
mov    %rdi,%r14
lea    0x4(%rsp),%rdi
call   1070 <pipe@plt>
xor    %eax,%eax
call   10a0 <fork@plt>
test   %eax,%eax
je     1205 <pipe_of_wish+0x85>
mov    0x8(%rsp),%edi
call   1060 <close@plt>
lea    0xc(%rsp),%rdi
call   1090 <wait@plt>
mov    0x2e1b(%rip),%r14
mov    (%r14),%edi
call   1040 <dup@plt>
mov    %eax,%ebp
mov    0x4(%rsp),%edi
mov    (%r14),%esi
call   1030 <dup2@plt>
mov    (%rbx),%rdi
mov    %rbx,%rsi
call   1050 <execute@plt>
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    (%r14),%esi
mov    %ebp,%edi
call   1030 <dup2@plt>
mov    %ebp,%edi
call   1060 <close@plt>
mov    0xc(%rsp),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x4(%rsp),%edi
call   1060 <close@plt>
mov    0x2ddb(%rip),%rbx
mov    (%rbx),%edi
call   1040 <dup@plt>
mov    0x8(%rsp),%edi
mov    (%rbx),%esi
call   1030 <dup2@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1050 <execute@plt>
mov    %eax,%edi
call   1080 <exit@plt>

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

LLVM IR (-O2):
@STDOUT_FILENO = global i32 0
@STDIN_FILENO = global i32 0
define i32 @pipe_of_wish(i8** %0, i8** %1) {
%3 = alloca [2 x i32]
%4 = alloca i32
%5 = bitcast [2 x i32]* %3 to i8*
%6 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%7 = call i32 @pipe(i32* %6)
%8 = call i32 (...) @fork()
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %22
10: ; preds = %2
%11 = load i32, i32* %6
%12 = call i32 @close(i32 %11)
%13 = load i32, i32* @STDOUT_FILENO
%14 = call i32 @dup(i32 %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%16 = load i32, i32* %15
%17 = load i32, i32* @STDOUT_FILENO
%18 = call i32 @dup2(i32 %16, i32 %17)
%19 = load i8*, i8** %0
%20 = call i32 @execute(i8* %19, i8** %0)
%21 = call i32 @exit(i32 %20)
unreachable
22: ; preds = %2
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%24 = load i32, i32* %23
%25 = call i32 @close(i32 %24)
%26 = bitcast i32* %4 to i8*
%27 = call i32 @wait(i32* %4)
%28 = load i32, i32* @STDIN_FILENO
%29 = call i32 @dup(i32 %28)
%30 = load i32, i32* %6
%31 = load i32, i32* @STDIN_FILENO
%32 = call i32 @dup2(i32 %30, i32 %31)
%33 = load i8*, i8** %1
%34 = call i32 @execute(i8* %33, i8** %1)
%35 = load i32, i32* %6
%36 = call i32 @close(i32 %35)
%37 = load i32, i32* @STDIN_FILENO
%38 = call i32 @dup2(i32 %29, i32 %37)
%39 = call i32 @close(i32 %29)
%40 = load i32, i32* %4
ret i32 %40
}