#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 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)) {
    int line_len;
    size_t n;
    line_len = getline(&line, &n, file);
    if (line_len < 0 || !line)
      break;
    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    $0x30,%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    1269 <list_available_events+0xd9>
mov    -0x10(%rbp),%rdx
lea    -0x18(%rbp),%rdi
lea    -0x28(%rbp),%rsi
call   10a0 <getline@plt>
mov    %eax,-0x1c(%rbp)
cmpl   $0x0,-0x1c(%rbp)
jl     122d <list_available_events+0x9d>
cmpq   $0x0,-0x18(%rbp)
jne    1232 <list_available_events+0xa2>
jmp    1269 <list_available_events+0xd9>
cmpq   $0x0,-0x8(%rbp)
je     1254 <list_available_events+0xc4>
mov    -0x18(%rbp),%rdi
mov    -0x8(%rbp),%rsi
call   1070 <strglobmatch@plt>
cmp    $0x0,%rax
je     1264 <list_available_events+0xd4>
mov    -0x18(%rbp),%rsi
lea    0xe05(%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    $0x30,%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     125c <list_available_events+0xcc>
mov    %rax,%rbx
mov    %rax,%rdi
call   1060 <feof@plt>
test   %eax,%eax
je     11d7 <list_available_events+0x47>
xor    %esi,%esi
jmp    123e <list_available_events+0xae>
mov    %rsp,%r15
lea    0x8(%rsp),%r12
lea    0xe7e(%rip),%r13
jmp    1204 <list_available_events+0x74>
nopl   0x0(%rax,%rax,1)
mov    %r13,%rdi
call   1050 <printf@plt>
mov    %rbx,%rdi
call   1060 <feof@plt>
test   %eax,%eax
jne    123a <list_available_events+0xaa>
mov    %r15,%rdi
mov    %r12,%rsi
mov    %rbx,%rdx
call   10a0 <getline@plt>
mov    (%rsp),%rsi
test   %eax,%eax
js     123e <list_available_events+0xae>
test   %rsi,%rsi
je     123e <list_available_events+0xae>
test   %r14,%r14
je     11f0 <list_available_events+0x60>
mov    %rsi,%rdi
mov    %r14,%rsi
call   1070 <strglobmatch@plt>
test   %rax,%rax
je     11f8 <list_available_events+0x68>
mov    (%rsp),%rsi
jmp    11f0 <list_available_events+0x60>
mov    (%rsp),%rsi
mov    %rsi,%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    0xdca(%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 i32
%6 = alloca i64
store i8* %0, i8** %2
store i8* null, i8** %4
%7 = 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* %7, i32** %3
%8 = load i32*, i32** %3
%9 = icmp eq i32* %8, null
br i1 %9, label %10, label %15
10: ; preds = %1
br label %11
11: ; preds = %10
%12 = call i32 @perror(i8* getelementptr inbounds ([55 x i8], [55 x i8]* @.str.2, i64 0, i64 0))
%13 = call i32 @exit(i32 -1)
unreachable
14: ; No predecessors!
br label %15
15: ; preds = %14, %1
br label %16
16: ; preds = %41, %15
%17 = load i32*, i32** %3
%18 = call i32 @feof(i32* %17)
%19 = icmp ne i32 %18, 0
%20 = xor i1 %19, true
br i1 %20, label %21, label %42
21: ; preds = %16
%22 = load i32*, i32** %3
%23 = call i32 @getline(i8** %4, i64* %6, i32* %22)
store i32 %23, i32* %5
%24 = load i32, i32* %5
%25 = icmp slt i32 %24, 0
br i1 %25, label %29, label %26
26: ; preds = %21
%27 = load i8*, i8** %4
%28 = icmp ne i8* %27, null
br i1 %28, label %30, label %29
29: ; preds = %26, %21
br label %42
30: ; preds = %26
%31 = load i8*, i8** %2
%32 = icmp ne i8* %31, null
br i1 %32, label %33, label %38
33: ; preds = %30
%34 = load i8*, i8** %4
%35 = load i8*, i8** %2
%36 = call i64 @strglobmatch(i8* %34, i8* %35)
%37 = icmp ne i64 %36, 0
br i1 %37, label %38, label %41
38: ; preds = %33, %30
%39 = load i8*, i8** %4
%40 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %39)
br label %41
41: ; preds = %38, %33
br label %16
42: ; preds = %29, %16
%43 = load i8*, i8** %4
%44 = call i32 @free(i8* %43)
%45 = load i32*, i32** %3
%46 = call i32 @fclose(i32* %45)
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 %37
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, %32
%17 = call i32 @getline(i8** %2, i64* %3, i32* %5)
%18 = icmp sgt i32 %17, -1
%19 = load i8*, i8** %2
%20 = icmp ne i8* %19, null
%21 = select i1 %18, i1 %20, i1 false
br i1 %21, label %23, label %22
22: ; preds = %16
br label %37
23: ; preds = %16
br i1 %12, label %29, label %24
24: ; preds = %23
%25 = call i64 @strglobmatch(i8* %19, i8* %0)
%26 = icmp eq i64 %25, 0
br i1 %26, label %32, label %27
27: ; preds = %24
%28 = load i8*, i8** %2
br label %29
29: ; preds = %27, %23
%30 = phi i8* [ %28, %27 ], [ %19, %23 ]
%31 = call i32 @printf(i8* getelementptr inbounds ([3 x i8], [3 x i8]* @.str.3, i64 0, i64 0), i8* %30)
br label %32
32: ; preds = %24, %29
%33 = call i32 @feof(i32* %5)
%34 = icmp eq i32 %33, 0
br i1 %34, label %16, label %35
35: ; preds = %32
%36 = load i8*, i8** %2
br label %37
37: ; preds = %35, %7, %22
%38 = phi i8* [ %36, %35 ], [ null, %7 ], [ %19, %22 ]
%39 = call i32 @free(i8* %38)
%40 = call i32 @fclose(i32* %5)
ret void
}