user: Converte this assembly snippet into its equivalent C code:

```asm
<xmlEncodeCdata>:
  endbr64
  push   %rbp
  push   %rbx
  lea    D2(%rip),%rbx
  lea    0x9(%rbx),%r11
  mov    %rbx,%rax
L81:
  test   %esi,%esi
  je     L328
  movzbl (%rax),%r8d
  sub    $0x1,%esi
  add    $0x1,%rdi
  mov    %r8b,-0x1(%rdi)
L771:
  add    $0x1,%rax
  cmp    %rax,%r11
  jne    L81
  lea    -0x1(%rcx),%r9d
  test   %ecx,%ecx
  je     L594
L717:
  mov    $0x9,%r8d
  mov    $0xffffd9ff,%r10d
L687:
  movzbl (%rdx),%eax
  cmp    $0x5d,%al
  je     L394
  ja     L510
  cmp    $0x1f,%al
  ja     L450
  bt     %rax,%r10
  jae    L450
L427:
  mov    $0xffffffff,%eax
L499:
  pop    %rbx
  pop    %rbp
  ret
  nop
L328:
  add    $0x1,%rax
  cmp    %rax,%r11
  jne    L771
  lea    -0x1(%rcx),%r9d
  test   %ecx,%ecx
  jne    L717
  mov    $0x9,%r8d
  jmp    L399
  nopl   0x0(%rax)
L510:
  cmp    $0x7f,%al
  je     L427
  test   %al,%al
  jns    L450
  test   %r9d,%r9d
  je     L427
  mov    %eax,%ebp
  and    $0xffffffe0,%ebp
  cmp    $0xc0,%bpl
  je     L59
  cmp    $0x1,%r9d
  je     L427
  mov    %eax,%ebp
  and    $0xfffffff0,%ebp
  cmp    $0xe0,%bpl
  je     L390
  cmp    $0x2,%r9d
  jbe    L749
  mov    %eax,%ebp
  and    $0xfffffff8,%ebp
  cmp    $0xf0,%bpl
  jne    L749
  movzbl 0x1(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x2(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x3(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  cmp    $0x3,%esi
  jbe    L555
  mov    %al,(%rdi)
  movzbl 0x1(%rdx),%eax
  sub    $0x4,%esi
  add    $0x4,%rdx
  add    $0x4,%rdi
  mov    %al,-0x3(%rdi)
  movzbl -0x2(%rdx),%eax
  mov    %al,-0x2(%rdi)
  movzbl -0x1(%rdx),%eax
  mov    %al,-0x1(%rdi)
L600:
  add    $0x4,%r8d
  sub    $0x4,%ecx
  jmp    L753
  nopl   0x0(%rax,%rax,1)
L394:
  cmp    $0x1,%r9d
  jbe    L725
  cmpb   $0x5d,0x1(%rdx)
  je     L492
L725:
  test   %esi,%esi
  jne    L211
L774:
  add    $0x1,%rdx
  add    $0x1,%r8d
  mov    %r9d,%ecx
L753:
  lea    -0x1(%rcx),%r9d
  test   %ecx,%ecx
  jne    L687
L308:
  test   %esi,%esi
  je     L399
  movb   $0x5d,(%rdi)
  cmp    $0x1,%esi
  je     L399
  movb   $0x5d,0x1(%rdi)
  cmp    $0x2,%esi
  je     L399
  movb   $0x3e,0x2(%rdi)
L399:
  lea    0x3(%r8),%eax
  jmp    L499
  nopl   0x0(%rax)
L450:
  add    $0x1,%rdx
  test   %esi,%esi
  je     L363
  mov    %al,(%rdi)
  sub    $0x1,%esi
  add    $0x1,%rdi
L363:
  add    $0x1,%r8d
  mov    %r9d,%ecx
  jmp    L753
  nopw   0x0(%rax,%rax,1)
L211:
  movb   $0x5d,(%rdi)
  sub    $0x1,%esi
  add    $0x1,%rdi
  jmp    L774
  nopl   0x0(%rax)
L492:
  cmpb   $0x3e,0x2(%rdx)
  jne    L725
  test   %esi,%esi
  jne    L743
  lea    0x2(%r8),%eax
  mov    %rdi,%r9
L596:
  xor    %esi,%esi
L509:
  mov    %rbx,%rdi
L188:
  test   %esi,%esi
  je     L184
  movzbl (%rdi),%ebp
  sub    $0x1,%esi
  add    $0x1,%r9
  mov    %bpl,-0x1(%r9)
L348:
  add    $0x1,%rdi
  cmp    %rdi,%r11
  jne    L188
  add    $0xb,%eax
  test   %esi,%esi
  je     L436
  movzbl 0x2(%rdx),%r8d
  lea    0x1(%r9),%rdi
  sub    $0x1,%esi
  mov    %r8b,(%r9)
L422:
  add    $0x3,%rdx
  lea    0x2(%rax),%r8d
  sub    $0x3,%ecx
  jmp    L753
L59:
  movzbl 0x1(%rdx),%ebp
  and    $0xffffffc0,%ebp
  cmp    $0x80,%bpl
  je     L454
  nopl   0x0(%rax)
L749:
  cmp    $0x3,%r9d
  jbe    L579
  mov    %eax,%ebp
  and    $0xfffffffc,%ebp
  cmp    $0xf8,%bpl
  jne    L579
  movzbl 0x1(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x2(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x3(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x4(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  cmp    $0x4,%esi
  jbe    L619
  mov    %al,(%rdi)
  movzbl 0x1(%rdx),%eax
  sub    $0x5,%esi
  add    $0x5,%rdx
  add    $0x5,%rdi
  mov    %al,-0x4(%rdi)
  movzbl -0x3(%rdx),%eax
  mov    %al,-0x3(%rdi)
  movzbl -0x2(%rdx),%eax
  mov    %al,-0x2(%rdi)
  movzbl -0x1(%rdx),%eax
  mov    %al,-0x1(%rdi)
L642:
  add    $0x5,%r8d
  sub    $0x5,%ecx
  jmp    L753
  nopl   0x0(%rax,%rax,1)
L390:
  movzbl 0x1(%rdx),%ebp
  and    $0xffffffc0,%ebp
  cmp    $0x80,%bpl
  je     L426
L579:
  cmp    $0x4,%r9d
  jbe    L427
  mov    %eax,%r9d
  and    $0xfffffffe,%r9d
  cmp    $0xfc,%r9b
  jne    L427
  movzbl 0x1(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x2(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x3(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x4(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  movzbl 0x5(%rdx),%r9d
  and    $0xffffffc0,%r9d
  cmp    $0x80,%r9b
  jne    L427
  cmp    $0x5,%esi
  jbe    L512
  mov    %al,(%rdi)
  movzbl 0x1(%rdx),%eax
  sub    $0x6,%esi
  add    $0x6,%rdx
  add    $0x6,%rdi
  mov    %al,-0x5(%rdi)
  movzbl -0x4(%rdx),%eax
  mov    %al,-0x4(%rdi)
  movzbl -0x3(%rdx),%eax
  mov    %al,-0x3(%rdi)
  movzbl -0x2(%rdx),%eax
  mov    %al,-0x2(%rdi)
  movzbl -0x1(%rdx),%eax
  mov    %al,-0x1(%rdi)
L615:
  add    $0x6,%r8d
  sub    $0x6,%ecx
  jmp    L753
  nopl   0x0(%rax)
L512:
  add    $0x6,%rdx
  jmp    L615
L426:
  movzbl 0x2(%rdx),%ebp
  and    $0xffffffc0,%ebp
  cmp    $0x80,%bpl
  jne    L579
  cmp    $0x2,%esi
  jbe    L755
  mov    %al,(%rdi)
  movzbl 0x1(%rdx),%eax
  sub    $0x3,%esi
  add    $0x3,%rdx
  add    $0x3,%rdi
  mov    %al,-0x2(%rdi)
  movzbl -0x1(%rdx),%eax
  mov    %al,-0x1(%rdi)
L751:
  add    $0x3,%r8d
  sub    $0x3,%ecx
  jmp    L753
L454:
  cmp    $0x1,%esi
  jbe    L673
  mov    %al,(%rdi)
  movzbl 0x1(%rdx),%eax
  sub    $0x2,%esi
  add    $0x2,%rdx
  add    $0x2,%rdi
  mov    %al,-0x1(%rdi)
L371:
  add    $0x2,%r8d
  sub    $0x2,%ecx
  jmp    L753
L594:
  mov    $0x9,%r8d
  jmp    L308
  nopl   0x0(%rax,%rax,1)
L184:
  add    $0x1,%rdi
  cmp    %rdi,%r11
  jne    L348
  add    $0xb,%eax
  mov    %r9,%rdi
  jmp    L422
L743:
  movb   $0x5d,(%rdi)
  lea    0x1(%rdi),%r9
  lea    0x2(%r8),%eax
  cmp    $0x1,%esi
  je     L596
  movzbl 0x1(%rdx),%eax
  lea    0x2(%rdi),%r9
  mov    %al,0x1(%rdi)
  lea    0x2(%r8),%eax
  cmp    $0x2,%esi
  je     L596
  movb   $0x5d,0x2(%rdi)
  lea    0x3(%rdi),%r9
  cmp    $0x3,%esi
  je     L596
  movb   $0x5d,0x3(%rdi)
  lea    0x4(%rdi),%r9
  cmp    $0x4,%esi
  je     L596
  movb   $0x3e,0x4(%rdi)
  lea    0x5(%rdi),%r9
  sub    $0x5,%esi
  jmp    L509
L673:
  add    $0x2,%rdx
  jmp    L371
L755:
  add    $0x3,%rdx
  jmp    L751
L555:
  add    $0x4,%rdx
  jmp    L600
L619:
  add    $0x5,%rdx
  jmp    L642
L436:
  mov    %r9,%rdi
  jmp    L422
```

