#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 dummy;
};

/* Variables and functions */
int stat(char *, struct stat *);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
int use_old_event_method(void) {
  static int old_event_method;
  static int processed;
  struct stat st;
  char *path;
  int ret;
  if (processed)
    return old_event_method;
  path = tracecmd_get_tracing_file("events/enable");
  ret = stat(path, &st);
  tracecmd_put_tracing_file(path);
  if (ret < 0)
    old_event_method = 1;
  processed = 1;
  return old_event_method;
}


x86 assembly (clang, -O0):
<use_old_event_method>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
cmpl   $0x0,0x2f01(%rip)
je     1153 <use_old_event_method+0x23>
mov    0x2ef1(%rip),%eax
mov    %eax,-0x4(%rbp)
jmp    11a3 <use_old_event_method+0x73>
lea    0xea6(%rip),%rdi
call   1040 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x10(%rbp)
mov    -0x10(%rbp),%rdi
lea    -0x8(%rbp),%rsi
call   1050 <stat@plt>
mov    %eax,-0x14(%rbp)
mov    -0x10(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmpl   $0x0,-0x14(%rbp)
jge    1190 <use_old_event_method+0x60>
movl   $0x1,0x2eac(%rip)
movl   $0x1,0x2ea6(%rip)
mov    0x2e9c(%rip),%eax
mov    %eax,-0x4(%rbp)
mov    -0x4(%rbp),%eax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<use_old_event_method>:
push   %rbp
push   %rbx
push   %rax
cmpb   $0x0,0x2f06(%rip)
jne    1172 <use_old_event_method+0x42>
lea    0xebd(%rip),%rdi
call   1040 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    %rsp,%rsi
mov    %rax,%rdi
call   1050 <stat@plt>
mov    %eax,%ebp
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
test   %ebp,%ebp
jns    116b <use_old_event_method+0x3b>
movb   $0x1,0x2ed1(%rip)
movb   $0x1,0x2ece(%rip)
movzbl 0x2ec3(%rip),%eax
add    $0x8,%rsp
pop    %rbx
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@use_old_event_method.old_event_method = internal global i32 0
@use_old_event_method.processed = internal global i32 0
@.str = [14 x i8] c"events/enable\00"
define i32 @use_old_event_method() {
%1 = alloca i32
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca i32
%5 = load i32, i32* @use_old_event_method.processed
%6 = icmp ne i32 %5, 0
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = load i32, i32* @use_old_event_method.old_event_method
store i32 %8, i32* %1
br label %20
9: ; preds = %0
%10 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
store i8* %10, i8** %3
%11 = load i8*, i8** %3
%12 = call i32 @stat(i8* %11, %struct.stat* %2)
store i32 %12, i32* %4
%13 = load i8*, i8** %3
%14 = call i32 @tracecmd_put_tracing_file(i8* %13)
%15 = load i32, i32* %4
%16 = icmp slt i32 %15, 0
br i1 %16, label %17, label %18
17: ; preds = %9
store i32 1, i32* @use_old_event_method.old_event_method
br label %18
18: ; preds = %17, %9
store i32 1, i32* @use_old_event_method.processed
%19 = load i32, i32* @use_old_event_method.old_event_method
store i32 %19, i32* %1
br label %20
20: ; preds = %18, %7
%21 = load i32, i32* %1
ret i32 %21
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@use_old_event_method.old_event_method = internal unnamed_addr global i1 false
@use_old_event_method.processed = internal unnamed_addr global i1 false
@.str = [14 x i8] c"events/enable\00"
define i32 @use_old_event_method() {
%1 = alloca %struct.stat
%2 = bitcast %struct.stat* %1 to i8*
%3 = load i1, i1* @use_old_event_method.processed
br i1 %3, label %11, label %4
4: ; preds = %0
%5 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([14 x i8], [14 x i8]* @.str, i64 0, i64 0))
%6 = call i32 @stat(i8* %5, %struct.stat* %1)
%7 = tail call i32 @tracecmd_put_tracing_file(i8* %5)
%8 = icmp slt i32 %6, 0
br i1 %8, label %9, label %10
9: ; preds = %4
store i1 true, i1* @use_old_event_method.old_event_method
br label %10
10: ; preds = %9, %4
store i1 true, i1* @use_old_event_method.processed
br label %11
11: ; preds = %0, %10
%12 = load i1, i1* @use_old_event_method.old_event_method
%13 = zext i1 %12 to i32
ret i32 %13
}