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

```asm
<main>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x1000,%rsp
  orq    $0x0,(%rsp)
  sub    $0x748,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x2738(%rsp)
  xor    %eax,%eax
  mov    %rsi,%rbx
  cmp    $0x2,%edi
  jle    L115
L81:
  pxor   %xmm0,%xmm0
  mov    $0x2700,%edx
  lea    0x30(%rsp),%rdi
  xor    %esi,%esi
  movaps %xmm0,0x20(%rsp)
  lea    D8(%rip),%r13
  call   <memset@plt>
  mov    0x8(%rbx),%rdi
  call   <atoi@plt>
  lea    0x0(,%rax,4),%edi
  mov    %eax,%r12d
  call   <malloc@plt>
  mov    0x10(%rbx),%r14
  mov    %rax,(%rsp)
  mov    %r14,%rdi
  call   <strlen@plt>
  mov    $0x2f,%ecx
  mov    %cx,(%r14,%rax,1)
  mov    0x10(%rbx),%rdi
  lea    D105(%rip),%rbx
  call   <opendir@plt>
  lea    D49(%rip),%rsi
  mov    %r13,%rdi
  mov    %rax,%rbp
  call   <fopen@plt>
  mov    %rax,%r15
  jmp    L164
  cs nopw 0x0(%rax,%rax,1)
L49:
  mov    (%rax),%rdx
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   <fprintf@plt>
L164:
  mov    %rbp,%rdi
  call   <readdir@plt>
  test   %rax,%rax
  jne    L49
  mov    %rbp,%rdi
  lea    D33(%rip),%rbx
  call   <closedir@plt>
  mov    %r15,%rdi
  lea    0x20(%rsp),%r15
  call   <fclose@plt>
  lea    D57(%rip),%rsi
  mov    %r13,%rdi
  call   <fopen@plt>
  mov    (%rsp),%rcx
  movq   $0x1,0x10(%rsp)
  mov    %rax,%rbp
  mov    %r12d,%eax
  lea    (%rcx,%rax,4),%rax
  mov    %rax,0x8(%rsp)
  jmp    L120
  nopl   0x0(%rax)
L145:
  mov    %r15,%rdi
  call   <strlen@plt>
  sub    $0x1,%eax
  cltq
  cmpb   $0xa,0x20(%rsp,%rax,1)
  jne    L119
  movb   $0x0,0x20(%rsp,%rax,1)
L119:
  mov    %rbx,%rsi
  mov    %r15,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L33
L120:
  mov    %rbp,%rdx
  mov    $0x2710,%esi
  mov    %r15,%rdi
  call   <fgets@plt>
  test   %rax,%rax
  jne    L145
  mov    %rbp,%rdi
  call   <fclose@plt>
  sub    $0x8,%rsp
  lea    D63(%rip),%r9
  lea    D144(%rip),%r8
  push   $0x0
  lea    D128(%rip),%rcx
  lea    D19(%rip),%rdx
  push   %r13
  lea    D126(%rip),%rsi
  lea    D65(%rip),%rdi
  push   %r13
  call   <execlp@plt>
  add    $0x20,%rsp
  xor    %eax,%eax
L17:
  mov    0x2738(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L121
  add    $0x2748,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L33:
  lea    D134(%rip),%rsi
  mov    %r15,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L120
  call   <fork@plt>
  test   %eax,%eax
  je     L158
  mov    (%rsp),%rdx
  mov    0x10(%rsp),%rcx
  mov    %eax,-0x4(%rdx,%rcx,4)
  cmp    %ecx,%r12d
  jle    L88
L85:
  addq   $0x1,0x10(%rsp)
  jmp    L120
L115:
  lea    D56(%rip),%rdi
  call   <perror@plt>
  xor    %edi,%edi
  call   <exit@plt>
  jmp    L81
L158:
  mov    %r15,%rsi
  mov    %r14,%rdi
  call   <strcat@plt>
  lea    D63(%rip),%r9
  lea    D144(%rip),%r8
  push   %rdx
  lea    D128(%rip),%rcx
  lea    D19(%rip),%rdx
  push   $0x0
  lea    D126(%rip),%rsi
  lea    D65(%rip),%rdi
  push   %r14
  push   %r14
  call   <execlp@plt>
  add    $0x20,%rsp
  lea    D149(%rip),%rdi
  call   <printf@plt>
  mov    $0x1,%eax
  jmp    L17
L88:
  mov    (%rsp),%rcx
  jmp    L50
L23:
  mov    (%rcx),%edi
  xor    %edx,%edx
  xor    %esi,%esi
  mov    %rcx,0x18(%rsp)
  call   <waitpid@plt>
  mov    0x18(%rsp),%rcx
  add    $0x4,%rcx
L50:
  cmp    0x8(%rsp),%rcx
  jne    L23
  jmp    L85
L121:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: retrieve_data
arguments: tag: D8
datatype: string
name: retrieve_data
arguments: tag: D105
datatype: string
name: retrieve_data
arguments: tag: D49
datatype: string
name: retrieve_data
arguments: tag: D33
datatype: string
name: retrieve_data
arguments: tag: D57
datatype: string
name: retrieve_data
arguments: tag: D63
datatype: string
name: retrieve_data
arguments: tag: D144
datatype: string
name: retrieve_data
arguments: tag: D128
datatype: string
name: retrieve_data
arguments: tag: D19
datatype: string
name: retrieve_data
arguments: tag: D126
datatype: string
name: retrieve_data
arguments: tag: D65
datatype: string
name: retrieve_data
arguments: tag: D134
datatype: string
name: retrieve_data
arguments: tag: D56
datatype: string
name: retrieve_data
arguments: tag: D149
datatype: string

tool: D8: list.txt

tool: D105: %s


tool: D49: w+

tool: D33: .

tool: D57: r

tool: D63: -o

tool: D144: -u

tool: D128: 1

tool: D19: -k

tool: D126: -n

tool: D65: sort

tool: D134: ..

tool: D56: The number of args is wrong!


tool: D149: error2


assistant: ```c
int main(int argc, char *argv[]) {
  if (argc < 3) {
    perror("The number of args is wrong!\n");
    exit(0);
  }
  int pid = 0;
  int len = 0;
  char buf[10000] = {0};
  int max = atoi(argv[1]);
  int *maxptr = malloc(sizeof(int) * max);
  int i = 0;
  char *dirname = strcat(argv[2], "/");
  DIR *dir;
  FILE *fp;
  struct dirent *ptr;
  dir = opendir(argv[2]);
  fp = fopen("list.txt", "w+");
  while ((ptr = readdir(dir)) != NULL) {
    fprintf(fp, "%s\n", ptr->d_name);
  }
  closedir(dir);
  fclose(fp);
  fp = fopen("list.txt", "r");
  while (fgets(buf, 10000, fp) != NULL) {
    len = (int)strlen(buf) - 1;
    if ('\n' == buf[len]) {
      buf[len] = '\0';
    }
    if ((strcmp(buf, ".") != 0) && (strcmp(buf, "..") != 0)) {
      pid = fork();
      if (0 == pid) {
        execlp("sort", "-n", "-k", "1", "-u", "-o", strcat(dirname, buf), dirname, (char *)NULL);
        printf("error2\n");
        return 1;
      } else {
        maxptr[i++] = pid;
      }
      if (i >= max) {
        for (int j = 0; j != max; ++j) {
          waitpid(maxptr[j], NULL, 0);
        }
      }
    }
  }
  fclose(fp);
  execlp("sort", "-n", "-k", "1", "-u", "-o", "list.txt", "list.txt", (char *)NULL);
  return 0;
}
```