#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 */
char *append_file(char const *, char *);
int /*<<< orphan*/ free(char *);
int read_file(char *, char **);
int stat(char *, struct stat *);
scalar_t__ strcmp(char *, char *);
int strlen(char *);
char *strtok_r(char *, char *, char **);
char **tracecmd_add_list(char **, char *, int /*<<< orphan*/);
char **tracecmd_local_plugins(const char *tracing_dir) {
  char *available_tracers;
  struct stat st;
  char **plugins = NULL;
  char *buf;
  char *str, *saveptr;
  char *plugin;
  int slen;
  int len;
  int ret;
  if (!tracing_dir)
    return NULL;
  available_tracers = append_file(tracing_dir, "available_tracers");
  if (!available_tracers)
    return NULL;
  ret = stat(available_tracers, &st);
  if (ret < 0)
    goto out_free;
  len = read_file(available_tracers, &buf);
  if (len < 0)
    goto out_free;
  len = 0;
  for (str = buf;; str = NULL) {
    plugin = strtok_r(str, " ", &saveptr);
    if (!plugin)
      break;
    if (!(slen = strlen(plugin)))
      continue;
    if (plugin[slen - 1] == '\n')
      plugin[slen - 1] = '\0';
    if (strcmp(plugin, "nop") == 0 || strcmp(plugin, "none") == 0)
      continue;
    plugins = tracecmd_add_list(plugins, plugin, len++);
  }
  free(buf);
out_free:
  free(available_tracers);
  return plugins;
}