tool_calls: name: parse_data
arguments: tag: D2
type_infered: string

tool: D2: <![CDATA[

assistant: ```c
int xmlEncodeCdata(unsigned char *out, unsigned int olen, const unsigned char *in, unsigned int ilen) {
  static const char b[] = "<![CDATA[";
  static const char e[] = "]]>";
  int len;
  unsigned int i;
  len = 0;
  for (i = 0; i < sizeof(b) - 1; i++, len++)
    if (olen > 0) {
      *out++ = b[i];
      olen--;
    }
  for (; ilen--;)
    switch (*in) {
    case 0x00:
    case 0x01:
    case 0x02:
    case 0x03:
    case 0x04:
    case 0x05:
    case 0x06:
    case 0x07:
    case 0x08:
    case 0x0b:
    case 0x0c:
    case 0x0e:
    case 0x0f:
    case 0x10:
    case 0x11:
    case 0x12:
    case 0x13:
    case 0x14:
    case 0x15:
    case 0x16:
    case 0x17:
    case 0x18:
    case 0x19:
    case 0x1a:
    case 0x1b:
    case 0x1c:
    case 0x1d:
    case 0x1e:
    case 0x1f:
    case 0x7f:
      return (-1);
      break;
    case ']':
      if (ilen > 1 && *(in + 1) == ']' && *(in + 2) == '>') {
        if (olen > 0) {
          *out++ = *in;
          olen--;
        }
        in++, len++;
        if (olen > 0) {
          *out++ = *in;
          olen--;
        }
        in++, len++;
        for (i = 0; i < sizeof(e) - 1; i++, len++)
          if (olen > 0) {
            *out++ = e[i];
            olen--;
          }
        for (i = 0; i < sizeof(b) - 1; i++, len++)
          if (olen > 0) {
            *out++ = b[i];
            olen--;
          }
        if (olen > 0) {
          *out++ = *in;
          olen--;
        }
        in++, len++;
        ilen -= 2;
      } else {
        if (olen > 0) {
          *out++ = *in;
          olen--;
        }
        in++, len++;
      }
      break;
    default:
      if ((*in & 0x80) == 0x00) {
        if (olen > 0) {
          *out++ = *in++;
          olen--;
        } else
          in++;
        len++;
      } else if (ilen > 0 && (*in & 0xe0) == 0xc0 && (*(in + 1) & 0xc0) == 0x80) {
        if (olen > 1) {
          *out++ = *in++;
          *out++ = *in++;
          olen -= 2;
        } else
          in += 2;
        len += 2;
        ilen--;
      } else if (ilen > 1 && (*in & 0xf0) == 0xe0 && (*(in + 1) & 0xc0) == 0x80 && (*(in + 2) & 0xc0) == 0x80) {
        if (olen > 2) {
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          olen -= 3;
        } else
          in += 3;
        len += 3;
        ilen -= 2;
      } else if (ilen > 2 && (*in & 0xf8) == 0xf0 && (*(in + 1) & 0xc0) == 0x80 && (*(in + 2) & 0xc0) == 0x80 && (*(in + 3) & 0xc0) == 0x80) {
        if (olen > 3) {
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          olen -= 4;
        } else
          in += 4;
        len += 4;
        ilen -= 3;
      } else if (ilen > 3 && (*in & 0xfc) == 0xf8 && (*(in + 1) & 0xc0) == 0x80 && (*(in + 2) & 0xc0) == 0x80 && (*(in + 3) & 0xc0) == 0x80 && (*(in + 4) & 0xc0) == 0x80) {
        if (olen > 4) {
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          olen -= 5;
        } else
          in += 5;
        len += 5;
        ilen -= 4;
      } else if (ilen > 4 && (*in & 0xfe) == 0xfc && (*(in + 1) & 0xc0) == 0x80 && (*(in + 2) & 0xc0) == 0x80 && (*(in + 3) & 0xc0) == 0x80 && (*(in + 4) & 0xc0) == 0x80 && (*(in + 5) & 0xc0) == 0x80) {
        if (olen > 5) {
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          *out++ = *in++;
          olen -= 6;
        } else
          in += 6;
        len += 6;
        ilen -= 5;
      } else
        return (-1);
      break;
    }
  for (i = 0; i < sizeof(e) - 1; i++, len++)
    if (olen > 0) {
      *out++ = e[i];
      olen--;
    }
  return (len);
}
```