user: Converte this assembly snippet into its equivalent C code:

```asm
<clear_hooks>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  movq   $0x0,-0x20(%rbp)
  movl   $0x0,-0x2c(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x28(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <opendir@plt>
  mov    %rax,-0x18(%rbp)
  cmpq   $0x0,-0x18(%rbp)
  je     L41
  jmp    L52
L126:
  mov    -0x10(%rbp),%rax
  mov    (%rax),%rax
  lea    D59(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L52
  mov    -0x10(%rbp),%rax
  mov    (%rax),%rax
  lea    D33(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L53
  jmp    L52
L53:
  mov    -0x10(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    -0x28(%rbp),%edx
  add    %edx,%eax
  add    $0x2,%eax
  mov    %eax,-0x24(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L122
  mov    -0x24(%rbp),%eax
  mov    %eax,%edi
  call   <malloc@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L133
  lea    D43(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <closedir@plt>
  mov    $0xffffffff,%eax
  jmp    L69
L122:
  mov    -0x24(%rbp),%edx
  mov    -0x20(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <realloc@plt>
  mov    %rax,-0x8(%rbp)
  cmpq   $0x0,-0x8(%rbp)
  jne    L85
  lea    D3(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <closedir@plt>
  mov    $0xffffffff,%eax
  jmp    L69
L85:
  mov    -0x8(%rbp),%rax
  mov    %rax,-0x20(%rbp)
L133:
  mov    -0x10(%rbp),%rax
  mov    (%rax),%rcx
  mov    -0x38(%rbp),%rdx
  mov    -0x24(%rbp),%esi
  mov    -0x20(%rbp),%rax
  mov    %rcx,%r8
  mov    %rdx,%rcx
  lea    D48(%rip),%rdx
  mov    %rax,%rdi
  call   <snprintf@plt>
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <unlink@plt>
  test   %rax,%rax
  je     L52
  lea    D46(%rip),%rax
  mov    %rax,%rdi
  call   <perror@plt>
  movl   $0xffffffff,-0x2c(%rbp)
L52:
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <readdir@plt>
  mov    %rax,-0x10(%rbp)
  cmpq   $0x0,-0x10(%rbp)
  jne    L126
  mov    -0x18(%rbp),%rax
  mov    %rax,%rdi
  call   <closedir@plt>
  cmpq   $0x0,-0x20(%rbp)
  je     L96
  mov    -0x20(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  jmp    L96
L41:
  movl   $0xffffffff,-0x2c(%rbp)
L96:
  mov    -0x2c(%rbp),%eax
L69:
  leave
  ret
```

tool_calls: name: parse_data
arguments: data_label: D59
type: string
name: parse_data
arguments: data_label: D33
type: string
name: parse_data
arguments: data_label: D43
type: string
name: parse_data
arguments: data_label: D3
type: string
name: parse_data
arguments: data_label: D48
type: string
name: parse_data
arguments: data_label: D46
type: string

tool: D59: .

tool: D33: ..

tool: D43: malloc path failed

tool: D3: realloc path failed

tool: D48: %s/%s

tool: D46: unlink 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;
}
```