#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 */
struct stat {
  int dummy;
};
typedef int pid_t;
typedef int /*<<< orphan*/ namespaces;
typedef int /*<<< orphan*/ jmp_buf;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
scalar_t__ ENOENT;
int O_DIRECTORY;
int O_RDONLY;
int PATH_MAX;
int /*<<< orphan*/ SIGKILL;
int atoi(char *);
int clone_parent(int /*<<< orphan*/ *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ exit(int);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstatat(int, char *, struct stat *, int /*<<< orphan*/);
char *getenv(char *);
int /*<<< orphan*/ kill(int, int /*<<< orphan*/);
int open(char *, int);
int openat(int, char *, int);
int setjmp(int /*<<< orphan*/);
int setns(int, int /*<<< orphan*/);
int snprintf(char *, int, char *, int);
int /*<<< orphan*/ stderr;
scalar_t__ strcmp(char *, char *);
int write(int, char *, int);
void nsexec() {
  char *namespaces[] = {"ipc", "uts", "net", "pid", "mnt"};
  const int num = sizeof(namespaces) / sizeof(char *);
  jmp_buf env;
  char buf[PATH_MAX], *val;
  int i, tfd, child, len;
  pid_t pid;
  val = getenv("_LIBCONTAINER_INITPID");
  if (val == NULL)
    return;
  pid = atoi(val);
  snprintf(buf, sizeof(buf), "%d", pid);
  if (strcmp(val, buf)) {
    fprintf(stderr, "nsenter: "
                    "Unable to parse _LIBCONTAINER_INITPID"
                    ": %m\n");
    exit(1);
  }
  snprintf(buf, PATH_MAX - 1, "/proc/%d/ns", pid);
  tfd = open(buf, O_DIRECTORY | O_RDONLY);
  if (tfd == -1) {
    fprintf(stderr,
            "nsenter: "
            "Failed to open \"%s\""
            ": %m\n",
            buf);
    exit(1);
  }
  for (i = 0; i < num; i++) {
    struct stat st;
    int fd;
    if (fstatat(tfd, namespaces[i], &st, AT_SYMLINK_NOFOLLOW) == -1) {
      if (errno == ENOENT)
        continue;
    }
    fd = openat(tfd, namespaces[i], O_RDONLY);
    if (fd == -1) {
      fprintf(stderr,
              "nsenter: "
              "Failed to open ns file %s for ns %s"
              ": %m\n",
              buf, namespaces[i]);
      exit(1);
    }
    if (setns(fd, 0) == -1) {
      fprintf(stderr,
              "nsenter: "
              "Failed to setns for %s"
              ": %m\n",
              namespaces[i]);
      exit(1);
    }
    close(fd);
  }
  if (setjmp(env) == 1) {
    return;
  }
  child = clone_parent(&env);
  if (child < 0) {
    fprintf(stderr, "nsenter: "
                    "Unable to fork"
                    ": %m\n");
    exit(1);
  }
  len = snprintf(buf, sizeof(buf), "{ \"pid\" : %d }\n", child);
  if (write(3, buf, len) != len) {
    fprintf(stderr, "nsenter: "
                    "Unable to send a child pid"
                    ": %m\n");
    kill(child, SIGKILL);
    exit(1);
  }
  exit(0);
}


x86 assembly (clang, -O0):
<nsexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x90,%rsp
xorps  %xmm0,%xmm0
movaps %xmm0,-0x20(%rbp)
movaps %xmm0,-0x30(%rbp)
movq   $0x0,-0x10(%rbp)
lea    0xdeb(%rip),%rax
mov    %rax,-0x30(%rbp)
lea    0xde4(%rip),%rax
mov    %rax,-0x28(%rbp)
lea    0xddd(%rip),%rax
mov    %rax,-0x20(%rbp)
lea    0xdd6(%rip),%rax
mov    %rax,-0x18(%rbp)
lea    0xdcf(%rip),%rax
mov    %rax,-0x10(%rbp)
movl   $0x5,-0x34(%rbp)
mov    0x2d9d(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x88(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x80(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x48(%rbp)
lea    0xd8e(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x50(%rbp)
cmpq   $0x0,-0x50(%rbp)
jne    12a6 <nsexec+0xb6>
movl   $0x1,-0x68(%rbp)
jmp    153e <nsexec+0x34e>
mov    -0x50(%rbp),%rdi
call   10f0 <atoi@plt>
mov    -0x80(%rbp),%rdi
mov    %eax,%ecx
mov    -0x88(%rbp),%rax
mov    %ecx,-0x64(%rbp)
mov    %eax,%esi
mov    -0x64(%rbp),%ecx
lea    0xd5f(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x80(%rbp),%rsi
mov    -0x50(%rbp),%rdi
call   10a0 <strcmp@plt>
cmp    $0x0,%rax
je     1308 <nsexec+0x118>
mov    0x2cda(%rip),%rax
mov    (%rax),%edi
lea    0xd36(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x80(%rbp),%rdi
mov    0x2cdd(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x64(%rbp),%ecx
lea    0xd3f(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x80(%rbp),%rdi
mov    0x2c9e(%rip),%rax
mov    (%rax),%esi
mov    0x2ca5(%rip),%rax
or     (%rax),%esi
call   10e0 <open@plt>
mov    %eax,-0x58(%rbp)
cmpl   $0xffffffff,-0x58(%rbp)
jne    1374 <nsexec+0x184>
mov    -0x80(%rbp),%rdx
mov    0x2c6e(%rip),%rax
mov    (%rax),%edi
lea    0xd0a(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
movl   $0x0,-0x54(%rbp)
cmpl   $0x5,-0x54(%rbp)
jge    1478 <nsexec+0x288>
mov    -0x58(%rbp),%edi
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
mov    0x2c18(%rip),%rax
mov    (%rax),%ecx
lea    -0x70(%rbp),%rdx
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    13d0 <nsexec+0x1e0>
mov    0x2c0d(%rip),%rax
mov    (%rax),%rax
mov    0x2be3(%rip),%rcx
cmp    (%rcx),%rax
jne    13cb <nsexec+0x1db>
jmp    146a <nsexec+0x27a>
jmp    13d0 <nsexec+0x1e0>
mov    -0x58(%rbp),%edi
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rsi
mov    0x2bfd(%rip),%rax
mov    (%rax),%edx
call   1060 <openat@plt>
mov    %eax,-0x74(%rbp)
cmpl   $0xffffffff,-0x74(%rbp)
jne    1425 <nsexec+0x235>
mov    -0x80(%rbp),%rdx
mov    0x2bc6(%rip),%rax
mov    (%rax),%edi
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rcx
lea    0xc7b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x74(%rbp),%edi
xor    %esi,%esi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
jne    1462 <nsexec+0x272>
mov    0x2b89(%rip),%rax
mov    (%rax),%edi
movslq -0x54(%rbp),%rax
mov    -0x30(%rbp,%rax,8),%rdx
lea    0xc70(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x74(%rbp),%edi
call   1090 <close@plt>
mov    -0x54(%rbp),%eax
add    $0x1,%eax
mov    %eax,-0x54(%rbp)
jmp    137b <nsexec+0x18b>
mov    -0x38(%rbp),%edi
call   10d0 <setjmp@plt>
cmp    $0x1,%eax
jne    1495 <nsexec+0x2a5>
movl   $0x1,-0x68(%rbp)
jmp    153e <nsexec+0x34e>
lea    -0x38(%rbp),%rdi
call   1040 <clone_parent@plt>
mov    %eax,-0x5c(%rbp)
cmpl   $0x0,-0x5c(%rbp)
jge    14cc <nsexec+0x2dc>
mov    0x2b16(%rip),%rax
mov    (%rax),%edi
lea    0xc2b(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    -0x80(%rbp),%rdi
mov    -0x88(%rbp),%rax
mov    %eax,%esi
mov    -0x5c(%rbp),%ecx
lea    0xc20(%rip),%rdx
call   1070 <snprintf@plt>
mov    -0x80(%rbp),%rsi
mov    %eax,-0x60(%rbp)
mov    -0x60(%rbp),%edx
mov    $0x3,%edi
call   1050 <write@plt>
cmp    -0x60(%rbp),%eax
je     1537 <nsexec+0x347>
mov    0x2abc(%rip),%rax
mov    (%rax),%edi
lea    0xbfe(%rip),%rsi
mov    $0x0,%al
call   10b0 <fprintf@plt>
mov    -0x5c(%rbp),%edi
mov    0x2a92(%rip),%rax
mov    (%rax),%esi
call   10c0 <kill@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
xor    %edi,%edi
call   1100 <exit@plt>
mov    -0x40(%rbp),%rax
mov    %rax,%rsp
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsexec>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsp,%r13
mov    0x2de5(%rip),%r14
mov    (%r14),%eax
mov    %eax,%ebx
mov    %rsp,%r15
lea    0xf(%rbx),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%r15
mov    %r15,%rsp
lea    0xdec(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     14ea <nsexec+0x2fa>
mov    %r15,-0x38(%rbp)
mov    %ebx,%r15d
mov    %rax,%rbx
mov    %rax,%rdi
call   10f0 <atoi@plt>
mov    %eax,%r12d
lea    0xdd8(%rip),%rdx
mov    -0x38(%rbp),%rdi
mov    %r15d,-0x3c(%rbp)
mov    %r15d,%esi
mov    -0x38(%rbp),%r15
mov    %eax,%ecx
call   1070 <snprintf@plt>
mov    %rbx,%rdi
mov    %r15,%rsi
call   10a0 <strcmp@plt>
test   %rax,%rax
jne    1523 <nsexec+0x333>
mov    %r13,-0x48(%rbp)
mov    (%r14),%esi
add    $0xffffffff,%esi
lea    0xdd4(%rip),%rdx
mov    %r15,%rdi
mov    %r12d,%ecx
call   1070 <snprintf@plt>
mov    0x2d31(%rip),%rax
mov    0x2d3a(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %r15,%rdi
call   10e0 <open@plt>
cmp    $0xffffffff,%eax
je     1535 <nsexec+0x345>
mov    %eax,%r13d
mov    0x2ceb(%rip),%r14
mov    (%r14),%ecx
lea    0xd31(%rip),%r12
lea    -0x30(%rbp),%rdx
mov    %eax,%edi
mov    %r12,%rsi
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    12f8 <nsexec+0x108>
mov    0x2cd7(%rip),%rax
mov    (%rax),%rax
mov    0x2cad(%rip),%rcx
cmp    (%rcx),%rax
je     1330 <nsexec+0x140>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <openat@plt>
cmp    $0xffffffff,%eax
je     14fc <nsexec+0x30c>
mov    %eax,%ebx
xor    %esi,%esi
mov    %eax,%edi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
je     157a <nsexec+0x38a>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r14),%ecx
lea    0xcca(%rip),%r12
lea    -0x30(%rbp),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    1364 <nsexec+0x174>
mov    0x2c6b(%rip),%rax
mov    (%rax),%rax
mov    0x2c41(%rip),%rcx
cmp    (%rcx),%rax
je     139c <nsexec+0x1ac>
mov    0x2c75(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <openat@plt>
cmp    $0xffffffff,%eax
je     14fc <nsexec+0x30c>
mov    %eax,%ebx
xor    %esi,%esi
mov    %eax,%edi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
je     1583 <nsexec+0x393>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r14),%ecx
lea    0xc62(%rip),%r12
lea    -0x30(%rbp),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    13d0 <nsexec+0x1e0>
mov    0x2bff(%rip),%rax
mov    (%rax),%rax
mov    0x2bd5(%rip),%rcx
cmp    (%rcx),%rax
je     1408 <nsexec+0x218>
mov    0x2c09(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <openat@plt>
cmp    $0xffffffff,%eax
je     14fc <nsexec+0x30c>
mov    %eax,%ebx
xor    %esi,%esi
mov    %eax,%edi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
je     158c <nsexec+0x39c>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r14),%ecx
lea    0xbfa(%rip),%r12
lea    -0x30(%rbp),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    143c <nsexec+0x24c>
mov    0x2b93(%rip),%rax
mov    (%rax),%rax
mov    0x2b69(%rip),%rcx
cmp    (%rcx),%rax
je     1474 <nsexec+0x284>
mov    0x2b9d(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <openat@plt>
cmp    $0xffffffff,%eax
je     14fc <nsexec+0x30c>
mov    %eax,%ebx
xor    %esi,%esi
mov    %eax,%edi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
je     1595 <nsexec+0x3a5>
mov    %ebx,%edi
call   1090 <close@plt>
mov    (%r14),%ecx
lea    0xb92(%rip),%r12
lea    -0x30(%rbp),%rdx
mov    %r13d,%edi
mov    %r12,%rsi
call   1110 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    14a8 <nsexec+0x2b8>
mov    0x2b27(%rip),%rax
mov    (%rax),%rax
mov    0x2afd(%rip),%rcx
cmp    (%rcx),%rax
je     14dc <nsexec+0x2ec>
mov    0x2b31(%rip),%rax
mov    (%rax),%edx
mov    %r13d,%edi
mov    %r12,%rsi
call   1060 <openat@plt>
cmp    $0xffffffff,%eax
je     14fc <nsexec+0x30c>
mov    %eax,%ebx
xor    %esi,%esi
mov    %eax,%edi
call   1080 <setns@plt>
cmp    $0xffffffff,%eax
je     159e <nsexec+0x3ae>
mov    %ebx,%edi
call   1090 <close@plt>
call   10d0 <setjmp@plt>
cmp    $0x1,%eax
mov    -0x48(%rbp),%r13
jne    154c <nsexec+0x35c>
mov    %r13,%rsp
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    0x2ac5(%rip),%rax
mov    (%rax),%edi
lea    0xb83(%rip),%rsi
xor    %eax,%eax
mov    %r15,%rdx
mov    %r12,%rcx
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    0x2a9e(%rip),%rax
mov    (%rax),%edi
lea    0xafa(%rip),%rsi
jmp    1569 <nsexec+0x379>
mov    0x2a8c(%rip),%rax
mov    (%rax),%edi
lea    0xb28(%rip),%rsi
xor    %eax,%eax
mov    %r15,%rdx
jmp    15b7 <nsexec+0x3c7>
lea    -0x4c(%rbp),%rdi
call   1040 <clone_parent@plt>
test   %eax,%eax
jns    15c6 <nsexec+0x3d6>
mov    0x2a68(%rip),%rax
mov    (%rax),%edi
lea    0xb7d(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
lea    0xa7f(%rip),%rdx
jmp    15a5 <nsexec+0x3b5>
lea    0xa7a(%rip),%rdx
jmp    15a5 <nsexec+0x3b5>
lea    0xa75(%rip),%rdx
jmp    15a5 <nsexec+0x3b5>
lea    0xa70(%rip),%rdx
jmp    15a5 <nsexec+0x3b5>
lea    0xa6b(%rip),%rdx
mov    0x2a1c(%rip),%rax
mov    (%rax),%edi
lea    0xb0c(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    $0x1,%edi
call   1100 <exit@plt>
mov    %eax,%r12d
lea    0xb33(%rip),%rdx
mov    -0x38(%rbp),%r14
mov    %r14,%rdi
mov    -0x3c(%rbp),%esi
mov    %eax,%ecx
call   1070 <snprintf@plt>
mov    %eax,%ebx
mov    $0x3,%edi
mov    %r14,%rsi
mov    %eax,%edx
call   1050 <write@plt>
cmp    %ebx,%eax
jne    15fd <nsexec+0x40d>
xor    %edi,%edi
call   1100 <exit@plt>
mov    0x29c4(%rip),%rax
mov    (%rax),%edi
lea    0xb06(%rip),%rsi
xor    %eax,%eax
call   10b0 <fprintf@plt>
mov    0x299d(%rip),%rax
mov    (%rax),%esi
mov    %r12d,%edi
call   10c0 <kill@plt>
mov    $0x1,%edi
call   1100 <exit@plt>

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [4 x i8] c"ipc\00"
@.str.1 = [4 x i8] c"uts\00"
@.str.2 = [4 x i8] c"net\00"
@.str.3 = [4 x i8] c"pid\00"
@.str.4 = [4 x i8] c"mnt\00"
@PATH_MAX = global i32 0
@.str.5 = [22 x i8] c"_LIBCONTAINER_INITPID\00"
@.str.6 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.7 = [52 x i8] c"nsenter: Unable to parse _LIBCONTAINER_INITPID: %m\0A\00"
@.str.8 = [12 x i8] c"/proc/%d/ns\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.9 = [34 x i8] c"nsenter: Failed to open \22%s\22: %m\0A\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.10 = [50 x i8] c"nsenter: Failed to open ns file %s for ns %s: %m\0A\00"
@.str.11 = [37 x i8] c"nsenter: Failed to setns for %s: %m\0A\00"
@.str.12 = [29 x i8] c"nsenter: Unable to fork: %m\0A\00"
@.str.13 = [16 x i8] c"{ \22pid\22 : %d }\0A\00"
@.str.14 = [41 x i8] c"nsenter: Unable to send a child pid: %m\0A\00"
@SIGKILL = global i32 0
define void @nsexec() {
%1 = alloca [5 x i8*]
%2 = alloca i32
%3 = alloca i32
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i32
%8 = alloca i32
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
%12 = alloca i32
%13 = alloca %struct.stat
%14 = alloca i32
%15 = bitcast [5 x i8*]* %1 to i8*
%16 = bitcast i8* %15 to [5 x i8*]*
%17 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 0
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i32 0, i32 0), i8** %17
%18 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 1
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i32 0, i32 0), i8** %18
%19 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 2
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i32 0, i32 0), i8** %19
%20 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 3
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i32 0, i32 0), i8** %20
%21 = getelementptr inbounds [5 x i8*], [5 x i8*]* %16, i32 0, i32 4
store i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i32 0, i32 0), i8** %21
store i32 5, i32* %2
%22 = load i32, i32* @PATH_MAX
%23 = zext i32 %22 to i64
%24 = call i8* @llvm.stacksave()
store i8* %24, i8** %4
%25 = alloca i8, i64 %23
store i64 %23, i64* %5
%26 = call i8* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
store i8* %26, i8** %6
%27 = load i8*, i8** %6
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %30
29: ; preds = %0
store i32 1, i32* %12
br label %143
30: ; preds = %0
%31 = load i8*, i8** %6
%32 = call i32 @atoi(i8* %31)
store i32 %32, i32* %11
%33 = trunc i64 %23 to i32
%34 = load i32, i32* %11
%35 = call i32 @snprintf(i8* %25, i32 %33, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %34)
%36 = load i8*, i8** %6
%37 = call i64 @strcmp(i8* %36, i8* %25)
%38 = icmp ne i64 %37, 0
br i1 %38, label %39, label %43
39: ; preds = %30
%40 = load i32, i32* @stderr
%41 = call i32 (i32, i8*, ...) @fprintf(i32 %40, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%42 = call i32 @exit(i32 1)
unreachable
43: ; preds = %30
%44 = load i32, i32* @PATH_MAX
%45 = sub nsw i32 %44, 1
%46 = load i32, i32* %11
%47 = call i32 @snprintf(i8* %25, i32 %45, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %46)
%48 = load i32, i32* @O_DIRECTORY
%49 = load i32, i32* @O_RDONLY
%50 = or i32 %48, %49
%51 = call i32 @open(i8* %25, i32 %50)
store i32 %51, i32* %8
%52 = load i32, i32* %8
%53 = icmp eq i32 %52, -1
br i1 %53, label %54, label %58
54: ; preds = %43
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %25)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %43
store i32 0, i32* %7
br label %59
59: ; preds = %110, %58
%60 = load i32, i32* %7
%61 = icmp slt i32 %60, 5
br i1 %61, label %62, label %113
62: ; preds = %59
%63 = load i32, i32* %8
%64 = load i32, i32* %7
%65 = sext i32 %64 to i64
%66 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %65
%67 = load i8*, i8** %66
%68 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%69 = call i32 @fstatat(i32 %63, i8* %67, %struct.stat* %13, i32 %68)
%70 = icmp eq i32 %69, -1
br i1 %70, label %71, label %77
71: ; preds = %62
%72 = load i64, i64* @errno
%73 = load i64, i64* @ENOENT
%74 = icmp eq i64 %72, %73
br i1 %74, label %75, label %76
75: ; preds = %71
br label %110
76: ; preds = %71
br label %77
77: ; preds = %76, %62
%78 = load i32, i32* %8
%79 = load i32, i32* %7
%80 = sext i32 %79 to i64
%81 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %80
%82 = load i8*, i8** %81
%83 = load i32, i32* @O_RDONLY
%84 = call i32 @openat(i32 %78, i8* %82, i32 %83)
store i32 %84, i32* %14
%85 = load i32, i32* %14
%86 = icmp eq i32 %85, -1
br i1 %86, label %87, label %95
87: ; preds = %77
%88 = load i32, i32* @stderr
%89 = load i32, i32* %7
%90 = sext i32 %89 to i64
%91 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %90
%92 = load i8*, i8** %91
%93 = call i32 (i32, i8*, ...) @fprintf(i32 %88, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %25, i8* %92)
%94 = call i32 @exit(i32 1)
unreachable
95: ; preds = %77
%96 = load i32, i32* %14
%97 = call i32 @setns(i32 %96, i32 0)
%98 = icmp eq i32 %97, -1
br i1 %98, label %99, label %107
99: ; preds = %95
%100 = load i32, i32* @stderr
%101 = load i32, i32* %7
%102 = sext i32 %101 to i64
%103 = getelementptr inbounds [5 x i8*], [5 x i8*]* %1, i64 0, i64 %102
%104 = load i8*, i8** %103
%105 = call i32 (i32, i8*, ...) @fprintf(i32 %100, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i8* %104)
%106 = call i32 @exit(i32 1)
unreachable
107: ; preds = %95
%108 = load i32, i32* %14
%109 = call i32 @close(i32 %108)
br label %110
110: ; preds = %107, %75
%111 = load i32, i32* %7
%112 = add nsw i32 %111, 1
store i32 %112, i32* %7
br label %59
113: ; preds = %59
%114 = load i32, i32* %3
%115 = call i32 @setjmp(i32 %114)
%116 = icmp eq i32 %115, 1
br i1 %116, label %117, label %118
117: ; preds = %113
store i32 1, i32* %12
br label %143
118: ; preds = %113
%119 = call i32 @clone_parent(i32* %3)
store i32 %119, i32* %9
%120 = load i32, i32* %9
%121 = icmp slt i32 %120, 0
br i1 %121, label %122, label %126
122: ; preds = %118
%123 = load i32, i32* @stderr
%124 = call i32 (i32, i8*, ...) @fprintf(i32 %123, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%125 = call i32 @exit(i32 1)
unreachable
126: ; preds = %118
%127 = trunc i64 %23 to i32
%128 = load i32, i32* %9
%129 = call i32 @snprintf(i8* %25, i32 %127, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %128)
store i32 %129, i32* %10
%130 = load i32, i32* %10
%131 = call i32 @write(i32 3, i8* %25, i32 %130)
%132 = load i32, i32* %10
%133 = icmp ne i32 %131, %132
br i1 %133, label %134, label %141
134: ; preds = %126
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0))
%137 = load i32, i32* %9
%138 = load i32, i32* @SIGKILL
%139 = call i32 @kill(i32 %137, i32 %138)
%140 = call i32 @exit(i32 1)
unreachable
141: ; preds = %126
%142 = call i32 @exit(i32 0)
unreachable
143: ; preds = %117, %29
%144 = load i8*, i8** %4
ret void
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [4 x i8] c"ipc\00"
@.str.1 = [4 x i8] c"uts\00"
@.str.2 = [4 x i8] c"net\00"
@.str.3 = [4 x i8] c"pid\00"
@.str.4 = [4 x i8] c"mnt\00"
@PATH_MAX = global i32 0
@.str.5 = [22 x i8] c"_LIBCONTAINER_INITPID\00"
@.str.6 = [3 x i8] c"%d\00"
@stderr = global i32 0
@.str.7 = [52 x i8] c"nsenter: Unable to parse _LIBCONTAINER_INITPID: %m\0A\00"
@.str.8 = [12 x i8] c"/proc/%d/ns\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.9 = [34 x i8] c"nsenter: Failed to open \22%s\22: %m\0A\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@.str.10 = [50 x i8] c"nsenter: Failed to open ns file %s for ns %s: %m\0A\00"
@.str.11 = [37 x i8] c"nsenter: Failed to setns for %s: %m\0A\00"
@.str.12 = [29 x i8] c"nsenter: Unable to fork: %m\0A\00"
@.str.13 = [16 x i8] c"{ \22pid\22 : %d }\0A\00"
@.str.14 = [41 x i8] c"nsenter: Unable to send a child pid: %m\0A\00"
@SIGKILL = global i32 0
define void @nsexec() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = bitcast i32* %1 to i8*
%4 = load i32, i32* @PATH_MAX
%5 = zext i32 %4 to i64
%6 = call i8* @llvm.stacksave()
%7 = alloca i8, i64 %5
%8 = call i8* @getenv(i8* getelementptr inbounds ([22 x i8], [22 x i8]* @.str.5, i64 0, i64 0))
%9 = icmp eq i8* %8, null
br i1 %9, label %150, label %10
10: ; preds = %0
%11 = call i32 @atoi(i8* %8)
%12 = call i32 @snprintf(i8* %7, i32 %4, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.6, i64 0, i64 0), i32 %11)
%13 = call i64 @strcmp(i8* %8, i8* %7)
%14 = icmp eq i64 %13, 0
br i1 %14, label %19, label %15
15: ; preds = %10
%16 = load i32, i32* @stderr
%17 = call i32 (i32, i8*, ...) @fprintf(i32 %16, i8* getelementptr inbounds ([52 x i8], [52 x i8]* @.str.7, i64 0, i64 0))
%18 = call i32 @exit(i32 1)
unreachable
19: ; preds = %10
%20 = load i32, i32* @PATH_MAX
%21 = add nsw i32 %20, -1
%22 = call i32 @snprintf(i8* %7, i32 %21, i8* getelementptr inbounds ([12 x i8], [12 x i8]* @.str.8, i64 0, i64 0), i32 %11)
%23 = load i32, i32* @O_DIRECTORY
%24 = load i32, i32* @O_RDONLY
%25 = or i32 %24, %23
%26 = call i32 @open(i8* %7, i32 %25)
%27 = icmp eq i32 %26, -1
br i1 %27, label %33, label %28
28: ; preds = %19
%29 = bitcast %struct.stat* %2 to i8*
%30 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%31 = call i32 @fstatat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %struct.stat* %2, i32 %30)
%32 = icmp eq i32 %31, -1
br i1 %32, label %37, label %41
33: ; preds = %19
%34 = load i32, i32* @stderr
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %34, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.9, i64 0, i64 0), i8* %7)
%36 = call i32 @exit(i32 1)
unreachable
37: ; preds = %28
%38 = load i64, i64* @errno
%39 = load i64, i64* @ENOENT
%40 = icmp eq i64 %38, %39
br i1 %40, label %60, label %41
41: ; preds = %37, %28
%42 = load i32, i32* @O_RDONLY
%43 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), i32 %42)
%44 = icmp eq i32 %43, -1
br i1 %44, label %45, label %50
45: ; preds = %119, %102, %85, %68, %41
%46 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %41 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %68 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %85 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %102 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %119 ]
%47 = load i32, i32* @stderr
%48 = call i32 (i32, i8*, ...) @fprintf(i32 %47, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.10, i64 0, i64 0), i8* %7, i8* %46)
%49 = call i32 @exit(i32 1)
unreachable
50: ; preds = %41
%51 = call i32 @setns(i32 %43, i32 0)
%52 = icmp eq i32 %51, -1
br i1 %52, label %53, label %58
53: ; preds = %123, %106, %89, %72, %50
%54 = phi i8* [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str, i64 0, i64 0), %50 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %72 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %89 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %106 ], [ getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %123 ]
%55 = load i32, i32* @stderr
%56 = call i32 (i32, i8*, ...) @fprintf(i32 %55, i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str.11, i64 0, i64 0), i8* %54)
%57 = call i32 @exit(i32 1)
unreachable
58: ; preds = %50
%59 = call i32 @close(i32 %43)
br label %60
60: ; preds = %37, %58
%61 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%62 = call i32 @fstatat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), %struct.stat* %2, i32 %61)
%63 = icmp eq i32 %62, -1
br i1 %63, label %64, label %68
64: ; preds = %60
%65 = load i64, i64* @errno
%66 = load i64, i64* @ENOENT
%67 = icmp eq i64 %65, %66
br i1 %67, label %77, label %68
68: ; preds = %64, %60
%69 = load i32, i32* @O_RDONLY
%70 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.1, i64 0, i64 0), i32 %69)
%71 = icmp eq i32 %70, -1
br i1 %71, label %45, label %72
72: ; preds = %68
%73 = call i32 @setns(i32 %70, i32 0)
%74 = icmp eq i32 %73, -1
br i1 %74, label %53, label %75
75: ; preds = %72
%76 = call i32 @close(i32 %70)
br label %77
77: ; preds = %75, %64
%78 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%79 = call i32 @fstatat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), %struct.stat* %2, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %85
81: ; preds = %77
%82 = load i64, i64* @errno
%83 = load i64, i64* @ENOENT
%84 = icmp eq i64 %82, %83
br i1 %84, label %94, label %85
85: ; preds = %81, %77
%86 = load i32, i32* @O_RDONLY
%87 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0), i32 %86)
%88 = icmp eq i32 %87, -1
br i1 %88, label %45, label %89
89: ; preds = %85
%90 = call i32 @setns(i32 %87, i32 0)
%91 = icmp eq i32 %90, -1
br i1 %91, label %53, label %92
92: ; preds = %89
%93 = call i32 @close(i32 %87)
br label %94
94: ; preds = %92, %81
%95 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%96 = call i32 @fstatat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), %struct.stat* %2, i32 %95)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %102
98: ; preds = %94
%99 = load i64, i64* @errno
%100 = load i64, i64* @ENOENT
%101 = icmp eq i64 %99, %100
br i1 %101, label %111, label %102
102: ; preds = %98, %94
%103 = load i32, i32* @O_RDONLY
%104 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.3, i64 0, i64 0), i32 %103)
%105 = icmp eq i32 %104, -1
br i1 %105, label %45, label %106
106: ; preds = %102
%107 = call i32 @setns(i32 %104, i32 0)
%108 = icmp eq i32 %107, -1
br i1 %108, label %53, label %109
109: ; preds = %106
%110 = call i32 @close(i32 %104)
br label %111
111: ; preds = %109, %98
%112 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%113 = call i32 @fstatat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), %struct.stat* %2, i32 %112)
%114 = icmp eq i32 %113, -1
br i1 %114, label %115, label %119
115: ; preds = %111
%116 = load i64, i64* @errno
%117 = load i64, i64* @ENOENT
%118 = icmp eq i64 %116, %117
br i1 %118, label %128, label %119
119: ; preds = %115, %111
%120 = load i32, i32* @O_RDONLY
%121 = call i32 @openat(i32 %26, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.4, i64 0, i64 0), i32 %120)
%122 = icmp eq i32 %121, -1
br i1 %122, label %45, label %123
123: ; preds = %119
%124 = call i32 @setns(i32 %121, i32 0)
%125 = icmp eq i32 %124, -1
br i1 %125, label %53, label %126
126: ; preds = %123
%127 = call i32 @close(i32 %121)
br label %128
128: ; preds = %126, %115
%129 = call i32 @setjmp(i32 undef)
%130 = icmp eq i32 %129, 1
br i1 %130, label %150, label %131
131: ; preds = %128
%132 = call i32 @clone_parent(i32* %1)
%133 = icmp slt i32 %132, 0
br i1 %133, label %134, label %138
134: ; preds = %131
%135 = load i32, i32* @stderr
%136 = call i32 (i32, i8*, ...) @fprintf(i32 %135, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.12, i64 0, i64 0))
%137 = call i32 @exit(i32 1)
unreachable
138: ; preds = %131
%139 = call i32 @snprintf(i8* %7, i32 %4, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str.13, i64 0, i64 0), i32 %132)
%140 = call i32 @write(i32 3, i8* %7, i32 %139)
%141 = icmp eq i32 %140, %139
br i1 %141, label %148, label %142
142: ; preds = %138
%143 = load i32, i32* @stderr
%144 = call i32 (i32, i8*, ...) @fprintf(i32 %143, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.14, i64 0, i64 0))
%145 = load i32, i32* @SIGKILL
%146 = call i32 @kill(i32 %132, i32 %145)
%147 = call i32 @exit(i32 1)
unreachable
148: ; preds = %138
%149 = call i32 @exit(i32 0)
unreachable
150: ; preds = %128, %0
ret void
}