#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 MS_PRIVATE;
scalar_t__ create_and_enter_userns();
scalar_t__ mount(int /*<<< orphan*/ *, char *, int /*<<< orphan*/ *, int,
                 int /*<<< orphan*/);
scalar_t__ unshare(int);
int prepare_unpriv_mountns(void) {
  if (create_and_enter_userns())
    return -1;
  if (unshare(0x00020000))
    return -1;
  if (mount(NULL, "/", NULL, 16384 | MS_PRIVATE, 0))
    return -1;
  return 0;
}


x86 assembly (clang, -O0):
<prepare_unpriv_mountns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x0,%al
call   1050 <create_and_enter_userns@plt>
cmp    $0x0,%rax
je     1155 <prepare_unpriv_mountns+0x25>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <prepare_unpriv_mountns+0x87>
mov    $0x20000,%edi
call   1030 <unshare@plt>
cmp    $0x0,%rax
je     1175 <prepare_unpriv_mountns+0x45>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <prepare_unpriv_mountns+0x87>
mov    0x2e64(%rip),%rax
mov    (%rax),%ecx
or     $0x4000,%ecx
xor    %eax,%eax
mov    %eax,%edx
lea    0xe71(%rip),%rsi
xor    %r8d,%r8d
mov    %rdx,%rdi
call   1040 <mount@plt>
cmp    $0x0,%rax
je     11b0 <prepare_unpriv_mountns+0x80>
movl   $0xffffffff,-0x4(%rbp)
jmp    11b7 <prepare_unpriv_mountns+0x87>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<prepare_unpriv_mountns>:
push   %rbx
xor    %eax,%eax
call   1050 <create_and_enter_userns@plt>
mov    $0xffffffff,%ebx
test   %rax,%rax
jne    1177 <prepare_unpriv_mountns+0x47>
mov    $0x20000,%edi
call   1030 <unshare@plt>
test   %rax,%rax
jne    1177 <prepare_unpriv_mountns+0x47>
mov    0x2e88(%rip),%rax
mov    $0x4000,%ecx
or     (%rax),%ecx
lea    0xe9a(%rip),%rsi
xor    %edi,%edi
xor    %edx,%edx
xor    %r8d,%r8d
call   1040 <mount@plt>
neg    %rax
sbb    %ebx,%ebx
mov    %ebx,%eax
pop    %rbx
ret

LLVM IR (-O0):
@.str = [2 x i8] c"/\00"
@MS_PRIVATE = global i32 0
define i32 @prepare_unpriv_mountns() {
%1 = alloca i32
%2 = call i64 (...) @create_and_enter_userns()
%3 = icmp ne i64 %2, 0
br i1 %3, label %4, label %5
4: ; preds = %0
store i32 -1, i32* %1
br label %16
5: ; preds = %0
%6 = call i64 @unshare(i32 131072)
%7 = icmp ne i64 %6, 0
br i1 %7, label %8, label %9
8: ; preds = %5
store i32 -1, i32* %1
br label %16
9: ; preds = %5
%10 = load i32, i32* @MS_PRIVATE
%11 = or i32 16384, %10
%12 = call i64 @mount(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* null, i32 %11, i32 0)
%13 = icmp ne i64 %12, 0
br i1 %13, label %14, label %15
14: ; preds = %9
store i32 -1, i32* %1
br label %16
15: ; preds = %9
store i32 0, i32* %1
br label %16
16: ; preds = %15, %14, %8, %4
%17 = load i32, i32* %1
ret i32 %17
}

LLVM IR (-O2):
@.str = [2 x i8] c"/\00"
@MS_PRIVATE = global i32 0
define i32 @prepare_unpriv_mountns() {
%1 = tail call i64 (...) @create_and_enter_userns()
%2 = icmp eq i64 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i64 @unshare(i32 131072)
%5 = icmp eq i64 %4, 0
br i1 %5, label %6, label %12
6: ; preds = %3
%7 = load i32, i32* @MS_PRIVATE
%8 = or i32 %7, 16384
%9 = tail call i64 @mount(i32* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0), i32* null, i32 %8, i32 0)
%10 = icmp ne i64 %9, 0
%11 = sext i1 %10 to i32
br label %12
12: ; preds = %6, %3, %0
%13 = phi i32 [ -1, %0 ], [ -1, %3 ], [ %11, %6 ]
ret i32 %13
}