#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;
typedef int /*<<< orphan*/ cmd;

/* Variables and functions */
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
scalar_t__ fork();
scalar_t__ pipe(int *);
int /*<<< orphan*/ printf(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char *argv[]) {
  char cmd[20];
  snprintf(cmd, sizeof(cmd), "%s %s", argv[1], argv[2]);
  int fdes[2];
  if (pipe(fdes) == 0) {
    pid_t pid = fork();
    if (pid == 0) {
      dup2(fdes[1], 1);
      close(fdes[0]);
      system(cmd);
    } else {
      dup2(fdes[0], 0);
      close(fdes[1]);
      system(argv[3]);
    }
  } else
    printf("Pipe error\n");
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rcx
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%r8
mov    $0x14,%esi
lea    0xe5a(%rip),%rdx
call   1060 <snprintf@plt>
lea    -0x38(%rbp),%rdi
call   1080 <pipe@plt>
cmp    $0x0,%rax
jne    121b <main+0xab>
mov    $0x0,%al
call   1090 <fork@plt>
mov    %rax,-0x40(%rbp)
cmpq   $0x0,-0x40(%rbp)
jne    11f7 <main+0x87>
mov    -0x34(%rbp),%edi
mov    $0x1,%esi
call   1040 <dup2@plt>
mov    -0x38(%rbp),%edi
call   1070 <close@plt>
lea    -0x30(%rbp),%rdi
call   1030 <system@plt>
jmp    1216 <main+0xa6>
mov    -0x38(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2@plt>
mov    -0x34(%rbp),%edi
call   1070 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rdi
call   1030 <system@plt>
jmp    1227 <main+0xb7>
lea    0xde4(%rip),%rdi
call   1050 <printf@plt>
mov    -0x4(%rbp),%eax
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbx
sub    $0x30,%rsp
mov    %rsi,%rbx
mov    0x8(%rsi),%rcx
mov    0x10(%rsi),%r8
lea    0xe79(%rip),%rdx
lea    0x10(%rsp),%rdi
mov    $0x14,%esi
call   1060 <snprintf@plt>
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
test   %rax,%rax
je     11b3 <main+0x43>
lea    0xe5a(%rip),%rdi
call   1030 <puts@plt>
jmp    11fa <main+0x8a>
xor    %eax,%eax
call   1090 <fork@plt>
test   %rax,%rax
je     11d9 <main+0x69>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1050 <dup2@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x18(%rbx),%rdi
jmp    11f5 <main+0x85>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1050 <dup2@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
lea    0x10(%rsp),%rdi
call   1040 <system@plt>
xor    %eax,%eax
add    $0x30,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [6 x i8] c"%s %s\00"
@.str.1 = [12 x i8] c"Pipe error\0A\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [20 x i8]
%7 = alloca [2 x i32]
%8 = alloca i64
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 1
%12 = load i8*, i8** %11
%13 = load i8**, i8*** %5
%14 = getelementptr inbounds i8*, i8** %13, i64 2
%15 = load i8*, i8** %14
%16 = call i32 @snprintf(i8* %9, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %12, i8* %15)
%17 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%18 = call i64 @pipe(i32* %17)
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %45
20: ; preds = %2
%21 = call i64 (...) @fork()
store i64 %21, i64* %8
%22 = load i64, i64* %8
%23 = icmp eq i64 %22, 0
br i1 %23, label %24, label %33
24: ; preds = %20
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @dup2(i32 %26, i32 1)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds [20 x i8], [20 x i8]* %6, i64 0, i64 0
%32 = call i32 @system(i8* %31)
br label %44
33: ; preds = %20
%34 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%35 = load i32, i32* %34
%36 = call i32 @dup2(i32 %35, i32 0)
%37 = getelementptr inbounds [2 x i32], [2 x i32]* %7, 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 3
%42 = load i8*, i8** %41
%43 = call i32 @system(i8* %42)
br label %44
44: ; preds = %33, %24
br label %47
45: ; preds = %2
%46 = call i32 @printf(i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.1, i64 0, i64 0))
br label %47
47: ; preds = %45, %44
%48 = load i32, i32* %3
ret i32 %48
}

LLVM IR (-O2):
@.str = [6 x i8] c"%s %s\00"
@str = [11 x i8] c"Pipe error\00"
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [20 x i8]
%4 = alloca [2 x i32]
%5 = getelementptr inbounds [20 x i8], [20 x i8]* %3, i64 0, i64 0
%6 = getelementptr inbounds i8*, i8** %1, i64 1
%7 = load i8*, i8** %6
%8 = getelementptr inbounds i8*, i8** %1, i64 2
%9 = load i8*, i8** %8
%10 = call i32 @snprintf(i8* %5, i32 20, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* %7, i8* %9)
%11 = bitcast [2 x i32]* %4 to i8*
%12 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 0
%13 = call i64 @pipe(i32* %12)
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %34
15: ; preds = %2
%16 = call i64 (...) @fork()
%17 = icmp eq i64 %16, 0
br i1 %17, label %18, label %25
18: ; preds = %15
%19 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%20 = load i32, i32* %19
%21 = call i32 @dup2(i32 %20, i32 1)
%22 = load i32, i32* %12
%23 = call i32 @close(i32 %22)
%24 = call i32 @system(i8* %5)
br label %36
25: ; preds = %15
%26 = load i32, i32* %12
%27 = call i32 @dup2(i32 %26, i32 0)
%28 = getelementptr inbounds [2 x i32], [2 x i32]* %4, i64 0, i64 1
%29 = load i32, i32* %28
%30 = call i32 @close(i32 %29)
%31 = getelementptr inbounds i8*, i8** %1, i64 3
%32 = load i8*, i8** %31
%33 = call i32 @system(i8* %32)
br label %36
34: ; preds = %2
%35 = call i32 @puts(i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @str, i64 0, i64 0))
br label %36
36: ; preds = %18, %25, %34
ret i32 0
}