#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*/ err(int, char *);
int /*<<< orphan*/ execute(char *, int *, int *);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pipe_or_die(int *);
int /*<<< orphan*/ stderr;
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "No command given.\n");
    exit(1);
  }
  int a2b[2];
  pipe_or_die(a2b);
  int b2a[2];
  pipe_or_die(b2a);
  pid_t pid = fork();
  switch (pid) {
  case -1:
    err(1, "fork(2) failed");
    break;
  case 0:
    execute(argv[1], b2a, a2b);
    break;
  default:
    break;
  }
  execute(argv[2], a2b, b2a);
  return 1;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     119f <main+0x3f>
mov    0x2e59(%rip),%rax
mov    (%rax),%edi
lea    0xe70(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
lea    -0x18(%rbp),%rdi
call   1030 <pipe_or_die@plt>
lea    -0x20(%rbp),%rdi
call   1030 <pipe_or_die@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,-0x24(%rbp)
mov    -0x24(%rbp),%eax
mov    %eax,-0x28(%rbp)
sub    $0xffffffff,%eax
je     11df <main+0x7f>
jmp    11cf <main+0x6f>
mov    -0x28(%rbp),%eax
test   %eax,%eax
je     11f5 <main+0x95>
jmp    120f <main+0xaf>
mov    $0x1,%edi
lea    0xe28(%rip),%rsi
call   1060 <err@plt>
jmp    1214 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
lea    -0x20(%rbp),%rsi
lea    -0x18(%rbp),%rdx
call   1040 <execute@plt>
jmp    1214 <main+0xb4>
jmp    1214 <main+0xb4>
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rdi
lea    -0x18(%rbp),%rsi
lea    -0x20(%rbp),%rdx
call   1040 <execute@plt>
mov    $0x1,%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x10,%rsp
cmp    $0x3,%edi
jne    11cf <main+0x6f>
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
call   1030 <pipe_or_die@plt>
mov    %rsp,%rdi
call   1030 <pipe_or_die@plt>
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     11a2 <main+0x42>
cmp    $0xffffffff,%eax
jne    11b3 <main+0x53>
lea    0xe7d(%rip),%rsi
mov    $0x1,%edi
call   1060 <err@plt>
jmp    11b3 <main+0x53>
mov    0x8(%rbx),%rdi
mov    %rsp,%rsi
lea    0x8(%rsp),%rdx
call   1040 <execute@plt>
mov    0x10(%rbx),%rdi
lea    0x8(%rsp),%rsi
mov    %rsp,%rdx
call   1040 <execute@plt>
mov    $0x1,%eax
add    $0x10,%rsp
pop    %rbx
ret
mov    0x2e0a(%rip),%rax
mov    (%rax),%edi
lea    0xe21(%rip),%rsi
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [19 x i8] c"No command given.\0A\00"
@.str.1 = [15 x i8] c"fork(2) failed\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = load i32, i32* %4
%10 = icmp ne i32 %9, 3
br i1 %10, label %11, label %15
11: ; preds = %2
%12 = load i32, i32* @stderr
%13 = call i32 @fprintf(i32 %12, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%14 = call i32 @exit(i32 1)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i32 @pipe_or_die(i32* %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%19 = call i32 @pipe_or_die(i32* %18)
%20 = call i32 (...) @fork()
store i32 %20, i32* %8
%21 = load i32, i32* %8
switch i32 %21, label %31 [
i32 -1, label %22
i32 0, label %24
]
22: ; preds = %15
%23 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %32
24: ; preds = %15
%25 = load i8**, i8*** %5
%26 = getelementptr inbounds i8*, i8** %25, i64 1
%27 = load i8*, i8** %26
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%29 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%30 = call i32 @execute(i8* %27, i32* %28, i32* %29)
br label %32
31: ; preds = %15
br label %32
32: ; preds = %31, %24, %22
%33 = load i8**, i8*** %5
%34 = getelementptr inbounds i8*, i8** %33, i64 2
%35 = load i8*, i8** %34
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%38 = call i32 @execute(i8* %35, i32* %36, i32* %37)
ret i32 1
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [19 x i8] c"No command given.\0A\00"
@.str.1 = [15 x i8] c"fork(2) failed\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = alloca [2 x i32]
%5 = icmp eq i32 %0, 3
br i1 %5, label %10, label %6
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([19 x i8], [19 x i8]* @.str, i64 0, i64 0))
%9 = tail call i32 @exit(i32 1)
unreachable
10: ; preds = %2
%11 = bitcast [2 x i32]* %3 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 0
%13 = call i32 @pipe_or_die(i32* %12)
%14 = bitcast [2 x i32]* %4 to i8*
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%16 = call i32 @pipe_or_die(i32* %15)
%17 = call i32 (...) @fork()
switch i32 %17, label %24 [
i32 -1, label %18
i32 0, label %20
]
18: ; preds = %10
%19 = call i32 @err(i32 1, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
br label %24
20: ; preds = %10
%21 = getelementptr inbounds i8*, i8** %1, i64 1
%22 = load i8*, i8** %21
%23 = call i32 @execute(i8* %22, i32* %15, i32* %12)
br label %24
24: ; preds = %10, %20, %18
%25 = getelementptr inbounds i8*, i8** %1, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @execute(i8* %26, i32* %12, i32* %15)
ret i32 1
}