#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 size_t ssize_t;
typedef int /*<<< orphan*/ buf;

/* Variables and functions */
int BUFSIZ;
int /*<<< orphan*/ O_RDONLY;
long errno;
int open(char *, int /*<<< orphan*/);
size_t read(int, char *, int);
long strtol(char *, int /*<<< orphan*/ *, int);
long get_user_ns(void) {
  int fd = open("/sys/fs/cgroup/cpu,cpuacct/sandbox"
                "/cpuacct.usage_user",
                O_RDONLY);
  if (fd >= 0) {
    char buf[BUFSIZ];
    ssize_t sz = read(fd, buf, sizeof(buf) - 1);
    if (sz >= 0) {
      buf[sz] = '\0';
      return strtol(buf, NULL, 10);
    }
  }
  return -errno;
}


x86 assembly (clang, -O0):
<get_user_ns>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    0x2ea9(%rip),%rax
mov    (%rax),%esi
lea    0xeb8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0xc(%rbp)
cmpl   $0x0,-0xc(%rbp)
jl     11f5 <get_user_ns+0xc5>
mov    0x2e77(%rip),%rax
mov    (%rax),%eax
mov    %rsp,%rcx
mov    %rcx,-0x18(%rbp)
mov    %rax,%rcx
add    $0xf,%rcx
and    $0xfffffffffffffff0,%rcx
mov    %rsp,%rsi
sub    %rcx,%rsi
mov    %rsi,-0x38(%rbp)
mov    %rsi,%rsp
mov    %rax,-0x20(%rbp)
mov    -0xc(%rbp),%edi
sub    $0x1,%rax
mov    %eax,%edx
call   1030 <read@plt>
mov    %rax,-0x28(%rbp)
cmpq   $0x0,-0x28(%rbp)
jb     11cd <get_user_ns+0x9d>
mov    -0x38(%rbp),%rdi
mov    -0x28(%rbp),%rax
movb   $0x0,(%rdi,%rax,1)
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %rax,-0x8(%rbp)
movl   $0x1,-0x2c(%rbp)
jmp    11d4 <get_user_ns+0xa4>
movl   $0x0,-0x2c(%rbp)
mov    -0x18(%rbp),%rax
mov    %rax,%rsp
mov    -0x2c(%rbp),%eax
test   %eax,%eax
je     11f0 <get_user_ns+0xc0>
jmp    11eb <get_user_ns+0xbb>
jmp    1205 <get_user_ns+0xd5>
jmp    11f5 <get_user_ns+0xc5>
xor    %eax,%eax
mov    0x2dd2(%rip),%rcx
sub    (%rcx),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
mov    %rbp,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<get_user_ns>:
push   %rbp
mov    %rsp,%rbp
push   %r14
push   %rbx
mov    0x2eaa(%rip),%rax
mov    (%rax),%esi
lea    0xeb9(%rip),%rdi
call   1050 <open@plt>
test   %eax,%eax
js     1195 <get_user_ns+0x65>
mov    %rsp,%r14
mov    0x2e7e(%rip),%rcx
mov    (%rcx),%ecx
mov    %rsp,%rbx
mov    %rcx,%rdx
add    $0xf,%rdx
and    $0xfffffffffffffff0,%rdx
sub    %rdx,%rbx
mov    %rbx,%rsp
lea    -0x1(%rcx),%edx
mov    %eax,%edi
mov    %rbx,%rsi
call   1030 <read@plt>
movb   $0x0,(%rax,%rbx,1)
mov    %rbx,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1040 <strtol@plt>
mov    %r14,%rsp
jmp    11a1 <get_user_ns+0x71>
mov    0x2e34(%rip),%rcx
xor    %eax,%eax
sub    (%rcx),%rax
lea    -0x10(%rbp),%rsp
pop    %rbx
pop    %r14
pop    %rbp
ret

LLVM IR (-O0):
@.str = [54 x i8] c"/sys/fs/cgroup/cpu,cpuacct/sandbox/cpuacct.usage_user\00"
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@errno = global i64 0
define i64 @get_user_ns() {
%1 = alloca i64
%2 = alloca i32
%3 = alloca i8*
%4 = alloca i64
%5 = alloca i64
%6 = alloca i32
%7 = load i32, i32* @O_RDONLY
%8 = call i32 @open(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %7)
store i32 %8, i32* %2
%9 = load i32, i32* %2
%10 = icmp sge i32 %9, 0
br i1 %10, label %11, label %31
11: ; preds = %0
%12 = load i32, i32* @BUFSIZ
%13 = zext i32 %12 to i64
%14 = call i8* @llvm.stacksave()
store i8* %14, i8** %3
%15 = alloca i8, i64 %13
store i64 %13, i64* %4
%16 = load i32, i32* %2
%17 = sub i64 %13, 1
%18 = trunc i64 %17 to i32
%19 = call i64 @read(i32 %16, i8* %15, i32 %18)
store i64 %19, i64* %5
%20 = load i64, i64* %5
%21 = icmp uge i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %11
%23 = load i64, i64* %5
%24 = getelementptr inbounds i8, i8* %15, i64 %23
store i8 0, i8* %24
%25 = call i64 @strtol(i8* %15, i32* null, i32 10)
store i64 %25, i64* %1
store i32 1, i32* %6
br label %27
26: ; preds = %11
store i32 0, i32* %6
br label %27
27: ; preds = %26, %22
%28 = load i8*, i8** %3
%29 = load i32, i32* %6
switch i32 %29, label %36 [
i32 0, label %30
i32 1, label %34
]
30: ; preds = %27
br label %31
31: ; preds = %30, %0
%32 = load i64, i64* @errno
%33 = sub nsw i64 0, %32
store i64 %33, i64* %1
br label %34
34: ; preds = %31, %27
%35 = load i64, i64* %1
ret i64 %35
36: ; preds = %27
unreachable
}

LLVM IR (-O2):
@.str = [54 x i8] c"/sys/fs/cgroup/cpu,cpuacct/sandbox/cpuacct.usage_user\00"
@O_RDONLY = global i32 0
@BUFSIZ = global i32 0
@errno = global i64 0
define i64 @get_user_ns() {
%1 = load i32, i32* @O_RDONLY
%2 = tail call i32 @open(i8* getelementptr inbounds ([54 x i8], [54 x i8]* @.str, i64 0, i64 0), i32 %1)
%3 = icmp sgt i32 %2, -1
br i1 %3, label %4, label %13
4: ; preds = %0
%5 = load i32, i32* @BUFSIZ
%6 = zext i32 %5 to i64
%7 = tail call i8* @llvm.stacksave()
%8 = alloca i8, i64 %6
%9 = add i32 %5, -1
%10 = call i64 @read(i32 %2, i8* %8, i32 %9)
%11 = getelementptr inbounds i8, i8* %8, i64 %10
store i8 0, i8* %11
%12 = call i64 @strtol(i8* nocapture %8, i32* null, i32 10)
tail call void @llvm.stackrestore(i8* %7)
br label %16
13: ; preds = %0
%14 = load i64, i64* @errno
%15 = sub nsw i64 0, %14
br label %16
16: ; preds = %4, %13
%17 = phi i64 [ %15, %13 ], [ %12, %4 ]
ret i64 %17
}