#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*/ exit(int);
int /*<<< orphan*/ fclose(int /*<<< orphan*/ *);
int /*<<< orphan*/ feof(int /*<<< orphan*/ *);
int /*<<< orphan*/ *fopen(char *, char *);
int /*<<< orphan*/ free(char *);
int /*<<< orphan*/ getline(char **, size_t *, int /*<<< orphan*/ *);
int /*<<< orphan*/ perror(char *);
int /*<<< orphan*/ printf(char *, char *);
scalar_t__ strglobmatch(char *, char const *);
void list_available_events(const char *match) {
  FILE *file;
  char *line = NULL;
  file = fopen("/sys/kernel/debug/tracing/available_events", "r");
  if (file == NULL)
    do {
      perror("open "
             "/sys/kernel/debug/tracing/available_events"
             " failed");
      exit(-1);
    } while (0);
  while (!feof(file)) {
    size_t n;
    getline(&line, &n, file);
    if (!match || strglobmatch(line, match))
      printf("%s", line);
  }
  free(line);
  fclose(file);
}


x86 assembly (clang, -O0):
<list_available_events>:
push   %rbp
mov    %rsp,%rbp
sub    $0x20,%rsp
mov    %rdi,-0x8(%rbp)
movq   $0x0,-0x18(%rbp)
lea    0xe55(%rip),%rdi
lea    0xe79(%rip),%rsi
call   1080 <fopen@plt>
mov    %rax,-0x10(%rbp)
cmpq   $0x0,-0x10(%rbp)
jne    11e1 <list_available_events+0x51>
jmp    11cb <list_available_events+0x3b>
lea    0xe5b(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>
jmp    11e6 <list_available_events+0x56>
mov    -0x10(%rbp),%rdi
call   1060 <feof@plt>
cmp    $0x0,%eax
setne  %al
xor    $0xff,%al
test   $0x1,%al
jne    1204 <list_available_events+0x74>
jmp    124c <list_available_events+0xbc>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x20(%rbp),%rsi
call   10a0 <getline@plt>
cmpq   $0x0,-0x8(%rbp)
je     1237 <list_available_events+0xa7>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strglobmatch@plt>
cmp    $0x0,%rax
je     1247 <list_available_events+0xb7>
mov    -0x18(%rbp),%rsi
lea    0xe22(%rip),%rdi
call   1050 <printf@plt>
jmp    11e6 <list_available_events+0x56>
mov    -0x18(%rbp),%rdi
call   1030 <free@plt>
mov    -0x10(%rbp),%rdi
call   1040 <fclose@plt>
add    $0x20,%rsp
pop    %rbp
ret

x86 assembly (clang, -O2):
<list_available_events>:
push   %r15
push   %r14
push   %r13
push   %r12
push   %rbx
sub    $0x10,%rsp
mov    %rdi,%r14
movq   $0x0,(%rsp)
lea    0xe51(%rip),%rdi
lea    0xe75(%rip),%rsi
call   1080 <fopen@plt>
test   %rax,%rax
je     124d <list_available_events+0xbd>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d7 <list_available_events+0x47>
xor    %edi,%edi
jmp    1232 <list_available_events+0xa2>
mov    %rsp,%r15
lea    0x8(%rsp),%r12
lea    0xe7e(%rip),%r13
jmp    1208 <list_available_events+0x78>
nopl   0x0(%rax,%rax,1)
mov    (%rsp),%rsi
mov    %r13,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    122e <list_available_events+0x9e>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
test   %r14,%r14
je     11f0 <list_available_events+0x60>
mov    (%rsp),%rdi
mov    %r14,%rsi
call   1070 <strglobmatch@plt>
test   %rax,%rax
jne    11f0 <list_available_events+0x60>
jmp    11fc <list_available_events+0x6c>
mov    (%rsp),%rdi
call   1030 <free@plt>
mov    %rbx,%rdi
call   1040 <fclose@plt>
add    $0x10,%rsp
pop    %rbx
pop    %r12
pop    %r13
pop    %r14
pop    %r15
ret
lea    0xdd9(%rip),%rdi
call   1090 <perror@plt>
mov    $0xffffffff,%edi
call   10b0 <exit@plt>

LLVM IR (-O0):
@.str = [43 x i8] c"/sys/kernel/debug/tracing/available_events\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [55 x i8] c"open /sys/kernel/debug/tracing/available_events failed\00"
@.str.3 = [3 x i8] c"%s\00"
define void @list_available_events(i8* %0) {
%2 = alloca i8*
%3 = alloca i32*
%4 = alloca i8*
%5 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
%6 = call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 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** %3
%7 = load i32*, i32** %3
%8 = icmp eq i32* %7, null
br i1 %8, label %9, label %14
9: ; preds = %1
br label %10
10: ; preds = %9
%11 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%12 = call i32 @exit(i32 -1)
unreachable
13: ; No predecessors!
br label %14
14: ; preds = %13, %1
br label %15
15: ; preds = %33, %14
%16 = load i32*, i32** %3
%17 = call i32 @feof(i32* %16)
%18 = icmp ne i32 %17, 0
%19 = xor i1 %18, true
br i1 %19, label %20, label %34
20: ; preds = %15
%21 = load i32*, i32** %3
%22 = call i32 @getline(i8** %4, i64* %5, i32* %21)
%23 = load i8*, i8** %2
%24 = icmp ne i8* %23, null
br i1 %24, label %25, label %30
25: ; preds = %20
%26 = load i8*, i8** %4
%27 = load i8*, i8** %2
%28 = call i64 @strglobmatch(i8* %26, i8* %27)
%29 = icmp ne i64 %28, 0
br i1 %29, label %30, label %33
30: ; preds = %25, %20
%31 = load i8*, i8** %4
%32 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %31)
br label %33
33: ; preds = %30, %25
br label %15
34: ; preds = %15
%35 = load i8*, i8** %4
%36 = call i32 @free(i8* %35)
%37 = load i32*, i32** %3
%38 = call i32 @fclose(i32* %37)
ret void
}

