#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 fscanf(int /*<<< orphan*/ *, char *, char *, char *);
char *malloc_or_die(scalar_t__);
scalar_t__ mount_debugfs();
int /*<<< orphan*/ sprintf(char *, char *, char *);
scalar_t__ strcmp(char *, char *);
int /*<<< orphan*/ strcpy(char *, char *);
scalar_t__ strlen(char *);
int /*<<< orphan*/ warning(char *);
char *tracecmd_find_tracing_dir(void) {
  char debugfs[1024 + 1];
  char *tracing_dir;
  char type[100];
  FILE *fp;
  if ((fp = fopen("/proc/mounts", "r")) == NULL) {
    warning("Can't open /proc/mounts for read");
    return NULL;
  }
  while (fscanf(fp,
                "%*s %"
                "1024"
                "s %99s %*s %*d %*d\n",
                debugfs, type) == 2) {
    if (strcmp(type, "debugfs") == 0)
      break;
  }
  fclose(fp);
  if (strcmp(type, "debugfs") != 0) {
    if (mount_debugfs() < 0) {
      warning("debugfs not mounted, please mount");
      return NULL;
    }
    strcpy(debugfs, "/sys/kernel/debug");
  }
  tracing_dir = malloc_or_die(strlen(debugfs) + 9);
  if (!tracing_dir)
    return NULL;
  sprintf(tracing_dir, "%s/tracing", debugfs);
  return tracing_dir;
}


