#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*/ free(char *);
int get_RUNVNETNSPID();
char *malloc(int);
int open(char *, int /*<<< orphan*/);
int /*<<< orphan*/ setns(int, int);
int /*<<< orphan*/ sprintf(char *, char *, int);
void nsexec(void) {
  int nsPid, nsFd;
  char *path;
  nsPid = get_RUNVNETNSPID();
  if (nsPid <= 0) {
    return;
  }
  path = malloc(sizeof(char) * 64);
  sprintf(path, "/proc/%d/ns/net", nsPid);
  nsFd = open(path, O_RDONLY);
  setns(nsFd, 0x40000000);
  free(path);
  close(nsFd);
  return;
}


x86 assembly (clang, -O0):
<nsexec>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1060 <get_RUNVNETNSPID@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jg     1191 <nsexec+0x21>
jmp    11e5 <nsexec+0x75>
mov    $0x40,%edi
call   1070 <malloc@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    -0x4(%rbp),%edx
lea    0xe53(%rip),%rsi
call   1090 <sprintf@plt>
mov    -0x10(%rbp),%rdi
mov    0x2e2b(%rip),%rax
mov    (%rax),%esi
call   1080 <open@plt>
mov    %eax,-0x8(%rbp)
mov    -0x8(%rbp),%edi
mov    $0x40000000,%esi
call   1040 <setns@plt>
mov    -0x10(%rbp),%rdi
call   1030 <free@plt>
mov    -0x8(%rbp),%edi
call   1050 <close@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nsexec>:
push   %r14
push   %rbx
push   %rax
xor    %eax,%eax
call   1060 <get_RUNVNETNSPID@plt>
test   %eax,%eax
jle    11d4 <nsexec+0x64>
mov    %eax,%ebx
mov    $0x40,%edi
call   1070 <malloc@plt>
mov    %rax,%r14
lea    0xe6b(%rip),%rsi
mov    %rax,%rdi
mov    %ebx,%edx
call   1090 <sprintf@plt>
mov    0x2e42(%rip),%rax
mov    (%rax),%esi
mov    %r14,%rdi
call   1080 <open@plt>
mov    %eax,%ebx
mov    %eax,%edi
mov    $0x40000000,%esi
call   1040 <setns@plt>
mov    %r14,%rdi
call   1030 <free@plt>
mov    %ebx,%edi
add    $0x8,%rsp
pop    %rbx
pop    %r14
jmp    1050 <close@plt>
add    $0x8,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [16 x i8] c"/proc/%d/ns/net\00"
@O_RDONLY = global i32 0
define void @nsexec() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i8*
%4 = call i32 (...) @get_RUNVNETNSPID()
store i32 %4, i32* %1
%5 = load i32, i32* %1
%6 = icmp sle i32 %5, 0
br i1 %6, label %7, label %8
7: ; preds = %0
br label %22
8: ; preds = %0
%9 = call i8* @malloc(i32 64)
store i8* %9, i8** %3
%10 = load i8*, i8** %3
%11 = load i32, i32* %1
%12 = call i32 @sprintf(i8* %10, i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %11)
%13 = load i8*, i8** %3
%14 = load i32, i32* @O_RDONLY
%15 = call i32 @open(i8* %13, i32 %14)
store i32 %15, i32* %2
%16 = load i32, i32* %2
%17 = call i32 @setns(i32 %16, i32 1073741824)
%18 = load i8*, i8** %3
%19 = call i32 @free(i8* %18)
%20 = load i32, i32* %2
%21 = call i32 @close(i32 %20)
br label %22
22: ; preds = %8, %7
ret void
}

LLVM IR (-O2):
@.str = [16 x i8] c"/proc/%d/ns/net\00"
@O_RDONLY = global i32 0
define void @nsexec() {
%1 = tail call i32 (...) @get_RUNVNETNSPID()
%2 = icmp slt i32 %1, 1
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = tail call dereferenceable_or_null(64) i8* @malloc(i32 64)
%5 = tail call i32 @sprintf(i8* dereferenceable(1) %4, i8* dereferenceable(1) getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0), i32 %1)
%6 = load i32, i32* @O_RDONLY
%7 = tail call i32 @open(i8* %4, i32 %6)
%8 = tail call i32 @setns(i32 %7, i32 1073741824)
%9 = tail call i32 @free(i8* %4)
%10 = tail call i32 @close(i32 %7)
br label %11
11: ; preds = %0, %3
ret void
}