#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_RDONLY;
int /*<<< orphan*/ close(int);
int /*<<< orphan*/ errno;
int /*<<< orphan*/ execvp(char *const, char *const *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *, ...);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ perror(char *);
int setns(int, int /*<<< orphan*/);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int main(int argc, char *argv[]) {
  char *const argv_default[] = {"bash", NULL};
  char *const *exec_argv = argv_default;
  if (argc > 2) {
    exec_argv = argv + 2;
  } else if (argc < 2) {
    fprintf(stderr, "Usage: %s ns-path [command [args...]]\n", argv[0]);
    return 255;
  }
  int fd = open(argv[1], O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "%s: %s: %s\n", argv[0], argv[1], strerror(errno));
    return 254;
  }
  if (setns(fd, 0) == -1) {
    perror(argv[0]);
    close(fd);
    return 253;
  }
  close(fd);
  execvp(exec_argv[0], exec_argv);
  fprintf(stderr, "%s: %s: %s\n", argv[0], exec_argv[0], strerror(errno));
  return 252;
}


x86 assembly (clang, -O0):
<main>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
movl   $0x0,-0x4(%rbp)
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2c63(%rip),%rax
mov    %rax,-0x20(%rbp)
mov    0x2c60(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    -0x20(%rbp),%rax
mov    %rax,-0x28(%rbp)
cmpl   $0x2,-0x8(%rbp)
jle    11bf <main+0x4f>
mov    -0x10(%rbp),%rax
add    $0x10,%rax
mov    %rax,-0x28(%rbp)
jmp    11f8 <main+0x88>
cmpl   $0x2,-0x8(%rbp)
jge    11f3 <main+0x83>
mov    0x2e00(%rip),%rax
mov    (%rax),%edi
mov    -0x10(%rbp),%rax
mov    (%rax),%rdx
lea    0xe25(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xff,-0x4(%rbp)
jmp    1312 <main+0x1a2>
jmp    11f8 <main+0x88>
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rdi
mov    0x2dd9(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0xffffffff,-0x2c(%rbp)
jne    1274 <main+0x104>
mov    0x2dae(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x44(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x40(%rbp)
mov    -0x10(%rbp),%rax
mov    0x8(%rax),%rax
mov    %rax,-0x38(%rbp)
mov    0x2d83(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x44(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    -0x38(%rbp),%rcx
mov    %rax,%r8
lea    0xdcb(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfe,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x2c(%rbp),%edi
xor    %esi,%esi
call   1030 <setns@plt>
cmp    $0xffffffff,%eax
jne    12a7 <main+0x137>
mov    -0x10(%rbp),%rax
mov    (%rax),%rdi
call   1070 <perror@plt>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
movl   $0xfd,-0x4(%rbp)
jmp    1312 <main+0x1a2>
mov    -0x2c(%rbp),%edi
call   1040 <close@plt>
mov    -0x28(%rbp),%rax
mov    (%rax),%rdi
mov    -0x28(%rbp),%rsi
call   1080 <execvp@plt>
mov    0x2d0a(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x5c(%rbp)
mov    -0x10(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x58(%rbp)
mov    -0x28(%rbp),%rax
mov    (%rax),%rax
mov    %rax,-0x50(%rbp)
mov    0x2ce0(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
mov    -0x5c(%rbp),%edi
mov    -0x58(%rbp),%rdx
mov    -0x50(%rbp),%rcx
mov    %rax,%r8
lea    0xd28(%rip),%rsi
mov    $0x0,%al
call   1050 <fprintf@plt>
movl   $0xfc,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<main>:
push   %rbp
push   %r14
push   %rbx
sub    $0x10,%rsp
mov    %rsi,%rbx
movaps 0x2c6e(%rip),%xmm0
movaps %xmm0,(%rsp)
cmp    $0x3,%edi
jl     1191 <main+0x21>
lea    0x10(%rbx),%r14
jmp    119d <main+0x2d>
cmp    $0x2,%edi
jne    1255 <main+0xe5>
mov    %rsp,%r14
mov    0x8(%rbx),%rdi
mov    0x2e38(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     1217 <main+0xa7>
mov    %eax,%ebp
mov    %eax,%edi
xor    %esi,%esi
call   1030 <setns@plt>
cmp    $0xffffffff,%eax
je     127d <main+0x10d>
mov    %ebp,%edi
call   1040 <close@plt>
mov    (%r14),%rdi
mov    %r14,%rsi
call   1080 <execvp@plt>
mov    0x2def(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%rbx
mov    (%r14),%r14
mov    0x2dd8(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xe2e(%rip),%rsi
mov    %ebp,%edi
mov    %rbx,%rdx
mov    %r14,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xfc,%eax
jmp    1274 <main+0x104>
mov    0x2db2(%rip),%rax
mov    (%rax),%ebp
mov    (%rbx),%r14
mov    0x8(%rbx),%rbx
mov    0x2d9a(%rip),%rax
mov    (%rax),%edi
call   1090 <strerror@plt>
lea    0xdf0(%rip),%rsi
mov    %ebp,%edi
mov    %r14,%rdx
mov    %rbx,%rcx
mov    %rax,%r8
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xfe,%eax
jmp    1274 <main+0x104>
mov    0x2d74(%rip),%rax
mov    (%rax),%edi
mov    (%rbx),%rdx
lea    0xd9d(%rip),%rsi
xor    %eax,%eax
call   1050 <fprintf@plt>
mov    $0xff,%eax
add    $0x10,%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret
mov    (%rbx),%rdi
call   1070 <perror@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    $0xfd,%eax
jmp    1274 <main+0x104>

LLVM IR (-O0):
@.str = [5 x i8] c"bash\00"
@__const.main.argv_default = [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.1 = [39 x i8] c"Usage: %s ns-path [command [args...]]\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca [2 x i8*]
%7 = alloca i8**
%8 = alloca i32
store i32 0, i32* %3
store i32 %0, i32* %4
store i8** %1, i8*** %5
%9 = bitcast [2 x i8*]* %6 to i8*
%10 = getelementptr inbounds [2 x i8*], [2 x i8*]* %6, i64 0, i64 0
store i8** %10, i8*** %7
%11 = load i32, i32* %4
%12 = icmp sgt i32 %11, 2
br i1 %12, label %13, label %16
13: ; preds = %2
%14 = load i8**, i8*** %5
%15 = getelementptr inbounds i8*, i8** %14, i64 2
store i8** %15, i8*** %7
br label %26
16: ; preds = %2
%17 = load i32, i32* %4
%18 = icmp slt i32 %17, 2
br i1 %18, label %19, label %25
19: ; preds = %16
%20 = load i32, i32* @stderr
%21 = load i8**, i8*** %5
%22 = getelementptr inbounds i8*, i8** %21, i64 0
%23 = load i8*, i8** %22
%24 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %23)
store i32 255, i32* %3
br label %74
25: ; preds = %16
br label %26
26: ; preds = %25, %13
%27 = load i8**, i8*** %5
%28 = getelementptr inbounds i8*, i8** %27, i64 1
%29 = load i8*, i8** %28
%30 = load i32, i32* @O_RDONLY
%31 = call i32 @open(i8* %29, i32 %30)
store i32 %31, i32* %8
%32 = load i32, i32* %8
%33 = icmp eq i32 %32, -1
br i1 %33, label %34, label %45
34: ; preds = %26
%35 = load i32, i32* @stderr
%36 = load i8**, i8*** %5
%37 = getelementptr inbounds i8*, i8** %36, i64 0
%38 = load i8*, i8** %37
%39 = load i8**, i8*** %5
%40 = getelementptr inbounds i8*, i8** %39, i64 1
%41 = load i8*, i8** %40
%42 = load i32, i32* @errno
%43 = call i8* @strerror(i32 %42)
%44 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %35, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %38, i8* %41, i8* %43)
store i32 254, i32* %3
br label %74
45: ; preds = %26
%46 = load i32, i32* %8
%47 = call i32 @setns(i32 %46, i32 0)
%48 = icmp eq i32 %47, -1
br i1 %48, label %49, label %56
49: ; preds = %45
%50 = load i8**, i8*** %5
%51 = getelementptr inbounds i8*, i8** %50, i64 0
%52 = load i8*, i8** %51
%53 = call i32 @perror(i8* %52)
%54 = load i32, i32* %8
%55 = call i32 @close(i32 %54)
store i32 253, i32* %3
br label %74
56: ; preds = %45
%57 = load i32, i32* %8
%58 = call i32 @close(i32 %57)
%59 = load i8**, i8*** %7
%60 = getelementptr inbounds i8*, i8** %59, i64 0
%61 = load i8*, i8** %60
%62 = load i8**, i8*** %7
%63 = call i32 @execvp(i8* %61, i8** %62)
%64 = load i32, i32* @stderr
%65 = load i8**, i8*** %5
%66 = getelementptr inbounds i8*, i8** %65, i64 0
%67 = load i8*, i8** %66
%68 = load i8**, i8*** %7
%69 = getelementptr inbounds i8*, i8** %68, i64 0
%70 = load i8*, i8** %69
%71 = load i32, i32* @errno
%72 = call i8* @strerror(i32 %71)
%73 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %67, i8* %70, i8* %72)
store i32 252, i32* %3
br label %74
74: ; preds = %56, %49, %34, %19
%75 = load i32, i32* %3
ret i32 %75
}

LLVM IR (-O2):
@.str = [5 x i8] c"bash\00"
@__const.main.argv_default = [2 x i8*] [i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str, i32 0, i32 0), i8* null]
@stderr = global i32 0
@.str.1 = [39 x i8] c"Usage: %s ns-path [command [args...]]\0A\00"
@O_RDONLY = global i32 0
@.str.2 = [12 x i8] c"%s: %s: %s\0A\00"
@errno = global i32 0
define i32 @main(i32 %0, i8** %1) {
%3 = alloca [2 x i8*]
%4 = bitcast [2 x i8*]* %3 to i8*
%5 = icmp sgt i32 %0, 2
br i1 %5, label %6, label %8
6: ; preds = %2
%7 = getelementptr inbounds i8*, i8** %1, i64 2
br label %15
8: ; preds = %2
%9 = getelementptr inbounds [2 x i8*], [2 x i8*]* %3, i64 0, i64 0
%10 = icmp eq i32 %0, 2
br i1 %10, label %15, label %11
11: ; preds = %8
%12 = load i32, i32* @stderr
%13 = load i8*, i8** %1
%14 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %12, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %13)
br label %46
15: ; preds = %8, %6
%16 = phi i8** [ %7, %6 ], [ %9, %8 ]
%17 = getelementptr inbounds i8*, i8** %1, i64 1
%18 = load i8*, i8** %17
%19 = load i32, i32* @O_RDONLY
%20 = tail call i32 @open(i8* %18, i32 %19)
%21 = icmp eq i32 %20, -1
br i1 %21, label %22, label %29
22: ; preds = %15
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %1
%25 = load i8*, i8** %17
%26 = load i32, i32* @errno
%27 = tail call i8* @strerror(i32 %26)
%28 = tail call i32 (i32, i8*, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %24, i8* %25, i8* %27)
br label %46
29: ; preds = %15
%30 = tail call i32 @setns(i32 %20, i32 0)
%31 = icmp eq i32 %30, -1
br i1 %31, label %32, label %36
32: ; preds = %29
%33 = load i8*, i8** %1
%34 = tail call i32 @perror(i8* %33)
%35 = tail call i32 @close(i32 %20)
br label %46
36: ; preds = %29
%37 = tail call i32 @close(i32 %20)
%38 = load i8*, i8** %16
%39 = call i32 @execvp(i8* %38, i8** %16)
%40 = load i32, i32* @stderr
%41 = load i8*, i8** %1
%42 = load i8*, i8** %16
%43 = load i32, i32* @errno
%44 = call i8* @strerror(i32 %43)
%45 = call i32 (i32, i8*, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.2, i64 0, i64 0), i8* %41, i8* %42, i8* %44)
br label %46
46: ; preds = %22, %32, %36, %11
%47 = phi i32 [ 255, %11 ], [ 254, %22 ], [ 253, %32 ], [ 252, %36 ]
ret i32 %47
}