LLVM IR (-O2):
@.str = [43 x i8] c"/sys/kernel/debug/tracing/available_events\00"
@.str.1 = [2 x i8] c"r\00"
@.str.2 = [55 x i8] c"open /sys/kernel/debug/tracing/available_events failed\00"
@.str.3 = [3 x i8] c"%s\00"
define void @list_available_events(i8* %0) {
%2 = alloca i8*
%3 = alloca i64
%4 = bitcast i8** %2 to i8*
store i8* null, i8** %2
%5 = tail call i32* @fopen(i8* getelementptr inbounds ([43 x i8], [43 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 %13, label %7
7: ; preds = %1
%8 = call i32 @feof(i32* %5)
%9 = icmp eq i32 %8, 0
br i1 %9, label %10, label %30
10: ; preds = %7
%11 = bitcast i64* %3 to i8*
%12 = icmp eq i8* %0, null
br label %16
13: ; preds = %1
%14 = tail call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%15 = tail call i32 @exit(i32 -1)
unreachable
16: ; preds = %10, %25
%17 = call i32 @getline(i8** %2, i64* %3, i32* %5)
br i1 %12, label %22, label %18
18: ; preds = %16
%19 = load i8*, i8** %2
%20 = call i64 @strglobmatch(i8* %19, i8* %0)
%21 = icmp eq i64 %20, 0
br i1 %21, label %25, label %22
22: ; preds = %18, %16
%23 = load i8*, i8** %2
%24 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %23)
br label %25
25: ; preds = %22, %18
%26 = call i32 @feof(i32* %5)
%27 = icmp eq i32 %26, 0
br i1 %27, label %16, label %28
28: ; preds = %25
%29 = load i8*, i8** %2
br label %30
30: ; preds = %28, %7
%31 = phi i8* [ %29, %28 ], [ null, %7 ]
%32 = call i32 @free(i8* %31)
%33 = call i32 @fclose(i32* %5)
ret void
}