#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 /*<<< orphan*/ sigset_t;
typedef scalar_t__ pid_t;

/* Variables and functions */
int EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ O_WRONLY;
int /*<<< orphan*/ SIG_UNBLOCK;
scalar_t__ STDERR_FILENO;
int /*<<< orphan*/ STDIN_FILENO;
int /*<<< orphan*/ STDOUT_FILENO;
int /*<<< orphan*/ _PATH_DEVNULL;
int chdir(char *);
scalar_t__ clearenv();
int close(int /*<<< orphan*/);
scalar_t__ dup2(int /*<<< orphan*/, scalar_t__);
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
scalar_t__ setsid();
int sigemptyset(int /*<<< orphan*/ *);
int sigprocmask(int /*<<< orphan*/, int /*<<< orphan*/ *, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ umask(int /*<<< orphan*/);
int unshare(int);
int main(int argc, char *argv[]) {
  sigset_t mask;
  if (1 >= argc) {
    (void)fprintf(stderr, "Usage: %s ARG...\n", argv[0]);
    goto end;
  }
  if (-1 == sigemptyset(&mask))
    goto end;
  if (-1 == sigprocmask(SIG_UNBLOCK, &mask, NULL))
    goto end;
  if (0 != clearenv())
    goto end;
  if (-1 == chdir("/run"))
    goto end;
  (void)umask(0);
  switch (fork()) {
  case (-1):
    goto end;
  case 0:
    break;
  default:
    exit(EXIT_SUCCESS);
  }
  if (((pid_t)-1) == setsid())
    goto end;
  switch (fork()) {
  case (-1):
    goto end;
  case 0:
    break;
  default:
    exit(EXIT_SUCCESS);
  }
  if (-1 == unshare(0x00020000))
    goto end;
  if (-1 == close(STDIN_FILENO))
    goto end;
  if (-1 == open(_PATH_DEVNULL, O_RDONLY))
    goto end;
  if (-1 == close(STDOUT_FILENO))
    goto end;
  if (-1 == open(_PATH_DEVNULL, O_WRONLY))
    goto end;
  if (STDERR_FILENO != dup2(STDOUT_FILENO, STDERR_FILENO))
    goto end;
  (void)execvp(argv[1], &argv[1]);
end:
  return EXIT_FAILURE;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    $0x1,%eax
cmp    -0x8(%rbp),%eax
jl     1225 <main+0x45>
mov    0x2dbd(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xde5(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    145c <main+0x27c>
lea    -0x14(%rbp),%rdi
call   10b0 <sigemptyset@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1242 <main+0x62>
jmp    145c <main+0x27c>
mov    0x2d97(%rip),%rax
mov    (%rax),%edi
lea    -0x14(%rbp),%rsi
xor    %eax,%eax
mov    %eax,%edx
call   1030 <sigprocmask@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    126c <main+0x8c>
jmp    145c <main+0x27c>
mov    $0x0,%al
call   1050 <clearenv@plt>
mov    %rax,%rcx
xor    %eax,%eax
cmp    %rcx,%rax
je     1286 <main+0xa6>
jmp    145c <main+0x27c>
lea    0xd85(%rip),%rdi
call   1060 <chdir@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    12a6 <main+0xc6>
jmp    145c <main+0x27c>
xor    %edi,%edi
mov    %edi,-0x1c(%rbp)
call   10c0 <umask@plt>
mov    -0x1c(%rbp),%eax
call   1100 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x18(%rbp)
sub    $0xffffffff,%eax
je     12db <main+0xfb>
jmp    12cb <main+0xeb>
mov    -0x18(%rbp),%eax
test   %eax,%eax
je     12e0 <main+0x100>
jmp    12e5 <main+0x105>
jmp    145c <main+0x27c>
jmp    12f3 <main+0x113>
mov    0x2cbc(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0x0,%al
call   1090 <setsid@plt>
mov    %rax,%rcx
mov    $0xffffffffffffffff,%rax
cmp    %rcx,%rax
jne    1312 <main+0x132>
jmp    145c <main+0x27c>
xor    %eax,%eax
call   1100 <fork@plt>
mov    %eax,%ecx
mov    %ecx,-0x20(%rbp)
sub    $0xffffffff,%eax
je     133c <main+0x15c>
jmp    132c <main+0x14c>
mov    -0x20(%rbp),%eax
test   %eax,%eax
je     1341 <main+0x161>
jmp    1346 <main+0x166>
jmp    145c <main+0x27c>
jmp    1354 <main+0x174>
mov    0x2c5b(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>
mov    $0x20000,%edi
call   1040 <unshare@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1372 <main+0x192>
jmp    145c <main+0x27c>
mov    0x2c27(%rip),%rax
mov    (%rax),%edi
call   1080 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    1394 <main+0x1b4>
jmp    145c <main+0x27c>
mov    0x2c15(%rip),%rax
mov    (%rax),%edi
mov    0x2c34(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13bf <main+0x1df>
jmp    145c <main+0x27c>
mov    0x2c2a(%rip),%rax
mov    (%rax),%edi
call   1080 <close@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    13e1 <main+0x201>
jmp    145c <main+0x27c>
mov    0x2bc8(%rip),%rax
mov    (%rax),%edi
mov    0x2b9f(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
mov    %eax,%ecx
mov    $0xffffffff,%eax
cmp    %ecx,%eax
jne    140c <main+0x22c>
jmp    145c <main+0x27c>
mov    0x2bad(%rip),%rax
mov    (%rax),%rax
mov    %rax,-0x28(%rbp)
mov    0x2bcf(%rip),%rax
mov    (%rax),%edi
mov    0x2b96(%rip),%rax
mov    (%rax),%rsi
call   1070 <dup2@plt>
mov    %rax,%rcx
mov    -0x28(%rbp),%rax
cmp    %rcx,%rax
je     1447 <main+0x267>
jmp    145c <main+0x27c>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    -0x10(%rbp),%rsi
add    $0x8,%rsi
call   10e0 <execvp@plt>
mov    0x2b55(%rip),%rax
mov    (%rax),%eax
add    $0x30,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %r15
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
cmp    $0x1,%edi
jg     120b <main+0x2b>
mov    0x2dd0(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xdfc(%rip),%rsi
call   10a0 <fprintf@plt>
jmp    1240 <main+0x60>
lea    0xc(%rsp),%rdi
call   10b0 <sigemptyset@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    0x2dbf(%rip),%rax
mov    (%rax),%edi
lea    0xc(%rsp),%rsi
xor    %edx,%edx
call   1030 <sigprocmask@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
xor    %eax,%eax
call   1050 <clearenv@plt>
test   %rax,%rax
je     1253 <main+0x73>
mov    0x2d71(%rip),%rax
mov    (%rax),%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %r15
ret
lea    0xdb8(%rip),%rdi
call   1060 <chdir@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
xor    %edi,%edi
call   10c0 <umask@plt>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
test   %eax,%eax
jne    134c <main+0x16c>
xor    %eax,%eax
call   1090 <setsid@plt>
cmp    $0xffffffffffffffff,%rax
je     1240 <main+0x60>
xor    %eax,%eax
call   1100 <fork@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
test   %eax,%eax
jne    134c <main+0x16c>
mov    $0x20000,%edi
call   1040 <unshare@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    0x2cea(%rip),%rax
mov    (%rax),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    0x2ce3(%rip),%r14
mov    (%r14),%edi
mov    0x2d01(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    0x2d02(%rip),%r15
mov    (%r15),%edi
call   1080 <close@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    (%r14),%edi
mov    0x2c87(%rip),%rax
mov    (%rax),%esi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     1240 <main+0x60>
mov    0x2ca0(%rip),%rax
mov    (%rax),%r14
mov    (%r15),%edi
mov    %r14,%rsi
call   1070 <dup2@plt>
cmp    %rax,%r14
jne    1240 <main+0x60>
mov    0x8(%rbx),%rdi
add    $0x8,%rbx
mov    %rbx,%rsi
call   10e0 <execvp@plt>
jmp    1240 <main+0x60>
mov    0x2c55(%rip),%rax
mov    (%rax),%edi
call   10f0 <exit@plt>

LLVM IR (-O0):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s ARG...\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [5 x i8] c"/run\00"
@EXIT_SUCCESS = global i32 0
@STDIN_FILENO = global i32 0
@_PATH_DEVNULL = global i32 0
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@O_WRONLY = global i32 0
@STDERR_FILENO = global i64 0
@EXIT_FAILURE = global i32 0
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 sge i32 1, %7
br i1 %8, label %9, label %15
9: ; preds = %2
%10 = load i32, i32* @stderr
%11 = load i8**, i8*** %5
%12 = getelementptr inbounds i8*, i8** %11, i64 0
%13 = load i8*, i8** %12
%14 = call i32 @fprintf(i32 %10, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %13)
br label %91
15: ; preds = %2
%16 = call i32 @sigemptyset(i32* %6)
%17 = icmp eq i32 -1, %16
br i1 %17, label %18, label %19
18: ; preds = %15
br label %91
19: ; preds = %15
%20 = load i32, i32* @SIG_UNBLOCK
%21 = call i32 @sigprocmask(i32 %20, i32* %6, i32* null)
%22 = icmp eq i32 -1, %21
br i1 %22, label %23, label %24
23: ; preds = %19
br label %91
24: ; preds = %19
%25 = call i64 (...) @clearenv()
%26 = icmp ne i64 0, %25
br i1 %26, label %27, label %28
27: ; preds = %24
br label %91
28: ; preds = %24
%29 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%30 = icmp eq i32 -1, %29
br i1 %30, label %31, label %32
31: ; preds = %28
br label %91
32: ; preds = %28
%33 = call i32 @umask(i32 0)
%34 = call i32 (...) @fork()
switch i32 %34, label %37 [
i32 -1, label %35
i32 0, label %36
]
35: ; preds = %32
br label %91
36: ; preds = %32
br label %40
37: ; preds = %32
%38 = load i32, i32* @EXIT_SUCCESS
%39 = call i32 @exit(i32 %38)
unreachable
40: ; preds = %36
%41 = call i64 (...) @setsid()
%42 = icmp eq i64 -1, %41
br i1 %42, label %43, label %44
43: ; preds = %40
br label %91
44: ; preds = %40
%45 = call i32 (...) @fork()
switch i32 %45, label %48 [
i32 -1, label %46
i32 0, label %47
]
46: ; preds = %44
br label %91
47: ; preds = %44
br label %51
48: ; preds = %44
%49 = load i32, i32* @EXIT_SUCCESS
%50 = call i32 @exit(i32 %49)
unreachable
51: ; preds = %47
%52 = call i32 @unshare(i32 131072)
%53 = icmp eq i32 -1, %52
br i1 %53, label %54, label %55
54: ; preds = %51
br label %91
55: ; preds = %51
%56 = load i32, i32* @STDIN_FILENO
%57 = call i32 @close(i32 %56)
%58 = icmp eq i32 -1, %57
br i1 %58, label %59, label %60
59: ; preds = %55
br label %91
60: ; preds = %55
%61 = load i32, i32* @_PATH_DEVNULL
%62 = load i32, i32* @O_RDONLY
%63 = call i32 @open(i32 %61, i32 %62)
%64 = icmp eq i32 -1, %63
br i1 %64, label %65, label %66
65: ; preds = %60
br label %91
66: ; preds = %60
%67 = load i32, i32* @STDOUT_FILENO
%68 = call i32 @close(i32 %67)
%69 = icmp eq i32 -1, %68
br i1 %69, label %70, label %71
70: ; preds = %66
br label %91
71: ; preds = %66
%72 = load i32, i32* @_PATH_DEVNULL
%73 = load i32, i32* @O_WRONLY
%74 = call i32 @open(i32 %72, i32 %73)
%75 = icmp eq i32 -1, %74
br i1 %75, label %76, label %77
76: ; preds = %71
br label %91
77: ; preds = %71
%78 = load i64, i64* @STDERR_FILENO
%79 = load i32, i32* @STDOUT_FILENO
%80 = load i64, i64* @STDERR_FILENO
%81 = call i64 @dup2(i32 %79, i64 %80)
%82 = icmp ne i64 %78, %81
br i1 %82, label %83, label %84
83: ; preds = %77
br label %91
84: ; preds = %77
%85 = load i8**, i8*** %5
%86 = getelementptr inbounds i8*, i8** %85, i64 1
%87 = load i8*, i8** %86
%88 = load i8**, i8*** %5
%89 = getelementptr inbounds i8*, i8** %88, i64 1
%90 = call i32 @execvp(i8* %87, i8** %89)
br label %91
91: ; preds = %84, %83, %76, %70, %65, %59, %54, %46, %43, %35, %31, %27, %23, %18, %9
%92 = load i32, i32* @EXIT_FAILURE
ret i32 %92
}

LLVM IR (-O2):
@stderr = global i32 0
@.str = [18 x i8] c"Usage: %s ARG...\0A\00"
@SIG_UNBLOCK = global i32 0
@.str.1 = [5 x i8] c"/run\00"
@EXIT_SUCCESS = global i32 0
@STDIN_FILENO = global i32 0
@_PATH_DEVNULL = global i32 0
@O_RDONLY = global i32 0
@STDOUT_FILENO = global i32 0
@O_WRONLY = global i32 0
@STDERR_FILENO = global i64 0
@EXIT_FAILURE = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = bitcast i32* %3 to i8*
%5 = icmp slt i32 %0, 2
br i1 %5, label %6, label %10
6: ; preds = %2
%7 = load i32, i32* @stderr
%8 = load i8*, i8** %1
%9 = tail call i32 @fprintf(i32 %7, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0), i8* %8)
br label %67
10: ; preds = %2
%11 = call i32 @sigemptyset(i32* %3)
%12 = icmp eq i32 %11, -1
br i1 %12, label %67, label %13
13: ; preds = %10
%14 = load i32, i32* @SIG_UNBLOCK
%15 = call i32 @sigprocmask(i32 %14, i32* %3, i32* null)
%16 = icmp eq i32 %15, -1
br i1 %16, label %67, label %17
17: ; preds = %13
%18 = call i64 (...) @clearenv()
%19 = icmp eq i64 %18, 0
br i1 %19, label %20, label %67
20: ; preds = %17
%21 = call i32 @chdir(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%22 = icmp eq i32 %21, -1
br i1 %22, label %67, label %23
23: ; preds = %20
%24 = call i32 @umask(i32 0)
%25 = call i32 (...) @fork()
switch i32 %25, label %26 [
i32 -1, label %67
i32 0, label %29
]
26: ; preds = %23
%27 = load i32, i32* @EXIT_SUCCESS
%28 = call i32 @exit(i32 %27)
unreachable
29: ; preds = %23
%30 = call i64 (...) @setsid()
%31 = icmp eq i64 %30, -1
br i1 %31, label %67, label %32
32: ; preds = %29
%33 = call i32 (...) @fork()
switch i32 %33, label %34 [
i32 -1, label %67
i32 0, label %37
]
34: ; preds = %32
%35 = load i32, i32* @EXIT_SUCCESS
%36 = call i32 @exit(i32 %35)
unreachable
37: ; preds = %32
%38 = call i32 @unshare(i32 131072)
%39 = icmp eq i32 %38, -1
br i1 %39, label %67, label %40
40: ; preds = %37
%41 = load i32, i32* @STDIN_FILENO
%42 = call i32 @close(i32 %41)
%43 = icmp eq i32 %42, -1
br i1 %43, label %67, label %44
44: ; preds = %40
%45 = load i32, i32* @_PATH_DEVNULL
%46 = load i32, i32* @O_RDONLY
%47 = call i32 @open(i32 %45, i32 %46)
%48 = icmp eq i32 %47, -1
br i1 %48, label %67, label %49
49: ; preds = %44
%50 = load i32, i32* @STDOUT_FILENO
%51 = call i32 @close(i32 %50)
%52 = icmp eq i32 %51, -1
br i1 %52, label %67, label %53
53: ; preds = %49
%54 = load i32, i32* @_PATH_DEVNULL
%55 = load i32, i32* @O_WRONLY
%56 = call i32 @open(i32 %54, i32 %55)
%57 = icmp eq i32 %56, -1
br i1 %57, label %67, label %58
58: ; preds = %53
%59 = load i64, i64* @STDERR_FILENO
%60 = load i32, i32* @STDOUT_FILENO
%61 = call i64 @dup2(i32 %60, i64 %59)
%62 = icmp eq i64 %59, %61
br i1 %62, label %63, label %67
63: ; preds = %58
%64 = getelementptr inbounds i8*, i8** %1, i64 1
%65 = load i8*, i8** %64
%66 = call i32 @execvp(i8* %65, i8** %64)
br label %67
67: ; preds = %58, %53, %49, %44, %40, %37, %32, %29, %23, %20, %17, %13, %10, %63, %6
%68 = load i32, i32* @EXIT_FAILURE
ret i32 %68
}