user: Please show me the C implementation that matches the assembly code listed below:

```asm
<tracecmd_event_systems>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L24
  lea    D30(%rip),%rsi
  call   <append_file@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L24
  lea    0x24(%rsp),%rbx
  mov    %rax,%rdi
  mov    %rbx,%rsi
  call   <stat@plt>
  test   %eax,%eax
  js     L83
  mov    0x24(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  je     L83
  mov    %rbp,%rdi
  call   <opendir@plt>
  mov    %rax,%r13
  test   %rax,%rax
  je     L83
  movl   $0x0,0x14(%rsp)
  xor    %r14d,%r14d
  lea    D35(%rip),%r15
  nopw   0x0(%rax,%rax,1)
L143:
  mov    %r13,%rdi
  call   <readdir@plt>
  test   %rax,%rax
  je     L112
L62:
  mov    (%rax),%r12
  mov    %r15,%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L143
  lea    D24(%rip),%rsi
  mov    %r12,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L143
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <append_file@plt>
  mov    %rbx,%rsi
  mov    %rax,%rdi
  mov    %rax,0x8(%rsp)
  call   <stat@plt>
  test   %eax,%eax
  js     L57
  mov    0x24(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  je     L57
  mov    0x8(%rsp),%rdi
  lea    D39(%rip),%rsi
  call   <append_file@plt>
  mov    %rbx,%rsi
  mov    %rax,%rdi
  mov    %rax,0x18(%rsp)
  call   <stat@plt>
  mov    0x18(%rsp),%r8
  test   %eax,%eax
  js     L25
  mov    0x14(%rsp),%edx
  mov    %r14,%rdi
  mov    %r12,%rsi
  lea    0x1(%rdx),%eax
  mov    %eax,0x14(%rsp)
  call   <tracecmd_add_list@plt>
  mov    0x18(%rsp),%r8
  mov    %rax,%r14
L25:
  mov    %r8,%rdi
  call   <free@plt>
L57:
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    %r13,%rdi
  call   <readdir@plt>
  test   %rax,%rax
  jne    L62
L112:
  mov    %r13,%rdi
  call   <closedir@plt>
  jmp    L31
  nopl   0x0(%rax)
L83:
  xor    %r14d,%r14d
L31:
  mov    %rbp,%rdi
  call   <free@plt>
L14:
  mov    0x28(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L139
  add    $0x38,%rsp
  mov    %r14,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L24:
  xor    %r14d,%r14d
  jmp    L14
L139:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D30
datatype: string
name: extract_symbolic_data
arguments: data_label: D35
datatype: string
name: extract_symbolic_data
arguments: data_label: D24
datatype: string
name: extract_symbolic_data
arguments: data_label: D39
datatype: string

tool: D30: events

tool: D35: .

tool: D24: ..

tool: D39: enable

assistant: ```c
char **tracecmd_event_systems(const char *tracing_dir) {
  struct dirent *dent;
  char **systems = NULL;
  char *events_dir;
  struct stat st;
  DIR *dir;
  int len = 0;
  int ret;
  if (!tracing_dir)
    return NULL;
  events_dir = append_file(tracing_dir, "events");
  if (!events_dir)
    return NULL;
  ret = stat(events_dir, &st);
  if (ret < 0 || !S_ISDIR(st.st_mode))
    goto out_free;
  dir = opendir(events_dir);
  if (!dir)
    goto out_free;
  while ((dent = readdir(dir))) {
    const char *name = dent->d_name;
    char *enable;
    char *sys;
    if (strcmp(name, ".") == 0 || strcmp(name, "..") == 0)
      continue;
    sys = append_file(events_dir, name);
    ret = stat(sys, &st);
    if (ret < 0 || !S_ISDIR(st.st_mode)) {
      free(sys);
      continue;
    }
    enable = append_file(sys, "enable");
    ret = stat(enable, &st);
    if (ret >= 0)
      systems = tracecmd_add_list(systems, name, len++);
    free(enable);
    free(sys);
  }
  closedir(dir);
out_free:
  free(events_dir);
  return systems;
}
```