x86 assembly (clang, -O0):
<tracecmd_local_plugins>:
push   %rbp
mov    %rsp,%rbp
sub    $0x60,%rsp
mov    %rdi,-0x10(%rbp)
movq   $0x0,-0x28(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11ac <tracecmd_local_plugins+0x2c>
movq   $0x0,-0x8(%rbp)
jmp    130e <tracecmd_local_plugins+0x18e>
mov    -0x10(%rbp),%rdi
lea    0xe49(%rip),%rsi
call   1050 <append_file@plt>
mov    %rax,-0x18(%rbp)
cmpq   $0x0,-0x18(%rbp)
jne    11d8 <tracecmd_local_plugins+0x58>
movq   $0x0,-0x8(%rbp)
jmp    130e <tracecmd_local_plugins+0x18e>
mov    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   1080 <stat@plt>
mov    %eax,-0x54(%rbp)
cmpl   $0x0,-0x54(%rbp)
jge    11f7 <tracecmd_local_plugins+0x77>
jmp    12fd <tracecmd_local_plugins+0x17d>
mov    -0x18(%rbp),%rdi
lea    -0x30(%rbp),%rsi
call   1090 <read_file@plt>
mov    %eax,-0x50(%rbp)
cmpl   $0x0,-0x50(%rbp)
jge    1216 <tracecmd_local_plugins+0x96>
jmp    12fd <tracecmd_local_plugins+0x17d>
movl   $0x0,-0x50(%rbp)
mov    -0x30(%rbp),%rax
mov    %rax,-0x38(%rbp)
mov    -0x38(%rbp),%rdi
lea    0xde2(%rip),%rsi
lea    -0x40(%rbp),%rdx
call   1060 <strtok_r@plt>
mov    %rax,-0x48(%rbp)
cmpq   $0x0,-0x48(%rbp)
jne    124d <tracecmd_local_plugins+0xcd>
jmp    12f4 <tracecmd_local_plugins+0x174>
mov    -0x48(%rbp),%rdi
call   1040 <strlen@plt>
mov    %eax,-0x4c(%rbp)
cmp    $0x0,%eax
jne    1267 <tracecmd_local_plugins+0xe7>
jmp    12e7 <tracecmd_local_plugins+0x167>
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movsbl (%rax,%rcx,1),%eax
cmp    $0xa,%eax
jne    1292 <tracecmd_local_plugins+0x112>
mov    -0x48(%rbp),%rax
mov    -0x4c(%rbp),%ecx
sub    $0x1,%ecx
movslq %ecx,%rcx
movb   $0x0,(%rax,%rcx,1)
mov    -0x48(%rbp),%rdi
lea    0xd77(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
je     12c6 <tracecmd_local_plugins+0x146>
mov    -0x48(%rbp),%rdi
lea    0xd61(%rip),%rsi
call   1070 <strcmp@plt>
cmp    $0x0,%rax
jne    12cb <tracecmd_local_plugins+0x14b>
jmp    12e7 <tracecmd_local_plugins+0x167>
mov    -0x28(%rbp),%rdi
mov    -0x48(%rbp),%rsi
mov    -0x50(%rbp),%edx
mov    %edx,%eax
add    $0x1,%eax
mov    %eax,-0x50(%rbp)
call   10a0 <tracecmd_add_list@plt>
mov    %rax,-0x28(%rbp)
movq   $0x0,-0x38(%rbp)
jmp    1225 <tracecmd_local_plugins+0xa5>
mov    -0x30(%rbp),%rdi
call   1030 <free@plt>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x28(%rbp),%rax
mov    %rax,-0x8(%rbp)
mov    -0x8(%rbp),%rax
add    $0x60,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<tracecmd_local_plugins>:
push   %rbp
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x28,%rsp
test   %rdi,%rdi
je     1298 <tracecmd_local_plugins+0x118>
lea    0xe62(%rip),%rsi
call   1050 <append_file@plt>
test   %rax,%rax
je     1298 <tracecmd_local_plugins+0x118>
mov    %rax,%rbp
lea    0x20(%rsp),%rsi
mov    %rax,%rdi
call   1080 <stat@plt>
test   %eax,%eax
js     129d <tracecmd_local_plugins+0x11d>
lea    0x8(%rsp),%rsi
mov    %rbp,%rdi
call   1090 <read_file@plt>
test   %eax,%eax
js     129d <tracecmd_local_plugins+0x11d>
mov    %rbp,0x10(%rsp)
mov    0x8(%rsp),%rdi
lea    0xe28(%rip),%rsi
lea    0x18(%rsp),%rdx
call   1060 <strtok_r@plt>
test   %rax,%rax
je     12a2 <tracecmd_local_plugins+0x122>
mov    %rax,%rbp
xor    %eax,%eax
mov    %rax,(%rsp)
lea    0xe05(%rip),%r14
lea    0x18(%rsp),%r12
lea    0xdfb(%rip),%rbx
xor    %r15d,%r15d
jmp    1235 <tracecmd_local_plugins+0xb5>
xchg   %ax,%ax
xor    %edi,%edi
mov    %r14,%rsi
mov    %r12,%rdx
call   1060 <strtok_r@plt>
mov    %rax,%rbp
test   %rax,%rax
je     12a5 <tracecmd_local_plugins+0x125>
mov    %rbp,%rdi
call   1040 <strlen@plt>
test   %eax,%eax
je     1220 <tracecmd_local_plugins+0xa0>
cltq
cmpb   $0xa,-0x1(%rax,%rbp,1)
jne    124f <tracecmd_local_plugins+0xcf>
movb   $0x0,-0x1(%rbp,%rax,1)
mov    %rbp,%rdi
mov    %rbx,%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <tracecmd_local_plugins+0xa0>
mov    %rbp,%rdi
lea    0xdaf(%rip),%rsi
call   1070 <strcmp@plt>
test   %rax,%rax
je     1220 <tracecmd_local_plugins+0xa0>
mov    %r14,%r13
mov    (%rsp),%rdx
lea    0x1(%rdx),%r14d
mov    %r15,%rdi
mov    %rbp,%rsi
call   10a0 <tracecmd_add_list@plt>
mov    %rax,%r15
mov    %r14d,%eax
mov    %rax,(%rsp)
mov    %r13,%r14
jmp    1220 <tracecmd_local_plugins+0xa0>
xor    %r15d,%r15d
jmp    12bc <tracecmd_local_plugins+0x13c>
xor    %r15d,%r15d
jmp    12b4 <tracecmd_local_plugins+0x134>
xor    %r15d,%r15d
mov    0x8(%rsp),%rdi
call   1030 <free@plt>
mov    0x10(%rsp),%rbp
mov    %rbp,%rdi
call   1030 <free@plt>
mov    %r15,%rax
add    $0x28,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
pop    %rbp
ret

LLVM IR (-O0):
%struct.stat = type { i32 }
@.str = [18 x i8] c"available_tracers\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"nop\00"
@.str.3 = [5 x i8] c"none\00"
define i8** @tracecmd_local_plugins(i8* %0) {
%2 = alloca i8**
%3 = alloca i8*
%4 = alloca i8*
%5 = alloca %struct.stat
%6 = alloca i8**
%7 = alloca i8*
%8 = alloca i8*
%9 = alloca i8*
%10 = alloca i8*
%11 = alloca i32
%12 = alloca i32
%13 = alloca i32
store i8* %0, i8** %3
store i8** null, i8*** %6
%14 = load i8*, i8** %3
%15 = icmp ne i8* %14, null
br i1 %15, label %17, label %16
16: ; preds = %1
store i8** null, i8*** %2
br label %86
17: ; preds = %1
%18 = load i8*, i8** %3
%19 = call i8* @append_file(i8* %18, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
store i8* %19, i8** %4
%20 = load i8*, i8** %4
%21 = icmp ne i8* %20, null
br i1 %21, label %23, label %22
22: ; preds = %17
store i8** null, i8*** %2
br label %86
23: ; preds = %17
%24 = load i8*, i8** %4
%25 = call i32 @stat(i8* %24, %struct.stat* %5)
store i32 %25, i32* %13
%26 = load i32, i32* %13
%27 = icmp slt i32 %26, 0
br i1 %27, label %28, label %29
28: ; preds = %23
br label %82
29: ; preds = %23
%30 = load i8*, i8** %4
%31 = call i32 @read_file(i8* %30, i8** %7)
store i32 %31, i32* %12
%32 = load i32, i32* %12
%33 = icmp slt i32 %32, 0
br i1 %33, label %34, label %35
34: ; preds = %29
br label %82
35: ; preds = %29
store i32 0, i32* %12
%36 = load i8*, i8** %7
store i8* %36, i8** %8
br label %37
37: ; preds = %78, %35
%38 = load i8*, i8** %8
%39 = call i8* @strtok_r(i8* %38, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %9)
store i8* %39, i8** %10
%40 = load i8*, i8** %10
%41 = icmp ne i8* %40, null
br i1 %41, label %43, label %42
42: ; preds = %37
br label %79
43: ; preds = %37
%44 = load i8*, i8** %10
%45 = call i32 @strlen(i8* %44)
store i32 %45, i32* %11
%46 = icmp ne i32 %45, 0
br i1 %46, label %48, label %47
47: ; preds = %43
br label %78
48: ; preds = %43
%49 = load i8*, i8** %10
%50 = load i32, i32* %11
%51 = sub nsw i32 %50, 1
%52 = sext i32 %51 to i64
%53 = getelementptr inbounds i8, i8* %49, i64 %52
%54 = load i8, i8* %53
%55 = sext i8 %54 to i32
%56 = icmp eq i32 %55, 10
br i1 %56, label %57, label %63
57: ; preds = %48
%58 = load i8*, i8** %10
%59 = load i32, i32* %11
%60 = sub nsw i32 %59, 1
%61 = sext i32 %60 to i64
%62 = getelementptr inbounds i8, i8* %58, i64 %61
store i8 0, i8* %62
br label %63
63: ; preds = %57, %48
%64 = load i8*, i8** %10
%65 = call i64 @strcmp(i8* %64, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%66 = icmp eq i64 %65, 0
br i1 %66, label %71, label %67
67: ; preds = %63
%68 = load i8*, i8** %10
%69 = call i64 @strcmp(i8* %68, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%70 = icmp eq i64 %69, 0
br i1 %70, label %71, label %72
71: ; preds = %67, %63
br label %78
72: ; preds = %67
%73 = load i8**, i8*** %6
%74 = load i8*, i8** %10
%75 = load i32, i32* %12
%76 = add nsw i32 %75, 1
store i32 %76, i32* %12
%77 = call i8** @tracecmd_add_list(i8** %73, i8* %74, i32 %75)
store i8** %77, i8*** %6
br label %78
78: ; preds = %72, %71, %47
store i8* null, i8** %8
br label %37
79: ; preds = %42
%80 = load i8*, i8** %7
%81 = call i32 @free(i8* %80)
br label %82
82: ; preds = %79, %34, %28
%83 = load i8*, i8** %4
%84 = call i32 @free(i8* %83)
%85 = load i8**, i8*** %6
store i8** %85, i8*** %2
br label %86
86: ; preds = %82, %22, %16
%87 = load i8**, i8*** %2
ret i8** %87
}

LLVM IR (-O2):
%struct.stat = type { i32 }
@.str = [18 x i8] c"available_tracers\00"
@.str.1 = [2 x i8] c" \00"
@.str.2 = [4 x i8] c"nop\00"
@.str.3 = [5 x i8] c"none\00"
define i8** @tracecmd_local_plugins(i8* %0) {
%2 = alloca %struct.stat
%3 = alloca i8*
%4 = alloca i8*
%5 = bitcast %struct.stat* %2 to i8*
%6 = bitcast i8** %3 to i8*
%7 = bitcast i8** %4 to i8*
%8 = icmp eq i8* %0, null
br i1 %8, label %56, label %9
9: ; preds = %1
%10 = tail call i8* @append_file(i8* %0, i8* getelementptr inbounds ([18 x i8], [18 x i8]* @.str, i64 0, i64 0))
%11 = icmp eq i8* %10, null
br i1 %11, label %56, label %12
12: ; preds = %9
%13 = call i32 @stat(i8* %10, %struct.stat* %2)
%14 = icmp slt i32 %13, 0
br i1 %14, label %53, label %15
15: ; preds = %12
%16 = call i32 @read_file(i8* %10, i8** %3)
%17 = icmp slt i32 %16, 0
br i1 %17, label %53, label %18
18: ; preds = %15
%19 = load i8*, i8** %3
%20 = call i8* @strtok_r(i8* %19, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%21 = icmp eq i8* %20, null
br i1 %21, label %49, label %22
22: ; preds = %18, %44
%23 = phi i8* [ %47, %44 ], [ %20, %18 ]
%24 = phi i32 [ %46, %44 ], [ 0, %18 ]
%25 = phi i8** [ %45, %44 ], [ null, %18 ]
%26 = call i32 @strlen(i8* %23)
%27 = icmp eq i32 %26, 0
br i1 %27, label %44, label %28
28: ; preds = %22
%29 = add nsw i32 %26, -1
%30 = sext i32 %29 to i64
%31 = getelementptr inbounds i8, i8* %23, i64 %30
%32 = load i8, i8* %31
%33 = icmp eq i8 %32, 10
br i1 %33, label %34, label %35
34: ; preds = %28
store i8 0, i8* %31
br label %35
35: ; preds = %34, %28
%36 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([4 x i8], [4 x i8]* @.str.2, i64 0, i64 0))
%37 = icmp eq i64 %36, 0
br i1 %37, label %44, label %38
38: ; preds = %35
%39 = call i64 @strcmp(i8* %23, i8* getelementptr inbounds ([5 x i8], [5 x i8]* @.str.3, i64 0, i64 0))
%40 = icmp eq i64 %39, 0
br i1 %40, label %44, label %41
41: ; preds = %38
%42 = add nsw i32 %24, 1
%43 = call i8** @tracecmd_add_list(i8** %25, i8* %23, i32 %24)
br label %44
44: ; preds = %35, %38, %22, %41
%45 = phi i8** [ %25, %35 ], [ %25, %38 ], [ %43, %41 ], [ %25, %22 ]
%46 = phi i32 [ %24, %35 ], [ %24, %38 ], [ %42, %41 ], [ %24, %22 ]
%47 = call i8* @strtok_r(i8* null, i8* getelementptr inbounds ([2 x i8], [2 x i8]* @.str.1, i64 0, i64 0), i8** %4)
%48 = icmp eq i8* %47, null
br i1 %48, label %49, label %22
49: ; preds = %44, %18
%50 = phi i8** [ null, %18 ], [ %45, %44 ]
%51 = load i8*, i8** %3
%52 = call i32 @free(i8* %51)
br label %53
53: ; preds = %15, %12, %49
%54 = phi i8** [ null, %12 ], [ null, %15 ], [ %50, %49 ]
%55 = call i32 @free(i8* %10)
br label %56
56: ; preds = %9, %1, %53
%57 = phi i8** [ %54, %53 ], [ null, %1 ], [ null, %9 ]
ret i8** %57
}