#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 /*<<< orphan*/ die(char *, char *);
int open(char *, int /*<<< orphan*/);
int read(int, char *, int);
char read_proc(void) {
  char buf[1];
  int fd;
  int n;
  fd = open("/proc/sys/kernel/stack_tracer_enabled", O_RDONLY);
  if (fd < 0)
    die("reading %s", "/proc/sys/kernel/stack_tracer_enabled");
  n = read(fd, buf, 1);
  close(fd);
  if (n != 1)
    die("error reading %s", "/proc/sys/kernel/stack_tracer_enabled");
  return buf[0];
}


x86 assembly (clang, -O0):
<read_proc>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
mov    0x2e99(%rip),%rax
mov    (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <open@plt>
mov    %eax,-0x8(%rbp)
cmpl   $0x0,-0x8(%rbp)
jge    117d <read_proc+0x3d>
lea    0xebb(%rip),%rdi
lea    0xe88(%rip),%rsi
call   1060 <die@plt>
mov    -0x8(%rbp),%edi
lea    -0x1(%rbp),%rsi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,-0xc(%rbp)
mov    -0x8(%rbp),%edi
call   1030 <close@plt>
cmpl   $0x1,-0xc(%rbp)
je     11b6 <read_proc+0x76>
lea    0xe7c(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   1060 <die@plt>
movsbl -0x1(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<read_proc>:
push   %rbp
push   %rbx
push   %rax
mov    0x2e9e(%rip),%rax
mov    (%rax),%esi
lea    0xead(%rip),%rdi
call   1050 <open@plt>
mov    %eax,%ebx
test   %eax,%eax
jns    1171 <read_proc+0x31>
lea    0xec7(%rip),%rdi
lea    0xe94(%rip),%rsi
call   1060 <die@plt>
lea    0x7(%rsp),%rsi
mov    %ebx,%edi
mov    $0x1,%edx
call   1040 <read@plt>
mov    %eax,%ebp
mov    %ebx,%edi
call   1030 <close@plt>
cmp    $0x1,%ebp
je     11a3 <read_proc+0x63>
lea    0xe8f(%rip),%rdi
lea    0xe62(%rip),%rsi
call   1060 <die@plt>
mov    0x7(%rsp),%al
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
@.str = [38 x i8] c"/proc/sys/kernel/stack_tracer_enabled\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"reading %s\00"
@.str.2 = [17 x i8] c"error reading %s\00"
define signext i8 @read_proc() {
%1 = alloca [1 x i8]
%2 = alloca i32
%3 = alloca i32
%4 = load i32, i32* @O_RDONLY
%5 = call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %4)
store i32 %5, i32* %2
%6 = load i32, i32* %2
%7 = icmp slt i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %10
10: ; preds = %8, %0
%11 = load i32, i32* %2
%12 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%13 = call i32 @read(i32 %11, i8* %12, i32 1)
store i32 %13, i32* %3
%14 = load i32, i32* %2
%15 = call i32 @close(i32 %14)
%16 = load i32, i32* %3
%17 = icmp ne i32 %16, 1
br i1 %17, label %18, label %20
18: ; preds = %10
%19 = call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %20
20: ; preds = %18, %10
%21 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%22 = load i8, i8* %21
ret i8 %22
}

LLVM IR (-O2):
@.str = [38 x i8] c"/proc/sys/kernel/stack_tracer_enabled\00"
@O_RDONLY = global i32 0
@.str.1 = [11 x i8] c"reading %s\00"
@.str.2 = [17 x i8] c"error reading %s\00"
define signext i8 @read_proc() {
%1 = alloca [1 x i8]
%2 = getelementptr inbounds [1 x i8], [1 x i8]* %1, i64 0, i64 0
%3 = load i32, i32* @O_RDONLY
%4 = tail call i32 @open(i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0), i32 %3)
%5 = icmp slt i32 %4, 0
br i1 %5, label %6, label %8
6: ; preds = %0
%7 = tail call i32 @die(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.1, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %8
8: ; preds = %6, %0
%9 = call i32 @read(i32 %4, i8* %2, i32 1)
%10 = tail call i32 @close(i32 %4)
%11 = icmp eq i32 %9, 1
br i1 %11, label %14, label %12
12: ; preds = %8
%13 = tail call i32 @die(i8* getelementptr inbounds ([17 x i8], [17 x i8]* @.str.2, i64 0, i64 0), i8* getelementptr inbounds ([38 x i8], [38 x i8]* @.str, i64 0, i64 0))
br label %14
14: ; preds = %12, %8
%15 = load i8, i8* %2
ret i8 %15
}