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

```asm
<dump_ps>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x38,%rsp
  mov    %edi,%r13d
  mov    %fs:0x28,%rax
  mov    %rax,0x28(%rsp)
  xor    %eax,%eax
  lea    D82(%rip),%rdi
  call   <opendir@plt>
  mov    %rax,%rbp
  movl   $0x0,0xc(%rsp)
  movl   $0x0,0x8(%rsp)
  lea    D128(%rip),%r15
  lea    D95(%rip),%r14
L2:
  mov    %rbp,%rdi
  call   <readdir@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L134
  mov    (%rbx),%rax
  movsbl (%rax),%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L2
  mov    (%rbx),%rcx
  lea    D94(%rip),%rdx
  mov    $0x80,%esi
  mov    %r15,%rdi
  call   <snprintf@plt>
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <fopen@plt>
  mov    %rax,%r12
  test   %rax,%rax
  je     L133
  lea    0x18(%rsp),%rdx
  lea    0x24(%rsp),%rax
  push   %rax
  push   %rdx
  push   %rdx
  push   %rdx
  lea    0x3c(%rsp),%rax
  push   %rax
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  push   %rdx
  lea    0xc0(%rsp),%r9
  lea    D62(%rip),%r8
  lea    D98(%rip),%rcx
  lea    D54(%rip),%rsi
  mov    %r12,%rdi
  call   <fscanf@plt>
  add    $0xa0,%rsp
  mov    0x24(%rsp),%r9d
  mov    0x1c(%rsp),%r8d
  mov    0x20(%rsp),%ecx
  mov    (%rbx),%rdx
  lea    D114(%rip),%rsi
  mov    %r13d,%edi
  mov    $0x0,%eax
  call   <sockprint@plt>
  mov    %eax,0x4(%rsp)
  addl   $0x1,0x8(%rsp)
  mov    0x1c(%rsp),%ecx
  add    %ecx,0xc(%rsp)
  mov    %r12,%rdi
  call   <fclose@plt>
  cmpl   $0x0,0x4(%rsp)
  jne    L37
  mov    (%rbx),%rcx
  lea    D137(%rip),%rdx
  mov    $0x80,%esi
  mov    %r15,%rdi
  call   <snprintf@plt>
  mov    %r14,%rsi
  mov    %r15,%rdi
  call   <fopen@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L133
  mov    %rax,%rcx
  mov    $0xfff,%edx
  mov    $0x1,%esi
  lea    D31(%rip),%rdi
  call   <fread@plt>
  mov    %eax,%edx
  test   %eax,%eax
  js     L68
  cltq
  lea    D31(%rip),%rcx
  movb   $0x0,(%rcx,%rax,1)
  jle    L74
  lea    -0x1(%rdx),%eax
  lea    0x1(%rcx),%rsi
  add    %rsi,%rax
  jmp    L56
L68:
  lea    D39(%rip),%rsi
  mov    %r13d,%edi
  call   <sockerror@plt>
  mov    %eax,0x4(%rsp)
  jmp    L53
L157:
  add    $0x1,%rcx
  cmp    %rax,%rcx
  je     L74
L56:
  cmpb   $0x0,(%rcx)
  jne    L157
  movb   $0x20,(%rcx)
  jmp    L157
L74:
  lea    D31(%rip),%rcx
  lea    D107(%rip),%rsi
  mov    %r13d,%edi
  mov    $0x0,%eax
  call   <sockprint@plt>
  mov    %eax,0x4(%rsp)
L53:
  mov    %rbx,%rdi
  call   <fclose@plt>
L158:
  cmpl   $0x0,0x4(%rsp)
  je     L2
  mov    0x4(%rsp),%r12d
  jmp    L155
L133:
  mov    %r15,%rdx
  lea    D144(%rip),%rsi
  mov    %r13d,%edi
  mov    $0x0,%eax
  call   <sockprint@plt>
  mov    %eax,0x4(%rsp)
  jmp    L158
L134:
  mov    $0x0,%r12d
L155:
  mov    %rbp,%rdi
  call   <closedir@plt>
  mov    0xc(%rsp),%ecx
  mov    0x8(%rsp),%edx
  lea    D18(%rip),%rsi
  mov    %r13d,%edi
  mov    $0x0,%eax
  call   <sockprint@plt>
  or     %r12d,%eax
  mov    0x28(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L100
  add    $0x38,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L37:
  mov    0x4(%rsp),%r12d
  jmp    L155
L100:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: data_tag: D82
type_infered: string
name: disassemble_data
arguments: data_tag: D95
type_infered: string
name: disassemble_data
arguments: data_tag: D94
type_infered: string
name: disassemble_data
arguments: data_tag: D54
type_infered: string
name: disassemble_data
arguments: data_tag: D114
type_infered: string
name: disassemble_data
arguments: data_tag: D137
type_infered: string
name: disassemble_data
arguments: data_tag: D39
type_infered: string
name: disassemble_data
arguments: data_tag: D107
type_infered: string
name: disassemble_data
arguments: data_tag: D144
type_infered: string
name: disassemble_data
arguments: data_tag: D18
type_infered: string

tool: D82: /proc

tool: D95: r

tool: D94: /proc/%s/stat

tool: D54: %d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d

tool: D114: %5s, ppid %5d, # threads: %2d, rss: %5d 

tool: D137: /proc/%s/cmdline

tool: D39: fread

tool: D107: %d %s


tool: D144: Error opening %s


tool: D18: # procs: %d, # threads: %d


assistant: ```c
int dump_ps(int fd) {
  int rc = 0, tnprocs = 0, tnthreads = 0;
  struct dirent *de;
  DIR *dirp = opendir("/proc");
  while ((de = readdir(dirp)) != NULL) {
    if (isdigit(de->d_name[0])) {
      FILE *fh;
      static char path[128];
      snprintf(path, sizeof(path), "/proc/%s/stat", de->d_name);
      fh = fopen(path, "r");
      if (fh) {
        static char fname[4096], dummystr[2];
        int dummy, nthreads, ppid, rss;
        fscanf(fh, "%d %s %c %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d %d", &dummy, fname, &dummystr[0], &ppid, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &dummy, &nthreads, &dummy, &dummy, &dummy, &rss);
        rc |= sockprint(fd, "%5s, ppid %5d, # threads: %2d, rss: %5d ", de->d_name, ppid, nthreads, rss);
        tnprocs++;
        tnthreads += nthreads;
      }
      if (fh) {
        fclose(fh);
        if (rc)
          break;
        snprintf(path, sizeof(path), "/proc/%s/cmdline", de->d_name);
        fh = fopen(path, "r");
      }
      if (fh) {
        int len, loop;
        static char non_ret_buffer[4096];
        len = fread(non_ret_buffer, 1, sizeof(non_ret_buffer) - 1, fh);
        if (len < 0)
          rc |= sockerror(fd, "fread");
        else {
          non_ret_buffer[len] = 0x00;
          for (loop = 0; loop < len; loop++) {
            if (non_ret_buffer[loop] == 0x00)
              non_ret_buffer[loop] = ' ';
          }
          rc |= sockprint(fd, "%d %s\r\n", len, non_ret_buffer);
        }
        fclose(fh);
      } else {
        rc |= sockprint(fd, "Error opening %s\r\n", path);
      }
      if (rc)
        break;
    }
  }
  closedir(dirp);
  rc |= sockprint(fd, "# procs: %d, # threads: %d\r\n", tnprocs, tnthreads);
  return rc;
}
```