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

```asm
<decode_bitstring>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x18,%rsp
  mov    %rdi,%r15
  mov    %rsi,0x8(%rsp)
  mov    (%rdi),%rbp
  movzbl 0x0(%rbp),%r14d
  test   %r14d,%r14d
  je     L28
  lea    0x3(%r14),%eax
  sar    $0x2,%eax
  cmp    $0x63,%r14d
  jg     L123
  cmp    $0x9,%r14d
  setg   %cl
  movzbl %cl,%ecx
  add    $0x7,%ecx
  jmp    L222
L28:
  mov    $0x40,%eax
  mov    $0x100,%r14d
  mov    $0x9,%ecx
L222:
  add    %ecx,%eax
  cltq
  mov    0x8(%rsp),%rbx
  add    %rbx,%rax
  cmp    %rax,%rdx
  jbe    L196
  add    $0x1,%rbp
  lea    D0(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L103
  cltq
  add    %rax,%rbx
  cmp    $0x7,%r14d
  jle    L66
  mov    %r14d,%r12d
  lea    D20(%rip),%r13
L162:
  movzbl 0x0(%rbp),%edx
  mov    %r13,%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L120
  cltq
  add    %rax,%rbx
  sub    $0x8,%r12d
  add    $0x1,%rbp
  cmp    $0x7,%r12d
  jg     L162
L129:
  cmp    $0x4,%r12d
  jg     L165
  test   %r12d,%r12d
  jg     L152
L23:
  mov    %r14d,%edx
  lea    D48(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L214
  mov    %rbp,(%r15)
  lea    (%rbx,%rax,1),%eax
  sub    0x8(%rsp),%eax
L121:
  add    $0x18,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L123:
  mov    $0x9,%ecx
  jmp    L222
L66:
  mov    %r14d,%r12d
  jmp    L129
L165:
  lea    0x1(%rbp),%r13
  mov    $0x8,%ecx
  sub    %r12d,%ecx
  mov    $0xff,%edx
  shl    %cl,%edx
  movsbl 0x0(%rbp),%eax
  and    %eax,%edx
  lea    D20(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L102
  cltq
  add    %rax,%rbx
  mov    %r13,%rbp
  jmp    L23
L152:
  lea    0x1(%rbp),%r13
  movzbl 0x0(%rbp),%edx
  shr    $0x4,%dl
  movsbl %dl,%edx
  mov    $0x4,%ecx
  sub    %r12d,%ecx
  mov    $0xf,%eax
  shl    %cl,%eax
  and    %eax,%edx
  lea    D18(%rip),%rsi
  mov    %rbx,%rdi
  mov    $0x0,%eax
  call   <sprintf@plt>
  test   %eax,%eax
  js     L69
  cltq
  add    %rax,%rbx
  mov    %r13,%rbp
  jmp    L23
L196:
  mov    $0xffffffff,%eax
  jmp    L121
L103:
  mov    $0xffffffff,%eax
  jmp    L121
L120:
  mov    $0xffffffff,%eax
  jmp    L121
L102:
  mov    $0xffffffff,%eax
  jmp    L121
L69:
  mov    $0xffffffff,%eax
  jmp    L121
L214:
  mov    $0xffffffff,%eax
  jmp    L121
```

tool_calls: name: unpack_data
arguments: data_label: D0
type_guessed: string
name: unpack_data
arguments: data_label: D20
type_guessed: string
name: unpack_data
arguments: data_label: D48
type_guessed: string
name: unpack_data
arguments: data_label: D18
type_guessed: string

tool: D0: \[x

tool: D20: %02x

tool: D48: /%d]

tool: D18: %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);
}
```