#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*/ O_WRONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ dup2(int, int);
int /*<<< orphan*/ execvp(char *, char **);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
int main(int argc, char **argv) {
  int devnull;
  if (argc < 2) {
    printf("Usage: %s command [args...]\n", argv[0]);
    return 1;
  }
  devnull = open("/dev/null", O_WRONLY);
  if (devnull < 0) {
    perror("open");
    return 1;
  }
  if (devnull != 1)
    dup2(devnull, 1);
  if (devnull != 2)
    dup2(devnull, 2);
  if (devnull != 1 && devnull != 2)
    close(devnull);
  execvp(argv[1], argv + 1);
  return 1;
}


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   $0x2,-0x8(%rbp)
jge    119f <main+0x3f>
mov    -0x10(%rbp),%rax
mov    (%rax),%rsi
lea    0xe72(%rip),%rdi
call   1040 <printf@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <main+0xdf>
mov    0x2e32(%rip),%rax
mov    (%rax),%esi
lea    0xe6e(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    11d9 <main+0x79>
lea    0xe5f(%rip),%rdi
call   1070 <perror@plt>
movl   $0x1,-0x4(%rbp)
jmp    123f <main+0xdf>
cmpl   $0x1,-0x14(%rbp)
je     11f0 <main+0x90>
mov    -0x14(%rbp),%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmpl   $0x2,-0x14(%rbp)
je     1207 <main+0xa7>
mov    -0x14(%rbp),%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
cmpl   $0x1,-0x14(%rbp)
je     1223 <main+0xc3>
cmpl   $0x2,-0x14(%rbp)
je     1223 <main+0xc3>
mov    -0x14(%rbp),%edi
call   1050 <close@plt>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   1080 <execvp@plt>
movl   $0x1,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %rbx
push   %rax
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     117c <main+0x1c>
mov    (%rbx),%rsi
lea    0xe8b(%rip),%rdi
call   1040 <printf@plt>
jmp    11eb <main+0x8b>
mov    0x2e55(%rip),%rax
mov    (%rax),%esi
lea    0xe91(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11f7 <main+0x97>
mov    %eax,%ebp
cmp    $0x1,%eax
jne    11ad <main+0x4d>
mov    $0x1,%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
jmp    11db <main+0x7b>
mov    %ebp,%edi
mov    $0x1,%esi
call   1030 <dup2@plt>
cmp    $0x2,%ebp
je     11db <main+0x7b>
mov    %ebp,%edi
mov    $0x2,%esi
call   1030 <dup2@plt>
mov    %ebp,%eax
add    $0xfffffffd,%eax
cmp    $0xfffffffd,%eax
ja     11db <main+0x7b>
mov    %ebp,%edi
call   1050 <close@plt>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   1080 <execvp@plt>
mov    $0x1,%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret
lea    0xe29(%rip),%rdi
call   1070 <perror@plt>
jmp    11eb <main+0x8b>

LLVM IR (-O0):
@.str = [29 x i8] c"Usage: %s command [args...]\0A\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%7 = load i32, i32* %4
%8 = icmp slt i32 %7, 2
br i1 %8, label %9, label %14
9: ; preds = %2
%10 = load i8**, i8*** %5
%11 = getelementptr inbounds i8*, i8** %10, i64 0
%12 = load i8*, i8** %11
%13 = call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %12)
store i32 1, i32* %3
br label %49
14: ; preds = %2
%15 = load i32, i32* @O_WRONLY
%16 = call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %15)
store i32 %16, i32* %6
%17 = load i32, i32* %6
%18 = icmp slt i32 %17, 0
br i1 %18, label %19, label %21
19: ; preds = %14
%20 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
store i32 1, i32* %3
br label %49
21: ; preds = %14
%22 = load i32, i32* %6
%23 = icmp ne i32 %22, 1
br i1 %23, label %24, label %27
24: ; preds = %21
%25 = load i32, i32* %6
%26 = call i32 @dup2(i32 %25, i32 1)
br label %27
27: ; preds = %24, %21
%28 = load i32, i32* %6
%29 = icmp ne i32 %28, 2
br i1 %29, label %30, label %33
30: ; preds = %27
%31 = load i32, i32* %6
%32 = call i32 @dup2(i32 %31, i32 2)
br label %33
33: ; preds = %30, %27
%34 = load i32, i32* %6
%35 = icmp ne i32 %34, 1
br i1 %35, label %36, label %42
36: ; preds = %33
%37 = load i32, i32* %6
%38 = icmp ne i32 %37, 2
br i1 %38, label %39, label %42
39: ; preds = %36
%40 = load i32, i32* %6
%41 = call i32 @close(i32 %40)
br label %42
42: ; preds = %39, %36, %33
%43 = load i8**, i8*** %5
%44 = getelementptr inbounds i8*, i8** %43, i64 1
%45 = load i8*, i8** %44
%46 = load i8**, i8*** %5
%47 = getelementptr inbounds i8*, i8** %46, i64 1
%48 = call i32 @execvp(i8* %45, i8** %47)
store i32 1, i32* %3
br label %49
49: ; preds = %42, %19, %9
%50 = load i32, i32* %3
ret i32 %50
}

LLVM IR (-O2):
@.str = [29 x i8] c"Usage: %s command [args...]\0A\00"
@.str.1 = [10 x i8] c"/dev/null\00"
@O_WRONLY = global i32 0
@.str.2 = [5 x i8] c"open\00"
define i32 @main(i32 %0, i8** %1) {
%3 = icmp slt i32 %0, 2
br i1 %3, label %4, label %7
4: ; preds = %2
%5 = load i8*, i8** %1
%6 = tail call i32 @printf(i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str, i64 0, i64 0), i8* %5)
br label %30
7: ; preds = %2
%8 = load i32, i32* @O_WRONLY
%9 = tail call i32 @open(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0), i32 %8)
%10 = icmp slt i32 %9, 0
br i1 %10, label %11, label %13
11: ; preds = %7
%12 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.2, i64 0, i64 0))
br label %30
13: ; preds = %7
%14 = icmp eq i32 %9, 1
br i1 %14, label %15, label %17
15: ; preds = %13
%16 = tail call i32 @dup2(i32 1, i32 2)
br label %26
17: ; preds = %13
%18 = tail call i32 @dup2(i32 %9, i32 1)
%19 = icmp eq i32 %9, 2
br i1 %19, label %26, label %20
20: ; preds = %17
%21 = tail call i32 @dup2(i32 %9, i32 2)
%22 = add nsw i32 %9, -3
%23 = icmp ult i32 %22, -2
br i1 %23, label %24, label %26
24: ; preds = %20
%25 = tail call i32 @close(i32 %9)
br label %26
26: ; preds = %17, %15, %24, %20
%27 = getelementptr inbounds i8*, i8** %1, i64 1
%28 = load i8*, i8** %27
%29 = tail call i32 @execvp(i8* %28, i8** %27)
br label %30
30: ; preds = %26, %11, %4
ret i32 1
}