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

/* Variables and functions */
int MAXPATHLEN;
int /*<<< orphan*/ MNT_DETACH;
int errno;
scalar_t__ rmdir(char *);
int /*<<< orphan*/ snprintf(char *, int, char *, char *, char const *);
int /*<<< orphan*/ umount2(char *, int /*<<< orphan*/);
int namespace_cleanup(const char *name) {
  char pidns_path[MAXPATHLEN];
  snprintf(pidns_path, sizeof(pidns_path), "%s/%s", "/var/run/pidns", name);
  umount2(pidns_path, MNT_DETACH);
  if (rmdir(pidns_path) < 0) {
    return errno;
  }
  return 0;
}


x86 assembly (clang, -O0):
<namespace_cleanup>:
push   %rbp
mov    %rsp,%rbp
sub    $0x30,%rsp
mov    %rdi,-0x10(%rbp)
mov    0x2ea5(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rdi
sub    %rcx,%rdi
mov    %rdi,-0x30(%rbp)
mov    %rdi,%rsp
mov    %rax,-0x20(%rbp)
mov    %eax,%esi
mov    -0x10(%rbp),%r8
lea    0xe8b(%rip),%rdx
lea    0xe8a(%rip),%rcx
call   1050 <snprintf@plt>
mov    -0x30(%rbp),%rdi
mov    0x2e44(%rip),%rax
mov    (%rax),%esi
call   1030 <umount2@plt>
mov    -0x30(%rbp),%rdi
call   1040 <rmdir@plt>
cmp    $0x0,%rax
jge    11be <namespace_cleanup+0x8e>
mov    0x2e2b(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
jmp    11cc <namespace_cleanup+0x9c>
movl   $0x0,-0x4(%rbp)
movl   $0x1,-0x24(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x4(%rbp),%eax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<namespace_cleanup>:
push   %rbp
mov    %rsp,%rbp
push   %rbx
push   %rax
mov    %rdi,%r8
mov    0x2ea8(%rip),%rax
mov    (%rax),%esi
mov    %rsp,%rbx
mov    %rsi,%rax
add    $0xf,%rax
and    $0xfffffffffffffff0,%rax
sub    %rax,%rbx
mov    %rbx,%rsp
lea    0xea3(%rip),%rdx
lea    0xea2(%rip),%rcx
mov    %rbx,%rdi
call   1050 <snprintf@plt>
mov    0x2e5d(%rip),%rax
mov    (%rax),%esi
mov    %rbx,%rdi
call   1030 <umount2@plt>
mov    %rbx,%rdi
call   1040 <rmdir@plt>
mov    0x2e4c(%rip),%rcx
sar    $0x3f,%rax
and    (%rcx),%eax
lea    -0x8(%rbp),%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [15 x i8] c"/var/run/pidns\00"
@MNT_DETACH = global i32 0
@errno = global i32 0
define i32 @namespace_cleanup(i8* %0) {
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i64
%6 = alloca i32
store i8* %0, i8** %3
%7 = load i32, i32* @MAXPATHLEN
%8 = zext i32 %7 to i64
%9 = call i8* @llvm.stacksave()
store i8* %9, i8** %4
%10 = alloca i8, i64 %8
store i64 %8, i64* %5
%11 = trunc i64 %8 to i32
%12 = load i8*, i8** %3
%13 = call i32 @snprintf(i8* %10, i32 %11, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %12)
%14 = load i32, i32* @MNT_DETACH
%15 = call i32 @umount2(i8* %10, i32 %14)
%16 = call i64 @rmdir(i8* %10)
%17 = icmp slt i64 %16, 0
br i1 %17, label %18, label %20
18: ; preds = %1
%19 = load i32, i32* @errno
store i32 %19, i32* %2
store i32 1, i32* %6
br label %21
20: ; preds = %1
store i32 0, i32* %2
store i32 1, i32* %6
br label %21
21: ; preds = %20, %18
%22 = load i8*, i8** %4
%23 = load i32, i32* %2
ret i32 %23
}

LLVM IR (-O2):
@MAXPATHLEN = global i32 0
@.str = [6 x i8] c"%s/%s\00"
@.str.1 = [15 x i8] c"/var/run/pidns\00"
@MNT_DETACH = global i32 0
@errno = global i32 0
define i32 @namespace_cleanup(i8* %0) {
%2 = load i32, i32* @MAXPATHLEN
%3 = zext i32 %2 to i64
%4 = alloca i8, i64 %3
%5 = call i32 @snprintf(i8* %4, i32 %2, i8* getelementptr inbounds ([6 x i8], [6 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str.1, i64 0, i64 0), i8* %0)
%6 = load i32, i32* @MNT_DETACH
%7 = call i32 @umount2(i8* %4, i32 %6)
%8 = call i64 @rmdir(i8* %4)
%9 = icmp slt i64 %8, 0
%10 = load i32, i32* @errno
%11 = select i1 %9, i32 %10, i32 0
ret i32 %11
}