#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 */
scalar_t__ EPERM;
scalar_t__ errno;
int /*<<< orphan*/ ksft_exit_skip(char *);
int /*<<< orphan*/ ksft_test_result_error(char *);
scalar_t__ unshare(int);
int unshare_timens(void) {
  if (unshare(0x00000080)) {
    if (errno == EPERM)
      ksft_exit_skip("need to run as root\n");
    return ({
      ksft_test_result_error("Can't unshare() timens"
                             ": %m"
                             "\n");
      -1;
    });
  }
  return 0;
}


x86 assembly (clang, -O0):
<unshare_timens>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    $0x80,%edi
call   1030 <unshare@plt>
cmp    $0x0,%rax
je     1190 <unshare_timens+0x60>
mov    0x2e8d(%rip),%rax
mov    (%rax),%rax
mov    0x2e73(%rip),%rcx
cmp    (%rcx),%rax
jne    1172 <unshare_timens+0x42>
lea    0xe93(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
lea    0xe9c(%rip),%rdi
call   1050 <ksft_test_result_error@plt>
movl   $0xffffffff,-0x8(%rbp)
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
jmp    1197 <unshare_timens+0x67>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<unshare_timens>:
push   %rax
mov    $0x80,%edi
call   1030 <unshare@plt>
test   %rax,%rax
je     1175 <unshare_timens+0x45>
mov    0x2e99(%rip),%rax
mov    (%rax),%rax
mov    0x2e7f(%rip),%rcx
cmp    (%rcx),%rax
jne    1162 <unshare_timens+0x32>
lea    0xea3(%rip),%rdi
call   1040 <ksft_exit_skip@plt>
lea    0xeac(%rip),%rdi
call   1050 <ksft_test_result_error@plt>
mov    $0xffffffff,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@errno = global i64 0
@EPERM = global i64 0
@.str = [21 x i8] c"need to run as root\0A\00"
@.str.1 = [28 x i8] c"Can't unshare() timens: %m\0A\00"
define i32 @unshare_timens() {
%1 = alloca i32
%2 = alloca i32
%3 = call i64 @unshare(i32 128)
%4 = icmp ne i64 %3, 0
br i1 %4, label %5, label %14
5: ; preds = %0
%6 = load i64, i64* @errno
%7 = load i64, i64* @EPERM
%8 = icmp eq i64 %6, %7
br i1 %8, label %9, label %11
9: ; preds = %5
%10 = call i32 @ksft_exit_skip(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %11
11: ; preds = %9, %5
%12 = call i32 @ksft_test_result_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
store i32 -1, i32* %2
%13 = load i32, i32* %2
store i32 %13, i32* %1
br label %15
14: ; preds = %0
store i32 0, i32* %1
br label %15
15: ; preds = %14, %11
%16 = load i32, i32* %1
ret i32 %16
}

LLVM IR (-O2):
@errno = global i64 0
@EPERM = global i64 0
@.str = [21 x i8] c"need to run as root\0A\00"
@.str.1 = [28 x i8] c"Can't unshare() timens: %m\0A\00"
define i32 @unshare_timens() {
%1 = tail call i64 @unshare(i32 128)
%2 = icmp eq i64 %1, 0
br i1 %2, label %11, label %3
3: ; preds = %0
%4 = load i64, i64* @errno
%5 = load i64, i64* @EPERM
%6 = icmp eq i64 %4, %5
br i1 %6, label %7, label %9
7: ; preds = %3
%8 = tail call i32 @ksft_exit_skip(i8* getelementptr inbounds ([21 x i8], [21 x i8]* @.str, i64 0, i64 0))
br label %9
9: ; preds = %7, %3
%10 = tail call i32 @ksft_test_result_error(i8* getelementptr inbounds ([28 x i8], [28 x i8]* @.str.1, i64 0, i64 0))
br label %11
11: ; preds = %0, %9
%12 = phi i32 [ -1, %9 ], [ 0, %0 ]
ret i32 %12
}