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

```asm
<escape>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,-0x68(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    %rsp,%rax
  mov    %rax,%rbx
  mov    -0x68(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,%edx
  mov    %edx,%eax
  add    %eax,%eax
  add    %edx,%eax
  add    $0x1,%eax
  movslq %eax,%rdx
  sub    $0x1,%rdx
  mov    %rdx,-0x50(%rbp)
  movslq %eax,%rdx
  mov    %rdx,%r14
  mov    $0x0,%r15d
  movslq %eax,%rdx
  mov    %rdx,%r12
  mov    $0x0,%r13d
  cltq
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%esi
  mov    $0x0,%edx
  div    %rsi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L21:
  cmp    %rdx,%rsp
  je     L113
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L21
L113:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L130
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L130:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x48(%rbp)
  mov    -0x68(%rbp),%rax
  mov    %rax,-0x58(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x60(%rbp)
  jmp    L60
L159:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x20,%al
  jne    L42
  mov    -0x60(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x60(%rbp)
  movb   $0x2b,(%rax)
  addq   $0x1,-0x58(%rbp)
  jmp    L60
L42:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  je     L167
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x20,%al
  jbe    L167
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2b,%al
  je     L167
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x25,%al
  je     L167
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  js     L167
  mov    -0x58(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x58(%rbp)
  movzbl (%rax),%ecx
  mov    -0x60(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x60(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
  jmp    L60
L167:
  mov    -0x60(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x60(%rbp)
  movb   $0x25,(%rax)
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x4,%al
  movzbl %al,%eax
  and    $0xf,%eax
  cmp    $0x9,%eax
  jg     L148
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x4,%al
  add    $0x30,%eax
  mov    %eax,%ecx
  jmp    L10
L148:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  shr    $0x4,%al
  add    $0x57,%eax
  mov    %eax,%ecx
L10:
  mov    -0x60(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x60(%rbp)
  mov    %cl,(%rax)
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xf,%eax
  cmp    $0x9,%eax
  jg     L67
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  and    $0xf,%eax
  add    $0x30,%eax
  mov    %eax,%ecx
  jmp    L175
L67:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  and    $0xf,%eax
  add    $0x57,%eax
  mov    %eax,%ecx
L175:
  mov    -0x60(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x60(%rbp)
  mov    %cl,(%rax)
  addq   $0x1,-0x58(%rbp)
L60:
  mov    -0x58(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L159
  mov    -0x60(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strdup@plt>
  mov    %rax,-0x40(%rbp)
  mov    -0x40(%rbp),%rax
  mov    %rbx,%rsp
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L57
  call   <__stack_chk_fail@plt>
L57:
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

assistant: ```c
char *escape(const char *str) {
  char *esc_str;
  char esc_tmp[strlen(str) * 3 + 1];
  char *q;
  const unsigned char *p;
  p = (unsigned char *)str;
  q = esc_tmp;
  while (*p) {
    if (*p == ' ') {
      *q++ = '+';
      p++;
    } else if ((*p != '.') && (*p > ' ') && (*p != '+') && (*p != '%') && (*p < 128)) {
      *q++ = *p++;
    } else {
      *q++ = '%';
      *q++ = ((((*p >> 4) & 0x0f) < 10) ? ('0' + ((*p >> 4) & 0x0f)) : ('a' + ((*p >> 4) & 0x0f) - 10));
      *q++ = (((*p & 0x0f) < 10) ? ('0' + (*p & 0x0f)) : ('a' + (*p & 0x0f) - 10));
      p++;
    }
  }
  *q = 0;
  esc_str = strdup(esc_tmp);
  return esc_str;
}
```