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

```asm
<escape_code>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x18(%rbp)
  xor    %eax,%eax
  lea    -0x1c(%rbp),%rax
  mov    $0x4,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  lea    -0x30(%rbp),%rax
  mov    $0x10,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  lea    -0x39(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <READ@plt>
  cmp    $0x1,%eax
  jne    L82
  movzbl -0x39(%rbp),%eax
  cmp    $0x5b,%al
  jne    L33
  movl   $0x0,-0x38(%rbp)
  movl   $0x0,-0x34(%rbp)
L121:
  lea    -0x39(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <READ@plt>
  cmp    $0x1,%eax
  jne    L8
  movzbl -0x39(%rbp),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isalpha@plt>
  test   %eax,%eax
  je     L29
  cmpl   $0x0,-0x34(%rbp)
  jle    L24
  cmpl   $0x3,-0x38(%rbp)
  jg     L24
  mov    -0x38(%rbp),%ebx
  lea    0x1(%rbx),%eax
  mov    %eax,-0x38(%rbp)
  lea    -0x1c(%rbp),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <atoi@plt>
  movslq %ebx,%rdx
  mov    %eax,-0x30(%rbp,%rdx,4)
L24:
  movzbl -0x39(%rbp),%eax
  movsbl %al,%esi
  lea    -0x30(%rbp),%rcx
  mov    -0x38(%rbp),%edx
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <escape_command@plt>
  jmp    L33
L29:
  movzbl -0x39(%rbp),%eax
  movsbl %al,%eax
  sub    $0x30,%eax
  cmp    $0x9,%eax
  ja     L122
  cmpl   $0x3,-0x34(%rbp)
  jg     L122
  mov    -0x34(%rbp),%eax
  lea    0x1(%rax),%edx
  mov    %edx,-0x34(%rbp)
  movzbl -0x39(%rbp),%edx
  cltq
  mov    %dl,-0x1c(%rbp,%rax,1)
  jmp    L137
L122:
  movzbl -0x39(%rbp),%eax
  cmp    $0x3b,%al
  jne    L121
  cmpl   $0x0,-0x34(%rbp)
  jle    L94
  cmpl   $0x3,-0x38(%rbp)
  jg     L94
  mov    -0x38(%rbp),%ebx
  lea    0x1(%rbx),%eax
  mov    %eax,-0x38(%rbp)
  lea    -0x1c(%rbp),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <atoi@plt>
  movslq %ebx,%rdx
  mov    %eax,-0x30(%rbp,%rdx,4)
L94:
  lea    -0x1c(%rbp),%rax
  mov    $0x4,%edx
  mov    $0x0,%esi
  mov    %rax,%rdi
  call   <memset@plt>
  movl   $0x0,-0x34(%rbp)
L137:
  jmp    L121
L82:
  nop
  jmp    L33
L8:
  nop
L33:
  mov    -0x18(%rbp),%rax
  sub    %fs:0x28,%rax
  je     L54
  call   <__stack_chk_fail@plt>
L54:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

assistant: ```c
void escape_code(struct pty *pty) {
  char digitbuf[4];
  memset(digitbuf, 0, sizeof(digitbuf));
  int args[4];
  memset(args, 0, sizeof(args));
  char c;
  if (READ(pty, &c) != 1) {
    return;
  }
  if (c == '[') {
    int argc = 0;
    int digitpos = 0;
    while (1) {
      if (READ(pty, &c) != 1) {
        return;
      }
      if (isalpha(c)) {
        if (digitpos > 0 && argc < 4) {
          args[argc++] = atoi(digitbuf);
        }
        escape_command(pty, c, argc, args);
        break;
      } else if (isdigit(c) && digitpos < 4) {
        digitbuf[digitpos++] = c;
      } else if (c == ';') {
        if (digitpos > 0 && argc < 4) {
          args[argc++] = atoi(digitbuf);
        }
        memset(digitbuf, 0, sizeof(digitbuf));
        digitpos = 0;
      }
    }
  }
}
```