#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*/ netns_path;

/* Variables and functions */
scalar_t__ EINVAL;
int MAXPATHLEN;
int MS_BIND;
int O_CREAT;
int O_EXCL;
int O_RDONLY;
int S_IRGRP;
int S_IROTH;
int S_IRWXU;
int S_IXGRP;
int S_IXOTH;
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, ...);
int /*<<< orphan*/ mkdir(char *, int);
scalar_t__ mount(char *, char *, char *, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ netns_delete(int, char **);
int open(char *, int, int /*<<< orphan*/);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ stderr;
char *strerror(scalar_t__);
scalar_t__ unshare(int);
int netns_add(int argc, char **argv) {
  char netns_path[MAXPATHLEN];
  const char *name;
  int fd;
  int made_netns_run_dir_mount = 0;
  if (argc < 1) {
    fprintf(stderr, "No netns name specified\n");
    return -1;
  }
  name = argv[0];
  snprintf(netns_path, sizeof(netns_path), "%s/%s", "/var/run/netns", name);
  mkdir("/var/run/netns", S_IRWXU | S_IRGRP | S_IXGRP | S_IROTH | S_IXOTH);
  while (mount("", "/var/run/netns", "none", (1 << 20) | 16384, NULL)) {
    if (errno != EINVAL || made_netns_run_dir_mount) {
      fprintf(stderr, "mount --make-shared %s failed: %s\n", "/var/run/netns",
              strerror(errno));
      return -1;
    }
    if (mount("/var/run/netns", "/var/run/netns", "none", MS_BIND, NULL)) {
      fprintf(stderr, "mount --bind %s %s failed: %s\n", "/var/run/netns",
              "/var/run/netns", strerror(errno));
      return -1;
    }
    made_netns_run_dir_mount = 1;
  }
  fd = open(netns_path, O_RDONLY | O_CREAT | O_EXCL, 0);
  if (fd < 0) {
    fprintf(stderr, "Cannot not create namespace file \"%s\": %s\n", netns_path,
            strerror(errno));
    return -1;
  }
  close(fd);
  if (unshare(0x40000000) < 0) {
    fprintf(stderr, "Failed to create a new network namespace \"%s\": %s\n",
            name, strerror(errno));
    goto out_delete;
  }
  if (mount("/proc/self/ns/net", netns_path, "none", MS_BIND, NULL) < 0) {
    fprintf(stderr, "Bind /proc/self/ns/net -> %s failed: %s\n", netns_path,
            strerror(errno));
    goto out_delete;
  }
  return 0;
out_delete:
  netns_delete(argc, argv);
  return -1;
}


x86 assembly (clang, -O0):
<netns_add>:
push   %rbp
mov    %rsp,%rbp
sub    $0x70,%rsp
mov    %edi,-0x8(%rbp)
mov    %rsi,-0x10(%rbp)
mov    0x2e1a(%rip),%rax
mov    (%rax),%eax
mov    %rax,-0x48(%rbp)
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
mov    %rsp,%rcx
sub    %rdx,%rcx
mov    %rcx,-0x40(%rbp)
mov    %rcx,%rsp
mov    %rax,-0x20(%rbp)
movl   $0x0,-0x30(%rbp)
cmpl   $0x1,-0x8(%rbp)
jge    120a <netns_add+0x7a>
mov    0x2dc1(%rip),%rax
mov    (%rax),%edi
lea    0xe10(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    14f9 <netns_add+0x369>
mov    -0x40(%rbp),%rdi
mov    -0x48(%rbp),%rax
mov    -0x10(%rbp),%rcx
mov    (%rcx),%rcx
mov    %rcx,-0x28(%rbp)
mov    %eax,%esi
mov    -0x28(%rbp),%r8
lea    0xdef(%rip),%rdx
lea    0xdee(%rip),%rcx
call   1070 <snprintf@plt>
mov    0x2da3(%rip),%rax
mov    (%rax),%esi
mov    0x2d4a(%rip),%rax
or     (%rax),%esi
mov    0x2d69(%rip),%rax
or     (%rax),%esi
mov    0x2d30(%rip),%rax
or     (%rax),%esi
mov    0x2d77(%rip),%rax
or     (%rax),%esi
lea    0xdb5(%rip),%rdi
call   1030 <mkdir@plt>
lea    0xda2(%rip),%rdi
lea    0xda2(%rip),%rsi
lea    0xdaa(%rip),%rdx
mov    $0x104000,%ecx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <mount@plt>
cmp    $0x0,%rax
je     1390 <netns_add+0x200>
mov    0x2cf4(%rip),%rax
mov    (%rax),%rax
mov    0x2cd2(%rip),%rcx
cmp    (%rcx),%rax
jne    12c1 <netns_add+0x131>
cmpl   $0x0,-0x30(%rbp)
je     130a <netns_add+0x17a>
mov    0x2ce0(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4c(%rbp)
mov    0x2cc4(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x4c(%rbp),%edi
mov    %rax,%rcx
lea    0xd4a(%rip),%rsi
lea    0xd2f(%rip),%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    14f9 <netns_add+0x369>
mov    0x2cb7(%rip),%rax
mov    (%rax),%ecx
lea    0xd05(%rip),%rsi
lea    0xd0d(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
mov    %rsi,%rdi
call   1060 <mount@plt>
cmp    $0x0,%rax
je     1384 <netns_add+0x1f4>
mov    0x2c69(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x50(%rbp)
mov    0x2c4d(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x50(%rbp),%edi
mov    %rax,%r8
lea    0xcf6(%rip),%rsi
lea    0xcb8(%rip),%rcx
mov    %rcx,%rdx
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    14f9 <netns_add+0x369>
movl   $0x1,-0x30(%rbp)
jmp    126f <netns_add+0xdf>
mov    -0x40(%rbp),%rdi
mov    0x2c35(%rip),%rax
mov    (%rax),%esi
mov    0x2c54(%rip),%rax
or     (%rax),%esi
mov    0x2bf3(%rip),%rax
or     (%rax),%esi
xor    %edx,%edx
call   10a0 <open@plt>
mov    %eax,-0x2c(%rbp)
cmpl   $0x0,-0x2c(%rbp)
jge    1409 <netns_add+0x279>
mov    0x2bde(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x54(%rbp)
mov    0x2bc2(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x54(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xc86(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    14f9 <netns_add+0x369>
mov    -0x2c(%rbp),%edi
call   1080 <close@plt>
mov    $0x40000000,%edi
call   1050 <unshare@plt>
cmp    $0x0,%rax
jge    1465 <netns_add+0x2d5>
mov    0x2b7c(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x64(%rbp)
mov    -0x28(%rbp),%rax
mov    %rax,-0x60(%rbp)
mov    0x2b58(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x64(%rbp),%edi
mov    -0x60(%rbp),%rdx
mov    %rax,%rcx
lea    0xc47(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    14df <netns_add+0x34f>
mov    -0x40(%rbp),%rsi
mov    0x2b58(%rip),%rax
mov    (%rax),%ecx
lea    0xc5a(%rip),%rdi
lea    0xbae(%rip),%rdx
xor    %eax,%eax
mov    %eax,%r8d
call   1060 <mount@plt>
cmp    $0x0,%rax
jge    14cc <netns_add+0x33c>
mov    0x2b0d(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x68(%rbp)
mov    0x2af1(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
mov    -0x68(%rbp),%edi
mov    -0x40(%rbp),%rdx
mov    %rax,%rcx
lea    0xc25(%rip),%rsi
mov    $0x0,%al
call   1090 <fprintf@plt>
jmp    14df <netns_add+0x34f>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
jmp    14f9 <netns_add+0x369>
mov    -0x8(%rbp),%edi
mov    -0x10(%rbp),%rsi
call   1040 <netns_delete@plt>
movl   $0xffffffff,-0x4(%rbp)
movl   $0x1,-0x34(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<netns_add>:
push   %rbp
mov    %rsp,%rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
mov    %rsi,%rdx
mov    0x2e15(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rcx
lea    0xf(%rsi),%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rcx
mov    %rcx,%rsp
test   %edi,%edi
jle    12d7 <netns_add+0x147>
mov    %edi,-0x2c(%rbp)
mov    %rdx,-0x40(%rbp)
mov    (%rdx),%r8
lea    0xe42(%rip),%rdx
lea    0xe41(%rip),%rbx
mov    %rcx,-0x48(%rbp)
mov    %rcx,%rdi
mov    %rbx,%rcx
mov    %r8,-0x38(%rbp)
call   1070 <snprintf@plt>
mov    0x2de8(%rip),%rax
mov    0x2d91(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2dae(%rip),%rax
or     (%rax),%esi
mov    0x2d75(%rip),%rax
or     (%rax),%esi
mov    0x2dbc(%rip),%rax
or     (%rax),%esi
mov    %rbx,%rdi
call   1030 <mkdir@plt>
xor    %r13d,%r13d
lea    0xde8(%rip),%r14
lea    0xdf7(%rip),%r12
mov    0x2d42(%rip),%r15
xchg   %ax,%ax
mov    %r14,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
mov    $0x104000,%ecx
xor    %r8d,%r8d
call   1060 <mount@plt>
test   %rax,%rax
je     12f3 <netns_add+0x163>
mov    0x2d32(%rip),%rax
mov    (%rax),%rdi
cmp    (%r15),%rdi
sete   %al
not    %r13b
test   %al,%r13b
je     1391 <netns_add+0x201>
mov    0x2d46(%rip),%rax
mov    (%rax),%ecx
mov    %rbx,%rdi
mov    %rbx,%rsi
mov    %r12,%rdx
xor    %r8d,%r8d
call   1060 <mount@plt>
mov    $0x1,%r13b
test   %rax,%rax
je     1240 <netns_add+0xb0>
mov    0x2d04(%rip),%rax
mov    (%rax),%ebx
mov    0x2ceb(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xd9a(%rip),%rsi
lea    0xd5c(%rip),%rcx
mov    %ebx,%edi
mov    %rcx,%rdx
mov    %rax,%r8
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    141c <netns_add+0x28c>
mov    0x2cca(%rip),%rax
mov    (%rax),%edi
lea    0xd19(%rip),%rsi
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    141c <netns_add+0x28c>
mov    0x2cd6(%rip),%rax
mov    0x2cf7(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    0x2c94(%rip),%rax
or     (%rax),%esi
mov    -0x48(%rbp),%r14
mov    %r14,%rdi
xor    %edx,%edx
call   10a0 <open@plt>
test   %eax,%eax
js     13b1 <netns_add+0x221>
mov    %eax,%edi
call   1080 <close@plt>
mov    $0x40000000,%edi
call   1050 <unshare@plt>
test   %rax,%rax
js     13e1 <netns_add+0x251>
mov    0x2c83(%rip),%rax
mov    (%rax),%ecx
lea    0xd85(%rip),%rdi
lea    0xcd9(%rip),%rdx
xor    %ebx,%ebx
mov    %r14,%rsi
xor    %r8d,%r8d
call   1060 <mount@plt>
test   %rax,%rax
jns    1421 <netns_add+0x291>
mov    0x2c36(%rip),%rax
mov    (%rax),%ebx
mov    0x2c1d(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xd5b(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
jmp    1406 <netns_add+0x276>
mov    0x2c10(%rip),%rax
mov    (%rax),%ebx
call   10b0 <strerror@plt>
lea    0xc8d(%rip),%rsi
lea    0xc72(%rip),%rdx
mov    %ebx,%edi
jmp    13d5 <netns_add+0x245>
mov    0x2bf0(%rip),%rax
mov    (%rax),%ebx
mov    0x2bd7(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xca5(%rip),%rsi
mov    %ebx,%edi
mov    %r14,%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
jmp    141c <netns_add+0x28c>
mov    0x2bc0(%rip),%rax
mov    (%rax),%ebx
mov    0x2ba7(%rip),%rax
mov    (%rax),%rdi
call   10b0 <strerror@plt>
lea    0xca0(%rip),%rsi
mov    %ebx,%edi
mov    -0x38(%rbp),%rdx
mov    %rax,%rcx
xor    %eax,%eax
call   1090 <fprintf@plt>
mov    -0x2c(%rbp),%edi
mov    -0x40(%rbp),%rsi
call   1040 <netns_delete@plt>
mov    $0xffffffff,%ebx
mov    %ebx,%eax
lea    -0x28(%rbp),%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"No netns name specified\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [15 x i8] c"/var/run/netns\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [5 x i8] c"none\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.5 = [35 x i8] c"mount --make-shared %s failed: %s\0A\00"
@MS_BIND = global i32 0
@.str.6 = [31 x i8] c"mount --bind %s %s failed: %s\0A\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.7 = [43 x i8] c"Cannot not create namespace file \22%s\22: %s\0A\00"
@.str.8 = [51 x i8] c"Failed to create a new network namespace \22%s\22: %s\0A\00"
@.str.9 = [18 x i8] c"/proc/self/ns/net\00"
@.str.10 = [41 x i8] c"Bind /proc/self/ns/net -> %s failed: %s\0A\00"
define i32 @netns_add(i32 %0, i8** %1) {
%3 = alloca i32
%4 = alloca i32
%5 = alloca i8**
%6 = alloca i8*
%7 = alloca i64
%8 = alloca i8*
%9 = alloca i32
%10 = alloca i32
%11 = alloca i32
store i32 %0, i32* %4
store i8** %1, i8*** %5
%12 = load i32, i32* @MAXPATHLEN
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %6
%15 = alloca i8, i64 %13
store i64 %13, i64* %7
store i32 0, i32* %10
%16 = load i32, i32* %4
%17 = icmp slt i32 %16, 1
br i1 %17, label %18, label %21
18: ; preds = %2
%19 = load i32, i32* @stderr
%20 = call i32 (i32, i8*, ...) @fprintf(i32 %19, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
store i32 -1, i32* %3
store i32 1, i32* %11
br label %102
21: ; preds = %2
%22 = load i8**, i8*** %5
%23 = getelementptr inbounds i8*, i8** %22, i64 0
%24 = load i8*, i8** %23
store i8* %24, i8** %8
%25 = trunc i64 %13 to i32
%26 = load i8*, i8** %8
%27 = call i32 @snprintf(i8* %15, i32 %25, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %26)
%28 = load i32, i32* @S_IRWXU
%29 = load i32, i32* @S_IRGRP
%30 = or i32 %28, %29
%31 = load i32, i32* @S_IXGRP
%32 = or i32 %30, %31
%33 = load i32, i32* @S_IROTH
%34 = or i32 %32, %33
%35 = load i32, i32* @S_IXOTH
%36 = or i32 %34, %35
%37 = call i32 @mkdir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %36)
br label %38
38: ; preds = %62, %21
%39 = call i64 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 1064960, i32* null)
%40 = icmp ne i64 %39, 0
br i1 %40, label %41, label %63
41: ; preds = %38
%42 = load i64, i64* @errno
%43 = load i64, i64* @EINVAL
%44 = icmp ne i64 %42, %43
br i1 %44, label %48, label %45
45: ; preds = %41
%46 = load i32, i32* %10
%47 = icmp ne i32 %46, 0
br i1 %47, label %48, label %53
48: ; preds = %45, %41
%49 = load i32, i32* @stderr
%50 = load i64, i64* @errno
%51 = call i8* @strerror(i64 %50)
%52 = call i32 (i32, i8*, ...) @fprintf(i32 %49, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %51)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %102
53: ; preds = %45
%54 = load i32, i32* @MS_BIND
%55 = call i64 @mount(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %54, i32* null)
%56 = icmp ne i64 %55, 0
br i1 %56, label %57, label %62
57: ; preds = %53
%58 = load i32, i32* @stderr
%59 = load i64, i64* @errno
%60 = call i8* @strerror(i64 %59)
%61 = call i32 (i32, i8*, ...) @fprintf(i32 %58, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %60)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %102
62: ; preds = %53
store i32 1, i32* %10
br label %38
63: ; preds = %38
%64 = load i32, i32* @O_RDONLY
%65 = load i32, i32* @O_CREAT
%66 = or i32 %64, %65
%67 = load i32, i32* @O_EXCL
%68 = or i32 %66, %67
%69 = call i32 @open(i8* %15, i32 %68, i32 0)
store i32 %69, i32* %9
%70 = load i32, i32* %9
%71 = icmp slt i32 %70, 0
br i1 %71, label %72, label %77
72: ; preds = %63
%73 = load i32, i32* @stderr
%74 = load i64, i64* @errno
%75 = call i8* @strerror(i64 %74)
%76 = call i32 (i32, i8*, ...) @fprintf(i32 %73, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i8* %15, i8* %75)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %102
77: ; preds = %63
%78 = load i32, i32* %9
%79 = call i32 @close(i32 %78)
%80 = call i64 @unshare(i32 1073741824)
%81 = icmp slt i64 %80, 0
br i1 %81, label %82, label %88
82: ; preds = %77
%83 = load i32, i32* @stderr
%84 = load i8*, i8** %8
%85 = load i64, i64* @errno
%86 = call i8* @strerror(i64 %85)
%87 = call i32 (i32, i8*, ...) @fprintf(i32 %83, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %84, i8* %86)
br label %98
88: ; preds = %77
%89 = load i32, i32* @MS_BIND
%90 = call i64 @mount(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %15, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %89, i32* null)
%91 = icmp slt i64 %90, 0
br i1 %91, label %92, label %97
92: ; preds = %88
%93 = load i32, i32* @stderr
%94 = load i64, i64* @errno
%95 = call i8* @strerror(i64 %94)
%96 = call i32 (i32, i8*, ...) @fprintf(i32 %93, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %15, i8* %95)
br label %98
97: ; preds = %88
store i32 0, i32* %3
store i32 1, i32* %11
br label %102
98: ; preds = %92, %82
%99 = load i32, i32* %4
%100 = load i8**, i8*** %5
%101 = call i32 @netns_delete(i32 %99, i8** %100)
store i32 -1, i32* %3
store i32 1, i32* %11
br label %102
102: ; preds = %98, %97, %72, %57, %48, %18
%103 = load i8*, i8** %6
%104 = load i32, i32* %3
ret i32 %104
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@stderr = global i32 0
@.str = [25 x i8] c"No netns name specified\0A\00"
@.str.1 = [6 x i8] c"%s/%s\00"
@.str.2 = [15 x i8] c"/var/run/netns\00"
@S_IRWXU = global i32 0
@S_IRGRP = global i32 0
@S_IXGRP = global i32 0
@S_IROTH = global i32 0
@S_IXOTH = global i32 0
@.str.3 = [1 x i8] zeroinitializer
@.str.4 = [5 x i8] c"none\00"
@errno = global i64 0
@EINVAL = global i64 0
@.str.5 = [35 x i8] c"mount --make-shared %s failed: %s\0A\00"
@MS_BIND = global i32 0
@.str.6 = [31 x i8] c"mount --bind %s %s failed: %s\0A\00"
@O_RDONLY = global i32 0
@O_CREAT = global i32 0
@O_EXCL = global i32 0
@.str.7 = [43 x i8] c"Cannot not create namespace file \22%s\22: %s\0A\00"
@.str.8 = [51 x i8] c"Failed to create a new network namespace \22%s\22: %s\0A\00"
@.str.9 = [18 x i8] c"/proc/self/ns/net\00"
@.str.10 = [41 x i8] c"Bind /proc/self/ns/net -> %s failed: %s\0A\00"
define i32 @netns_add(i32 %0, i8** %1) {
%3 = load i32, i32* @MAXPATHLEN
%4 = zext i32 %3 to i64
%5 = alloca i8, i64 %4
%6 = icmp slt i32 %0, 1
br i1 %6, label %7, label %10
7: ; preds = %2
%8 = load i32, i32* @stderr
%9 = tail call i32 (i32, i8*, ...) @fprintf(i32 %8, i8* getelementptr inbounds ([25 x i8], [25 x i8]* @.str, i64 0, i64 0))
br label %78
10: ; preds = %2
%11 = load i8*, i8** %1
%12 = call i32 @snprintf(i8* %5, i32 %3, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %11)
%13 = load i32, i32* @S_IRWXU
%14 = load i32, i32* @S_IRGRP
%15 = or i32 %14, %13
%16 = load i32, i32* @S_IXGRP
%17 = or i32 %15, %16
%18 = load i32, i32* @S_IROTH
%19 = or i32 %17, %18
%20 = load i32, i32* @S_IXOTH
%21 = or i32 %19, %20
%22 = call i32 @mkdir(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i32 %21)
br label %23
23: ; preds = %36, %10
%24 = phi i1 [ false, %10 ], [ true, %36 ]
%25 = call i64 @mount(i8* getelementptr inbounds ([1 x i8], [1 x i8]* @.str.3, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 1064960, i32* null)
%26 = icmp eq i64 %25, 0
br i1 %26, label %45, label %27
27: ; preds = %23
%28 = load i64, i64* @errno
%29 = load i64, i64* @EINVAL
%30 = icmp ne i64 %28, %29
%31 = or i1 %24, %30
br i1 %31, label %32, label %36
32: ; preds = %27
%33 = load i32, i32* @stderr
%34 = call i8* @strerror(i64 %28)
%35 = call i32 (i32, i8*, ...) @fprintf(i32 %33, i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str.5, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %34)
br label %78
36: ; preds = %27
%37 = load i32, i32* @MS_BIND
%38 = call i64 @mount(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %37, i32* null)
%39 = icmp eq i64 %38, 0
br i1 %39, label %23, label %40
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = load i64, i64* @errno
%43 = call i8* @strerror(i64 %42)
%44 = call i32 (i32, i8*, ...) @fprintf(i32 %41, i8* getelementptr inbounds ([31 x i8], [31 x i8]* @.str.6, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.2, i64 0, i64 0), i8* %43)
br label %78
45: ; preds = %23
%46 = load i32, i32* @O_RDONLY
%47 = load i32, i32* @O_CREAT
%48 = or i32 %47, %46
%49 = load i32, i32* @O_EXCL
%50 = or i32 %48, %49
%51 = call i32 @open(i8* %5, i32 %50, i32 0)
%52 = icmp slt i32 %51, 0
br i1 %52, label %53, label %58
53: ; preds = %45
%54 = load i32, i32* @stderr
%55 = load i64, i64* @errno
%56 = call i8* @strerror(i64 %55)
%57 = call i32 (i32, i8*, ...) @fprintf(i32 %54, i8* getelementptr inbounds ([43 x i8], [43 x i8]* @.str.7, i64 0, i64 0), i8* %5, i8* %56)
br label %78
58: ; preds = %45
%59 = call i32 @close(i32 %51)
%60 = call i64 @unshare(i32 1073741824)
%61 = icmp slt i64 %60, 0
br i1 %61, label %62, label %67
62: ; preds = %58
%63 = load i32, i32* @stderr
%64 = load i64, i64* @errno
%65 = call i8* @strerror(i64 %64)
%66 = call i32 (i32, i8*, ...) @fprintf(i32 %63, i8* getelementptr inbounds ([51 x i8], [51 x i8]* @.str.8, i64 0, i64 0), i8* %11, i8* %65)
br label %76
67: ; preds = %58
%68 = load i32, i32* @MS_BIND
%69 = call i64 @mount(i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.9, i64 0, i64 0), i8* %5, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.4, i64 0, i64 0), i32 %68, i32* null)
%70 = icmp slt i64 %69, 0
br i1 %70, label %71, label %78
71: ; preds = %67
%72 = load i32, i32* @stderr
%73 = load i64, i64* @errno
%74 = call i8* @strerror(i64 %73)
%75 = call i32 (i32, i8*, ...) @fprintf(i32 %72, i8* getelementptr inbounds ([41 x i8], [41 x i8]* @.str.10, i64 0, i64 0), i8* %5, i8* %74)
br label %76
76: ; preds = %71, %62
%77 = call i32 @netns_delete(i32 %0, i8** %1)
br label %78
78: ; preds = %67, %76, %53, %40, %32, %7
%79 = phi i32 [ -1, %7 ], [ -1, %32 ], [ -1, %40 ], [ -1, %53 ], [ -1, %76 ], [ 0, %67 ]
ret i32 %79
}