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

/* Variables and functions */
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char const *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char const *);
size_t fread(char *, int, int, int /*<<< orphan*/ *);
int /*<<< orphan*/ stderr;
scalar_t__ strtol(char *, int /*<<< orphan*/ *, int);
void check_proc_sys_userns_file(const char *path) {
  FILE *fp;
  fp = fopen(path, "r");
  if (fp) {
    char buf[32];
    size_t n_read = fread(buf, 1, sizeof(buf) - 1, fp);
    if (n_read > 0) {
      buf[n_read] = '\0';
      if (strtol(buf, NULL, 10) == 0)
        fprintf(stderr, "user namespaces are not enabled in %s\n", path);
    }
    fclose(fp);
  }
}


x86 assembly (clang, -O0):
<check_proc_sys_userns_file>:
push   %rbp
mov    %rsp,%rbp
sub    $0x40,%rsp
mov    %rdi,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
lea    0xe99(%rip),%rsi
call   1070 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
je     11ed <check_proc_sys_userns_file+0x9d>
lea    -0x30(%rbp),%rdi
mov    -0x10(%rbp),%rcx
mov    $0x1,%esi
mov    $0x1f,%edx
call   1030 <fread@plt>
mov    %rax,-0x38(%rbp)
cmpq   $0x0,-0x38(%rbp)
jbe    11e4 <check_proc_sys_userns_file+0x94>
mov    -0x38(%rbp),%rax
movb   $0x0,-0x30(%rbp,%rax,1)
lea    -0x30(%rbp),%rdi
xor    %eax,%eax
mov    %eax,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
cmp    $0x0,%rax
jne    11df <check_proc_sys_userns_file+0x8f>
mov    0x2e13(%rip),%rax
mov    (%rax),%edi
mov    -0x8(%rbp),%rdx
lea    0xe28(%rip),%rsi
call   1050 <fprintf@plt>
jmp    11e4 <check_proc_sys_userns_file+0x94>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x40,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_proc_sys_userns_file>:
push   %r14
push   %rbx
sub    $0x28,%rsp
mov    %rdi,%r14
lea    0xe9f(%rip),%rsi
call   1070 <fopen@plt>
test   %rax,%rax
je     11c0 <check_proc_sys_userns_file+0x70>
mov    %rax,%rbx
mov    %rsp,%rdi
mov    $0x1,%esi
mov    $0x1f,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
je     11b8 <check_proc_sys_userns_file+0x68>
movb   $0x0,(%rsp,%rax,1)
mov    %rsp,%rdi
xor    %esi,%esi
mov    $0xa,%edx
call   1060 <strtol@plt>
test   %rax,%rax
jne    11b8 <check_proc_sys_userns_file+0x68>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe52(%rip),%rsi
mov    %r14,%rdx
call   1050 <fprintf@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x28,%rsp
pop    %rbx
pop    %r14
ret

LLVM IR (-O0):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"user namespaces are not enabled in %s\0A\00"
define void @check_proc_sys_userns_file(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca [32 x i8]
%5 = alloca i64
store i8* %0, i8** %2
%6 = load i8*, i8** %2
%7 = call i32* @fopen(i8* %6, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
store i32* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp ne i32* %8, null
br i1 %9, label %10, label %30
10: ; preds = %1
%11 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%12 = load i32*, i32** %3
%13 = call i64 @fread(i8* %11, i32 1, i32 31, i32* %12)
store i64 %13, i64* %5
%14 = load i64, i64* %5
%15 = icmp ugt i64 %14, 0
br i1 %15, label %16, label %27
16: ; preds = %10
%17 = load i64, i64* %5
%18 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 %17
store i8 0, i8* %18
%19 = getelementptr inbounds [32 x i8], [32 x i8]* %4, i64 0, i64 0
%20 = call i64 @strtol(i8* %19, i32* null, i32 10)
%21 = icmp eq i64 %20, 0
br i1 %21, label %22, label %26
22: ; preds = %16
%23 = load i32, i32* @stderr
%24 = load i8*, i8** %2
%25 = call i32 @fprintf(i32 %23, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %24)
br label %26
26: ; preds = %22, %16
br label %27
27: ; preds = %26, %10
%28 = load i32*, i32** %3
%29 = call i32 @fclose(i32* %28)
br label %30
30: ; preds = %27, %1
ret void
}

LLVM IR (-O2):
@.str = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.1 = [39 x i8] c"user namespaces are not enabled in %s\0A\00"
define void @check_proc_sys_userns_file(i8* %0) {
%2 = alloca [32 x i8]
%3 = tail call i32* @fopen(i8* %0, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %18, label %5
5: ; preds = %1
%6 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 0
%7 = call i64 @fread(i8* %6, i32 1, i32 31, i32* %3)
%8 = icmp eq i64 %7, 0
br i1 %8, label %16, label %9
9: ; preds = %5
%10 = getelementptr inbounds [32 x i8], [32 x i8]* %2, i64 0, i64 %7
store i8 0, i8* %10
%11 = call i64 @strtol(i8* nocapture %6, i32* null, i32 10)
%12 = icmp eq i64 %11, 0
br i1 %12, label %13, label %16
13: ; preds = %9
%14 = load i32, i32* @stderr
%15 = tail call i32 @fprintf(i32 %14, i8* getelementptr inbounds ([39 x i8], [39 x i8]* @.str.1, i64 0, i64 0), i8* %0)
br label %16
16: ; preds = %9, %13, %5
%17 = tail call i32 @fclose(i32* %3)
br label %18
18: ; preds = %16, %1
ret void
}