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

/* Variables and functions */
int /*<<< orphan*/ *fopen(char *, char *);
scalar_t__ fread(char *, int, int, int /*<<< orphan*/ *);
int yama_enabled(void) {
  FILE *fh = fopen("/proc/sys/kernel/yama/ptrace_scope", "r");
  if (!fh)
    return 0;
  char yama_byte;
  if (fread(&yama_byte, 1, 1, fh) < 0)
    return 0;
  return yama_byte == '1';
}


x86 assembly (clang, -O0):
<yama_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xed1(%rip),%rdi
lea    0xeed(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    1156 <yama_enabled+0x36>
movl   $0x0,-0x4(%rbp)
jmp    1192 <yama_enabled+0x72>
mov    -0x10(%rbp),%rcx
lea    -0x11(%rbp),%rdi
mov    $0x1,%edx
mov    %edx,%esi
call   1030 <fread@plt>
cmp    $0x0,%rax
jge    1180 <yama_enabled+0x60>
movl   $0x0,-0x4(%rbp)
jmp    1192 <yama_enabled+0x72>
movsbl -0x11(%rbp),%eax
cmp    $0x31,%eax
sete   %al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<yama_enabled>:
push   %rax
lea    0xed8(%rip),%rdi
lea    0xef4(%rip),%rsi
call   1040 <fopen@plt>
test   %rax,%rax
je     1165 <yama_enabled+0x45>
lea    0x7(%rsp),%rdi
mov    $0x1,%esi
mov    $0x1,%edx
mov    %rax,%rcx
call   1030 <fread@plt>
test   %rax,%rax
setns  %al
cmpb   $0x31,0x7(%rsp)
sete   %cl
and    %al,%cl
movzbl %cl,%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/proc/sys/kernel/yama/ptrace_scope\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @yama_enabled() {
%1 = alloca i32
%2 = alloca i32*
%3 = alloca i8
%4 = call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %4, i32** %2
%5 = load i32*, i32** %2
%6 = icmp ne i32* %5, null
br i1 %6, label %8, label %7
7: ; preds = %0
store i32 0, i32* %1
br label %18
8: ; preds = %0
%9 = load i32*, i32** %2
%10 = call i64 @fread(i8* %3, i32 1, i32 1, i32* %9)
%11 = icmp slt i64 %10, 0
br i1 %11, label %12, label %13
12: ; preds = %8
store i32 0, i32* %1
br label %18
13: ; preds = %8
%14 = load i8, i8* %3
%15 = sext i8 %14 to i32
%16 = icmp eq i32 %15, 49
%17 = zext i1 %16 to i32
store i32 %17, i32* %1
br label %18
18: ; preds = %13, %12, %7
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/kernel/yama/ptrace_scope\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @yama_enabled() {
%1 = alloca i8
%2 = tail call i32* @fopen(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%3 = icmp eq i32* %2, null
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = call i64 @fread(i8* %1, i32 1, i32 1, i32* %2)
%6 = icmp sgt i64 %5, -1
%7 = load i8, i8* %1
%8 = icmp eq i8 %7, 49
%9 = select i1 %6, i1 %8, i1 false
%10 = zext i1 %9 to i32
br label %11
11: ; preds = %0, %4
%12 = phi i32 [ %10, %4 ], [ 0, %0 ]
ret i32 %12
}