user: 请将以下的汇编代码转换成C语言代码：

```asm
<close_nonstd_fds>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x58,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  mov    %rsp,%rax
  mov    %rax,%rbx
  movl   $0x20,-0x50(%rbp)
  movl   $0xffffffff,-0x54(%rbp)
  movl   $0xffffffff,-0x4c(%rbp)
  movq   $0x0,-0x48(%rbp)
  movq   $0x0,-0x40(%rbp)
  mov    -0x50(%rbp),%eax
  cltq
  sub    $0x1,%rax
  mov    %rax,-0x38(%rbp)
  mov    -0x50(%rbp),%eax
  cltq
  mov    %rax,%r8
  mov    $0x0,%r9d
  mov    -0x50(%rbp),%eax
  cltq
  mov    %rax,%rsi
  mov    $0x0,%edi
  mov    -0x50(%rbp),%eax
  cltq
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%esi
  mov    $0x0,%edx
  div    %rsi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L63:
  cmp    %rdx,%rsp
  je     L75
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L63
L75:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L182
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L182:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x30(%rbp)
  movq   $0x0,-0x28(%rbp)
  movq   $0x0,-0x20(%rbp)
  lea    D3(%rip),%rax
  mov    %rax,%rdi
  call   <opendir@plt>
  mov    %rax,-0x28(%rbp)
  cmpq   $0x0,-0x28(%rbp)
  je     L203
  jmp    L212
L161:
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rax
  lea    D12(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L79
  jmp    L212
L79:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rax
  lea    D45(%rip),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L214
  jmp    L212
L214:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rdx
  lea    -0x40(%rbp),%rax
  lea    D5(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <asprintf@plt>
  cmp    $0xffffffff,%eax
  je     L160
  mov    $0x0,%eax
  call   <getpid@plt>
  mov    %rax,%rdx
  lea    -0x48(%rbp),%rax
  lea    D26(%rip),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <asprintf@plt>
  cmp    $0xffffffff,%eax
  je     L89
  mov    -0x50(%rbp),%edx
  mov    -0x30(%rbp),%rax
  mov    %edx,%esi
  mov    %rax,%rdi
  call   <bzero@plt>
  mov    -0x50(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    -0x40(%rbp),%rax
  mov    -0x30(%rbp),%rcx
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <readlink@plt>
  cmp    $0xffffffff,%eax
  je     L146
  mov    -0x48(%rbp),%rax
  mov    -0x30(%rbp),%rdx
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L187
  jmp    L212
L187:
  mov    -0x20(%rbp),%rax
  mov    (%rax),%rax
  mov    %rax,%rdi
  call   <atoi@plt>
  mov    %eax,-0x4c(%rbp)
  mov    -0x4c(%rbp),%eax
  cmp    $0x2,%eax
  ja     L33
  jmp    L212
L33:
  mov    -0x4c(%rbp),%eax
  mov    %eax,%edi
  call   <close@plt>
L212:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <readdir@plt>
  mov    %rax,-0x20(%rbp)
  cmpq   $0x0,-0x20(%rbp)
  jne    L161
  movl   $0x0,-0x54(%rbp)
  jmp    L171
L203:
  nop
  jmp    L171
L160:
  nop
  jmp    L171
L89:
  nop
  jmp    L171
L146:
  nop
L171:
  mov    -0x28(%rbp),%rax
  mov    %rax,%rdi
  call   <closedir@plt>
  movq   $0x0,-0x28(%rbp)
  movq   $0x0,-0x20(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  mov    -0x40(%rbp),%rax
  mov    %rax,%rdi
  call   <free@plt>
  movq   $0x0,-0x40(%rbp)
  mov    -0x40(%rbp),%rax
  mov    %rax,-0x48(%rbp)
  mov    -0x54(%rbp),%eax
  mov    %rbx,%rsp
  mov    -0x18(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L153
  call   <__stack_chk_fail@plt>
L153:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

tool_calls: name: read_data
arguments: tag: D3
type_guessed: string
name: read_data
arguments: tag: D12
type_guessed: string
name: read_data
arguments: tag: D45
type_guessed: string
name: read_data
arguments: tag: D5
type_guessed: string
name: read_data
arguments: tag: D26
type_guessed: string

tool: D3: /proc/self/fd

tool: D12: .

tool: D45: ..

tool: D5: /proc/self/fd/%s

tool: D26: /proc/%d/fd

assistant: ```c
int close_nonstd_fds(void) {
  const int procpidfdmax = 32;
  int rv = -1;
  int fd = -1;
  char *cmp = NULL;
  char *sym = NULL;
  char phys[procpidfdmax];
  DIR *dir = NULL;
  struct dirent *ent = NULL;
  dir = opendir("/proc/self/fd");
  if (!dir) {
    goto out;
  }
  while ((ent = readdir(dir)) != NULL) {
    free(cmp);
    free(sym);
    if (strcmp(ent->d_name, ".") == 0)
      continue;
    if (strcmp(ent->d_name, "..") == 0)
      continue;
    if (asprintf(&sym, "/proc/self/fd/%s", ent->d_name) == -1)
      goto out;
    if (asprintf(&cmp, "/proc/%d/fd", getpid()) == -1)
      goto out;
    bzero(phys, sizeof(phys));
    if (readlink(sym, phys, procpidfdmax - 1) == -1)
      goto out;
    if (strcmp(cmp, phys) == 0)
      continue;
    fd = atoi(ent->d_name);
    switch (fd) {
    case 0:
    case 1:
    case 2:
      break;
    default:
      close(fd);
    }
  }
  rv = 0;
out:
  closedir(dir);
  dir = NULL;
  ent = NULL;
  free(cmp);
  free(sym);
  cmp = sym = NULL;
  return rv;
}
```