user: 请显示与下面列出的汇编代码相匹配的C语言实现：

```asm
<Tcl_ConvertCountedElement>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbx
  mov    %esi,%eax
  mov    %rdx,%rbp
  mov    %ecx,%r12d
  test   %rdi,%rdi
  je     L102
  cmp    $0xffffffff,%esi
  jne    L102
  call   <strlen@plt>
L102:
  test   %rbx,%rbx
  je     L49
  test   %eax,%eax
  je     L49
  cltq
  lea    (%rbx,%rax,1),%rsi
  mov    %r12d,%edx
  and    $0x3,%edx
  cmp    $0x2,%edx
  je     L111
  mov    %rbp,%rax
  cmpb   $0x7b,(%rbx)
  je     L61
L223:
  and    $0x4,%r12d
  mov    $0x1,%r8d
  movabs $0x800001500000000,%rdi
  cmp    %rbx,%rsi
  jne    L141
  jmp    L58
L49:
  movb   $0x7b,0x0(%rbp)
  movb   $0x7d,0x1(%rbp)
  movb   $0x0,0x2(%rbp)
  mov    $0x2,%eax
  jmp    L204
L111:
  movb   $0x7b,0x0(%rbp)
  mov    $0x0,%edx
L252:
  movzbl (%rbx,%rdx,1),%ecx
  mov    %cl,0x1(%rbp,%rdx,1)
  add    $0x1,%rdx
  cmp    %rdx,%rax
  jne    L252
  lea    0x1(%rbp,%rax,1),%rax
  movb   $0x7d,(%rax)
  add    $0x1,%rax
L58:
  movb   $0x0,(%rax)
  sub    %ebp,%eax
L204:
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L61:
  movb   $0x5c,0x0(%rbp)
  movb   $0x7b,0x1(%rbp)
  lea    0x2(%rbp),%rax
  add    $0x1,%rbx
  or     $0x4,%r12d
  jmp    L223
L71:
  cmp    $0x9,%cl
  jne    L127
  movb   $0x5c,(%rax)
  movb   $0x74,0x1(%rax)
  add    $0x2,%rax
  jmp    L212
L121:
  mov    %r8,%rdx
  shl    %cl,%rdx
  test   %rdi,%rdx
  jne    L56
  cmp    $0xd,%cl
  je     L203
  cmp    $0xc,%cl
  je     L160
L127:
  movzbl (%rbx),%edx
  mov    %dl,(%rax)
  add    $0x1,%rax
L212:
  add    $0x1,%rbx
  cmp    %rbx,%rsi
  je     L58
L141:
  movzbl (%rbx),%ecx
  cmp    $0x3b,%cl
  jg     L194
  cmp    $0xb,%cl
  jg     L121
  cmp    $0xa,%cl
  je     L120
  cmp    $0xb,%cl
  jne    L71
  movb   $0x5c,(%rax)
  movb   $0x76,0x1(%rax)
  add    $0x2,%rax
  jmp    L212
L194:
  cmp    $0x7b,%cl
  je     L6
  jle    L92
  cmp    $0x7d,%cl
  jne    L127
L6:
  test   %r12d,%r12d
  je     L127
  movb   $0x5c,(%rax)
  add    $0x1,%rax
  jmp    L127
L92:
  sub    $0x5b,%ecx
  cmp    $0x2,%cl
  ja     L127
L56:
  movb   $0x5c,(%rax)
  add    $0x1,%rax
  jmp    L127
L160:
  movb   $0x5c,(%rax)
  movb   $0x66,0x1(%rax)
  add    $0x2,%rax
  jmp    L212
L120:
  movb   $0x5c,(%rax)
  movb   $0x6e,0x1(%rax)
  add    $0x2,%rax
  jmp    L212
L203:
  movb   $0x5c,(%rax)
  movb   $0x72,0x1(%rax)
  add    $0x2,%rax
  jmp    L212
```

assistant: ```c
int Tcl_ConvertCountedElement(src, length, dst, flags) const char *src;
int length;
char *dst;
int flags;
{
  char *p = dst;
  const char *lastChar;
  if (src && length == -1) {
    length = strlen(src);
  }
  if ((src == 0) || (length == 0)) {
    p[0] = '{';
    p[1] = '}';
    p[2] = 0;
    return 2;
  }
  lastChar = src + length;
  if ((flags & 2) && !(flags & 1)) {
    *p = '{';
    p++;
    for (; src != lastChar; src++, p++) {
      *p = *src;
    }
    *p = '}';
    p++;
  } else {
    if (*src == '{') {
      p[0] = '\\';
      p[1] = '{';
      p += 2;
      src++;
      flags |= 4;
    }
    for (; src != lastChar; src++) {
      switch (*src) {
      case ']':
      case '[':
      case '$':
      case ';':
      case ' ':
      case '\\':
      case '"':
        *p = '\\';
        p++;
        break;
      case '{':
      case '}':
        if (flags & 4) {
          *p = '\\';
          p++;
        }
        break;
      case '\f':
        *p = '\\';
        p++;
        *p = 'f';
        p++;
        continue;
      case '\n':
        *p = '\\';
        p++;
        *p = 'n';
        p++;
        continue;
      case '\r':
        *p = '\\';
        p++;
        *p = 'r';
        p++;
        continue;
      case '\t':
        *p = '\\';
        p++;
        *p = 't';
        p++;
        continue;
      case '\v':
        *p = '\\';
        p++;
        *p = 'v';
        p++;
        continue;
      }
      *p = *src;
      p++;
    }
  }
  *p = '\0';
  return p - dst;
}
```