#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*/ errno;
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *, char *);
int /*<<< orphan*/ fscanf(int /*<<< orphan*/ *, char *, int *);
int /*<<< orphan*/ stderr;
char *strerror(int /*<<< orphan*/);
int check_paranoid(void) {
  int paranoid_value;
  FILE *fff;
  fff = fopen("/proc/sys/kernel/perf_event_paranoid", "r");
  if (fff == NULL) {
    fprintf(stderr,
            "Error! could not open /proc/sys/kernel/perf_event_paranoid %s\n",
            strerror(errno));
    return 500;
  }
  fscanf(fff, "%d", &paranoid_value);
  fclose(fff);
  return paranoid_value;
}


x86 assembly (clang, -O0):
<check_paranoid>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
lea    0xea1(%rip),%rdi
lea    0xebf(%rip),%rsi
call   1060 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11b2 <check_paranoid+0x62>
mov    0x2e5f(%rip),%rax
mov    (%rax),%eax
mov    %eax,-0x14(%rbp)
mov    0x2e4b(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
mov    -0x14(%rbp),%edi
mov    %rax,%rdx
lea    0xe86(%rip),%rsi
call   1050 <fprintf@plt>
movl   $0x1f4,-0x4(%rbp)
jmp    11d5 <check_paranoid+0x85>
mov    -0x10(%rbp),%rdi
lea    0xea9(%rip),%rsi
lea    -0x8(%rbp),%rdx
call   1040 <fscanf@plt>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    -0x8(%rbp),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_paranoid>:
push   %rbx
sub    $0x10,%rsp
lea    0xea4(%rip),%rdi
lea    0xec2(%rip),%rsi
call   1060 <fopen@plt>
test   %rax,%rax
je     1192 <check_paranoid+0x42>
mov    %rax,%rbx
lea    0xeef(%rip),%rsi
lea    0xc(%rsp),%rdx
mov    %rax,%rdi
call   1040 <fscanf@plt>
mov    %rbx,%rdi
call   1030 <fclose@plt>
mov    0xc(%rsp),%eax
jmp    11bf <check_paranoid+0x6f>
mov    0x2e47(%rip),%rax
mov    (%rax),%ebx
mov    0x2e36(%rip),%rax
mov    (%rax),%edi
call   1070 <strerror@plt>
lea    0xe77(%rip),%rsi
mov    %ebx,%edi
mov    %rax,%rdx
call   1050 <fprintf@plt>
mov    $0x1f4,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
@.str = [37 x i8] c"/proc/sys/kernel/perf_event_paranoid\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"Error! could not open /proc/sys/kernel/perf_event_paranoid %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%d\00"
define i32 @check_paranoid() {
%1 = alloca i32
%2 = alloca i32
%3 = alloca i32*
%4 = call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 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** %3
%5 = load i32*, i32** %3
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %12
7: ; preds = %0
%8 = load i32, i32* @stderr
%9 = load i32, i32* @errno
%10 = call i8* @strerror(i32 %9)
%11 = call i32 @fprintf(i32 %8, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %10)
store i32 500, i32* %1
br label %18
12: ; preds = %0
%13 = load i32*, i32** %3
%14 = call i32 @fscanf(i32* %13, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %2)
%15 = load i32*, i32** %3
%16 = call i32 @fclose(i32* %15)
%17 = load i32, i32* %2
store i32 %17, i32* %1
br label %18
18: ; preds = %12, %7
%19 = load i32, i32* %1
ret i32 %19
}

LLVM IR (-O2):
@.str = [37 x i8] c"/proc/sys/kernel/perf_event_paranoid\00"
@.str.1 = [2 x i8] c"r\00"
@stderr = global i32 0
@.str.2 = [63 x i8] c"Error! could not open /proc/sys/kernel/perf_event_paranoid %s\0A\00"
@errno = global i32 0
@.str.3 = [3 x i8] c"%d\00"
define i32 @check_paranoid() {
%1 = alloca i32
%2 = bitcast i32* %1 to i8*
%3 = tail call i32* @fopen(i8* getelementptr inbounds ([37 x i8], [37 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%4 = icmp eq i32* %3, null
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = load i32, i32* @stderr
%7 = load i32, i32* @errno
%8 = tail call i8* @strerror(i32 %7)
%9 = tail call i32 @fprintf(i32 %6, i8* getelementptr inbounds ([63 x i8], [63 x i8]* @.str.2, i64 0, i64 0), i8* %8)
br label %14
10: ; preds = %0
%11 = call i32 @fscanf(i32* %3, i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i32* %1)
%12 = call i32 @fclose(i32* %3)
%13 = load i32, i32* %1
br label %14
14: ; preds = %10, %5
%15 = phi i32 [ 500, %5 ], [ %13, %10 ]
ret i32 %15
}