#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*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int op_cpu_has_timer_fs(void) {
  static int cached_has_timer_fs_p = -1;
  FILE *fp;
  if (cached_has_timer_fs_p != -1)
    return cached_has_timer_fs_p;
  fp = fopen("/dev/oprofile/timer", "r");
  cached_has_timer_fs_p = !!fp;
  if (fp)
    fclose(fp);
  return cached_has_timer_fs_p;
}


x86 assembly (clang, -O0):
<op_cpu_has_timer_fs>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0xffffffff,0x2f01(%rip)
je     1143 <op_cpu_has_timer_fs+0x23>
mov    0x2ef5(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    118e <op_cpu_has_timer_fs+0x6e>
lea    0xeb6(%rip),%rdi
lea    0xec1(%rip),%rsi
call   1040 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
setne  %al
xor    $0xff,%al
xor    $0xff,%al
and    $0x1,%al
movzbl %al,%eax
mov    %eax,0x2ebf(%rip)
cmpq   $0x0,-0x10(%rbp)
je     1185 <op_cpu_has_timer_fs+0x65>
mov    -0x10(%rbp),%rdi
call   1030 <fclose@plt>
mov    0x2ea5(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<op_cpu_has_timer_fs>:
push   %rax
mov    0x2f09(%rip),%eax
cmp    $0xffffffff,%eax
je     112e <op_cpu_has_timer_fs+0xe>
pop    %rcx
ret
lea    0xecb(%rip),%rdi
lea    0xed6(%rip),%rsi
call   1040 <fopen@plt>
xor    %ecx,%ecx
test   %rax,%rax
setne  %cl
mov    %ecx,0x2ee1(%rip)
je     1161 <op_cpu_has_timer_fs+0x41>
mov    %rax,%rdi
call   1030 <fclose@plt>
mov    0x2ed1(%rip),%eax
pop    %rcx
ret
xor    %eax,%eax
pop    %rcx
ret

LLVM IR (-O0):
@op_cpu_has_timer_fs.cached_has_timer_fs_p = internal global i32 -1
@.str = [20 x i8] c"/dev/oprofile/timer\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @op_cpu_has_timer_fs() {
%1 = alloca i32
%2 = alloca i32*
%3 = load i32, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
%4 = icmp ne i32 %3, -1
br i1 %4, label %5, label %7
5: ; preds = %0
%6 = load i32, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
store i32 %6, i32* %1
br label %21
7: ; preds = %0
%8 = call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %8, i32** %2
%9 = load i32*, i32** %2
%10 = icmp ne i32* %9, null
%11 = xor i1 %10, true
%12 = xor i1 %11, true
%13 = zext i1 %12 to i32
store i32 %13, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
%14 = load i32*, i32** %2
%15 = icmp ne i32* %14, null
br i1 %15, label %16, label %19
16: ; preds = %7
%17 = load i32*, i32** %2
%18 = call i32 @fclose(i32* %17)
br label %19
19: ; preds = %16, %7
%20 = load i32, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
store i32 %20, i32* %1
br label %21
21: ; preds = %19, %5
%22 = load i32, i32* %1
ret i32 %22
}

LLVM IR (-O2):
@op_cpu_has_timer_fs.cached_has_timer_fs_p = internal unnamed_addr global i32 -1
@.str = [20 x i8] c"/dev/oprofile/timer\00"
@.str.1 = [2 x i8] c"r\00"
define i32 @op_cpu_has_timer_fs() {
%1 = load i32, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
%2 = icmp eq i32 %1, -1
br i1 %2, label %3, label %10
3: ; preds = %0
%4 = tail call i32* @fopen(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%5 = icmp ne i32* %4, null
%6 = zext i1 %5 to i32
store i32 %6, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
br i1 %5, label %7, label %10
7: ; preds = %3
%8 = tail call i32 @fclose(i32* %4)
%9 = load i32, i32* @op_cpu_has_timer_fs.cached_has_timer_fs_p
br label %10
10: ; preds = %3, %7, %0
%11 = phi i32 [ %1, %0 ], [ %9, %7 ], [ 0, %3 ]
ret i32 %11
}