#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 long pid_t;

/* Variables and functions */
int /*<<< orphan*/ AT_SYMLINK_NOFOLLOW;
scalar_t__ ENOENT;
scalar_t__ ERANGE;
long LONG_MAX;
long LONG_MIN;
int O_DIRECTORY;
int O_RDONLY;
int PATH_MAX;
scalar_t__ checkProcessName(long, char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int fstatat(int, char *, struct stat *, int /*<<< orphan*/);
char *getenv(char *);
scalar_t__ geteuid();
long getppid();
int open(char *, int);
int openat(int, char *, int);
int /*<<< orphan*/ printf(char *, char *);
int setns(int, int /*<<< orphan*/);
scalar_t__ snprintf(char *, int, char *, long);
int /*<<< orphan*/ stderr;
long strtol(char *, char **, int);
int enter_mount_namespace(void) {
  if (geteuid() != 0) {
    fprintf(stderr, "E Must run as root\n");
    return -1;
  }
  pid_t ppid = getppid();
  if (checkProcessName(ppid, "oz-daemon") != 0) {
    fprintf(stderr, "E unable to verify that oz-daemon is parent\n");
    return -1;
  }
  char *envv, *envvend;
  long nspid;
  envv = getenv("_OZ_NSPID");
  if (envv == NULL) {
    fprintf(stderr, "E unable to get namespace pid from environment\n");
    return -1;
  }
  errno = 0;
  nspid = strtol(envv, &envvend, 10);
  if ((errno == ERANGE && (nspid == LONG_MAX || nspid == LONG_MIN)) ||
      (errno != 0 && nspid == 0)) {
    fprintf(stderr, "E unable to parse namespace pid from environment\n");
    return -1;
  }
  if (envvend == envv || nspid < 0) {
    fprintf(stderr, "E unable to parse namespace pid from environment\n");
    return -1;
  }
  if (checkProcessName(nspid, "oz-init") != 0) {
    fprintf(stderr, "E unable to verify that oz-init is the target\n");
    return -1;
  }
  char nspath[PATH_MAX];
  if (snprintf(nspath, PATH_MAX - 1, "/proc/%ld/ns", nspid) < 0) {
    fprintf(stderr, "E unable to parse namespace path `/proc/%ld/ns`\n", nspid);
    return -1;
  }
  printf("D Opening: %s\n", nspath);
  struct stat st;
  int tfd, fd;
  tfd = open(nspath, O_DIRECTORY | O_RDONLY);
  if (tfd == -1) {
    fprintf(stderr, "E failed to open child namespace\n");
    return -1;
  }
  if (fstatat(tfd, "mnt", &st, AT_SYMLINK_NOFOLLOW) == -1) {
    if (errno == ENOENT) {
      fprintf(stderr, "E failed to open child namespace\n");
      return -1;
    }
  }
  fd = openat(tfd, "mnt", O_RDONLY);
  if (fd == -1) {
    fprintf(stderr, "E failed to open child mount namespace: %s\n", nspath);
    return -1;
  }
  if (setns(fd, 0) == -1) {
    fprintf(stderr, "E failed to setns for: %s\n", nspath);
    return -1;
  }
  close(fd);
}


x86 assembly (clang, -O0):
<enter_mount_namespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x50,%rsp
mov    $0x0,%al
call   1080 <geteuid@plt>
cmp    $0x0,%rax
je     120c <enter_mount_namespace+0x3c>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe07(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
mov    $0x0,%al
call   10e0 <getppid@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    0xdf2(%rip),%rsi
call   10c0 <checkProcessName@plt>
cmp    $0x0,%rax
je     1254 <enter_mount_namespace+0x84>
mov    0x2d80(%rip),%rax
mov    (%rax),%edi
lea    0xddd(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
lea    0xdf0(%rip),%rdi
call   1030 <getenv@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    1292 <enter_mount_namespace+0xc2>
mov    0x2d42(%rip),%rax
mov    (%rax),%edi
lea    0xdd6(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
mov    0x2d0f(%rip),%rax
movq   $0x0,(%rax)
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,-0x28(%rbp)
mov    0x2ceb(%rip),%rax
mov    (%rax),%rax
mov    0x2d09(%rip),%rcx
cmp    (%rcx),%rax
jne    12f8 <enter_mount_namespace+0x128>
mov    -0x28(%rbp),%rax
mov    0x2cd5(%rip),%rcx
cmp    (%rcx),%rax
je     1314 <enter_mount_namespace+0x144>
mov    -0x28(%rbp),%rax
mov    0x2ce9(%rip),%rcx
cmp    (%rcx),%rax
je     1314 <enter_mount_namespace+0x144>
mov    0x2ca9(%rip),%rax
cmpq   $0x0,(%rax)
je     1337 <enter_mount_namespace+0x167>
cmpq   $0x0,-0x28(%rbp)
jne    1337 <enter_mount_namespace+0x167>
mov    0x2c9d(%rip),%rax
mov    (%rax),%edi
lea    0xd61(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
mov    -0x20(%rbp),%rax
cmp    -0x18(%rbp),%rax
je     1350 <enter_mount_namespace+0x180>
cmpq   $0x0,-0x28(%rbp)
jge    1373 <enter_mount_namespace+0x1a3>
mov    0x2c61(%rip),%rax
mov    (%rax),%edi
lea    0xd25(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
mov    -0x28(%rbp),%rdi
lea    0xd39(%rip),%rsi
call   10c0 <checkProcessName@plt>
cmp    $0x0,%rax
je     13b0 <enter_mount_namespace+0x1e0>
mov    0x2c24(%rip),%rax
mov    (%rax),%edi
lea    0xd22(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
jmp    15aa <enter_mount_namespace+0x3da>
mov    0x2c39(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x30(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x50(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x38(%rbp)
mov    0x2c0d(%rip),%rax
mov    (%rax),%esi
sub    $0x1,%esi
mov    -0x28(%rbp),%rcx
lea    0xcfb(%rip),%rdx
call   1060 <snprintf@plt>
cmp    $0x0,%rax
jge    1430 <enter_mount_namespace+0x260>
mov    0x2baf(%rip),%rax
mov    (%rax),%edi
mov    -0x28(%rbp),%rdx
lea    0xce5(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    15a3 <enter_mount_namespace+0x3d3>
mov    -0x50(%rbp),%rsi
lea    0xcf1(%rip),%rdi
call   1050 <printf@plt>
mov    -0x50(%rbp),%rdi
mov    0x2b75(%rip),%rax
mov    (%rax),%esi
mov    0x2b8c(%rip),%rax
or     (%rax),%esi
call   10d0 <open@plt>
mov    %eax,-0x44(%rbp)
cmpl   $0xffffffff,-0x44(%rbp)
jne    1492 <enter_mount_namespace+0x2c2>
mov    0x2b49(%rip),%rax
mov    (%rax),%edi
lea    0xcc3(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    15a3 <enter_mount_namespace+0x3d3>
mov    -0x44(%rbp),%edi
mov    0x2b04(%rip),%rax
mov    (%rax),%ecx
lea    0xcb8(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   10f0 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    1500 <enter_mount_namespace+0x330>
mov    0x2aea(%rip),%rax
mov    (%rax),%rax
mov    0x2ac8(%rip),%rcx
cmp    (%rcx),%rax
jne    14fb <enter_mount_namespace+0x32b>
mov    0x2ae0(%rip),%rax
mov    (%rax),%edi
lea    0xc5a(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    15a3 <enter_mount_namespace+0x3d3>
jmp    1500 <enter_mount_namespace+0x330>
mov    -0x44(%rbp),%edi
mov    0x2ad6(%rip),%rax
mov    (%rax),%edx
lea    0xc4a(%rip),%rsi
call   1040 <openat@plt>
mov    %eax,-0x48(%rbp)
cmpl   $0xffffffff,-0x48(%rbp)
jne    1553 <enter_mount_namespace+0x383>
mov    -0x50(%rbp),%rdx
mov    0x2a88(%rip),%rax
mov    (%rax),%edi
lea    0xc28(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    15a3 <enter_mount_namespace+0x3d3>
mov    -0x48(%rbp),%edi
xor    %esi,%esi
call   1070 <setns@plt>
cmp    $0xffffffff,%eax
jne    1594 <enter_mount_namespace+0x3c4>
mov    -0x50(%rbp),%rdx
mov    0x2a47(%rip),%rax
mov    (%rax),%edi
lea    0xc13(%rip),%rsi
mov    $0x0,%al
call   10a0 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x3c(%rbp)
jmp    15a3 <enter_mount_namespace+0x3d3>
mov    -0x48(%rbp),%edi
call   1090 <close@plt>
movl   $0x0,-0x3c(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<enter_mount_namespace>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x18,%rsp
xor    %eax,%eax
call   1080 <geteuid@plt>
test   %rax,%rax
je     1202 <enter_mount_namespace+0x32>
mov    0x2dc4(%rip),%rax
mov    (%rax),%edi
lea    0xe03(%rip),%rsi
jmp    12f2 <enter_mount_namespace+0x122>
xor    %eax,%eax
call   10e0 <getppid@plt>
lea    0xe04(%rip),%rsi
mov    %rax,%rdi
call   10c0 <checkProcessName@plt>
test   %rax,%rax
je     1232 <enter_mount_namespace+0x62>
mov    0x2d94(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
jmp    12f2 <enter_mount_namespace+0x122>
lea    0xe12(%rip),%rdi
call   1030 <getenv@plt>
test   %rax,%rax
je     12e2 <enter_mount_namespace+0x112>
mov    %rax,%rbx
mov    0x2d57(%rip),%r13
movq   $0x0,0x0(%r13)
lea    -0x38(%rbp),%rsi
mov    %rax,%rdi
mov    $0xa,%edx
call   10b0 <strtol@plt>
mov    %rax,%r15
mov    0x0(%r13),%rax
mov    0x2d58(%rip),%rcx
cmp    (%rcx),%rax
jne    1295 <enter_mount_namespace+0xc5>
mov    0x2d2c(%rip),%rcx
cmp    (%rcx),%r15
je     12d0 <enter_mount_namespace+0x100>
mov    0x2d48(%rip),%rcx
cmp    (%rcx),%r15
je     12d0 <enter_mount_namespace+0x100>
test   %rax,%rax
je     129f <enter_mount_namespace+0xcf>
test   %r15,%r15
je     12d0 <enter_mount_namespace+0x100>
cmp    %rbx,-0x38(%rbp)
je     12d0 <enter_mount_namespace+0x100>
test   %r15,%r15
js     12d0 <enter_mount_namespace+0x100>
lea    0xe06(%rip),%rsi
mov    %r15,%rdi
call   10c0 <checkProcessName@plt>
test   %rax,%rax
je     130d <enter_mount_namespace+0x13d>
mov    0x2cf3(%rip),%rax
mov    (%rax),%edi
lea    0xdf1(%rip),%rsi
jmp    12f2 <enter_mount_namespace+0x122>
mov    0x2ce1(%rip),%rax
mov    (%rax),%edi
lea    0xda5(%rip),%rsi
jmp    12f2 <enter_mount_namespace+0x122>
mov    0x2ccf(%rip),%rax
mov    (%rax),%edi
lea    0xd63(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    $0xffffffff,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret
mov    %rsp,%r12
mov    0x2cd9(%rip),%rax
mov    (%rax),%ecx
mov    %rsp,%r14
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
sub    %rcx,%r14
mov    %r14,%rsp
mov    (%rax),%esi
add    $0xffffffff,%esi
lea    0xdb8(%rip),%rdx
mov    %r14,%rdi
mov    %r15,%rcx
call   1060 <snprintf@plt>
test   %rax,%rax
js     13c0 <enter_mount_namespace+0x1f0>
lea    0xddf(%rip),%rdi
mov    %r14,%rsi
call   1050 <printf@plt>
mov    0x2c64(%rip),%rax
mov    0x2c7d(%rip),%r15
mov    (%r15),%esi
or     (%rax),%esi
mov    %r14,%rdi
call   10d0 <open@plt>
cmp    $0xffffffff,%eax
je     13a7 <enter_mount_namespace+0x1d7>
mov    %eax,%ebx
mov    0x2c22(%rip),%rax
mov    (%rax),%ecx
lea    0xdd6(%rip),%rsi
lea    -0x30(%rbp),%rdx
mov    %ebx,%edi
call   10f0 <fstatat@plt>
cmp    $0xffffffff,%eax
jne    13d5 <enter_mount_namespace+0x205>
mov    0x0(%r13),%rax
mov    0x2bee(%rip),%rcx
cmp    (%rcx),%rax
jne    13d5 <enter_mount_namespace+0x205>
mov    0x2c0a(%rip),%rax
mov    (%rax),%edi
lea    0xd84(%rip),%rsi
xor    %eax,%eax
call   10a0 <fprintf@plt>
jmp    1430 <enter_mount_namespace+0x260>
mov    0x2bf1(%rip),%rax
mov    (%rax),%edi
lea    0xd2b(%rip),%rsi
mov    %r15,%rdx
jmp    1429 <enter_mount_namespace+0x259>
mov    (%r15),%edx
lea    0xd7e(%rip),%rsi
mov    %ebx,%edi
call   1040 <openat@plt>
cmp    $0xffffffff,%eax
je     1404 <enter_mount_namespace+0x234>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1070 <setns@plt>
cmp    $0xffffffff,%eax
je     1416 <enter_mount_namespace+0x246>
mov    %ebx,%edi
call   1090 <close@plt>
jmp    1430 <enter_mount_namespace+0x260>
mov    0x2bad(%rip),%rax
mov    (%rax),%edi
lea    0xd4d(%rip),%rsi
jmp    1426 <enter_mount_namespace+0x256>
mov    0x2b9b(%rip),%rax
mov    (%rax),%edi
lea    0xd67(%rip),%rsi
mov    %r14,%rdx
xor    %eax,%eax
call   10a0 <fprintf@plt>
mov    %r12,%rsp
jmp    12f9 <enter_mount_namespace+0x129>

LLVM IR (-O0):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"E Must run as root\0A\00"
@.str.1 = [10 x i8] c"oz-daemon\00"
@.str.2 = [45 x i8] c"E unable to verify that oz-daemon is parent\0A\00"
@.str.3 = [10 x i8] c"_OZ_NSPID\00"
@.str.4 = [48 x i8] c"E unable to get namespace pid from environment\0A\00"
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.5 = [50 x i8] c"E unable to parse namespace pid from environment\0A\00"
@.str.6 = [8 x i8] c"oz-init\00"
@.str.7 = [47 x i8] c"E unable to verify that oz-init is the target\0A\00"
@PATH_MAX = global i32 0
@.str.8 = [13 x i8] c"/proc/%ld/ns\00"
@.str.9 = [49 x i8] c"E unable to parse namespace path `/proc/%ld/ns`\0A\00"
@.str.10 = [15 x i8] c"D Opening: %s\0A\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.11 = [34 x i8] c"E failed to open child namespace\0A\00"
@.str.12 = [4 x i8] c"mnt\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@ENOENT = global i64 0
@.str.13 = [44 x i8] c"E failed to open child mount namespace: %s\0A\00"
@.str.14 = [27 x i8] c"E failed to setns for: %s\0A\00"
define i32 @enter_mount_namespace() {
%1 = alloca i32
%2 = alloca i64
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i32
%9 = alloca %struct.stat
%10 = alloca i32
%11 = alloca i32
%12 = call i64 (...) @geteuid()
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %17
14: ; preds = %0
%15 = load i32, i32* @stderr
%16 = call i32 (i32, i8*, ...) @fprintf(i32 %15, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
17: ; preds = %0
%18 = call i64 (...) @getppid()
store i64 %18, i64* %2
%19 = load i64, i64* %2
%20 = call i64 @checkProcessName(i64 %19, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%21 = icmp ne i64 %20, 0
br i1 %21, label %22, label %25
22: ; preds = %17
%23 = load i32, i32* @stderr
%24 = call i32 (i32, i8*, ...) @fprintf(i32 %23, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
25: ; preds = %17
%26 = call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
store i8* %26, i8** %3
%27 = load i8*, i8** %3
%28 = icmp eq i8* %27, null
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = call i32 (i32, i8*, ...) @fprintf(i32 %30, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
32: ; preds = %25
store i64 0, i64* @errno
%33 = load i8*, i8** %3
%34 = call i64 @strtol(i8* %33, i8** %4, i32 10)
store i64 %34, i64* %5
%35 = load i64, i64* @errno
%36 = load i64, i64* @ERANGE
%37 = icmp eq i64 %35, %36
br i1 %37, label %38, label %46
38: ; preds = %32
%39 = load i64, i64* %5
%40 = load i64, i64* @LONG_MAX
%41 = icmp eq i64 %39, %40
br i1 %41, label %52, label %42
42: ; preds = %38
%43 = load i64, i64* %5
%44 = load i64, i64* @LONG_MIN
%45 = icmp eq i64 %43, %44
br i1 %45, label %52, label %46
46: ; preds = %42, %32
%47 = load i64, i64* @errno
%48 = icmp ne i64 %47, 0
br i1 %48, label %49, label %55
49: ; preds = %46
%50 = load i64, i64* %5
%51 = icmp eq i64 %50, 0
br i1 %51, label %52, label %55
52: ; preds = %49, %42, %38
%53 = load i32, i32* @stderr
%54 = call i32 (i32, i8*, ...) @fprintf(i32 %53, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
55: ; preds = %49, %46
%56 = load i8*, i8** %4
%57 = load i8*, i8** %3
%58 = icmp eq i8* %56, %57
br i1 %58, label %62, label %59
59: ; preds = %55
%60 = load i64, i64* %5
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %65
62: ; preds = %59, %55
%63 = load i32, i32* @stderr
%64 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
65: ; preds = %59
%66 = load i64, i64* %5
%67 = call i64 @checkProcessName(i64 %66, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%68 = icmp ne i64 %67, 0
br i1 %68, label %69, label %72
69: ; preds = %65
%70 = load i32, i32* @stderr
%71 = call i32 (i32, i8*, ...) @fprintf(i32 %70, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
store i32 -1, i32* %1
br label %132
72: ; preds = %65
%73 = load i32, i32* @PATH_MAX
%74 = zext i32 %73 to i64
%75 = call i8* @llvm.stacksave()
store i8* %75, i8** %6
%76 = alloca i8, i64 %74
store i64 %74, i64* %7
%77 = load i32, i32* @PATH_MAX
%78 = sub nsw i32 %77, 1
%79 = load i64, i64* %5
%80 = call i64 @snprintf(i8* %76, i32 %78, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %79)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %86
82: ; preds = %72
%83 = load i32, i32* @stderr
%84 = load i64, i64* %5
%85 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), i64 %84)
store i32 -1, i32* %1
store i32 1, i32* %8
br label %129
86: ; preds = %72
%87 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %76)
%88 = load i32, i32* @O_DIRECTORY
%89 = load i32, i32* @O_RDONLY
%90 = or i32 %88, %89
%91 = call i32 @open(i8* %76, i32 %90)
store i32 %91, i32* %10
%92 = load i32, i32* %10
%93 = icmp eq i32 %92, -1
br i1 %93, label %94, label %97
94: ; preds = %86
%95 = load i32, i32* @stderr
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %95, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %1
store i32 1, i32* %8
br label %129
97: ; preds = %86
%98 = load i32, i32* %10
%99 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%100 = call i32 @fstatat(i32 %98, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), %struct.stat* %9, i32 %99)
%101 = icmp eq i32 %100, -1
br i1 %101, label %102, label %110
102: ; preds = %97
%103 = load i64, i64* @errno
%104 = load i64, i64* @ENOENT
%105 = icmp eq i64 %103, %104
br i1 %105, label %106, label %109
106: ; preds = %102
%107 = load i32, i32* @stderr
%108 = call i32 (i32, i8*, ...) @fprintf(i32 %107, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
store i32 -1, i32* %1
store i32 1, i32* %8
br label %129
109: ; preds = %102
br label %110
110: ; preds = %109, %97
%111 = load i32, i32* %10
%112 = load i32, i32* @O_RDONLY
%113 = call i32 @openat(i32 %111, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i32 %112)
store i32 %113, i32* %11
%114 = load i32, i32* %11
%115 = icmp eq i32 %114, -1
br i1 %115, label %116, label %119
116: ; preds = %110
%117 = load i32, i32* @stderr
%118 = call i32 (i32, i8*, ...) @fprintf(i32 %117, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.13, i64 0, i64 0), i8* %76)
store i32 -1, i32* %1
store i32 1, i32* %8
br label %129
119: ; preds = %110
%120 = load i32, i32* %11
%121 = call i32 @setns(i32 %120, i32 0)
%122 = icmp eq i32 %121, -1
br i1 %122, label %123, label %126
123: ; preds = %119
%124 = load i32, i32* @stderr
%125 = call i32 (i32, i8*, ...) @fprintf(i32 %124, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %76)
store i32 -1, i32* %1
store i32 1, i32* %8
br label %129
126: ; preds = %119
%127 = load i32, i32* %11
%128 = call i32 @close(i32 %127)
store i32 0, i32* %8
br label %129
129: ; preds = %126, %123, %116, %106, %94, %82
%130 = load i8*, i8** %6
%131 = load i32, i32* %8
switch i32 %131, label %134 [
i32 0, label %132
i32 1, label %132
]
132: ; preds = %14, %22, %29, %52, %62, %69, %129, %129
%133 = load i32, i32* %1
ret i32 %133
134: ; preds = %129
unreachable
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@stderr = global i32 0
@.str = [20 x i8] c"E Must run as root\0A\00"
@.str.1 = [10 x i8] c"oz-daemon\00"
@.str.2 = [45 x i8] c"E unable to verify that oz-daemon is parent\0A\00"
@.str.3 = [10 x i8] c"_OZ_NSPID\00"
@.str.4 = [48 x i8] c"E unable to get namespace pid from environment\0A\00"
@errno = global i64 0
@ERANGE = global i64 0
@LONG_MAX = global i64 0
@LONG_MIN = global i64 0
@.str.5 = [50 x i8] c"E unable to parse namespace pid from environment\0A\00"
@.str.6 = [8 x i8] c"oz-init\00"
@.str.7 = [47 x i8] c"E unable to verify that oz-init is the target\0A\00"
@PATH_MAX = global i32 0
@.str.8 = [13 x i8] c"/proc/%ld/ns\00"
@.str.9 = [49 x i8] c"E unable to parse namespace path `/proc/%ld/ns`\0A\00"
@.str.10 = [15 x i8] c"D Opening: %s\0A\00"
@O_DIRECTORY = global i32 0
@O_RDONLY = global i32 0
@.str.11 = [34 x i8] c"E failed to open child namespace\0A\00"
@.str.12 = [4 x i8] c"mnt\00"
@AT_SYMLINK_NOFOLLOW = global i32 0
@ENOENT = global i64 0
@.str.13 = [44 x i8] c"E failed to open child mount namespace: %s\0A\00"
@.str.14 = [27 x i8] c"E failed to setns for: %s\0A\00"
define i32 @enter_mount_namespace() {
%1 = alloca i8*
%2 = alloca %struct.stat
%3 = tail call i64 (...) @geteuid()
%4 = icmp eq i64 %3, 0
br i1 %4, label %8, label %5
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = tail call i32 (i32, i8*, ...) @fprintf(i32 %6, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %106
8: ; preds = %0
%9 = tail call i64 (...) @getppid()
%10 = tail call i64 @checkProcessName(i64 %9, i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.1, i64 0, i64 0))
%11 = icmp eq i64 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %8
%13 = load i32, i32* @stderr
%14 = tail call i32 (i32, i8*, ...) @fprintf(i32 %13, i8* getelementptr inbounds ([45 x i8], [45 x i8]* @.str.2, i64 0, i64 0))
br label %106
15: ; preds = %8
%16 = bitcast i8** %1 to i8*
%17 = tail call i8* @getenv(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str.3, i64 0, i64 0))
%18 = icmp eq i8* %17, null
br i1 %18, label %19, label %22
19: ; preds = %15
%20 = load i32, i32* @stderr
%21 = tail call i32 (i32, i8*, ...) @fprintf(i32 %20, i8* getelementptr inbounds ([48 x i8], [48 x i8]* @.str.4, i64 0, i64 0))
br label %105
22: ; preds = %15
store i64 0, i64* @errno
%23 = call i64 @strtol(i8* %17, i8** %1, i32 10)
%24 = load i64, i64* @errno
%25 = load i64, i64* @ERANGE
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %33
27: ; preds = %22
%28 = load i64, i64* @LONG_MAX
%29 = icmp eq i64 %23, %28
%30 = load i64, i64* @LONG_MIN
%31 = icmp eq i64 %23, %30
%32 = select i1 %29, i1 true, i1 %31
br i1 %32, label %37, label %33
33: ; preds = %27, %22
%34 = icmp ne i64 %24, 0
%35 = icmp eq i64 %23, 0
%36 = select i1 %34, i1 %35, i1 false
br i1 %36, label %37, label %40
37: ; preds = %33, %27
%38 = load i32, i32* @stderr
%39 = tail call i32 (i32, i8*, ...) @fprintf(i32 %38, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %105
40: ; preds = %33
%41 = load i8*, i8** %1
%42 = icmp eq i8* %41, %17
%43 = icmp slt i64 %23, 0
%44 = select i1 %42, i1 true, i1 %43
br i1 %44, label %45, label %48
45: ; preds = %40
%46 = load i32, i32* @stderr
%47 = tail call i32 (i32, i8*, ...) @fprintf(i32 %46, i8* getelementptr inbounds ([50 x i8], [50 x i8]* @.str.5, i64 0, i64 0))
br label %105
48: ; preds = %40
%49 = tail call i64 @checkProcessName(i64 %23, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.6, i64 0, i64 0))
%50 = icmp eq i64 %49, 0
br i1 %50, label %54, label %51
51: ; preds = %48
%52 = load i32, i32* @stderr
%53 = tail call i32 (i32, i8*, ...) @fprintf(i32 %52, i8* getelementptr inbounds ([47 x i8], [47 x i8]* @.str.7, i64 0, i64 0))
br label %105
54: ; preds = %48
%55 = load i32, i32* @PATH_MAX
%56 = zext i32 %55 to i64
%57 = tail call i8* @llvm.stacksave()
%58 = alloca i8, i64 %56
%59 = load i32, i32* @PATH_MAX
%60 = add nsw i32 %59, -1
%61 = call i64 @snprintf(i8* %58, i32 %60, i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str.8, i64 0, i64 0), i64 %23)
%62 = icmp slt i64 %61, 0
br i1 %62, label %63, label %66
63: ; preds = %54
%64 = load i32, i32* @stderr
%65 = call i32 (i32, i8*, ...) @fprintf(i32 %64, i8* getelementptr inbounds ([49 x i8], [49 x i8]* @.str.9, i64 0, i64 0), i64 %23)
br label %104
66: ; preds = %54
%67 = call i32 @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.10, i64 0, i64 0), i8* %58)
%68 = bitcast %struct.stat* %2 to i8*
%69 = load i32, i32* @O_DIRECTORY
%70 = load i32, i32* @O_RDONLY
%71 = or i32 %70, %69
%72 = call i32 @open(i8* %58, i32 %71)
%73 = icmp eq i32 %72, -1
br i1 %73, label %74, label %77
74: ; preds = %66
%75 = load i32, i32* @stderr
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %75, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
br label %103
77: ; preds = %66
%78 = load i32, i32* @AT_SYMLINK_NOFOLLOW
%79 = call i32 @fstatat(i32 %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), %struct.stat* %2, i32 %78)
%80 = icmp eq i32 %79, -1
br i1 %80, label %81, label %88
81: ; preds = %77
%82 = load i64, i64* @errno
%83 = load i64, i64* @ENOENT
%84 = icmp eq i64 %82, %83
br i1 %84, label %85, label %88
85: ; preds = %81
%86 = load i32, i32* @stderr
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %86, i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.11, i64 0, i64 0))
br label %103
88: ; preds = %81, %77
%89 = load i32, i32* @O_RDONLY
%90 = call i32 @openat(i32 %72, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.12, i64 0, i64 0), i32 %89)
%91 = icmp eq i32 %90, -1
br i1 %91, label %92, label %95
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([44 x i8], [44 x i8]* @.str.13, i64 0, i64 0), i8* %58)
br label %103
95: ; preds = %88
%96 = call i32 @setns(i32 %90, i32 0)
%97 = icmp eq i32 %96, -1
br i1 %97, label %98, label %101
98: ; preds = %95
%99 = load i32, i32* @stderr
%100 = call i32 (i32, i8*, ...) @fprintf(i32 %99, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.14, i64 0, i64 0), i8* %58)
br label %103
101: ; preds = %95
%102 = call i32 @close(i32 %90)
br label %103
103: ; preds = %101, %98, %92, %85, %74
br label %104
104: ; preds = %103, %63
br label %105
105: ; preds = %104, %51, %45, %37, %19
br label %106
106: ; preds = %12, %105, %5
ret i32 -1
}