#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 */
scalar_t__ EPERM;
int R_OK;
int W_OK;
int access(char *, int);
scalar_t__ errno;
int /*<<< orphan*/ fprintf(int /*<<< orphan*/, char *);
int /*<<< orphan*/ stderr;
int /*<<< orphan*/ strcpy(char *, char *);
char *find_tracefs_location(char *buffer, int quiet) {
  int result;
  result = access("/sys/kernel/tracing", R_OK | W_OK);
  if (result == 0) {
    strcpy(buffer, "/sys/kernel/tracing");
    return buffer;
  } else {
    if (errno == EPERM) {
      fprintf(stderr, "Insufficient permissions!\n");
      return NULL;
    }
  }
  result = access("/sys/kernel/debug/tracing", R_OK | W_OK);
  if (result == 0) {
    strcpy(buffer, "/sys/kernel/debug/tracing");
    return buffer;
  } else {
    if (errno == EPERM) {
      fprintf(stderr, "Insufficient permissions!\n");
      return NULL;
    }
  }
  return NULL;
}


x86 assembly (clang, -O0):
<find_tracefs_location>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x10(%rbp)
mov    %esi,-0x14(%rbp)
mov    0x2e82(%rip),%rax
mov    (%rax),%esi
mov    0x2e99(%rip),%rax
or     (%rax),%esi
lea    0xea8(%rip),%rdi
call   1050 <access@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1187 <find_tracefs_location+0x57>
mov    -0x10(%rbp),%rdi
lea    0xe8b(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1259 <find_tracefs_location+0x129>
mov    0x2e42(%rip),%rax
mov    (%rax),%rax
mov    0x2e20(%rip),%rcx
cmp    (%rcx),%rax
jne    11c3 <find_tracefs_location+0x93>
mov    0x2e30(%rip),%rax
mov    (%rax),%edi
lea    0xe63(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1259 <find_tracefs_location+0x129>
jmp    11c8 <find_tracefs_location+0x98>
mov    0x2df9(%rip),%rax
mov    (%rax),%esi
mov    0x2e10(%rip),%rax
or     (%rax),%esi
lea    0xe4e(%rip),%rdi
call   1050 <access@plt>
mov    %eax,-0x18(%rbp)
cmpl   $0x0,-0x18(%rbp)
jne    1210 <find_tracefs_location+0xe0>
mov    -0x10(%rbp),%rdi
lea    0xe31(%rip),%rsi
call   1030 <strcpy@plt>
mov    -0x10(%rbp),%rax
mov    %rax,-0x8(%rbp)
jmp    1259 <find_tracefs_location+0x129>
mov    0x2db9(%rip),%rax
mov    (%rax),%rax
mov    0x2d97(%rip),%rcx
cmp    (%rcx),%rax
jne    124c <find_tracefs_location+0x11c>
mov    0x2da7(%rip),%rax
mov    (%rax),%edi
lea    0xdda(%rip),%rsi
call   1040 <fprintf@plt>
movq   $0x0,-0x8(%rbp)
jmp    1259 <find_tracefs_location+0x129>
jmp    1251 <find_tracefs_location+0x121>
movq   $0x0,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<find_tracefs_location>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
mov    %rdi,%rbx
mov    0x2e85(%rip),%r14
mov    0x2e9e(%rip),%r15
mov    (%r15),%esi
or     (%r14),%esi
lea    0xea9(%rip),%rdi
call   1050 <access@plt>
test   %eax,%eax
je     11b1 <find_tracefs_location+0x81>
mov    0x2e69(%rip),%r12
mov    (%r12),%rax
mov    0x2e46(%rip),%r13
cmp    0x0(%r13),%rax
je     1198 <find_tracefs_location+0x68>
mov    (%r15),%esi
or     (%r14),%esi
lea    0xeaa(%rip),%rdi
call   1050 <access@plt>
test   %eax,%eax
je     11ba <find_tracefs_location+0x8a>
mov    (%r12),%rax
cmp    0x0(%r13),%rax
jne    11ad <find_tracefs_location+0x7d>
mov    0x2e39(%rip),%rax
mov    (%rax),%edi
lea    0xe6c(%rip),%rsi
call   1040 <fprintf@plt>
xor    %ebx,%ebx
jmp    11c9 <find_tracefs_location+0x99>
lea    0xe48(%rip),%rsi
jmp    11c1 <find_tracefs_location+0x91>
lea    0xe6e(%rip),%rsi
mov    %rbx,%rdi
call   1030 <strcpy@plt>
mov    %rbx,%rax
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [20 x i8] c"/sys/kernel/tracing\00"
@R_OK = global i32 0
@W_OK = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Insufficient permissions!\0A\00"
@.str.2 = [26 x i8] c"/sys/kernel/debug/tracing\00"
define i8* @find_tracefs_location(i8* %0, i32 %1) {
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca i32
%6 = alloca i32
store i8* %0, i8** %4
store i32 %1, i32* %5
%7 = load i32, i32* @R_OK
%8 = load i32, i32* @W_OK
%9 = or i32 %7, %8
%10 = call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %9)
store i32 %10, i32* %6
%11 = load i32, i32* %6
%12 = icmp eq i32 %11, 0
br i1 %12, label %13, label %17
13: ; preds = %2
%14 = load i8*, i8** %4
%15 = call i32 @strcpy(i8* %14, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
%16 = load i8*, i8** %4
store i8* %16, i8** %3
br label %45
17: ; preds = %2
%18 = load i64, i64* @errno
%19 = load i64, i64* @EPERM
%20 = icmp eq i64 %18, %19
br i1 %20, label %21, label %24
21: ; preds = %17
%22 = load i32, i32* @stderr
%23 = call i32 @fprintf(i32 %22, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %45
24: ; preds = %17
br label %25
25: ; preds = %24
%26 = load i32, i32* @R_OK
%27 = load i32, i32* @W_OK
%28 = or i32 %26, %27
%29 = call i32 @access(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %28)
store i32 %29, i32* %6
%30 = load i32, i32* %6
%31 = icmp eq i32 %30, 0
br i1 %31, label %32, label %36
32: ; preds = %25
%33 = load i8*, i8** %4
%34 = call i32 @strcpy(i8* %33, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
%35 = load i8*, i8** %4
store i8* %35, i8** %3
br label %45
36: ; preds = %25
%37 = load i64, i64* @errno
%38 = load i64, i64* @EPERM
%39 = icmp eq i64 %37, %38
br i1 %39, label %40, label %43
40: ; preds = %36
%41 = load i32, i32* @stderr
%42 = call i32 @fprintf(i32 %41, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
store i8* null, i8** %3
br label %45
43: ; preds = %36
br label %44
44: ; preds = %43
store i8* null, i8** %3
br label %45
45: ; preds = %44, %40, %32, %21, %13
%46 = load i8*, i8** %3
ret i8* %46
}

LLVM IR (-O2):
@.str = [20 x i8] c"/sys/kernel/tracing\00"
@R_OK = global i32 0
@W_OK = global i32 0
@errno = global i64 0
@EPERM = global i64 0
@stderr = global i32 0
@.str.1 = [27 x i8] c"Insufficient permissions!\0A\00"
@.str.2 = [26 x i8] c"/sys/kernel/debug/tracing\00"
define i8* @find_tracefs_location(i8* %0, i32 %1) {
%3 = load i32, i32* @R_OK
%4 = load i32, i32* @W_OK
%5 = or i32 %4, %3
%6 = tail call i32 @access(i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0), i32 %5)
%7 = icmp eq i32 %6, 0
br i1 %7, label %8, label %10
8: ; preds = %2
%9 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([20 x i8], [20 x i8]* @.str, i64 0, i64 0))
br label %32
10: ; preds = %2
%11 = load i64, i64* @errno
%12 = load i64, i64* @EPERM
%13 = icmp eq i64 %11, %12
br i1 %13, label %14, label %17
14: ; preds = %10
%15 = load i32, i32* @stderr
%16 = tail call i32 @fprintf(i32 %15, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %32
17: ; preds = %10
%18 = load i32, i32* @R_OK
%19 = load i32, i32* @W_OK
%20 = or i32 %19, %18
%21 = tail call i32 @access(i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0), i32 %20)
%22 = icmp eq i32 %21, 0
br i1 %22, label %23, label %25
23: ; preds = %17
%24 = tail call i32 @strcpy(i8* %0, i8* getelementptr inbounds ([26 x i8], [26 x i8]* @.str.2, i64 0, i64 0))
br label %32
25: ; preds = %17
%26 = load i64, i64* @errno
%27 = load i64, i64* @EPERM
%28 = icmp eq i64 %26, %27
br i1 %28, label %29, label %32
29: ; preds = %25
%30 = load i32, i32* @stderr
%31 = tail call i32 @fprintf(i32 %30, i8* getelementptr inbounds ([27 x i8], [27 x i8]* @.str.1, i64 0, i64 0))
br label %32
32: ; preds = %25, %29, %23, %14, %8
%33 = phi i8* [ %0, %8 ], [ null, %14 ], [ %0, %23 ], [ null, %29 ], [ null, %25 ]
ret i8* %33
}