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

```asm
<ll2escaped>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %edx,-0x34(%rbp)
  mov    %rcx,-0x40(%rbp)
  mov    %r8d,-0x38(%rbp)
  mov    -0x30(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  cmpl   $0x0,-0x38(%rbp)
  jg     L246
  lea    D57(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xffffffff,%eax
  jmp    L173
L246:
  mov    -0x34(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x34(%rbp)
  test   %eax,%eax
  jne    L189
  lea    D47(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xfffffffe,%eax
  jmp    L173
L189:
  mov    -0x30(%rbp),%rax
  lea    0x4(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    (%rax),%eax
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x0,-0x1c(%rbp)
  je     L231
  mov    -0x1c(%rbp),%eax
  and    $0xc0,%eax
  cmp    $0xc0,%eax
  jne    L193
  cmpq   $0x0,-0x28(%rbp)
  jne    L79
  mov    $0xfffffffd,%eax
  jmp    L173
L79:
  mov    -0x34(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x34(%rbp)
  test   %eax,%eax
  jne    L34
  lea    D47(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xfffffffe,%eax
  jmp    L173
L34:
  mov    -0x30(%rbp),%rax
  lea    0x4(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    (%rax),%eax
  mov    %eax,-0x14(%rbp)
  mov    -0x1c(%rbp),%eax
  cltd
  shr    $0x1a,%edx
  add    %edx,%eax
  and    $0x3f,%eax
  sub    %edx,%eax
  shl    $0x8,%eax
  movslq %eax,%rdx
  mov    -0x14(%rbp),%eax
  cltq
  add    %rdx,%rax
  lea    0x0(,%rax,4),%rdx
  mov    -0x28(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  mov    -0x34(%rbp),%eax
  cltq
  lea    0x0(,%rax,4),%rdx
  mov    -0x30(%rbp),%rax
  add    %rdx,%rax
  sub    -0x8(%rbp),%rax
  sar    $0x2,%rax
  mov    %eax,%edi
  mov    -0x38(%rbp),%ecx
  mov    -0x40(%rbp),%rdx
  mov    -0x8(%rbp),%rsi
  mov    -0x28(%rbp),%rax
  mov    %ecx,%r8d
  mov    %rdx,%rcx
  mov    %edi,%edx
  mov    %rax,%rdi
  call   <ll2escaped>
  mov    %eax,-0x18(%rbp)
  cmpl   $0x0,-0x18(%rbp)
  jns    L16
  mov    -0x18(%rbp),%eax
  jmp    L173
L16:
  mov    -0x30(%rbp),%rax
  sub    -0x10(%rbp),%rax
  sar    $0x2,%rax
  jmp    L173
L193:
  mov    -0x1c(%rbp),%eax
  and    $0xc0,%eax
  test   %eax,%eax
  je     L45
  lea    D11(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xfffffffe,%eax
  jmp    L173
L45:
  mov    -0x1c(%rbp),%eax
  sub    %eax,-0x34(%rbp)
  cmpl   $0x0,-0x34(%rbp)
  jns    L150
  mov    -0x34(%rbp),%eax
  neg    %eax
  mov    %eax,%ecx
  mov    -0x1c(%rbp),%eax
  mov    %eax,%edx
  mov    %ecx,%esi
  lea    D60(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xfffffffe,%eax
  jmp    L173
L150:
  mov    -0x38(%rbp),%ecx
  mov    -0x40(%rbp),%rdx
  mov    -0x1c(%rbp),%esi
  mov    -0x30(%rbp),%rax
  mov    %rax,%rdi
  call   <l2escaped@plt>
  mov    %eax,-0x18(%rbp)
  cmpl   $0x0,-0x18(%rbp)
  jns    L242
  mov    -0x18(%rbp),%eax
  jmp    L173
L242:
  mov    -0x1c(%rbp),%eax
  cltq
  shl    $0x2,%rax
  add    %rax,-0x30(%rbp)
  mov    -0x18(%rbp),%eax
  cltq
  add    %rax,-0x40(%rbp)
  mov    -0x18(%rbp),%eax
  sub    %eax,-0x38(%rbp)
L231:
  cmpl   $0x0,-0x1c(%rbp)
  je     L117
  mov    -0x38(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x38(%rbp)
  test   %eax,%eax
  jne    L233
  mov    $0x2e,%esi
  lea    D56(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xffffffff,%eax
  jmp    L173
L233:
  mov    -0x40(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x40(%rbp)
  movb   $0x2e,(%rax)
  jmp    L246
L117:
  nop
  mov    -0x38(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x38(%rbp)
  test   %eax,%eax
  jne    L2
  mov    $0x0,%esi
  lea    D56(%rip),%rax
  mov    %rax,%rdi
  mov    $0x0,%eax
  call   <L_DEBUG@plt>
  mov    $0xffffffff,%eax
  jmp    L173
L2:
  mov    -0x40(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x40(%rbp)
  movb   $0x0,(%rax)
  mov    -0x30(%rbp),%rax
  sub    -0x10(%rbp),%rax
  sar    $0x2,%rax
L173:
  leave
  ret
```

tool_calls: name: unpack_data
arguments: data_tag: D57
data_type: string
name: unpack_data
arguments: data_tag: D47
data_type: string
name: unpack_data
arguments: data_tag: D11
data_type: string
name: unpack_data
arguments: data_tag: D60
data_type: string
name: unpack_data
arguments: data_tag: D56
data_type: string

tool: D57: no output string available

tool: D47: out of input string (before last null label)

tool: D11: high-order bits set in length

tool: D60: %d/%d bytes of label body missing

tool: D56: out of space in escaped pushing %d

assistant: ```c
int ll2escaped(const uint8_t *base, const uint8_t *ll, int ll_left, char *escaped, int escaped_left) {
  const uint8_t *oll = ll;
  int r;
  if (escaped_left <= 0) {
    L_DEBUG("no output string available");
    return -1;
  }
  while (1) {
    if (!ll_left--) {
      L_DEBUG("out of input string (before last null label)");
      return -2;
    }
    uint8_t c = *(ll++);
    if (c) {
      if ((c & (64 | 128)) == (64 | 128)) {
        if (!base)
          return -3;
        if (!ll_left--) {
          L_DEBUG("out of input string (before last null label)");
          return -2;
        }
        uint8_t c2 = *(ll++);
        const uint8_t *nofs = base + ((c % 64) << 8) + c2;
        r = ll2escaped(base, nofs, ll + ll_left - nofs, escaped, escaped_left);
        if (r < 0)
          return r;
        return ll - oll;
      }
      if (c & (64 | 128)) {
        L_DEBUG("high-order bits set in length");
        return -2;
      }
      ll_left -= c;
      if (ll_left < 0) {
        L_DEBUG("%d/%d bytes of label body missing", -ll_left, c);
        return -2;
      }
      r = l2escaped(ll, c, escaped, escaped_left);
      if (r < 0)
        return r;
      ll += c;
      escaped += r;
      escaped_left -= r;
    }
    if (!c)
      break;
    do {
      if (!escaped_left--) {
        L_DEBUG("out of space in escaped pushing %d", '.');
        return -1;
      }
      *(escaped++) = '.';
    } while (0);
  }
  do {
    if (!escaped_left--) {
      L_DEBUG("out of space in escaped pushing %d", 0);
      return -1;
    }
    *(escaped++) = 0;
  } while (0);
  return ll - oll;
}
```