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

```asm
<__dn_expand>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %rdx,-0x48(%rbp)
  mov    %rcx,-0x50(%rbp)
  mov    %r8d,-0x54(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x50(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  movl   $0xffffffff,-0x24(%rbp)
  mov    -0x18(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  je     L48
  cmpl   $0x0,-0x54(%rbp)
  jg     L126
L48:
  mov    $0xffffffff,%eax
  jmp    L160
L126:
  mov    -0x54(%rbp),%eax
  mov    $0xfe,%edx
  cmp    %edx,%eax
  cmovg  %edx,%eax
  movslq %eax,%rdx
  mov    -0x50(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x8(%rbp)
  movl   $0x0,-0x20(%rbp)
  jmp    L24
L40:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  and    $0xc0,%eax
  test   %eax,%eax
  je     L139
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  cmp    %rax,-0x40(%rbp)
  jne    L113
  mov    $0xffffffff,%eax
  jmp    L160
L113:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  shl    $0x8,%eax
  and    $0x3f00,%eax
  mov    %eax,%edx
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  movzbl %al,%eax
  or     %edx,%eax
  mov    %eax,-0x1c(%rbp)
  cmpl   $0x0,-0x24(%rbp)
  jns    L130
  mov    -0x18(%rbp),%rax
  add    $0x2,%rax
  sub    -0x48(%rbp),%rax
  mov    %eax,-0x24(%rbp)
L130:
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  sub    -0x38(%rbp),%rax
  cmp    %rax,%rdx
  jl     L91
  mov    $0xffffffff,%eax
  jmp    L160
L91:
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x38(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  jmp    L34
L139:
  mov    -0x18(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L33
  mov    -0x50(%rbp),%rax
  cmp    -0x10(%rbp),%rax
  je     L192
  mov    -0x50(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x50(%rbp)
  movb   $0x2e,(%rax)
L192:
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%eax
  movzbl %al,%eax
  mov    %eax,-0x1c(%rbp)
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  sub    -0x18(%rbp),%rax
  cmp    %rax,%rdx
  jge    L206
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x8(%rbp),%rax
  sub    -0x50(%rbp),%rax
  cmp    %rax,%rdx
  jl     L29
L206:
  mov    $0xffffffff,%eax
  jmp    L160
L80:
  mov    -0x18(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x18(%rbp)
  movzbl (%rax),%ecx
  mov    -0x50(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x50(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
L29:
  mov    -0x1c(%rbp),%eax
  lea    -0x1(%rax),%edx
  mov    %edx,-0x1c(%rbp)
  test   %eax,%eax
  jne    L80
  jmp    L34
L33:
  mov    -0x50(%rbp),%rax
  movb   $0x0,(%rax)
  cmpl   $0x0,-0x24(%rbp)
  jns    L179
  mov    -0x18(%rbp),%rax
  add    $0x1,%rax
  sub    -0x48(%rbp),%rax
  mov    %eax,-0x24(%rbp)
L179:
  mov    -0x24(%rbp),%eax
  jmp    L160
L34:
  addl   $0x2,-0x20(%rbp)
L24:
  mov    -0x20(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x40(%rbp),%rax
  sub    -0x38(%rbp),%rax
  cmp    %rax,%rdx
  jl     L40
  mov    $0xffffffff,%eax
L160:
  pop    %rbp
  ret
```

assistant: ```c
int __dn_expand(const unsigned char *base, const unsigned char *end, const unsigned char *src, char *dest, int space) {
  const unsigned char *p = src;
  char *dend, *dbegin = dest;
  int len = -1, i, j;
  if (p == end || space <= 0)
    return -1;
  dend = dest + (space > 254 ? 254 : space);
  for (i = 0; i < end - base; i += 2) {
    if (*p & 0xc0) {
      if (p + 1 == end)
        return -1;
      j = ((p[0] & 0x3f) << 8) | p[1];
      if (len < 0)
        len = p + 2 - src;
      if (j >= end - base)
        return -1;
      p = base + j;
    } else if (*p) {
      if (dest != dbegin)
        *dest++ = '.';
      j = *p++;
      if (j >= end - p || j >= dend - dest)
        return -1;
      while (j--)
        *dest++ = *p++;
    } else {
      *dest = 0;
      if (len < 0)
        len = p + 1 - src;
      return len;
    }
  }
  return -1;
}
```