#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*/ EXIT_FAILURE;
int /*<<< orphan*/ EXIT_SUCCESS;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ execvp(char *, char **);
int /*<<< orphan*/ exit(int /*<<< orphan*/);
int fork();
int getopt(int, char **, char *);
int open(int /*<<< orphan*/, int /*<<< orphan*/);
int /*<<< orphan*/ optarg;
int optind;
int /*<<< orphan*/ perror(char *);
int setns(int, int /*<<< orphan*/);
int /*<<< orphan*/ usage(char *);
int waitpid(int, int /*<<< orphan*/ *, int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  int fd, opt, do_fork;
  pid_t pid;
  do_fork = 0;
  while ((opt = getopt(argc, argv, "+fn:")) != -1) {
    switch (opt) {
    case 'n':
      fd = open(optarg, O_RDONLY);
      if (fd == -1)
        do {
          perror("open");
          exit(EXIT_FAILURE);
        } while (0);
      if (setns(fd, 0) == -1)
        do {
          perror("setns");
          exit(EXIT_FAILURE);
        } while (0);
      break;
    case 'f':
      do_fork = 1;
      break;
    default:
      usage(argv[0]);
    }
  }
  if (argc <= optind)
    usage(argv[0]);
  if (do_fork) {
    pid = fork();
    if (pid == -1)
      do {
        perror("fork");
        exit(EXIT_FAILURE);
      } while (0);
    if (pid != 0) {
      if (waitpid(-1, NULL, 0) == -1)
        do {
          perror("waitpid");
          exit(EXIT_FAILURE);
        } while (0);
      exit(EXIT_SUCCESS);
    }
  }
  execvp(argv[optind], &argv[optind]);
  do {
    perror("execvp");
    exit(EXIT_FAILURE);
  } while (0);
}


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)
movl   $0x0,-0x1c(%rbp)
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
lea    0xe45(%rip),%rdx
call   1080 <getopt@plt>
mov    %eax,-0x18(%rbp)
cmp    $0xffffffff,%eax
je     1288 <main+0xf8>
mov    -0x18(%rbp),%eax
mov    %eax,-0x24(%rbp)
sub    $0x66,%eax
je     126b <main+0xdb>
jmp    11e0 <main+0x50>
mov    -0x24(%rbp),%eax
sub    $0x6e,%eax
jne    1277 <main+0xe7>
jmp    11f1 <main+0x61>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    0x2ddf(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
cmpl   $0xffffffff,-0x14(%rbp)
jne    1234 <main+0xa4>
jmp    121a <main+0x8a>
lea    0xde4(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d9b(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    -0x14(%rbp),%edi
xor    %esi,%esi
call   1030 <setns@plt>
cmp    $0xffffffff,%eax
jne    1266 <main+0xd6>
jmp    124c <main+0xbc>
lea    0xdb7(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d69(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1283 <main+0xf3>
movl   $0x1,-0x1c(%rbp)
jmp    1283 <main+0xf3>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
jmp    11ad <main+0x1d>
mov    -0x8(%rbp),%eax
mov    0x2d46(%rip),%rcx
cmp    (%rcx),%eax
jg     12a6 <main+0x116>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1040 <usage@plt>
cmpl   $0x0,-0x1c(%rbp)
je     1338 <main+0x1a8>
mov    $0x0,%al
call   10b0 <fork@plt>
mov    %eax,-0x20(%rbp)
cmpl   $0xffffffff,-0x20(%rbp)
jne    12e3 <main+0x153>
jmp    12c9 <main+0x139>
lea    0xd40(%rip),%rdi
call   1070 <perror@plt>
mov    0x2cec(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
cmpl   $0x0,-0x20(%rbp)
je     1333 <main+0x1a3>
mov    $0xffffffff,%edi
xor    %eax,%eax
mov    %eax,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    1325 <main+0x195>
jmp    130b <main+0x17b>
lea    0xd03(%rip),%rdi
call   1070 <perror@plt>
mov    0x2caa(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    0x2c94(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
jmp    1338 <main+0x1a8>
mov    -0x10(%rbp),%rax
mov    0x2c95(%rip),%rcx
movslq (%rcx),%rcx
mov    (%rax,%rcx,8),%rdi
mov    -0x10(%rbp),%rsi
mov    0x2c83(%rip),%rax
movslq (%rax),%rax
shl    $0x3,%rax
add    %rax,%rsi
call   1090 <execvp@plt>
lea    0xcb2(%rip),%rdi
call   1070 <perror@plt>
mov    0x2c51(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
push   %rax
mov    %rsi,%rbx
mov    %edi,%ebp
mov    $0x1,%r15b
lea    0xe56(%rip),%r14
mov    0x2e47(%rip),%r12
mov    0x2e28(%rip),%r13
jmp    11c0 <main+0x30>
xor    %r15d,%r15d
nopl   (%rax)
mov    %ebp,%edi
mov    %rbx,%rsi
mov    %r14,%rdx
call   1080 <getopt@plt>
cmp    $0x6e,%eax
je     11f0 <main+0x60>
cmp    $0x66,%eax
je     11ba <main+0x2a>
cmp    $0xffffffff,%eax
je     1219 <main+0x89>
mov    (%rbx),%rdi
call   1040 <usage@plt>
jmp    11c0 <main+0x30>
cs nopw 0x0(%rax,%rax,1)
mov    (%r12),%edi
mov    0x0(%r13),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     124c <main+0xbc>
mov    %eax,%edi
xor    %esi,%esi
call   1030 <setns@plt>
cmp    $0xffffffff,%eax
jne    11c0 <main+0x30>
lea    0xdf3(%rip),%rdi
jmp    126c <main+0xdc>
mov    0x2db8(%rip),%r14
cmp    %ebp,(%r14)
jl     122d <main+0x9d>
mov    (%rbx),%rdi
call   1040 <usage@plt>
test   $0x1,%r15b
jne    1255 <main+0xc5>
xor    %eax,%eax
call   10b0 <fork@plt>
test   %eax,%eax
je     1255 <main+0xc5>
cmp    $0xffffffff,%eax
jne    127f <main+0xef>
lea    0xdc6(%rip),%rdi
jmp    126c <main+0xdc>
lea    0xdb2(%rip),%rdi
jmp    126c <main+0xdc>
movslq (%r14),%rax
lea    (%rbx,%rax,8),%rsi
mov    (%rbx,%rax,8),%rdi
call   1090 <execvp@plt>
lea    0xdb1(%rip),%rdi
call   1070 <perror@plt>
mov    0x2d50(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>
mov    $0xffffffff,%edi
xor    %esi,%esi
xor    %edx,%edx
call   1050 <waitpid@plt>
cmp    $0xffffffff,%eax
jne    129b <main+0x10b>
lea    0xd7c(%rip),%rdi
jmp    126c <main+0xdc>
mov    0x2d1e(%rip),%rax
mov    (%rax),%edi
call   10a0 <exit@plt>

LLVM IR (-O0):
@.str = [5 x i8] c"+fn:\00"
@optarg = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"setns\00"
@optind = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [8 x i8] c"waitpid\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i32
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
store i32 0, i32* %8
br label %10
10: ; preds = %46, %2
%11 = load i32, i32* %4
%12 = load i8**, i8*** %5
%13 = call i32 @getopt(i32 %11, i8** %12, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
store i32 %13, i32* %7
%14 = icmp ne i32 %13, -1
br i1 %14, label %15, label %47
15: ; preds = %10
%16 = load i32, i32* %7
switch i32 %16, label %41 [
i32 110, label %17
i32 102, label %40
]
17: ; preds = %15
%18 = load i32, i32* @optarg
%19 = load i32, i32* @O_RDONLY
%20 = call i32 @open(i32 %18, i32 %19)
store i32 %20, i32* %6
%21 = load i32, i32* %6
%22 = icmp eq i32 %21, -1
br i1 %22, label %23, label %29
23: ; preds = %17
br label %24
24: ; preds = %23
%25 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%26 = load i32, i32* @EXIT_FAILURE
%27 = call i32 @exit(i32 %26)
unreachable
28: ; No predecessors!
br label %29
29: ; preds = %28, %17
%30 = load i32, i32* %6
%31 = call i32 @setns(i32 %30, i32 0)
%32 = icmp eq i32 %31, -1
br i1 %32, label %33, label %39
33: ; preds = %29
br label %34
34: ; preds = %33
%35 = call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%36 = load i32, i32* @EXIT_FAILURE
%37 = call i32 @exit(i32 %36)
unreachable
38: ; No predecessors!
br label %39
39: ; preds = %38, %29
br label %46
40: ; preds = %15
store i32 1, i32* %8
br label %46
41: ; preds = %15
%42 = load i8**, i8*** %5
%43 = getelementptr inbounds i8*, i8** %42, i64 0
%44 = load i8*, i8** %43
%45 = call i32 @usage(i8* %44)
br label %46
46: ; preds = %41, %40, %39
br label %10
47: ; preds = %10
%48 = load i32, i32* %4
%49 = load i32, i32* @optind
%50 = icmp sle i32 %48, %49
br i1 %50, label %51, label %56
51: ; preds = %47
%52 = load i8**, i8*** %5
%53 = getelementptr inbounds i8*, i8** %52, i64 0
%54 = load i8*, i8** %53
%55 = call i32 @usage(i8* %54)
br label %56
56: ; preds = %51, %47
%57 = load i32, i32* %8
%58 = icmp ne i32 %57, 0
br i1 %58, label %59, label %85
59: ; preds = %56
%60 = call i32 (...) @fork()
store i32 %60, i32* %9
%61 = load i32, i32* %9
%62 = icmp eq i32 %61, -1
br i1 %62, label %63, label %69
63: ; preds = %59
br label %64
64: ; preds = %63
%65 = call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%66 = load i32, i32* @EXIT_FAILURE
%67 = call i32 @exit(i32 %66)
unreachable
68: ; No predecessors!
br label %69
69: ; preds = %68, %59
%70 = load i32, i32* %9
%71 = icmp ne i32 %70, 0
br i1 %71, label %72, label %84
72: ; preds = %69
%73 = call i32 @waitpid(i32 -1, i32* null, i32 0)
%74 = icmp eq i32 %73, -1
br i1 %74, label %75, label %81
75: ; preds = %72
br label %76
76: ; preds = %75
%77 = call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%78 = load i32, i32* @EXIT_FAILURE
%79 = call i32 @exit(i32 %78)
unreachable
80: ; No predecessors!
br label %81
81: ; preds = %80, %72
%82 = load i32, i32* @EXIT_SUCCESS
%83 = call i32 @exit(i32 %82)
unreachable
84: ; preds = %69
br label %85
85: ; preds = %84, %56
%86 = load i8**, i8*** %5
%87 = load i32, i32* @optind
%88 = sext i32 %87 to i64
%89 = getelementptr inbounds i8*, i8** %86, i64 %88
%90 = load i8*, i8** %89
%91 = load i8**, i8*** %5
%92 = load i32, i32* @optind
%93 = sext i32 %92 to i64
%94 = getelementptr inbounds i8*, i8** %91, i64 %93
%95 = call i32 @execvp(i8* %90, i8** %94)
br label %96
96: ; preds = %85
%97 = call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%98 = load i32, i32* @EXIT_FAILURE
%99 = call i32 @exit(i32 %98)
unreachable
100: ; No predecessors!
%101 = load i32, i32* %3
ret i32 %101
}

LLVM IR (-O2):
@.str = [5 x i8] c"+fn:\00"
@optarg = global i32 0
@O_RDONLY = global i32 0
@.str.1 = [5 x i8] c"open\00"
@EXIT_FAILURE = global i32 0
@.str.2 = [6 x i8] c"setns\00"
@optind = global i32 0
@.str.3 = [5 x i8] c"fork\00"
@.str.4 = [8 x i8] c"waitpid\00"
@EXIT_SUCCESS = global i32 0
@.str.5 = [7 x i8] c"execvp\00"
define i32 @main(i32 %0, i8** %1) {
br label %3
3: ; preds = %5, %2
%4 = phi i1 [ true, %2 ], [ false, %5 ]
br label %5
5: ; preds = %19, %3
%6 = tail call i32 @getopt(i32 %0, i8** %1, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i64 0, i64 0))
switch i32 %6, label %24 [
i32 -1, label %27
i32 110, label %7
i32 102, label %3
]
7: ; preds = %5
%8 = load i32, i32* @optarg
%9 = load i32, i32* @O_RDONLY
%10 = tail call i32 @open(i32 %8, i32 %9)
%11 = icmp eq i32 %10, -1
br i1 %11, label %12, label %16
12: ; preds = %7
%13 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.1, i64 0, i64 0))
%14 = load i32, i32* @EXIT_FAILURE
%15 = tail call i32 @exit(i32 %14)
unreachable
16: ; preds = %7
%17 = tail call i32 @setns(i32 %10, i32 0)
%18 = icmp eq i32 %17, -1
br i1 %18, label %20, label %19
19: ; preds = %16, %24
br label %5
20: ; preds = %16
%21 = tail call i32 @perror(i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.2, i64 0, i64 0))
%22 = load i32, i32* @EXIT_FAILURE
%23 = tail call i32 @exit(i32 %22)
unreachable
24: ; preds = %5
%25 = load i8*, i8** %1
%26 = tail call i32 @usage(i8* %25)
br label %19
27: ; preds = %5
%28 = load i32, i32* @optind
%29 = icmp slt i32 %28, %0
br i1 %29, label %33, label %30
30: ; preds = %27
%31 = load i8*, i8** %1
%32 = tail call i32 @usage(i8* %31)
br label %33
33: ; preds = %30, %27
br i1 %4, label %50, label %34
34: ; preds = %33
%35 = tail call i32 (...) @fork()
switch i32 %35, label %40 [
i32 -1, label %36
i32 0, label %50
]
36: ; preds = %34
%37 = tail call i32 @perror(i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%38 = load i32, i32* @EXIT_FAILURE
%39 = tail call i32 @exit(i32 %38)
unreachable
40: ; preds = %34
%41 = tail call i32 @waitpid(i32 -1, i32* null, i32 0)
%42 = icmp eq i32 %41, -1
br i1 %42, label %43, label %47
43: ; preds = %40
%44 = tail call i32 @perror(i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%45 = load i32, i32* @EXIT_FAILURE
%46 = tail call i32 @exit(i32 %45)
unreachable
47: ; preds = %40
%48 = load i32, i32* @EXIT_SUCCESS
%49 = tail call i32 @exit(i32 %48)
unreachable
50: ; preds = %34, %33
%51 = load i32, i32* @optind
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8*, i8** %1, i64 %52
%54 = load i8*, i8** %53
%55 = tail call i32 @execvp(i8* %54, i8** %53)
%56 = tail call i32 @perror(i8* getelementptr inbounds ([7 x i8], [7 x i8]* @.str.5, i64 0, i64 0))
%57 = load i32, i32* @EXIT_FAILURE
%58 = tail call i32 @exit(i32 %57)
unreachable
}