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

```asm
<canonicalize>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x78(%rbp)
  mov    %rsi,-0x80(%rbp)
  mov    %edx,-0x84(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  mov    D96(%rip),%rax
  mov    (%rax),%eax
  cmp    %eax,-0x84(%rbp)
  jge    L94
  mov    D89(%rip),%rax
  mov    (%rax),%rdx
  mov    D30(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L248
L94:
  mov    -0x78(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    D96(%rip),%rdx
  mov    (%rdx),%edx
  cmp    %edx,%eax
  jle    L51
  mov    D113(%rip),%rax
  mov    (%rax),%rdx
  mov    D30(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L248
L51:
  mov    -0x80(%rbp),%rdx
  mov    -0x78(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <realpath@plt>
  test   %rax,%rax
  je     L112
  mov    -0x80(%rbp),%rax
  mov    %rax,%rdi
  call   <collapse@plt>
  mov    $0x0,%eax
  jmp    L248
L112:
  mov    %rsp,%rax
  mov    %rax,%rbx
  movq   $0x0,-0x58(%rbp)
  mov    D96(%rip),%rax
  mov    (%rax),%eax
  add    $0x1,%eax
  movslq %eax,%rdx
  sub    $0x1,%rdx
  mov    %rdx,-0x50(%rbp)
  movslq %eax,%rdx
  mov    %rdx,%r14
  mov    $0x0,%r15d
  movslq %eax,%rdx
  mov    %rdx,%r12
  mov    $0x0,%r13d
  cltq
  mov    $0x10,%edx
  sub    $0x1,%rdx
  add    %rdx,%rax
  mov    $0x10,%esi
  mov    $0x0,%edx
  div    %rsi
  imul   $0x10,%rax,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rcx
  mov    %rsp,%rdx
  sub    %rcx,%rdx
L127:
  cmp    %rdx,%rsp
  je     L45
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  jmp    L127
L45:
  mov    %rax,%rdx
  and    $0xfff,%edx
  sub    %rdx,%rsp
  mov    %rax,%rdx
  and    $0xfff,%edx
  test   %rdx,%rdx
  je     L226
  and    $0xfff,%eax
  sub    $0x8,%rax
  add    %rsp,%rax
  orq    $0x0,(%rax)
L226:
  mov    %rsp,%rax
  add    $0x0,%rax
  mov    %rax,-0x48(%rbp)
  mov    D96(%rip),%rax
  mov    (%rax),%edx
  mov    -0x78(%rbp),%rcx
  mov    -0x48(%rbp),%rax
  mov    %rcx,%rsi
  mov    %rax,%rdi
  call   <strncpy@plt>
  mov    D96(%rip),%rax
  mov    (%rax),%eax
  mov    -0x48(%rbp),%rdx
  cltq
  movb   $0x0,(%rdx,%rax,1)
  mov    -0x48(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  movslq %eax,%rdx
  mov    -0x48(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x40(%rbp)
  mov    -0x40(%rbp),%rax
  mov    %rax,-0x60(%rbp)
  jmp    L202
L40:
  nop
L77:
  subq   $0x1,-0x60(%rbp)
  mov    -0x60(%rbp),%rax
  cmp    -0x48(%rbp),%rax
  jbe    L3
  mov    -0x60(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L77
L3:
  mov    -0x48(%rbp),%rax
  cmp    -0x60(%rbp),%rax
  je     L1
  mov    -0x60(%rbp),%rax
  movb   $0x0,(%rax)
  mov    -0x80(%rbp),%rdx
  mov    -0x48(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <realpath@plt>
  mov    %rax,-0x58(%rbp)
  mov    -0x60(%rbp),%rax
  cmp    -0x40(%rbp),%rax
  jne    L242
  mov    $0x0,%edx
  jmp    L251
L242:
  mov    $0x2f,%edx
L251:
  mov    -0x60(%rbp),%rax
  mov    %dl,(%rax)
  cmpq   $0x0,-0x58(%rbp)
  jne    L206
  mov    D30(%rip),%rax
  mov    (%rax),%rdx
  mov    D50(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L202
  mov    D30(%rip),%rax
  mov    (%rax),%rdx
  mov    D140(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L202
  mov    D30(%rip),%rax
  mov    (%rax),%rdx
  mov    D12(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  jne    L288
  jmp    L202
L288:
  mov    $0xffffffff,%eax
  jmp    L78
L202:
  mov    -0x48(%rbp),%rax
  cmp    -0x60(%rbp),%rax
  jb     L40
  jmp    L252
L1:
  nop
  jmp    L252
L206:
  nop
L252:
  cmpq   $0x0,-0x58(%rbp)
  je     L270
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    %eax,-0x64(%rbp)
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  mov    -0x64(%rbp),%edx
  add    %edx,%eax
  cmp    %eax,-0x84(%rbp)
  jg     L50
  mov    D113(%rip),%rax
  mov    (%rax),%rdx
  mov    D30(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L78
L50:
  cmpl   $0x0,-0x64(%rbp)
  jle    L290
  mov    -0x64(%rbp),%eax
  cltq
  lea    -0x1(%rax),%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L290
  mov    -0x60(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L290
  addq   $0x1,-0x60(%rbp)
L290:
  mov    -0x64(%rbp),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rax,%rdx
  mov    -0x60(%rbp),%rax
  mov    %rax,%rsi
  mov    %rdx,%rdi
  call   <strcpy@plt>
  mov    -0x58(%rbp),%rax
  mov    %rax,%rdi
  call   <collapse@plt>
  mov    $0x0,%eax
  jmp    L78
L270:
  mov    -0x48(%rbp),%rdx
  mov    -0x80(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <strcpy@plt>
  mov    -0x80(%rbp),%rax
  mov    %rax,%rdi
  call   <collapse@plt>
  mov    $0x0,%eax
L78:
  mov    %rbx,%rsp
L248:
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L58
  call   <__stack_chk_fail@plt>
L58:
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
```

assistant: ```c
int canonicalize(char *original, char *resolved, int len) {
  if (len < PATH_MAX) {
    errno = EINVAL;
    return -1;
  }
  if (strlen(original) > PATH_MAX) {
    errno = ENAMETOOLONG;
    return -1;
  }
  if (realpath(original, resolved)) {
    collapse(resolved);
    return 0;
  } else {
    char *p, *end, *r = NULL;
    char path[PATH_MAX + 1];
    strncpy(path, original, PATH_MAX);
    path[PATH_MAX] = '\0';
    end = path + strlen(path);
    for (p = end; p > path;) {
      while ((--p > path) && (*p != '/'))
        ;
      if (p == path)
        break;
      *p = '\0';
      r = realpath(path, resolved);
      *p = (p == end) ? '\0' : '/';
      if (r != NULL) {
        break;
      } else if (errno == ENOENT || errno == ENOTDIR || errno == EACCES) {
        continue;
      } else {
        return -1;
      }
    }
    if (r != NULL) {
      int rn = strlen(r);
      if (rn + (int)strlen(p) >= len) {
        errno = ENAMETOOLONG;
        return -1;
      }
      if ((rn > 0) && (r[rn - 1] == '/') && (*p == '/')) {
        p++;
      }
      strcpy(r + rn, p);
      collapse(r);
      return 0;
    } else {
      strcpy(resolved, path);
      collapse(resolved);
      return 0;
    }
  }
}
```