#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*/ closeSafe(int);
int /*<<< orphan*/ dup2Safe(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ stderr;
void runProcess(int in, int *pipe_out, char *command, char **args) {
  pid_t pid = fork();
  if (pid == 0) {
    dup2Safe(in, 0);
    dup2Safe(pipe_out[1], 1);
    closeSafe(in);
    closeSafe(pipe_out[0]);
    closeSafe(pipe_out[1]);
    execvp(command, args);
    fprintf(stderr, "Unable to execute command %s", command);
    exit(1);
  } else if (pid == -1) {
    fprintf(stderr, "Unable to fork");
    exit(1);
  }
}


x86 assembly (clang, -O0):
<runProcess>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %edi,-0x4(%rbp)
mov    %rsi,-0x10(%rbp)
mov    %rdx,-0x18(%rbp)
mov    %rcx,-0x20(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %eax,-0x24(%rbp)
cmpl   $0x0,-0x24(%rbp)
jne    11f7 <runProcess+0x97>
mov    -0x4(%rbp),%edi
xor    %esi,%esi
call   1040 <dup2Safe@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
mov    $0x1,%esi
call   1040 <dup2Safe@plt>
mov    -0x4(%rbp),%edi
call   1030 <closeSafe@plt>
mov    -0x10(%rbp),%rax
mov    (%rax),%edi
call   1030 <closeSafe@plt>
mov    -0x10(%rbp),%rax
mov    0x4(%rax),%edi
call   1030 <closeSafe@plt>
mov    -0x18(%rbp),%rdi
mov    -0x20(%rbp),%rsi
call   1060 <execvp@plt>
mov    0x2e07(%rip),%rax
mov    (%rax),%edi
mov    -0x18(%rbp),%rdx
lea    0xe1a(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
cmpl   $0xffffffff,-0x24(%rbp)
jne    1222 <runProcess+0xc2>
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
lea    0xe0c(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
jmp    1227 <runProcess+0xc7>
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runProcess>:
push   %rbp
push   %r15
push   %r14
push   %rbx
push   %rax
mov    %rcx,%r15
mov    %rdx,%r14
mov    %rsi,%rbx
mov    %edi,%ebp
xor    %eax,%eax
call   1080 <fork@plt>
cmp    $0xffffffff,%eax
je     118d <runProcess+0x2d>
test   %eax,%eax
je     11ae <runProcess+0x4e>
add    $0x8,%rsp
pop    %rbx
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2e4c(%rip),%rax
mov    (%rax),%edi
lea    0xe80(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>
mov    %ebp,%edi
xor    %esi,%esi
call   1040 <dup2Safe@plt>
mov    0x4(%rbx),%edi
mov    $0x1,%esi
call   1040 <dup2Safe@plt>
mov    %ebp,%edi
call   1030 <closeSafe@plt>
mov    (%rbx),%edi
call   1030 <closeSafe@plt>
mov    0x4(%rbx),%edi
call   1030 <closeSafe@plt>
mov    %r14,%rdi
mov    %r15,%rsi
call   1060 <execvp@plt>
mov    0x2df4(%rip),%rax
mov    (%rax),%edi
lea    0xe0b(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0x1,%edi
call   1070 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [29 x i8] c"Unable to execute command %s\00"
@.str.1 = [15 x i8] c"Unable to fork\00"
define void @runProcess(i32 %0, i32* %1, i8* %2, i8** %3) {
%5 = alloca i32
%6 = alloca i32*
%7 = alloca i8*
%8 = alloca i8**
%9 = alloca i32
store i32 %0, i32* %5
store i32* %1, i32** %6
store i8* %2, i8** %7
store i8** %3, i8*** %8
%10 = call i32 (...) @fork()
store i32 %10, i32* %9
%11 = load i32, i32* %9
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %37
13: ; preds = %4
%14 = load i32, i32* %5
%15 = call i32 @dup2Safe(i32 %14, i32 0)
%16 = load i32*, i32** %6
%17 = getelementptr inbounds i32, i32* %16, i64 1
%18 = load i32, i32* %17
%19 = call i32 @dup2Safe(i32 %18, i32 1)
%20 = load i32, i32* %5
%21 = call i32 @closeSafe(i32 %20)
%22 = load i32*, i32** %6
%23 = getelementptr inbounds i32, i32* %22, i64 0
%24 = load i32, i32* %23
%25 = call i32 @closeSafe(i32 %24)
%26 = load i32*, i32** %6
%27 = getelementptr inbounds i32, i32* %26, i64 1
%28 = load i32, i32* %27
%29 = call i32 @closeSafe(i32 %28)
%30 = load i8*, i8** %7
%31 = load i8**, i8*** %8
%32 = call i32 @execvp(i8* %30, i8** %31)
%33 = load i32, i32* @stderr
%34 = load i8*, i8** %7
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %34)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %4
%38 = load i32, i32* %9
%39 = icmp eq i32 %38, -1
br i1 %39, label %40, label %44
40: ; preds = %37
%41 = load i32, i32* @stderr
%42 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%43 = call i32 @exit(i32 1)
unreachable
44: ; preds = %37
br label %45
45: ; preds = %44
ret void
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [29 x i8] c"Unable to execute command %s\00"
@.str.1 = [15 x i8] c"Unable to fork\00"
define void @runProcess(i32 %0, i32* nocapture %1, i8* %2, i8** %3) {
%5 = tail call i32 (...) @fork()
switch i32 %5, label %24 [
i32 0, label %6
i32 -1, label %20
]
6: ; preds = %4
%7 = tail call i32 @dup2Safe(i32 %0, i32 0)
%8 = getelementptr inbounds i32, i32* %1, i64 1
%9 = load i32, i32* %8
%10 = tail call i32 @dup2Safe(i32 %9, i32 1)
%11 = tail call i32 @closeSafe(i32 %0)
%12 = load i32, i32* %1
%13 = tail call i32 @closeSafe(i32 %12)
%14 = load i32, i32* %8
%15 = tail call i32 @closeSafe(i32 %14)
%16 = tail call i32 @execvp(i8* %2, i8** %3)
%17 = load i32, i32* @stderr
%18 = tail call i32 (i32, i8*, ...) @fprintf(i32 %17, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %2)
%19 = tail call i32 @exit(i32 1)
unreachable
20: ; preds = %4
%21 = load i32, i32* @stderr
%22 = tail call i32 (i32, i8*, ...) @fprintf(i32 %21, i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0))
%23 = tail call i32 @exit(i32 1)
unreachable
24: ; preds = %4
ret void
}