user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<clear_hooks>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%rbx
  mov    %rdi,(%rsp)
  call   <strlen@plt>
  mov    %eax,0x8(%rsp)
  mov    %rbx,%rdi
  call   <opendir@plt>
  test   %rax,%rax
  je     L94
  mov    %rax,%r12
  movl   $0x0,0xc(%rsp)
  mov    $0x0,%ebp
  lea    D38(%rip),%r13
  lea    D7(%rip),%r15
L48:
  mov    %r12,%rdi
  call   <readdir@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L117
  mov    %r13,%rsi
  mov    (%rbx),%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L48
  mov    %r15,%rsi
  mov    (%rbx),%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L48
  mov    (%rbx),%rdi
  call   <strlen@plt>
  mov    0x8(%rsp),%edx
  lea    0x2(%rdx,%rax,1),%r14d
  test   %rbp,%rbp
  je     L35
  mov    %r14d,%esi
  mov    %rbp,%rdi
  call   <realloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L18
L5:
  mov    (%rbx),%r8
  mov    (%rsp),%rcx
  lea    D29(%rip),%rdx
  mov    %r14d,%esi
  mov    %rbp,%rdi
  call   <snprintf@plt>
  mov    %rbp,%rdi
  call   <unlink@plt>
  test   %rax,%rax
  je     L48
  lea    D8(%rip),%rdi
  call   <perror@plt>
  movl   $0xffffffff,0xc(%rsp)
  jmp    L48
L94:
  movl   $0xffffffff,0xc(%rsp)
  jmp    L30
L35:
  mov    %r14d,%edi
  call   <malloc@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  jne    L5
  lea    D16(%rip),%rdi
  call   <perror@plt>
  mov    %r12,%rdi
  call   <closedir@plt>
  movl   $0xffffffff,0xc(%rsp)
  jmp    L30
L18:
  lea    D0(%rip),%rdi
  call   <perror@plt>
  mov    %r12,%rdi
  call   <closedir@plt>
  movl   $0xffffffff,0xc(%rsp)
  jmp    L30
L117:
  mov    %r12,%rdi
  call   <closedir@plt>
  test   %rbp,%rbp
  je     L30
  mov    %rbp,%rdi
  call   <free@plt>
L30:
  mov    0xc(%rsp),%eax
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

tool_calls: name: retrieve_data
arguments: data_label: D38
data_type: string
name: retrieve_data
arguments: data_label: D7
data_type: string
name: retrieve_data
arguments: data_label: D29
data_type: string
name: retrieve_data
arguments: data_label: D8
data_type: string
name: retrieve_data
arguments: data_label: D16
data_type: string
name: retrieve_data
arguments: data_label: D0
data_type: string

tool: D38: .

tool: D7: ..

tool: D29: %s/%s

tool: D8: unlink failed

tool: D16: malloc path failed

tool: D0: realloc path failed

assistant: ```c
int clear_hooks(char *dirname) {
  DIR *dir;
  struct dirent *ent;
  char *path = NULL;
  char *new_path;
  int path_len;
  int dirname_len;
  int status = 0;
  dirname_len = strlen(dirname);
  if ((dir = opendir(dirname)) != NULL) {
    while ((ent = readdir(dir)) != NULL) {
      if (strcmp(ent->d_name, ".") == 0 || strcmp(ent->d_name, "..") == 0) {
        continue;
      }
      path_len = dirname_len + strlen(ent->d_name) + 2;
      if (path == NULL) {
        path = malloc(path_len);
        if (path == NULL) {
          perror("malloc path failed");
          closedir(dir);
          return -1;
        }
      } else {
        new_path = realloc(path, path_len);
        if (new_path == NULL) {
          perror("realloc path failed");
          closedir(dir);
          return -1;
        }
        path = new_path;
      }
      snprintf(path, path_len, "%s/%s", dirname, ent->d_name);
      if (unlink(path) != 0) {
        perror("unlink failed");
        status = -1;
      }
    }
    closedir(dir);
    if (path != NULL) {
      free(path);
    }
  } else {
    status = -1;
  }
  return status;
}
```