user: Please show me the C implementation that matches the assembly code listed below:

```asm
<getcmd>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  mov    %esi,%r12d
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x58,%rsp
  mov    0x90(%rsp),%rax
  mov    %rdi,0x20(%rsp)
  mov    $0x28,%edi
  mov    %rcx,0x10(%rsp)
  mov    %rdx,0x8(%rsp)
  mov    %rax,%rcx
  mov    %r8,0x28(%rsp)
  mov    %r9,0x38(%rsp)
  mov    %rax,0x30(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x48(%rsp)
  xor    %eax,%eax
  movl   $0x0,(%rcx)
  call   <malloc@plt>
  cmpl   $0x10,(%rbx)
  mov    %rax,%rbp
  je     L62
  mov    %r12d,%edi
  call   <prompt@plt>
L62:
  lea    0x40(%rsp),%r13
  lea    D53(%rip),%rbx
  mov    $0x4,%r12d
  mov    %r13,%rsi
  mov    %rbx,%rdi
  lea    D29(%rip),%r14
  call   <scanf@plt>
  mov    0x40(%rsp),%rax
  movl   $0x1,0x1c(%rsp)
  lea    D17(%rip),%r15
  mov    %rax,0x0(%rbp)
  nopl   (%rax)
L208:
  xor    %eax,%eax
  call   <getchar@plt>
  cmp    $0xa,%al
  je     L183
L160:
  test   %r12d,%r12d
  je     L90
L161:
  mov    %r13,%rsi
  mov    %rbx,%rdi
  call   <scanf@plt>
  mov    0x40(%rsp),%rdi
  mov    %r14,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L58
  call   <getchar@plt>
  cmp    $0xa,%al
  je     L208
  mov    0x8(%rsp),%rax
  mov    0x10(%rsp),%rsi
  mov    %rbx,%rdi
  movl   $0x1,(%rax)
  call   <scanf@plt>
  xor    %eax,%eax
  call   <getchar@plt>
  cmp    $0xa,%al
  jne    L160
L183:
  test   %r12d,%r12d
  jne    L139
  mov    %rbp,%rdi
  mov    $0x1,%esi
  call   <realloc@plt>
  mov    %rax,%rbp
L139:
  movslq 0x1c(%rsp),%rax
  movq   $0x0,0x0(%rbp,%rax,8)
  mov    0x20(%rsp),%rax
  mov    %rbp,(%rax)
  mov    0x48(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L106
  mov    0x1c(%rsp),%eax
  add    $0x58,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nop
L58:
  mov    0x40(%rsp),%rdi
  mov    %r15,%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L122
  call   <getchar@plt>
  cmp    $0xa,%al
  je     L208
  mov    0x8(%rsp),%rax
  mov    0x10(%rsp),%rsi
  mov    %rbx,%rdi
  movl   $0x2,(%rax)
  call   <scanf@plt>
  jmp    L208
  nopl   0x0(%rax)
L90:
  mov    %rbp,%rdi
  mov    $0x28,%esi
  mov    $0x5,%r12d
  call   <realloc@plt>
  mov    %rax,%rbp
  jmp    L161
  nopl   0x0(%rax,%rax,1)
L122:
  mov    0x40(%rsp),%rdi
  lea    D67(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L95
  call   <getchar@plt>
  cmp    $0xa,%al
  je     L208
  mov    0x8(%rsp),%rax
  mov    0x28(%rsp),%rsi
  mov    %rbx,%rdi
  movl   $0x4,(%rax)
  call   <scanf@plt>
  jmp    L208
L95:
  mov    0x40(%rsp),%rdi
  lea    D50(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L195
  call   <getchar@plt>
  cmp    $0xa,%al
  je     L208
  mov    0x8(%rsp),%rax
  mov    0x38(%rsp),%rsi
  mov    %rbx,%rdi
  movl   $0x8,(%rax)
  call   <scanf@plt>
  jmp    L208
L195:
  mov    0x40(%rsp),%rdi
  lea    D19(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L222
  mov    0x30(%rsp),%rax
  movl   $0x1,(%rax)
  jmp    L208
  cs nopw 0x0(%rax,%rax,1)
L222:
  mov    0x40(%rsp),%rdi
  lea    D64(%rip),%rsi
  call   <strcmp@plt>
  test   %rax,%rax
  jne    L87
  mov    0x8(%rsp),%rax
  movl   $0x10,(%rax)
  xor    %eax,%eax
  call   <getchar@plt>
  jmp    L139
L87:
  movslq 0x1c(%rsp),%rax
  mov    0x40(%rsp),%rdx
  sub    $0x1,%r12d
  mov    %rax,%rcx
  mov    %rdx,0x0(%rbp,%rax,8)
  add    $0x1,%ecx
  mov    %ecx,0x1c(%rsp)
  jmp    L208
L106:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: disassemble_data
arguments: tag: D53
datatype: string
name: disassemble_data
arguments: tag: D29
datatype: string
name: disassemble_data
arguments: tag: D17
datatype: string
name: disassemble_data
arguments: tag: D67
datatype: string
name: disassemble_data
arguments: tag: D50
datatype: string
name: disassemble_data
arguments: tag: D19
datatype: string
name: disassemble_data
arguments: tag: D64
datatype: string

tool: D53: %ms

tool: D29: >

tool: D17: >>

tool: D67: <

tool: D50: 2>

tool: D19: &

tool: D64: |

assistant: ```c
int getcmd(char ***ret, int retVal, int *redir, char **fileOut, char **fileIn, char **fileErr, int *wait) {
  int argc, freeblocks;
  char *buf, **argv, pipe = 0;
  *wait = 0;
  argc = 0;
  freeblocks = 5;
  argv = (char **)malloc(5 * sizeof(char *));
  if (*redir != 16)
    prompt(retVal);
  scanf("%ms", &buf);
  argv[argc] = buf;
  argc++;
  freeblocks--;
  while (getchar() != '\n' && pipe == 0) {
    if (freeblocks == 0) {
      argv = (char **)realloc(argv, 5 * sizeof(char *));
      freeblocks = 5;
    }
    scanf("%ms", &buf);
    if (strcmp(buf, ">") == 0) {
      if (getchar() != '\n') {
        *redir = 1;
        scanf("%ms", fileOut);
      }
    } else if (strcmp(buf, ">>") == 0) {
      if (getchar() != '\n') {
        *redir = 2;
        scanf("%ms", fileOut);
      }
    } else if (strcmp(buf, "<") == 0) {
      if (getchar() != '\n') {
        *redir = 4;
        scanf("%ms", fileIn);
      }
    } else if (strcmp(buf, "2>") == 0) {
      if (getchar() != '\n') {
        *redir = 8;
        scanf("%ms", fileErr);
      }
    } else if (strcmp(buf, "&") == 0) {
      *wait = 1;
    } else if (strcmp(buf, "|") == 0) {
      pipe = 1;
      *redir = 16;
    } else {
      argv[argc] = buf;
      argc++;
      freeblocks--;
    }
  }
  if (freeblocks == 0) {
    argv = (char **)realloc(argv, sizeof(char));
  }
  argv[argc] = NULL;
  *ret = argv;
  return argc;
}
```