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

```asm
<decode_bitstring>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x18,%rsp
  mov    (%rdi),%r14
  mov    %rdi,(%rsp)
  movzbl (%r14),%r12d
  test   %r12d,%r12d
  je     L149
  lea    0x3(%r12),%eax
  sar    $0x2,%eax
  cmp    $0x63,%r12d
  jg     L107
  lea    0x7(%rax),%ecx
  add    $0x8,%eax
  cmp    $0x9,%r12d
  cmovle %rcx,%rax
  jmp    L102
  nopw   0x0(%rax,%rax,1)
L149:
  mov    $0x49,%eax
  mov    $0x100,%r12d
L102:
  add    %rbx,%rax
  cmp    %rax,%rdx
  jbe    L93
  xor    %eax,%eax
  lea    D3(%rip),%rsi
  mov    %rbx,%rdi
  add    $0x1,%r14
  call   <sprintf@plt>
  test   %eax,%eax
  js     L93
  cltq
  mov    %r12d,%r15d
  lea    (%rbx,%rax,1),%r13
  cmp    $0x7,%r12d
  jle    L1
  lea    D5(%rip),%rbp
  jmp    L136
  nopl   0x0(%rax,%rax,1)
L143:
  cltq
  sub    $0x8,%r15d
  add    $0x1,%r14
  add    %rax,%r13
  cmp    $0x7,%r15d
  jle    L30
L136:
  movzbl (%r14),%edx
  xor    %eax,%eax
  mov    %rbp,%rsi
  mov    %r13,%rdi
  call   <sprintf@plt>
  test   %eax,%eax
  jns    L143
L93:
  add    $0x18,%rsp
  mov    $0xffffffff,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L30:
  cmp    $0x4,%r15d
  jg     L111
  test   %r15d,%r15d
  jne    L36
L122:
  xor    %eax,%eax
  mov    %r12d,%edx
  lea    D0(%rip),%rsi
  mov    %r13,%rdi
  call   <sprintf@plt>
  test   %eax,%eax
  js     L93
  mov    (%rsp),%rcx
  add    %r13d,%eax
  sub    %ebx,%eax
  mov    %r14,(%rcx)
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopw   0x0(%rax,%rax,1)
L107:
  add    $0x9,%eax
  jmp    L102
L1:
  cmp    $0x4,%r12d
  jle    L36
  lea    D5(%rip),%rbp
  nopl   (%rax)
L111:
  lea    0x1(%r14),%rax
  mov    $0x8,%ecx
  mov    %rbp,%rsi
  mov    %r13,%rdi
  sub    %r15d,%ecx
  mov    %rax,0x8(%rsp)
  mov    $0xff,%edx
  movsbl (%r14),%eax
  shl    %cl,%edx
  and    %eax,%edx
  xor    %eax,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L93
  cltq
  mov    0x8(%rsp),%r14
  add    %rax,%r13
  jmp    L122
  nopw   0x0(%rax,%rax,1)
L36:
  movzbl (%r14),%edx
  mov    $0x4,%ecx
  mov    %r13,%rdi
  lea    0x1(%r14),%rbp
  sub    %r15d,%ecx
  mov    $0xf,%eax
  lea    D17(%rip),%rsi
  shr    $0x4,%dl
  shl    %cl,%eax
  movzbl %dl,%edx
  and    %eax,%edx
  xor    %eax,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L93
  cltq
  mov    %rbp,%r14
  add    %rax,%r13
  jmp    L122
```

tool_calls: name: disassemble_data
arguments: label: D3
type_guessed: string
name: disassemble_data
arguments: label: D5
type_guessed: string
name: disassemble_data
arguments: label: D0
type_guessed: string
name: disassemble_data
arguments: label: D17
type_guessed: string

tool: D3: \[x

tool: D5: %02x

tool: D0: /%d]

tool: D17: %1x

assistant: ```c
int decode_bitstring(const unsigned char **cpp, char *dn, const char *eom) {
  const unsigned char *cp = *cpp;
  char *beg = dn, tc;
  int b, blen, plen, i;
  if ((blen = (*cp & 0xff)) == 0)
    blen = 256;
  plen = (blen + 3) / 4;
  plen += sizeof("\\[x/]") + (blen > 99 ? 3 : (blen > 9) ? 2 : 1);
  if (dn + plen >= eom)
    return (-1);
  cp++;
  i = ((size_t)sprintf(dn, "\\[x"));
  if (i < 0)
    return (-1);
  dn += i;
  for (b = blen; b > 7; b -= 8, cp++) {
    i = ((size_t)sprintf(dn, "%02x", *cp & 0xff));
    if (i < 0)
      return (-1);
    dn += i;
  }
  if (b > 4) {
    tc = *cp++;
    i = ((size_t)sprintf(dn, "%02x", tc & (0xff << (8 - b))));
    if (i < 0)
      return (-1);
    dn += i;
  } else if (b > 0) {
    tc = *cp++;
    i = ((size_t)sprintf(dn, "%1x", ((tc >> 4) & 0x0f) & (0x0f << (4 - b))));
    if (i < 0)
      return (-1);
    dn += i;
  }
  i = ((size_t)sprintf(dn, "/%d]", blen));
  if (i < 0)
    return (-1);
  dn += i;
  *cpp = cp;
  return (dn - beg);
}
```