#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*/ EXIT_FAILURE;
int EXIT_SUCCESS;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ pipe(int *);
int /*<<< orphan*/ printf(char *, int);
int /*<<< orphan*/ runDestination(int *, char *);
int /*<<< orphan*/ runSource(int *, char *);
int /*<<< orphan*/ stderr;
int wait(int /*<<< orphan*/ *);
int main(int argc, char *argv[]) {
  if (argc != 3) {
    fprintf(stderr, "Error in number of arguments\n");
    _exit(EXIT_FAILURE);
  }
  pid_t pid;
  int pipefd[2];
  pipe(pipefd);
  runSource(pipefd, argv[1]);
  runDestination(pipefd, argv[2]);
  close(pipefd[0]);
  close(pipefd[1]);
  while ((pid = wait(NULL)) != -1) {
    printf("Process %d ends\n", pid);
  }
  return EXIT_SUCCESS;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
cmpl   $0x3,-0x8(%rbp)
je     11c3 <main+0x43>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe50(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2e1c(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
lea    -0x1c(%rbp),%rdi
call   1060 <pipe@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rsi
call   1080 <runSource@plt>
lea    -0x1c(%rbp),%rdi
mov    -0x10(%rbp),%rax
mov    0x10(%rax),%rsi
call   1090 <runDestination@plt>
mov    -0x1c(%rbp),%edi
call   1050 <close@plt>
mov    -0x18(%rbp),%edi
call   1050 <close@plt>
xor    %eax,%eax
mov    %eax,%edi
call   10a0 <wait@plt>
mov    %eax,-0x14(%rbp)
cmp    $0xffffffff,%eax
je     1227 <main+0xa7>
mov    -0x14(%rbp),%esi
lea    0xe01(%rip),%rdi
call   1040 <printf@plt>
jmp    11fe <main+0x7e>
mov    0x2da2(%rip),%rax
mov    (%rax),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r14
push   %rbx
push   %rax
cmp    $0x3,%edi
jne    1207 <main+0x87>
mov    %rsi,%rbx
mov    %rsp,%r14
mov    %r14,%rdi
call   1060 <pipe@plt>
mov    0x8(%rbx),%rsi
mov    %r14,%rdi
call   1080 <runSource@plt>
mov    0x10(%rbx),%rsi
mov    %r14,%rdi
call   1090 <runDestination@plt>
mov    (%rsp),%edi
call   1050 <close@plt>
mov    0x4(%rsp),%edi
call   1050 <close@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
je     11f6 <main+0x76>
lea    0xe4b(%rip),%rbx
cs nopw 0x0(%rax,%rax,1)
nopl   (%rax)
mov    %rbx,%rdi
mov    %eax,%esi
call   1040 <printf@plt>
xor    %edi,%edi
call   10a0 <wait@plt>
cmp    $0xffffffff,%eax
jne    11e0 <main+0x60>
mov    0x2dd3(%rip),%rax
mov    (%rax),%eax
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2dd2(%rip),%rax
mov    (%rax),%edi
lea    0xde9(%rip),%rsi
call   1070 <fprintf@plt>
mov    0x2db5(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Process %d ends\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca [2 x i32]
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%8 = load i32, i32* %4
%9 = icmp ne i32 %8, 3
br i1 %9, label %10, label %15
10: ; preds = %2
%11 = load i32, i32* @stderr
%12 = call i32 @fprintf(i32 %11, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%13 = load i32, i32* @EXIT_FAILURE
%14 = call i32 @_exit(i32 %13)
unreachable
15: ; preds = %2
%16 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%17 = call i32 @pipe(i32* %16)
%18 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%19 = load i8**, i8*** %5
%20 = getelementptr inbounds i8*, i8** %19, i64 1
%21 = load i8*, i8** %20
%22 = call i32 @runSource(i32* %18, i8* %21)
%23 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%24 = load i8**, i8*** %5
%25 = getelementptr inbounds i8*, i8** %24, i64 2
%26 = load i8*, i8** %25
%27 = call i32 @runDestination(i32* %23, i8* %26)
%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 [2 x i32], [2 x i32]* %7, i64 0, i64 1
%32 = load i32, i32* %31
%33 = call i32 @close(i32 %32)
br label %34
34: ; preds = %37, %15
%35 = call i32 @wait(i32* null)
store i32 %35, i32* %6
%36 = icmp ne i32 %35, -1
br i1 %36, label %37, label %40
37: ; preds = %34
%38 = load i32, i32* %6
%39 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %38)
br label %34
40: ; preds = %34
%41 = load i32, i32* @EXIT_SUCCESS
ret i32 %41
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [30 x i8] c"Error in number of arguments\0A\00"
@EXIT_FAILURE = global i32 0
@.str.1 = [17 x i8] c"Process %d ends\0A\00"
@EXIT_SUCCESS = global i32 0
define i32 @main(i32 %0, i8** nocapture %1) {
%3 = alloca [2 x i32]
%4 = icmp eq i32 %0, 3
br i1 %4, label %10, label %5
5: ; preds = %2
%6 = load i32, i32* @stderr
%7 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([30 x i8], [30 x i8]* @.str, i64 0, i64 0))
%8 = load i32, i32* @EXIT_FAILURE
%9 = tail call i32 @_exit(i32 %8)
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(i32* %12)
%14 = getelementptr inbounds i8*, i8** %1, i64 1
%15 = load i8*, i8** %14
%16 = call i32 @runSource(i32* %12, i8* %15)
%17 = getelementptr inbounds i8*, i8** %1, i64 2
%18 = load i8*, i8** %17
%19 = call i32 @runDestination(i32* %12, i8* %18)
%20 = load i32, i32* %12
%21 = call i32 @close(i32 %20)
%22 = getelementptr inbounds [2 x i32], [2 x i32]* %3, i64 0, i64 1
%23 = load i32, i32* %22
%24 = call i32 @close(i32 %23)
%25 = call i32 @wait(i32* null)
%26 = icmp eq i32 %25, -1
br i1 %26, label %32, label %27
27: ; preds = %10, %27
%28 = phi i32 [ %30, %27 ], [ %25, %10 ]
%29 = call i32 @printf(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.1, i64 0, i64 0), i32 %28)
%30 = call i32 @wait(i32* null)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %27
32: ; preds = %27, %10
%33 = load i32, i32* @EXIT_SUCCESS
ret i32 %33
}