#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 O_CLOEXEC;
int O_WRONLY;
int open(char *, int);
char *tracecmd_get_tracing_file(char *);
int /*<<< orphan*/ tracecmd_put_tracing_file(char *);
int /*<<< orphan*/ write(int, char *, int);
void check_tracing_enabled(void) {
  static int fd = -1;
  char *path;
  if (fd < 0) {
    path = tracecmd_get_tracing_file("tracing_enabled");
    fd = open(path, O_WRONLY | O_CLOEXEC);
    tracecmd_put_tracing_file(path);
    if (fd < 0)
      return;
  }
  write(fd, "1", 1);
}


x86 assembly (clang, -O0):
<check_tracing_enabled>:
push   %rbp
mov    %rsp,%rbp
sub    $0x10,%rsp
cmpl   $0x0,0x2ef1(%rip)
jge    11a6 <check_tracing_enabled+0x66>
lea    0xea4(%rip),%rdi
call   1050 <tracecmd_get_tracing_file@plt>
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rdi
mov    0x2e68(%rip),%rax
mov    (%rax),%esi
mov    0x2e57(%rip),%rax
or     (%rax),%esi
call   1060 <open@plt>
mov    %eax,0x2eba(%rip)
mov    -0x8(%rbp),%rdi
call   1030 <tracecmd_put_tracing_file@plt>
cmpl   $0x0,0x2eaa(%rip)
jge    11a1 <check_tracing_enabled+0x61>
jmp    11bd <check_tracing_enabled+0x7d>
jmp    11a6 <check_tracing_enabled+0x66>
mov    0x2e94(%rip),%edi
lea    0xe5d(%rip),%rsi
mov    $0x1,%edx
call   1040 <write@plt>
add    $0x10,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<check_tracing_enabled>:
push   %rbx
mov    0x2ef9(%rip),%edi
test   %edi,%edi
jns    118c <check_tracing_enabled+0x4c>
lea    0xeae(%rip),%rdi
call   1050 <tracecmd_get_tracing_file@plt>
mov    %rax,%rbx
mov    0x2e77(%rip),%rax
mov    0x2e68(%rip),%rcx
mov    (%rcx),%esi
or     (%rax),%esi
mov    %rbx,%rdi
call   1060 <open@plt>
mov    %eax,0x2ec6(%rip)
mov    %rbx,%rdi
call   1030 <tracecmd_put_tracing_file@plt>
mov    0x2eb8(%rip),%edi
test   %edi,%edi
js     119e <check_tracing_enabled+0x5e>
lea    0xe7d(%rip),%rsi
mov    $0x1,%edx
pop    %rbx
jmp    1040 <write@plt>
pop    %rbx
ret

LLVM IR (-O0):
@check_tracing_enabled.fd = internal global i32 -1
@.str = [16 x i8] c"tracing_enabled\00"
@O_WRONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [2 x i8] c"1\00"
define void @check_tracing_enabled() {
%1 = alloca i8*
%2 = load i32, i32* @check_tracing_enabled.fd
%3 = icmp slt i32 %2, 0
br i1 %3, label %4, label %17
4: ; preds = %0
%5 = call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
store i8* %5, i8** %1
%6 = load i8*, i8** %1
%7 = load i32, i32* @O_WRONLY
%8 = load i32, i32* @O_CLOEXEC
%9 = or i32 %7, %8
%10 = call i32 @open(i8* %6, i32 %9)
store i32 %10, i32* @check_tracing_enabled.fd
%11 = load i8*, i8** %1
%12 = call i32 @tracecmd_put_tracing_file(i8* %11)
%13 = load i32, i32* @check_tracing_enabled.fd
%14 = icmp slt i32 %13, 0
br i1 %14, label %15, label %16
15: ; preds = %4
br label %20
16: ; preds = %4
br label %17
17: ; preds = %16, %0
%18 = load i32, i32* @check_tracing_enabled.fd
%19 = call i32 @write(i32 %18, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %20
20: ; preds = %17, %15
ret void
}

LLVM IR (-O2):
@check_tracing_enabled.fd = internal unnamed_addr global i32 -1
@.str = [16 x i8] c"tracing_enabled\00"
@O_WRONLY = global i32 0
@O_CLOEXEC = global i32 0
@.str.1 = [2 x i8] c"1\00"
define void @check_tracing_enabled() {
%1 = load i32, i32* @check_tracing_enabled.fd
%2 = icmp slt i32 %1, 0
br i1 %2, label %3, label %12
3: ; preds = %0
%4 = tail call i8* @tracecmd_get_tracing_file(i8* getelementptr inbounds ([16 x i8], [16 x i8]* @.str, i64 0, i64 0))
%5 = load i32, i32* @O_WRONLY
%6 = load i32, i32* @O_CLOEXEC
%7 = or i32 %6, %5
%8 = tail call i32 @open(i8* %4, i32 %7)
store i32 %8, i32* @check_tracing_enabled.fd
%9 = tail call i32 @tracecmd_put_tracing_file(i8* %4)
%10 = load i32, i32* @check_tracing_enabled.fd
%11 = icmp slt i32 %10, 0
br i1 %11, label %15, label %12
12: ; preds = %3, %0
%13 = phi i32 [ %10, %3 ], [ %1, %0 ]
%14 = tail call i32 @write(i32 %13, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i32 1)
br label %15
15: ; preds = %3, %12
ret void
}