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

```asm
<dn_expand>:
  endbr64
  movslq %r8d,%r8
  push   %r15
  push   %r14
  push   %r13
  lea    (%rcx,%r8,4),%r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    (%rdx),%r8d
  mov    %rcx,%rbx
  test   %r8d,%r8d
  je     L152
  mov    %rdx,%r11
  lea    0x4(%rdx),%rax
  mov    %rsi,%rdx
  mov    %rdi,%rbp
  sub    %rdi,%rdx
  mov    %rsi,%r9
  xor    %r14d,%r14d
  mov    $0xffffffff,%r12d
  sar    $0x2,%rdx
  mov    %rdx,-0x8(%rsp)
  mov    %r11,%rdx
L17:
  mov    %r8d,%esi
  and    $0xc0,%esi
  je     L110
  cmp    $0xc0,%esi
  jne    L180
  test   %r12d,%r12d
  js     L98
L170:
  mov    %r8d,%eax
  movzbl 0x4(%rdx),%edx
  shl    $0x8,%eax
  and    $0x3f00,%eax
  or     %edx,%eax
  cltq
  lea    0x0(%rbp,%rax,4),%rdx
  cmp    %rdx,%rbp
  ja     L180
  cmp    %r9,%rdx
  jae    L180
  add    $0x2,%r14d
  movslq %r14d,%rax
  cmp    -0x8(%rsp),%rax
  jge    L180
L35:
  mov    (%rdx),%r8d
  lea    0x4(%rdx),%rax
  test   %r8d,%r8d
  jne    L17
  sub    %r11,%rax
  movl   $0x0,(%rcx)
  sar    $0x2,%rax
  test   %r12d,%r12d
  cmovs  %eax,%r12d
  jmp    L105
  xchg   %ax,%ax
L180:
  mov    $0xffffffff,%r12d
L105:
  pop    %rbx
  mov    %r12d,%eax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L110:
  cmp    %rcx,%rbx
  je     L195
  cmp    %rcx,%r13
  jbe    L180
  movl   $0x2e,(%rcx)
  lea    0x4(%rcx),%rdi
L33:
  movslq %r8d,%rdx
  shl    $0x2,%rdx
  lea    (%rdi,%rdx,1),%rcx
  cmp    %rcx,%r13
  jbe    L180
  mov    %r8d,%ecx
  lea    0x8(%rax,%rdx,1),%r10
  jmp    L106
  nopw   0x0(%rax,%rax,1)
L172:
  mov    %esi,(%rdx)
  lea    0x4(%rdx),%rdi
  cmp    %rax,%r9
  jbe    L180
L106:
  mov    %rax,%rdx
  lea    0x4(%rax),%rax
  mov    -0x4(%rax),%esi
  sub    $0x1,%ecx
  js     L177
  mov    %rdi,%rdx
  cmp    $0x2e,%esi
  jne    L172
  mov    %r10,%r15
  sub    %rax,%r15
  add    %rdi,%r15
  cmp    %r15,%r13
  jbe    L180
  movl   $0x5c,(%rdi)
  add    $0x4,%rdx
  jmp    L172
  nopl   0x0(%rax)
L98:
  sub    %r11,%rax
  sar    $0x2,%rax
  lea    0x1(%rax),%r12d
  jmp    L170
L177:
  lea    0x1(%r14,%r8,1),%r14d
  mov    %rdi,%rcx
  jmp    L35
  nopl   (%rax)
L195:
  mov    %rbx,%rdi
  jmp    L33
L152:
  movl   $0x0,(%rcx)
  mov    $0x1,%r12d
  jmp    L105
```

assistant: ```c
int dn_expand(u_char *msg, u_char *eomorig, u_char *comp_dn, u_char *exp_dn, int length) {
  u_char *cp, *dn;
  int n, c;
  u_char *eom;
  int len = -1, checked = 0;
  dn = exp_dn;
  cp = comp_dn;
  eom = exp_dn + length;
  while (n = *cp++) {
    switch (n & 0xc0) {
    case 0:
      if (dn != exp_dn) {
        if (dn >= eom)
          return (-1);
        *dn++ = '.';
      }
      if (dn + n >= eom)
        return (-1);
      checked += n + 1;
      while (--n >= 0) {
        if ((c = *cp++) == '.') {
          if (dn + n + 2 >= eom)
            return (-1);
          *dn++ = '\\';
        }
        *dn++ = c;
        if (cp >= eomorig)
          return (-1);
      }
      break;
    case 0xc0:
      if (len < 0)
        len = cp - comp_dn + 1;
      cp = msg + (((n & 0x3f) << 8) | (*cp & 0xff));
      if (cp < msg || cp >= eomorig)
        return (-1);
      checked += 2;
      if (checked >= eomorig - msg)
        return (-1);
      break;
    default:
      return (-1);
    }
  }
  *dn = '\0';
  if (len < 0)
    len = cp - comp_dn;
  return (len);
}
```