#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 scalar_t__ pid_t;

/* Variables and functions */
int /*<<< orphan*/ O_RDWR;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup(int);
int /*<<< orphan*/ execv(char const *, char *const *);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
scalar_t__ fork();
int open(char *, int /*<<< orphan*/);
void run(const char *what, const char *pars[]) {
  pid_t pid = fork();
  if (pid == 0) {
    int fd = open("/dev/null", O_RDWR);
    close(0);
    dup(fd);
    close(1);
    dup(fd);
    close(2);
    dup(fd);
    if (pars)
      pars[0] = what;
    execv(what, (char *const *)pars);
    exit(0);
  }
}


x86 assembly (clang, -O0):
<run>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x0,%al
call   1080 <fork@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11fb <run+0x9b>
mov    0x2e5b(%rip),%rax
mov    (%rax),%esi
lea    0xe6a(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x1c(%rbp)
xor    %edi,%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <dup@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <dup@plt>
mov    $0x2,%edi
call   1040 <close@plt>
mov    -0x1c(%rbp),%edi
call   1030 <dup@plt>
cmpq   $0x0,-0x10(%rbp)
je     11e7 <run+0x87>
mov    -0x8(%rbp),%rcx
mov    -0x10(%rbp),%rax
mov    %rcx,(%rax)
mov    -0x8(%rbp),%rdi
mov    -0x10(%rbp),%rsi
call   1070 <execv@plt>
xor    %edi,%edi
call   1060 <exit@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<run>:
push   %rbp
push   %r14
push   %rbx
mov    %rsi,%r14
mov    %rdi,%rbx
xor    %eax,%eax
call   1080 <fork@plt>
test   %rax,%rax
je     117b <run+0x1b>
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    0x2e66(%rip),%rax
mov    (%rax),%esi
lea    0xe75(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebp
xor    %edi,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1030 <dup@plt>
mov    $0x1,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1030 <dup@plt>
mov    $0x2,%edi
call   1040 <close@plt>
mov    %ebp,%edi
call   1030 <dup@plt>
test   %r14,%r14
je     11ca <run+0x6a>
mov    %rbx,(%r14)
mov    %rbx,%rdi
mov    %r14,%rsi
call   1070 <execv@plt>
xor    %edi,%edi
call   1060 <exit@plt>

LLVM IR (-O0):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define void @run(i8* %0, i8** %1) {
%3 = alloca i8*
%4 = alloca i8**
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
store i8** %1, i8*** %4
%7 = call i64 (...) @fork()
store i64 %7, i64* %5
%8 = load i64, i64* %5
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %33
10: ; preds = %2
%11 = load i32, i32* @O_RDWR
%12 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %11)
store i32 %12, i32* %6
%13 = call i32 @close(i32 0)
%14 = load i32, i32* %6
%15 = call i32 @dup(i32 %14)
%16 = call i32 @close(i32 1)
%17 = load i32, i32* %6
%18 = call i32 @dup(i32 %17)
%19 = call i32 @close(i32 2)
%20 = load i32, i32* %6
%21 = call i32 @dup(i32 %20)
%22 = load i8**, i8*** %4
%23 = icmp ne i8** %22, null
br i1 %23, label %24, label %28
24: ; preds = %10
%25 = load i8*, i8** %3
%26 = load i8**, i8*** %4
%27 = getelementptr inbounds i8*, i8** %26, i64 0
store i8* %25, i8** %27
br label %28
28: ; preds = %24, %10
%29 = load i8*, i8** %3
%30 = load i8**, i8*** %4
%31 = call i32 @execv(i8* %29, i8** %30)
%32 = call i32 @exit(i32 0)
unreachable
33: ; preds = %2
ret void
}

LLVM IR (-O2):
@.str = [10 x i8] c"/dev/null\00"
@O_RDWR = global i32 0
define void @run(i8* %0, i8** %1) {
%3 = tail call i64 (...) @fork()
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %19
5: ; preds = %2
%6 = load i32, i32* @O_RDWR
%7 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), i32 %6)
%8 = tail call i32 @close(i32 0)
%9 = tail call i32 @dup(i32 %7)
%10 = tail call i32 @close(i32 1)
%11 = tail call i32 @dup(i32 %7)
%12 = tail call i32 @close(i32 2)
%13 = tail call i32 @dup(i32 %7)
%14 = icmp eq i8** %1, null
br i1 %14, label %16, label %15
15: ; preds = %5
store i8* %0, i8** %1
br label %16
16: ; preds = %15, %5
%17 = tail call i32 @execv(i8* %0, i8** %1)
%18 = tail call i32 @exit(i32 0)
unreachable
19: ; preds = %2
ret void
}