#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__ ENOENT;
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ atoi(char *);
int /*<<< orphan*/ close(int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
int /*<<< orphan*/ stderr;
void check_yama_ptrace_scope(void) {
  int fd = open("/proc/sys/kernel/yama/ptrace_scope", O_RDONLY);
  if (fd >= 0) {
    char buf[256];
    int n;
    n = read(fd, buf, sizeof buf);
    close(fd);
    if (n > 0) {
      if (!atoi(buf)) {
        return;
      }
    }
  } else if (errno == ENOENT)
    return;
  fprintf(
      stderr,
      "The kernel denied permission while attaching. If your uid matches\n");
  fprintf(
      stderr,
      "the target's, check the value of /proc/sys/kernel/yama/ptrace_scope.\n");
  fprintf(stderr, "For more information, see /etc/sysctl.d/10-ptrace.conf\n");
}


x86 assembly (clang, -O0):
<check_yama_ptrace_scope>:
push   %rbp
mov    %rsp,%rbp
sub    $0x120,%rsp
mov    0x2e86(%rip),%rax
mov    (%rax),%esi
lea    0xe95(%rip),%rdi
call   1060 <open@plt>
mov    %eax,-0x4(%rbp)
cmpl   $0x0,-0x4(%rbp)
jl     11d0 <check_yama_ptrace_scope+0x80>
mov    -0x4(%rbp),%edi
lea    -0x110(%rbp),%rsi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,-0x114(%rbp)
mov    -0x4(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x0,-0x114(%rbp)
jle    11cb <check_yama_ptrace_scope+0x7b>
lea    -0x110(%rbp),%rdi
call   1070 <atoi@plt>
cmp    $0x0,%eax
jne    11c6 <check_yama_ptrace_scope+0x76>
jmp    1233 <check_yama_ptrace_scope+0xe3>
jmp    11cb <check_yama_ptrace_scope+0x7b>
jmp    11f4 <check_yama_ptrace_scope+0xa4>
mov    0x2df9(%rip),%rax
mov    (%rax),%rax
mov    0x2ddf(%rip),%rcx
cmp    (%rcx),%rax
jne    11ef <check_yama_ptrace_scope+0x9f>
jmp    1233 <check_yama_ptrace_scope+0xe3>
jmp    11f4 <check_yama_ptrace_scope+0xa4>
mov    0x2ddd(%rip),%rax
mov    (%rax),%edi
lea    0xe1f(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2dc8(%rip),%rax
mov    (%rax),%edi
lea    0xe4d(%rip),%rsi
call   1050 <fprintf@plt>
mov    0x2db3(%rip),%rax
mov    (%rax),%edi
lea    0xe7e(%rip),%rsi
call   1050 <fprintf@plt>
add    $0x120,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_yama_ptrace_scope>:
push   %rbp
push   %rbx
sub    $0x108,%rsp
mov    0x2e88(%rip),%rax
mov    (%rax),%esi
lea    0xe97(%rip),%rdi
call   1060 <open@plt>
test   %eax,%eax
js     11d6 <check_yama_ptrace_scope+0x86>
mov    %eax,%ebx
mov    %rsp,%rsi
mov    %eax,%edi
mov    $0x100,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
test   %ebp,%ebp
jle    119c <check_yama_ptrace_scope+0x4c>
mov    %rsp,%rdi
call   1070 <atoi@plt>
test   %eax,%eax
je     11ec <check_yama_ptrace_scope+0x9c>
mov    0x2e35(%rip),%rbx
mov    (%rbx),%edi
lea    0xe77(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xeac(%rip),%rsi
call   1050 <fprintf@plt>
mov    (%rbx),%edi
lea    0xee4(%rip),%rsi
add    $0x108,%rsp
pop    %rbx
pop    %rbp
jmp    1050 <fprintf@plt>
mov    0x2df3(%rip),%rax
mov    (%rax),%rax
mov    0x2dd9(%rip),%rcx
cmp    (%rcx),%rax
jne    119c <check_yama_ptrace_scope+0x4c>
add    $0x108,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [35 x i8] c"/proc/sys/kernel/yama/ptrace_scope\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [67 x i8] c"The kernel denied permission while attaching. If your uid matches\0A\00"
@.str.2 = [70 x i8] c"the target's, check the value of /proc/sys/kernel/yama/ptrace_scope.\0A\00"
@.str.3 = [56 x i8] c"For more information, see /etc/sysctl.d/10-ptrace.conf\0A\00"
define void @check_yama_ptrace_scope() {
%1 = alloca i32
%2 = alloca [256 x i8]
%3 = alloca i32
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %1
%6 = load i32, i32* %1
%7 = icmp sge i32 %6, 0
br i1 %7, label %8, label %23
8: ; preds = %0
%9 = load i32, i32* %1
%10 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%11 = call i32 @read(i32 %9, i8* %10, i32 256)
store i32 %11, i32* %3
%12 = load i32, i32* %1
%13 = call i32 @close(i32 %12)
%14 = load i32, i32* %3
%15 = icmp sgt i32 %14, 0
br i1 %15, label %16, label %22
16: ; preds = %8
%17 = getelementptr inbounds [256 x i8], [256 x i8]* %2, i64 0, i64 0
%18 = call i32 @atoi(i8* %17)
%19 = icmp ne i32 %18, 0
br i1 %19, label %21, label %20
20: ; preds = %16
br label %36
21: ; preds = %16
br label %22
22: ; preds = %21, %8
br label %29
23: ; preds = %0
%24 = load i64, i64* @errno
%25 = load i64, i64* @ENOENT
%26 = icmp eq i64 %24, %25
br i1 %26, label %27, label %28
27: ; preds = %23
br label %36
28: ; preds = %23
br label %29
29: ; preds = %28, %22
%30 = load i32, i32* @stderr
%31 = call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%32 = load i32, i32* @stderr
%33 = call i32 @fprintf(i32 %32, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%34 = load i32, i32* @stderr
%35 = call i32 @fprintf(i32 %34, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %36
36: ; preds = %29, %27, %20
ret void
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/kernel/yama/ptrace_scope\00"
@O_RDONLY = global i32 0
@errno = global i64 0
@ENOENT = global i64 0
@stderr = global i32 0
@.str.1 = [67 x i8] c"The kernel denied permission while attaching. If your uid matches\0A\00"
@.str.2 = [70 x i8] c"the target's, check the value of /proc/sys/kernel/yama/ptrace_scope.\0A\00"
@.str.3 = [56 x i8] c"For more information, see /etc/sysctl.d/10-ptrace.conf\0A\00"
define void @check_yama_ptrace_scope() {
%1 = alloca [256 x i8]
%2 = load i32, i32* @O_RDONLY
%3 = tail call i32 @open(i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i32 %2)
%4 = icmp sgt i32 %3, -1
br i1 %4, label %5, label %15
5: ; preds = %0
%6 = getelementptr inbounds [256 x i8], [256 x i8]* %1, i64 0, i64 0
%7 = call i32 @read(i32 %3, i8* %6, i32 256)
%8 = tail call i32 @close(i32 %3)
%9 = icmp sgt i32 %7, 0
br i1 %9, label %10, label %13
10: ; preds = %5
%11 = call i32 @atoi(i8* %6)
%12 = icmp eq i32 %11, 0
br i1 %12, label %14, label %13
13: ; preds = %10, %5
br label %19
14: ; preds = %10
br label %26
15: ; preds = %0
%16 = load i64, i64* @errno
%17 = load i64, i64* @ENOENT
%18 = icmp eq i64 %16, %17
br i1 %18, label %26, label %19
19: ; preds = %13, %15
%20 = load i32, i32* @stderr
%21 = tail call i32 @fprintf(i32 %20, i8* getelementptr inbounds ([67 x i8], [67 x i8]* @.str.1, i64 0, i64 0))
%22 = load i32, i32* @stderr
%23 = tail call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([70 x i8], [70 x i8]* @.str.2, i64 0, i64 0))
%24 = load i32, i32* @stderr
%25 = tail call i32 @fprintf(i32 %24, i8* getelementptr inbounds ([56 x i8], [56 x i8]* @.str.3, i64 0, i64 0))
br label %26
26: ; preds = %15, %14, %19
ret void
}