#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*/ EXIT_FAILURE;
int STDIN_FILENO;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execlp(char *, char *, char *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
void runDestination(int pipefd[], char *prog2) {
  switch (fork()) {
  case 0:
    close(STDIN_FILENO);
    dup(pipefd[0]);
    close(pipefd[1]);
    execlp(prog2, prog2, (char *)NULL);
    break;
  default:
    break;
  case -1:
    fprintf(stderr, "Error in fork()\n");
    exit(EXIT_FAILURE);
    break;
  }
}


x86 assembly (clang, -O0):
<runDestination>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
xor    %eax,%eax
call   1080 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x14(%rbp)
sub    $0xffffffff,%eax
je     11da <runDestination+0x7a>
jmp    118a <runDestination+0x2a>
mov    -0x14(%rbp),%eax
test   %eax,%eax
jne    11d5 <runDestination+0x75>
jmp    119a <runDestination+0x3a>
mov    0x2e2f(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    -0x8(%rbp),%rax
mov    (%rax),%edi
call   1030 <dup@plt>
mov    -0x8(%rbp),%rax
mov    0x4(%rax),%edi
call   1040 <close@plt>
mov    -0x10(%rbp),%rdi
mov    -0x10(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1070 <execlp@plt>
jmp    11fd <runDestination+0x9d>
jmp    11fd <runDestination+0x9d>
mov    0x2dff(%rip),%rax
mov    (%rax),%edi
lea    0xe16(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2de2(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<runDestination>:
push   %r14
push   %rbx
push   %rax
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %eax,%eax
je     1182 <runDestination+0x22>
cmp    $0xffffffff,%eax
je     11b3 <runDestination+0x53>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret
mov    0x2e47(%rip),%rax
mov    (%rax),%edi
call   1040 <close@plt>
mov    (%rbx),%edi
call   1030 <dup@plt>
mov    0x4(%rbx),%edi
call   1040 <close@plt>
mov    %r14,%rdi
mov    %r14,%rsi
xor    %edx,%edx
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1070 <execlp@plt>
mov    0x2e26(%rip),%rax
mov    (%rax),%edi
lea    0xe3d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2e09(%rip),%rax
mov    (%rax),%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Error in fork()\0A\00"
@EXIT_FAILURE = global i32 0
define void @runDestination(i32* %0, i8* %1) {
%3 = alloca i32*
%4 = alloca i8*
store i32* %0, i32** %3
store i8* %1, i8** %4
%5 = call i32 (...) @fork()
switch i32 %5, label %20 [
i32 0, label %6
i32 -1, label %21
]
6: ; preds = %2
%7 = load i32, i32* @STDIN_FILENO
%8 = call i32 @close(i32 %7)
%9 = load i32*, i32** %3
%10 = getelementptr inbounds i32, i32* %9, i64 0
%11 = load i32, i32* %10
%12 = call i32 @dup(i32 %11)
%13 = load i32*, i32** %3
%14 = getelementptr inbounds i32, i32* %13, i64 1
%15 = load i32, i32* %14
%16 = call i32 @close(i32 %15)
%17 = load i8*, i8** %4
%18 = load i8*, i8** %4
%19 = call i32 @execlp(i8* %17, i8* %18, i8* null)
br label %26
20: ; preds = %2
br label %26
21: ; preds = %2
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%24 = load i32, i32* @EXIT_FAILURE
%25 = call i32 @exit(i32 %24)
unreachable
26: ; preds = %20, %6
ret void
}

LLVM IR (-O2):
@STDIN_FILENO = global i32 0
@stderr = global i32 0
@.str = [17 x i8] c"Error in fork()\0A\00"
@EXIT_FAILURE = global i32 0
define void @runDestination(i32* nocapture %0, i8* %1) {
%3 = tail call i32 (...) @fork()
switch i32 %3, label %18 [
i32 0, label %4
i32 -1, label %13
]
4: ; preds = %2
%5 = load i32, i32* @STDIN_FILENO
%6 = tail call i32 @close(i32 %5)
%7 = load i32, i32* %0
%8 = tail call i32 @dup(i32 %7)
%9 = getelementptr inbounds i32, i32* %0, i64 1
%10 = load i32, i32* %9
%11 = tail call i32 @close(i32 %10)
%12 = tail call i32 @execlp(i8* %1, i8* %1, i8* null)
br label %18
13: ; preds = %2
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str, i64 0, i64 0))
%16 = load i32, i32* @EXIT_FAILURE
%17 = tail call i32 @exit(i32 %16)
unreachable
18: ; preds = %2, %4
ret void
}