user: Demonstrate the C code that generates the assembly output below:

```asm
<close_nonstd_fds>:
  endbr64
  push   %r15
  lea    D17(%rip),%rdi
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  movq   $0x0,(%rsp)
  movq   $0x0,0x8(%rsp)
  call   <opendir@plt>
  mov    %rax,%rbp
  test   %rax,%rax
  je     L24
  lea    D25(%rip),%r12
  lea    D46(%rip),%r13
  lea    D49(%rip),%r14
L66:
  mov    %rbp,%rdi
  call   <readdir@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L4
L74:
  mov    (%rsp),%rdi
  call   <free@plt>
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    (%rbx),%rdi
  mov    %r12,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L66
  mov    (%rbx),%rdi
  mov    %r13,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L66
  mov    (%rbx),%rdx
  lea    0x8(%rsp),%rdi
  mov    %r14,%rsi
  call   <asprintf@plt>
  cmp    $0xffffffff,%eax
  je     L24
  xor    %eax,%eax
  call   <getpid@plt>
  mov    %rsp,%rdi
  lea    D21(%rip),%rsi
  mov    %rax,%rdx
  call   <asprintf@plt>
  cmp    $0xffffffff,%eax
  je     L24
  lea    0x10(%rsp),%r15
  mov    $0x20,%esi
  mov    %r15,%rdi
  call   <bzero@plt>
  mov    0x8(%rsp),%rdi
  mov    $0x1f,%edx
  mov    %r15,%rsi
  call   <readlink@plt>
  cmp    $0xffffffff,%eax
  je     L24
  mov    (%rsp),%rdi
  mov    %r15,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L66
  mov    (%rbx),%rdi
  call   <atoi@plt>
  cmp    $0x2,%eax
  jbe    L66
  mov    %eax,%edi
  call   <close@plt>
  mov    %rbp,%rdi
  call   <readdir@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  jne    L74
L4:
  xor    %r12d,%r12d
L52:
  mov    %rbp,%rdi
  call   <closedir@plt>
  mov    (%rsp),%rdi
  call   <free@plt>
  mov    0x8(%rsp),%rdi
  call   <free@plt>
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L109
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L24:
  mov    $0xffffffff,%r12d
  jmp    L52
L109:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: read_data
arguments: label: D17
type: string
name: read_data
arguments: label: D25
type: string
name: read_data
arguments: label: D46
type: string
name: read_data
arguments: label: D49
type: string
name: read_data
arguments: label: D21
type: string

tool: D17: /proc/self/fd

tool: D25: .

tool: D46: ..

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

tool: D21: /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;
}
```