x86 assembly (clang, -O0):
<tracecmd_find_tracing_dir>:
push   %rbp
mov    %rsp,%rbp
sub    $0x490,%rsp
lea    0xe4e(%rip),%rdi
lea    0xe54(%rip),%rsi
call   10b0 <fopen@plt>
mov    %rax,-0x488(%rbp)
cmp    $0x0,%rax
jne    11e8 <tracecmd_find_tracing_dir+0x48>
lea    0xe39(%rip),%rdi
call   1040 <warning@plt>
movq   $0x0,-0x8(%rbp)
jmp    1303 <tracecmd_find_tracing_dir+0x163>
jmp    11ed <tracecmd_find_tracing_dir+0x4d>
mov    -0x488(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    -0x480(%rbp),%rcx
lea    0xe27(%rip),%rsi
call   1080 <fscanf@plt>
cmp    $0x2,%eax
jne    123e <tracecmd_find_tracing_dir+0x9e>
lea    -0x480(%rbp),%rdi
lea    0xe28(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
jne    1239 <tracecmd_find_tracing_dir+0x99>
jmp    123e <tracecmd_find_tracing_dir+0x9e>
jmp    11ed <tracecmd_find_tracing_dir+0x4d>
mov    -0x488(%rbp),%rdi
call   1050 <fclose@plt>
lea    -0x480(%rbp),%rdi
lea    0xdf5(%rip),%rsi
call   1090 <strcmp@plt>
cmp    $0x0,%rax
je     12a4 <tracecmd_find_tracing_dir+0x104>
mov    $0x0,%al
call   1070 <mount_debugfs@plt>
cmp    $0x0,%rax
jge    1291 <tracecmd_find_tracing_dir+0xf1>
lea    0xdd6(%rip),%rdi
call   1040 <warning@plt>
movq   $0x0,-0x8(%rbp)
jmp    1303 <tracecmd_find_tracing_dir+0x163>
lea    -0x410(%rbp),%rdi
lea    0xdd8(%rip),%rsi
call   1030 <strcpy@plt>
lea    -0x410(%rbp),%rdi
call   1060 <strlen@plt>
mov    %rax,%rdi
add    $0x9,%rdi
call   10a0 <malloc_or_die@plt>
mov    %rax,-0x418(%rbp)
cmpq   $0x0,-0x418(%rbp)
jne    12de <tracecmd_find_tracing_dir+0x13e>
movq   $0x0,-0x8(%rbp)
jmp    1303 <tracecmd_find_tracing_dir+0x163>
mov    -0x418(%rbp),%rdi
lea    -0x410(%rbp),%rdx
lea    0xd96(%rip),%rsi
call   10c0 <sprintf@plt>
mov    -0x418(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x490,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_find_tracing_dir>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x480,%rsp
lea    0xe49(%rip),%rdi
lea    0xe4f(%rip),%rsi
call   10b0 <fopen@plt>
test   %rax,%rax
je     1280 <tracecmd_find_tracing_dir+0xe0>
mov    %rax,%rbx
lea    0xe5a(%rip),%r14
lea    0x70(%rsp),%r15
mov    %rsp,%r12
lea    0xe68(%rip),%r13
cs nopw 0x0(%rax,%rax,1)
nop
mov    %rbx,%rdi
mov    %r14,%rsi
mov    %r15,%rdx
mov    %r12,%rcx
call   1080 <fscanf@plt>
cmp    $0x2,%eax
jne    1216 <tracecmd_find_tracing_dir+0x76>
mov    %r12,%rdi
mov    %r13,%rsi
call   1090 <strcmp@plt>
test   %rax,%rax
jne    11f0 <tracecmd_find_tracing_dir+0x50>
mov    %rbx,%rdi
call   1050 <fclose@plt>
lea    0xe28(%rip),%rsi
mov    %rsp,%rdi
call   1090 <strcmp@plt>
test   %rax,%rax
je     124f <tracecmd_find_tracing_dir+0xaf>
xor    %eax,%eax
call   1070 <mount_debugfs@plt>
test   %rax,%rax
js     1289 <tracecmd_find_tracing_dir+0xe9>
lea    0xe32(%rip),%rsi
lea    0x70(%rsp),%rdi
call   1030 <strcpy@plt>
lea    0x70(%rsp),%rdi
call   1060 <strlen@plt>
lea    0x9(%rax),%rdi
call   10a0 <malloc_or_die@plt>
test   %rax,%rax
je     1295 <tracecmd_find_tracing_dir+0xf5>
mov    %rax,%rbx
lea    0xe18(%rip),%rsi
lea    0x70(%rsp),%rdx
mov    %rax,%rdi
call   10c0 <sprintf@plt>
jmp    1297 <tracecmd_find_tracing_dir+0xf7>
lea    0xd88(%rip),%rdi
jmp    1290 <tracecmd_find_tracing_dir+0xf0>
lea    0xdc5(%rip),%rdi
call   1040 <warning@plt>
xor    %ebx,%ebx
mov    %rbx,%rax
add    $0x480,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret

LLVM IR (-O0):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Can't open /proc/mounts for read\00"
@.str.3 = [29 x i8] c"%*s %1024s %99s %*s %*d %*d\0A\00"
@.str.4 = [8 x i8] c"debugfs\00"
@.str.5 = [34 x i8] c"debugfs not mounted, please mount\00"
@.str.6 = [18 x i8] c"/sys/kernel/debug\00"
@.str.7 = [11 x i8] c"%s/tracing\00"
define i8* @tracecmd_find_tracing_dir() {
%1 = alloca i8*
%2 = alloca [1025 x i8]
%3 = alloca i8*
%4 = alloca [100 x i8]
%5 = alloca i32*
%6 = call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
store i32* %6, i32** %5
%7 = icmp eq i32* %6, null
br i1 %7, label %8, label %10
8: ; preds = %0
%9 = call i32 @warning(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
store i8* null, i8** %1
br label %50
10: ; preds = %0
br label %11
11: ; preds = %22, %10
%12 = load i32*, i32** %5
%13 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%14 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%15 = call i32 @fscanf(i32* %12, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %13, i8* %14)
%16 = icmp eq i32 %15, 2
br i1 %16, label %17, label %23
17: ; preds = %11
%18 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%19 = call i64 @strcmp(i8* %18, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%20 = icmp eq i64 %19, 0
br i1 %20, label %21, label %22
21: ; preds = %17
br label %23
22: ; preds = %17
br label %11
23: ; preds = %21, %11
%24 = load i32*, i32** %5
%25 = call i32 @fclose(i32* %24)
%26 = getelementptr inbounds [100 x i8], [100 x i8]* %4, i64 0, i64 0
%27 = call i64 @strcmp(i8* %26, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%28 = icmp ne i64 %27, 0
br i1 %28, label %29, label %37
29: ; preds = %23
%30 = call i64 (...) @mount_debugfs()
%31 = icmp slt i64 %30, 0
br i1 %31, label %32, label %34
32: ; preds = %29
%33 = call i32 @warning(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
store i8* null, i8** %1
br label %50
34: ; preds = %29
%35 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%36 = call i32 @strcpy(i8* %35, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %37
37: ; preds = %34, %23
%38 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%39 = call i64 @strlen(i8* %38)
%40 = add nsw i64 %39, 9
%41 = call i8* @malloc_or_die(i64 %40)
store i8* %41, i8** %3
%42 = load i8*, i8** %3
%43 = icmp ne i8* %42, null
br i1 %43, label %45, label %44
44: ; preds = %37
store i8* null, i8** %1
br label %50
45: ; preds = %37
%46 = load i8*, i8** %3
%47 = getelementptr inbounds [1025 x i8], [1025 x i8]* %2, i64 0, i64 0
%48 = call i32 @sprintf(i8* %46, i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %47)
%49 = load i8*, i8** %3
store i8* %49, i8** %1
br label %50
50: ; preds = %45, %44, %32, %8
%51 = load i8*, i8** %1
ret i8* %51
}

LLVM IR (-O2):
@.str = [13 x i8] c"/proc/mounts\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [33 x i8] c"Can't open /proc/mounts for read\00"
@.str.3 = [29 x i8] c"%*s %1024s %99s %*s %*d %*d\0A\00"
@.str.4 = [8 x i8] c"debugfs\00"
@.str.5 = [34 x i8] c"debugfs not mounted, please mount\00"
@.str.6 = [18 x i8] c"/sys/kernel/debug\00"
@.str.7 = [11 x i8] c"%s/tracing\00"
define i8* @tracecmd_find_tracing_dir() {
%1 = alloca [1025 x i8]
%2 = alloca [100 x i8]
%3 = getelementptr inbounds [1025 x i8], [1025 x i8]* %1, i64 0, i64 0
%4 = getelementptr inbounds [100 x i8], [100 x i8]* %2, i64 0, i64 0
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([13 x i8], [13 x i8]* @.str, i64 0, i64 0), i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0))
%6 = icmp eq i32* %5, null
br i1 %6, label %7, label %9
7: ; preds = %0
%8 = tail call i32 @warning(i8* getelementptr inbounds ([33 x i8], [33 x i8]* @.str.2, i64 0, i64 0))
br label %33
9: ; preds = %0, %12
%10 = call i32 @fscanf(i32* %5, i8* getelementptr inbounds ([29 x i8], [29 x i8]* @.str.3, i64 0, i64 0), i8* %3, i8* %4)
%11 = icmp eq i32 %10, 2
br i1 %11, label %12, label %15
12: ; preds = %9
%13 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%14 = icmp eq i64 %13, 0
br i1 %14, label %15, label %9
15: ; preds = %12, %9
%16 = call i32 @fclose(i32* %5)
%17 = call i64 @strcmp(i8* %4, i8* getelementptr inbounds ([8 x i8], [8 x i8]* @.str.4, i64 0, i64 0))
%18 = icmp eq i64 %17, 0
br i1 %18, label %26, label %19
19: ; preds = %15
%20 = call i64 (...) @mount_debugfs()
%21 = icmp slt i64 %20, 0
br i1 %21, label %22, label %24
22: ; preds = %19
%23 = call i32 @warning(i8* getelementptr inbounds ([34 x i8], [34 x i8]* @.str.5, i64 0, i64 0))
br label %33
24: ; preds = %19
%25 = call i32 @strcpy(i8* %3, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str.6, i64 0, i64 0))
br label %26
26: ; preds = %24, %15
%27 = call i64 @strlen(i8* %3)
%28 = add nsw i64 %27, 9
%29 = call i8* @malloc_or_die(i64 %28)
%30 = icmp eq i8* %29, null
br i1 %30, label %33, label %31
31: ; preds = %26
%32 = call i32 @sprintf(i8* %29, i8* dereferenceable(1) getelementptr inbounds ([11 x i8], [11 x i8]* @.str.7, i64 0, i64 0), i8* %3)
br label %33
33: ; preds = %26, %31, %22, %7
%34 = phi i8* [ null, %7 ], [ null, %22 ], [ %29, %31 ], [ null, %26 ]
ret i8* %34
}