#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 */
struct stat {
  int /*<<< orphan*/ st_mode;
};

/* Variables and functions */
scalar_t__ ENOENT;
scalar_t__ S_ISDIR(int /*<<< orphan*/);
scalar_t__ errno;
int /*<<< orphan*/ report_errno(char *);
scalar_t__ stat(char *, struct stat *);
bool is_pmu_present() {
  struct stat pmu_dir;
  bool is_present = false;
  if (stat("/proc/pmu", &pmu_dir) == 0 && S_ISDIR(pmu_dir.st_mode)) {
    is_present = true;
  } else if (errno != ENOENT) {
    report_errno("/proc/pmu");
  }
  return is_present;
}


x86 assembly (clang, -O0):
<is_pmu_present>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
movl   $0x0,-0xc(%rbp)
lea    0xeba(%rip),%rdi
lea    -0x8(%rbp),%rsi
call   1040 <stat@plt>
cmp    $0x0,%rax
jne    1177 <is_pmu_present+0x47>
mov    -0x8(%rbp),%edi
call   1030 <S_ISDIR@plt>
cmp    $0x0,%rax
je     1177 <is_pmu_present+0x47>
movl   $0x1,-0xc(%rbp)
jmp    11a2 <is_pmu_present+0x72>
mov    0x2e62(%rip),%rax
mov    (%rax),%rax
mov    0x2e48(%rip),%rcx
cmp    (%rcx),%rax
je     119d <is_pmu_present+0x6d>
lea    0xe68(%rip),%rdi
call   1050 <report_errno@plt>
jmp    11a2 <is_pmu_present+0x72>
mov    -0xc(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<is_pmu_present>:
push   %rbx
sub    $0x10,%rsp
lea    0xec4(%rip),%rdi
lea    0x8(%rsp),%rsi
call   1040 <stat@plt>
test   %rax,%rax
jne    115e <is_pmu_present+0x2e>
mov    0x8(%rsp),%edi
call   1030 <S_ISDIR@plt>
mov    $0x1,%ebx
test   %rax,%rax
jne    1182 <is_pmu_present+0x52>
mov    0x2e7b(%rip),%rax
mov    (%rax),%rax
mov    0x2e61(%rip),%rcx
xor    %ebx,%ebx
cmp    (%rcx),%rax
je     1182 <is_pmu_present+0x52>
lea    0xe83(%rip),%rdi
call   1050 <report_errno@plt>
mov    %ebx,%eax
add    $0x10,%rsp
pop    %rbx
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/proc/pmu\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @is_pmu_present() {
%1 = alloca %struct.stat
%2 = alloca i32
store i32 0, i32* %2
%3 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %11
5: ; preds = %0
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i32 0, i32 0
%7 = load i32, i32* %6
%8 = call i64 @S_ISDIR(i32 %7)
%9 = icmp ne i64 %8, 0
br i1 %9, label %10, label %11
10: ; preds = %5
store i32 1, i32* %2
br label %18
11: ; preds = %5, %0
%12 = load i64, i64* @errno
%13 = load i64, i64* @ENOENT
%14 = icmp ne i64 %12, %13
br i1 %14, label %15, label %17
15: ; preds = %11
%16 = call i32 @report_errno(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %17
17: ; preds = %15, %11
br label %18
18: ; preds = %17, %10
%19 = load i32, i32* %2
ret i32 %19
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [10 x i8] c"/proc/pmu\00"
@errno = global i64 0
@ENOENT = global i64 0
define i32 @is_pmu_present() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = call i64 @stat(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0), %struct.stat* %1)
%4 = icmp eq i64 %3, 0
br i1 %4, label %5, label %10
5: ; preds = %0
%6 = getelementptr inbounds %struct.stat, %struct.stat* %1, i64 0, i32 0
%7 = load i32, i32* %6
%8 = call i64 @S_ISDIR(i32 %7)
%9 = icmp eq i64 %8, 0
br i1 %9, label %10, label %16
10: ; preds = %5, %0
%11 = load i64, i64* @errno
%12 = load i64, i64* @ENOENT
%13 = icmp eq i64 %11, %12
br i1 %13, label %16, label %14
14: ; preds = %10
%15 = call i32 @report_errno(i8* getelementptr inbounds ([10 x i8], [10 x i8]* @.str, i64 0, i64 0))
br label %16
16: ; preds = %5, %10, %14
%17 = phi i32 [ 0, %14 ], [ 0, %10 ], [ 1, %5 ]
ret i32 %17
}