#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 */
int /*<<< orphan*/ O_RDONLY;
int /*<<< orphan*/ close(int);
int open(char const *, int /*<<< orphan*/);
int /*<<< orphan*/ printf(char *, char const *, char);
int /*<<< orphan*/ read(int, char *, int);
int nonparent_ptrace_allowed(void) {
  const char *name = "/proc/sys/kernel/yama/ptrace_scope";
  int fd = open(name, O_RDONLY);
  char value = '0';
  if (fd < 0)
    return 1;
  read(fd, &value, 1);
  close(fd);
  if (value == '0')
    return 1;
  printf("('%s' has value '%c') ", name, value);
  return 0;
}


x86 assembly (clang, -O0):
<nonparent_ptrace_allowed>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xeb1(%rip),%rax
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
mov    0x2e8a(%rip),%rax
mov    (%rax),%esi
call   1060 <open@plt>
mov    %eax,-0x14(%rbp)
movb   $0x30,-0x15(%rbp)
cmpl   $0x0,-0x14(%rbp)
jge    1182 <nonparent_ptrace_allowed+0x42>
movl   $0x1,-0x4(%rbp)
jmp    11cf <nonparent_ptrace_allowed+0x8f>
mov    -0x14(%rbp),%edi
lea    -0x15(%rbp),%rsi
mov    $0x1,%edx
call   1050 <read@plt>
mov    -0x14(%rbp),%edi
call   1040 <close@plt>
movsbl -0x15(%rbp),%eax
cmp    $0x30,%eax
jne    11b4 <nonparent_ptrace_allowed+0x74>
movl   $0x1,-0x4(%rbp)
jmp    11cf <nonparent_ptrace_allowed+0x8f>
mov    -0x10(%rbp),%rsi
lea    0xe64(%rip),%rdi
movsbl -0x15(%rbp),%edx
call   1030 <printf@plt>
movl   $0x0,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<nonparent_ptrace_allowed>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1060 <open@plt>
movb   $0x30,0x7(%rsp)
test   %eax,%eax
js     11a2 <nonparent_ptrace_allowed+0x62>
mov    %eax,%ebp
lea    0x7(%rsp),%rsi
mov    $0x1,%ebx
mov    %eax,%edi
mov    $0x1,%edx
call   1050 <read@plt>
mov    %ebp,%edi
call   1040 <close@plt>
mov    0x7(%rsp),%al
cmp    $0x30,%al
je     11a7 <nonparent_ptrace_allowed+0x67>
movsbl %al,%edx
lea    0xe91(%rip),%rdi
lea    0xe67(%rip),%rsi
call   1030 <printf@plt>
xor    %ebx,%ebx
jmp    11a7 <nonparent_ptrace_allowed+0x67>
mov    $0x1,%ebx
mov    %ebx,%eax
add    $0x8,%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
@.str.1 = [23 x i8] c"('%s' has value '%c') \00"
define i32 @nonparent_ptrace_allowed() {
%1 = alloca i32
%2 = alloca i8*
%3 = alloca i32
%4 = alloca i8
store i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8** %2
%5 = load i8*, i8** %2
%6 = load i32, i32* @O_RDONLY
%7 = call i32 @open(i8* %5, i32 %6)
store i32 %7, i32* %3
store i8 48, i8* %4
%8 = load i32, i32* %3
%9 = icmp slt i32 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %0
store i32 1, i32* %1
br label %24
11: ; preds = %0
%12 = load i32, i32* %3
%13 = call i32 @read(i32 %12, i8* %4, i32 1)
%14 = load i32, i32* %3
%15 = call i32 @close(i32 %14)
%16 = load i8, i8* %4
%17 = sext i8 %16 to i32
%18 = icmp eq i32 %17, 48
br i1 %18, label %19, label %20
19: ; preds = %11
store i32 1, i32* %1
br label %24
20: ; preds = %11
%21 = load i8*, i8** %2
%22 = load i8, i8* %4
%23 = call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* %21, i8 signext %22)
store i32 0, i32* %1
br label %24
24: ; preds = %20, %19, %10
%25 = load i32, i32* %1
ret i32 %25
}

LLVM IR (-O2):
@.str = [35 x i8] c"/proc/sys/kernel/yama/ptrace_scope\00"
@O_RDONLY = global i32 0
@.str.1 = [23 x i8] c"('%s' has value '%c') \00"
define i32 @nonparent_ptrace_allowed() {
%1 = alloca 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)
store i8 48, i8* %1
%4 = icmp slt i32 %3, 0
br i1 %4, label %12, label %5
5: ; preds = %0
%6 = call i32 @read(i32 %3, i8* %1, i32 1)
%7 = tail call i32 @close(i32 %3)
%8 = load i8, i8* %1
%9 = icmp eq i8 %8, 48
br i1 %9, label %12, label %10
10: ; preds = %5
%11 = tail call i32 @printf(i8* getelementptr inbounds ([23 x i8], [23 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([35 x i8], [35 x i8]* @.str, i64 0, i64 0), i8 signext %8)
br label %12
12: ; preds = %5, %0, %10
%13 = phi i32 [ 0, %10 ], [ 1, %0 ], [ 1, %5 ]
ret i32 %13
}