#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*/ close(int);
int /*<<< orphan*/ dup2(int, int);
scalar_t__ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ pipe(int *);
int processExec(char *path, char **args) {
  pid_t pid;
  int p1[2], p2[2];
  int i = 0;
  char buf[1024];
  args[0] = path;
  pipe(p1);
  pipe(p2);
  pid = fork();
  if (pid == 0) {
    dup2(p1[0], 0);
    dup2(p2[1], 1);
    close(p1[0]);
    close(p1[1]);
    close(p2[0]);
    close(p2[1]);
    if (execvp(path, args)) {
      exit(1);
      return 0;
    }
  } else {
    if (pid != -1) {
      dup2(p2[0], 0);
      dup2(p1[1], 1);
      close(p1[0]);
      close(p1[1]);
      close(p2[0]);
      close(p2[1]);
    }
  }
  return pid;
}


x86 assembly (clang, -O0):
<processExec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x430,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
movl   $0x0,-0x28(%rbp)
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
lea    -0x1c(%rbp),%rdi
call   1050 <pipe@plt>
lea    -0x24(%rbp),%rdi
call   1050 <pipe@plt>
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jne    1208 <processExec+0xa8>
mov    -0x1c(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x20(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1060 <execvp@plt>
cmp    $0x0,%rax
je     1203 <processExec+0xa3>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    124e <processExec+0xee>
cmpl   $0xffffffff,-0x14(%rbp)
je     1249 <processExec+0xe9>
mov    -0x24(%rbp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    -0x18(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    -0x1c(%rbp),%edi
call   1040 <close@plt>
mov    -0x18(%rbp),%edi
call   1040 <close@plt>
mov    -0x24(%rbp),%edi
call   1040 <close@plt>
mov    -0x20(%rbp),%edi
call   1040 <close@plt>
jmp    124e <processExec+0xee>
mov    -0x14(%rbp),%eax
add    $0x430,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<processExec>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%r14
mov    %rdi,%r15
mov    %rdi,(%rsi)
lea    0x8(%rsp),%rdi
call   1050 <pipe@plt>
mov    %rsp,%rdi
call   1050 <pipe@plt>
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ebx
cmp    $0xffffffff,%eax
je     122b <processExec+0xcb>
test   %ebx,%ebx
jne    11f0 <processExec+0x90>
mov    0x8(%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0x4(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    %r15,%rdi
mov    %r14,%rsi
call   1060 <execvp@plt>
test   %rax,%rax
je     122b <processExec+0xcb>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    (%rsp),%edi
xor    %esi,%esi
call   1030 <dup2@plt>
mov    0xc(%rsp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
mov    0x8(%rsp),%edi
call   1040 <close@plt>
mov    0xc(%rsp),%edi
call   1040 <close@plt>
mov    (%rsp),%edi
call   1040 <close@plt>
mov    0x4(%rsp),%edi
call   1040 <close@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
define i32 @processExec(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i32
%6 = alloca [2 x i32]
%7 = alloca [2 x i32]
%8 = alloca i32
%9 = alloca [1024 x i8]
store i8* %0, i8** %3
store i8** %1, i8*** %4
store i32 0, i32* %8
%10 = load i8*, i8** %3
%11 = load i8**, i8*** %4
%12 = getelementptr inbounds i8*, i8** %11, i64 0
store i8* %10, i8** %12
%13 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%14 = call i32 @pipe(i32* %13)
%15 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%16 = call i32 @pipe(i32* %15)
%17 = call i32 (...) @fork()
store i32 %17, i32* %5
%18 = load i32, i32* %5
%19 = icmp eq i32 %18, 0
br i1 %19, label %20, label %46
20: ; preds = %2
%21 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%22 = load i32, i32* %21
%23 = call i32 @dup2(i32 %22, i32 0)
%24 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%25 = load i32, i32* %24
%26 = call i32 @dup2(i32 %25, i32 1)
%27 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%28 = load i32, i32* %27
%29 = call i32 @close(i32 %28)
%30 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%31 = load i32, i32* %30
%32 = call i32 @close(i32 %31)
%33 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%34 = load i32, i32* %33
%35 = call i32 @close(i32 %34)
%36 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%37 = load i32, i32* %36
%38 = call i32 @close(i32 %37)
%39 = load i8*, i8** %3
%40 = load i8**, i8*** %4
%41 = call i64 @execvp(i8* %39, i8** %40)
%42 = icmp ne i64 %41, 0
br i1 %42, label %43, label %45
43: ; preds = %20
%44 = call i32 @exit(i32 1)
unreachable
45: ; preds = %20
br label %69
46: ; preds = %2
%47 = load i32, i32* %5
%48 = icmp ne i32 %47, -1
br i1 %48, label %49, label %68
49: ; preds = %46
%50 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%51 = load i32, i32* %50
%52 = call i32 @dup2(i32 %51, i32 0)
%53 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%54 = load i32, i32* %53
%55 = call i32 @dup2(i32 %54, i32 1)
%56 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 0
%57 = load i32, i32* %56
%58 = call i32 @close(i32 %57)
%59 = getelementptr inbounds [2 x i32], [2 x i32]* %6, i64 0, i64 1
%60 = load i32, i32* %59
%61 = call i32 @close(i32 %60)
%62 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 0
%63 = load i32, i32* %62
%64 = call i32 @close(i32 %63)
%65 = getelementptr inbounds [2 x i32], [2 x i32]* %7, i64 0, i64 1
%66 = load i32, i32* %65
%67 = call i32 @close(i32 %66)
br label %68
68: ; preds = %49, %46
br label %69
69: ; preds = %68, %45
%70 = load i32, i32* %5
ret i32 %70
}

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