#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*/ dup2(int, int);
int /*<<< orphan*/ exit(int);
int fork();
char *malloc(size_t);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ strcat(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
int strlen(char *);
int /*<<< orphan*/ system(char *);
int main(int argc, char **argv) {
  int fds[2];
  pipe(fds);
  int pid = fork();
  if (pid == -1) {
    perror("fork");
    exit(-1);
  } else if (pid == 0) {
    char *arg1 = argv[3];
    char *arg2 = argv[4];
    size_t len = strlen(arg1) + strlen(arg2) + 2;
    char *arg = malloc(len);
    strcpy(arg, arg1);
    strcat(arg, " ");
    strcat(arg, arg2);
    close(fds[1]);
    dup2(fds[0], 0);
    system(arg);
  } else {
    char *arg1 = argv[1];
    char *arg2 = argv[2];
    size_t len = strlen(arg1) + strlen(arg2) + 2;
    char *arg = malloc(len);
    strcpy(arg, arg1);
    strcat(arg, " ");
    strcat(arg, arg2);
    close(fds[0]);
    dup2(fds[1], 1);
    system(arg);
  }
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
lea    -0x18(%rbp),%rdi
call   1080 <pipe@plt>
mov    $0x0,%al
call   10d0 <fork@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0xffffffff,-0x1c(%rbp)
jne    11f9 <main+0x49>
lea    0xe16(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>
cmpl   $0x0,-0x1c(%rbp)
jne    1297 <main+0xe7>
mov    -0x10(%rbp),%rax
mov    0x18(%rax),%rax
mov    %rax,-0x28(%rbp)
mov    -0x10(%rbp),%rax
mov    0x20(%rax),%rax
mov    %rax,-0x30(%rbp)
mov    -0x28(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x64(%rbp)
mov    -0x30(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x64(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x40(%rbp)
mov    -0x40(%rbp),%rdi
mov    -0x28(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x40(%rbp),%rdi
lea    0xda0(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x40(%rbp),%rdi
mov    -0x30(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x14(%rbp),%edi
call   1070 <close@plt>
mov    -0x18(%rbp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    -0x40(%rbp),%rdi
call   1050 <system@plt>
jmp    1329 <main+0x179>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x48(%rbp)
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rax
mov    %rax,-0x50(%rbp)
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x68(%rbp)
mov    -0x50(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,%ecx
mov    -0x68(%rbp),%eax
add    %ecx,%eax
add    $0x2,%eax
cltq
mov    %rax,-0x58(%rbp)
mov    -0x58(%rbp),%rdi
call   1090 <malloc@plt>
mov    %rax,-0x60(%rbp)
mov    -0x60(%rbp),%rdi
mov    -0x48(%rbp),%rsi
call   1030 <strcpy@plt>
mov    -0x60(%rbp),%rdi
lea    0xd0c(%rip),%rsi
call   10b0 <strcat@plt>
mov    -0x60(%rbp),%rdi
mov    -0x50(%rbp),%rsi
call   10b0 <strcat@plt>
mov    -0x18(%rbp),%edi
call   1070 <close@plt>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1060 <dup2@plt>
mov    -0x60(%rbp),%rdi
call   1050 <system@plt>
jmp    132e <main+0x17e>
mov    -0x4(%rbp),%eax
add    $0x70,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
lea    0x8(%rsp),%rdi
call   1080 <pipe@plt>
xor    %eax,%eax
call   10d0 <fork@plt>
test   %eax,%eax
je     123d <main+0x8d>
cmp    $0xffffffff,%eax
je     12b4 <main+0x104>
mov    0x8(%rbx),%r15
mov    0x10(%rbx),%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xdef(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    0x8(%rsp),%edi
call   1070 <close@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
jmp    129b <main+0xeb>
mov    0x18(%rbx),%r15
mov    0x20(%rbx),%r14
mov    %r15,%rdi
call   1040 <strlen@plt>
mov    %eax,%ebx
mov    %r14,%rdi
call   1040 <strlen@plt>
add    %ebx,%eax
add    $0x2,%eax
movslq %eax,%rdi
call   1090 <malloc@plt>
mov    %rax,%rbx
mov    %rax,%rdi
mov    %r15,%rsi
call   1030 <strcpy@plt>
lea    0xd8c(%rip),%rsi
mov    %rbx,%rdi
call   10b0 <strcat@plt>
mov    %rbx,%rdi
mov    %r14,%rsi
call   10b0 <strcat@plt>
mov    0xc(%rsp),%edi
call   1070 <close@plt>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1060 <dup2@plt>
mov    %rbx,%rdi
call   1050 <system@plt>
xor    %eax,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xd45(%rip),%rdi
call   10a0 <perror@plt>
mov    $0xffffffff,%edi
call   10c0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"fork\00"
@.str.1 = [2 x i8] c" \00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i32]
%7 = alloca i32
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i64
%11 = alloca i8*
%12 = alloca i8*
%13 = alloca i8*
%14 = alloca i64
%15 = alloca i8*
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = call i32 (...) @fork()
store i32 %18, i32* %7
%19 = load i32, i32* %7
%20 = icmp eq i32 %19, -1
br i1 %20, label %21, label %24
21: ; preds = %2
%22 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%23 = call i32 @exit(i32 -1)
unreachable
24: ; preds = %2
%25 = load i32, i32* %7
%26 = icmp eq i32 %25, 0
br i1 %26, label %27, label %59
27: ; preds = %24
%28 = load i8**, i8*** %5
%29 = getelementptr inbounds i8*, i8** %28, i64 3
%30 = load i8*, i8** %29
store i8* %30, i8** %8
%31 = load i8**, i8*** %5
%32 = getelementptr inbounds i8*, i8** %31, i64 4
%33 = load i8*, i8** %32
store i8* %33, i8** %9
%34 = load i8*, i8** %8
%35 = call i32 @strlen(i8* %34)
%36 = load i8*, i8** %9
%37 = call i32 @strlen(i8* %36)
%38 = add nsw i32 %35, %37
%39 = add nsw i32 %38, 2
%40 = sext i32 %39 to i64
store i64 %40, i64* %10
%41 = load i64, i64* %10
%42 = call i8* @malloc(i64 %41)
store i8* %42, i8** %11
%43 = load i8*, i8** %11
%44 = load i8*, i8** %8
%45 = call i32 @strcpy(i8* %43, i8* %44)
%46 = load i8*, i8** %11
%47 = call i32 @strcat(i8* %46, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%48 = load i8*, i8** %11
%49 = load i8*, i8** %9
%50 = call i32 @strcat(i8* %48, i8* %49)
%51 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%52 = load i32, i32* %51
%53 = call i32 @close(i32 %52)
%54 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%55 = load i32, i32* %54
%56 = call i32 @dup2(i32 %55, i32 0)
%57 = load i8*, i8** %11
%58 = call i32 @system(i8* %57)
br label %91
59: ; preds = %24
%60 = load i8**, i8*** %5
%61 = getelementptr inbounds i8*, i8** %60, i64 1
%62 = load i8*, i8** %61
store i8* %62, i8** %12
%63 = load i8**, i8*** %5
%64 = getelementptr inbounds i8*, i8** %63, i64 2
%65 = load i8*, i8** %64
store i8* %65, i8** %13
%66 = load i8*, i8** %12
%67 = call i32 @strlen(i8* %66)
%68 = load i8*, i8** %13
%69 = call i32 @strlen(i8* %68)
%70 = add nsw i32 %67, %69
%71 = add nsw i32 %70, 2
%72 = sext i32 %71 to i64
store i64 %72, i64* %14
%73 = load i64, i64* %14
%74 = call i8* @malloc(i64 %73)
store i8* %74, i8** %15
%75 = load i8*, i8** %15
%76 = load i8*, i8** %12
%77 = call i32 @strcpy(i8* %75, i8* %76)
%78 = load i8*, i8** %15
%79 = call i32 @strcat(i8* %78, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%80 = load i8*, i8** %15
%81 = load i8*, i8** %13
%82 = call i32 @strcat(i8* %80, i8* %81)
%83 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%84 = load i32, i32* %83
%85 = call i32 @close(i32 %84)
%86 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%87 = load i32, i32* %86
%88 = call i32 @dup2(i32 %87, i32 1)
%89 = load i8*, i8** %15
%90 = call i32 @system(i8* %89)
br label %91
91: ; preds = %59, %27
br label %92
92: ; preds = %91
%93 = load i32, i32* %3
ret i32 %93
}

LLVM IR (-O2):
@.str = [5 x i8] c"fork\00"
@.str.1 = [2 x i8] c" \00"
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 i32 (...) @fork()
switch i32 %7, label %30 [
i32 -1, label %8
i32 0, label %11
]
8: ; preds = %2
%9 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
%10 = call i32 @exit(i32 -1)
unreachable
11: ; preds = %2
%12 = getelementptr inbounds i8*, i8** %1, i64 3
%13 = load i8*, i8** %12
%14 = getelementptr inbounds i8*, i8** %1, i64 4
%15 = load i8*, i8** %14
%16 = call i32 @strlen(i8* %13)
%17 = call i32 @strlen(i8* %15)
%18 = add i32 %16, 2
%19 = add i32 %18, %17
%20 = sext i32 %19 to i64
%21 = call i8* @malloc(i64 %20)
%22 = call i32 @strcpy(i8* %21, i8* %13)
%23 = call i32 @strcat(i8* %21, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%24 = call i32 @strcat(i8* %21, i8* %15)
%25 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%26 = load i32, i32* %25
%27 = call i32 @close(i32 %26)
%28 = load i32, i32* %5
%29 = call i32 @dup2(i32 %28, i32 0)
br label %49
30: ; preds = %2
%31 = getelementptr inbounds i8*, i8** %1, i64 1
%32 = load i8*, i8** %31
%33 = getelementptr inbounds i8*, i8** %1, i64 2
%34 = load i8*, i8** %33
%35 = call i32 @strlen(i8* %32)
%36 = call i32 @strlen(i8* %34)
%37 = add i32 %35, 2
%38 = add i32 %37, %36
%39 = sext i32 %38 to i64
%40 = call i8* @malloc(i64 %39)
%41 = call i32 @strcpy(i8* %40, i8* %32)
%42 = call i32 @strcat(i8* %40, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @strcat(i8* %40, i8* %34)
%44 = load i32, i32* %5
%45 = call i32 @close(i32 %44)
%46 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%47 = load i32, i32* %46
%48 = call i32 @dup2(i32 %47, i32 1)
br label %49
49: ; preds = %11, %30
%50 = phi i8* [ %21, %11 ], [ %40, %30 ]
%51 = call i32 @system(i8* %50)
ret i32 0
}