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

```asm
<Tcl_ScanCountedElement>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x50,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %esi,-0x3c(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  movl   $0x0,-0x1c(%rbp)
  movl   $0x0,-0x20(%rbp)
  cmpq   $0x0,-0x38(%rbp)
  jne    L224
  lea    D2(%rip),%rax
  mov    %rax,-0x38(%rbp)
L224:
  cmpl   $0xffffffff,-0x3c(%rbp)
  jne    L101
  mov    -0x38(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x3c(%rbp)
L101:
  mov    -0x3c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  je     L125
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x7b,%al
  je     L125
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x22,%al
  jne    L208
L125:
  orl    $0x2,-0x20(%rbp)
  jmp    L208
L38:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  cmp    $0x7d,%eax
  je     L121
  cmp    $0x7d,%eax
  jg     L194
  cmp    $0x7b,%eax
  je     L178
  cmp    $0x7b,%eax
  jg     L194
  cmp    $0x5c,%eax
  je     L57
  cmp    $0x5c,%eax
  jg     L194
  cmp    $0xd,%eax
  jg     L150
  cmp    $0x9,%eax
  jge    L205
  jmp    L194
L167:
  sub    $0x20,%eax
  movabs $0x800000008000011,%rdx
  mov    %eax,%ecx
  shr    %cl,%rdx
  mov    %rdx,%rax
  and    $0x1,%eax
  test   %rax,%rax
  setne  %al
  test   %al,%al
  jne    L205
  jmp    L194
L150:
  cmp    $0x5b,%eax
  jg     L194
  cmp    $0x20,%eax
  jge    L167
  jmp    L194
L178:
  addl   $0x1,-0x1c(%rbp)
  jmp    L194
L121:
  subl   $0x1,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  jns    L296
  orl    $0x5,-0x20(%rbp)
  jmp    L296
L205:
  orl    $0x2,-0x20(%rbp)
  jmp    L194
L57:
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  cmp    %rax,-0x10(%rbp)
  je     L172
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  jne    L126
L172:
  movl   $0x5,-0x20(%rbp)
  jmp    L194
L126:
  lea    -0x24(%rbp),%rdx
  mov    -0x18(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <Tcl_Backslash@plt>
  mov    -0x24(%rbp),%eax
  cltq
  sub    $0x1,%rax
  add    %rax,-0x18(%rbp)
  orl    $0x2,-0x20(%rbp)
  jmp    L194
L296:
  nop
L194:
  addq   $0x1,-0x18(%rbp)
L208:
  mov    -0x18(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  jne    L38
  cmpl   $0x0,-0x1c(%rbp)
  je     L72
  movl   $0x5,-0x20(%rbp)
L72:
  mov    -0x48(%rbp),%rax
  mov    -0x20(%rbp),%edx
  mov    %edx,(%rax)
  mov    -0x18(%rbp),%rax
  sub    -0x38(%rbp),%rax
  add    $0x1,%rax
  add    %eax,%eax
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L84
  call   <__stack_chk_fail@plt>
L84:
  leave
  ret
```

tool_calls: name: extract_symbolic_data
arguments: data_label: D2
datatype: string

tool: 

assistant: ```c
int Tcl_ScanCountedElement(string, length, flagPtr) const char *string;
int length;
int *flagPtr;
{
  int flags, nestingLevel;
  const char *p, *lastChar;
  nestingLevel = 0;
  flags = 0;
  if (string == 0) {
    string = "";
  }
  if (length == -1) {
    length = strlen(string);
  }
  lastChar = string + length;
  p = string;
  if ((p == lastChar) || (*p == '{') || (*p == '"')) {
    flags |= 2;
  }
  for (; p != lastChar; p++) {
    switch (*p) {
    case '{':
      nestingLevel++;
      break;
    case '}':
      nestingLevel--;
      if (nestingLevel < 0) {
        flags |= 1 | 4;
      }
      break;
    case '[':
    case '$':
    case ';':
    case ' ':
    case '\f':
    case '\n':
    case '\r':
    case '\t':
    case '\v':
      flags |= 2;
      break;
    case '\\':
      if ((p + 1 == lastChar) || (p[1] == '\n')) {
        flags = 1 | 4;
      } else {
        int size;
        (void)Tcl_Backslash(p, &size);
        p += size - 1;
        flags |= 2;
      }
      break;
    }
  }
  if (nestingLevel != 0) {
    flags = 1 | 4;
  }
  *flagPtr = flags;
  return 2 * (p - string) + 2;
}
```