#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*/ EX_OSERR;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ _exit(int /*<<< orphan*/);
scalar_t__ close(int);
int open(char *, int /*<<< orphan*/);
scalar_t__ setns(int, int /*<<< orphan*/);
void join_namespace(char *namespace) {
  int fd;
  if (namespace == NULL || namespace[0] == '\0') {
    return;
  }
  fd = open(namespace, O_RDONLY);
  if (fd == -1) {
    _exit(EX_OSERR);
  }
  if (setns(fd, 0) != 0) {
    _exit(EX_OSERR);
  }
  if (close(fd) != 0) {
    _exit(EX_OSERR);
  }
}


x86 assembly (clang, -O0):
<join_namespace>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    %rdi,-0x8(%rbp)
cmpq   $0x0,-0x8(%rbp)
je     1167 <join_namespace+0x27>
mov    -0x8(%rbp),%rax
movsbl (%rax),%eax
cmp    $0x0,%eax
jne    116c <join_namespace+0x2c>
jmp    11db <join_namespace+0x9b>
mov    -0x8(%rbp),%rdi
mov    0x2e71(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0xffffffff,-0xc(%rbp)
jne    1199 <join_namespace+0x59>
mov    0x2e46(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0xc(%rbp),%edi
xor    %esi,%esi
call   1040 <setns@plt>
cmp    $0x0,%rax
je     11bb <join_namespace+0x7b>
mov    0x2e24(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
mov    -0xc(%rbp),%edi
call   1050 <close@plt>
cmp    $0x0,%rax
je     11db <join_namespace+0x9b>
mov    0x2e04(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<join_namespace>:
push   %rbx
test   %rdi,%rdi
je     117a <join_namespace+0x3a>
cmpb   $0x0,(%rdi)
je     117a <join_namespace+0x3a>
mov    0x2e96(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
cmp    $0xffffffff,%eax
je     117c <join_namespace+0x3c>
mov    %eax,%ebx
mov    %eax,%edi
xor    %esi,%esi
call   1040 <setns@plt>
test   %rax,%rax
jne    117c <join_namespace+0x3c>
mov    %ebx,%edi
call   1050 <close@plt>
test   %rax,%rax
jne    117c <join_namespace+0x3c>
pop    %rbx
ret
mov    0x2e55(%rip),%rax
mov    (%rax),%edi
call   1030 <_exit@plt>

LLVM IR (-O0):
@O_RDONLY = global i32 0
@EX_OSERR = global i32 0
define void @join_namespace(i8* %0) {
%2 = alloca i8*
%3 = alloca i32
store i8* %0, i8** %2
%4 = load i8*, i8** %2
%5 = icmp eq i8* %4, null
br i1 %5, label %12, label %6
6: ; preds = %1
%7 = load i8*, i8** %2
%8 = getelementptr inbounds i8, i8* %7, i64 0
%9 = load i8, i8* %8
%10 = sext i8 %9 to i32
%11 = icmp eq i32 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %6, %1
br label %36
13: ; preds = %6
%14 = load i8*, i8** %2
%15 = load i32, i32* @O_RDONLY
%16 = call i32 @open(i8* %14, i32 %15)
store i32 %16, i32* %3
%17 = load i32, i32* %3
%18 = icmp eq i32 %17, -1
br i1 %18, label %19, label %22
19: ; preds = %13
%20 = load i32, i32* @EX_OSERR
%21 = call i32 @_exit(i32 %20)
unreachable
22: ; preds = %13
%23 = load i32, i32* %3
%24 = call i64 @setns(i32 %23, i32 0)
%25 = icmp ne i64 %24, 0
br i1 %25, label %26, label %29
26: ; preds = %22
%27 = load i32, i32* @EX_OSERR
%28 = call i32 @_exit(i32 %27)
unreachable
29: ; preds = %22
%30 = load i32, i32* %3
%31 = call i64 @close(i32 %30)
%32 = icmp ne i64 %31, 0
br i1 %32, label %33, label %36
33: ; preds = %29
%34 = load i32, i32* @EX_OSERR
%35 = call i32 @_exit(i32 %34)
unreachable
36: ; preds = %12, %29
ret void
}

LLVM IR (-O2):
@O_RDONLY = global i32 0
@EX_OSERR = global i32 0
define void @join_namespace(i8* %0) {
%2 = icmp eq i8* %0, null
br i1 %2, label %25, label %3
3: ; preds = %1
%4 = load i8, i8* %0
%5 = icmp eq i8 %4, 0
br i1 %5, label %25, label %6
6: ; preds = %3
%7 = load i32, i32* @O_RDONLY
%8 = tail call i32 @open(i8* %0, i32 %7)
%9 = icmp eq i32 %8, -1
br i1 %9, label %10, label %13
10: ; preds = %6
%11 = load i32, i32* @EX_OSERR
%12 = tail call i32 @_exit(i32 %11)
unreachable
13: ; preds = %6
%14 = tail call i64 @setns(i32 %8, i32 0)
%15 = icmp eq i64 %14, 0
br i1 %15, label %19, label %16
16: ; preds = %13
%17 = load i32, i32* @EX_OSERR
%18 = tail call i32 @_exit(i32 %17)
unreachable
19: ; preds = %13
%20 = tail call i64 @close(i32 %8)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %19
%23 = load i32, i32* @EX_OSERR
%24 = tail call i32 @_exit(i32 %23)
unreachable
25: ; preds = %19, %1, %3
ret void
}