user: 请从给定的汇编指令推导出C源代码：

```asm
<canonicalize>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbx
  sub    $0x28,%rsp
  mov    D58(%rip),%r13
  mov    %fs:0x28,%rax
  mov    %rax,-0x38(%rbp)
  xor    %eax,%eax
  cmp    %edx,0x0(%r13)
  jg     L252
  mov    %rdi,%r14
  mov    %rsi,%r12
  mov    %edx,%ebx
  call   <strlen@plt>
  cmp    0x0(%r13),%eax
  jg     L56
  mov    %r12,%rsi
  mov    %r14,%rdi
  call   <realpath@plt>
  test   %rax,%rax
  je     L123
  mov    %r12,%rdi
  call   <collapse@plt>
  xor    %eax,%eax
L53:
  mov    -0x38(%rbp),%rdx
  sub    %fs:0x28,%rdx
  jne    L143
  lea    -0x28(%rbp),%rsp
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  pop    %rbp
  ret
  nopl   0x0(%rax,%rax,1)
L123:
  mov    0x0(%r13),%edx
  mov    %rsp,%rsi
  mov    %rsp,-0x50(%rbp)
  lea    0x1(%rdx),%eax
  cltq
  add    $0xf,%rax
  mov    %rax,%rcx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rsi
  and    $0xfffffffffffffff0,%rcx
  cmp    %rsi,%rsp
  je     L20
L121:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rsi,%rsp
  jne    L121
L20:
  and    $0xfff,%ecx
  sub    %rcx,%rsp
  test   %rcx,%rcx
  je     L183
  orq    $0x0,-0x8(%rsp,%rcx,1)
L183:
  mov    %r14,%rsi
  mov    %rsp,%rdi
  mov    %rsp,%r15
  call   <strncpy@plt>
  movslq 0x0(%r13),%rax
  mov    %rsp,%rdi
  movb   $0x0,(%rsp,%rax,1)
  call   <strlen@plt>
  movslq %eax,%r13
  lea    (%rsp,%r13,1),%rax
  mov    %rax,-0x48(%rbp)
  mov    %rax,%r13
  cmp    %rax,%rsp
  jb     L3
  jmp    L168
  nopl   0x0(%rax,%rax,1)
L96:
  cmpb   $0x2f,0x0(%r13)
  je     L87
L3:
  mov    %r13,%r14
  sub    $0x1,%r13
  cmp    %r13,%r15
  jb     L96
  je     L168
L87:
  movb   $0x0,0x0(%r13)
  mov    %r12,%rsi
  mov    %r15,%rdi
  call   <realpath@plt>
  cmp    %r13,-0x48(%rbp)
  mov    $0x0,%ecx
  mov    %rax,%r10
  mov    $0x2f,%eax
  cmove  %ecx,%eax
  mov    %al,0x0(%r13)
  test   %r10,%r10
  jne    L115
  mov    D40(%rip),%rax
  mov    D31(%rip),%rdx
  mov    (%rax),%rax
  cmp    (%rdx),%rax
  je     L231
  mov    D26(%rip),%rdx
  cmp    (%rdx),%rax
  je     L231
  mov    D59(%rip),%rdx
  cmp    (%rdx),%rax
  je     L231
  mov    $0xffffffff,%eax
L11:
  mov    -0x50(%rbp),%rsp
  jmp    L53
  xchg   %ax,%ax
L231:
  cmp    %r13,%r15
  jb     L3
L168:
  mov    %r15,%rsi
  mov    %r12,%rdi
  call   <strcpy@plt>
  mov    %r12,%rdi
  call   <collapse@plt>
  xor    %eax,%eax
  jmp    L11
L115:
  mov    %r10,%rdi
  mov    %r10,-0x48(%rbp)
  call   <strlen@plt>
  mov    %r13,%rdi
  mov    %eax,%r12d
  call   <strlen@plt>
  add    %r12d,%eax
  cmp    %ebx,%eax
  jge    L37
  mov    -0x48(%rbp),%r10
  movslq %r12d,%rax
  test   %r12d,%r12d
  jle    L204
  cmpb   $0x2f,-0x1(%r10,%rax,1)
  jne    L204
  cmpb   $0x2f,0x0(%r13)
  cmove  %r14,%r13
L204:
  lea    (%r10,%rax,1),%rdi
  mov    %r13,%rsi
  mov    %r10,-0x48(%rbp)
  call   <strcpy@plt>
  mov    -0x48(%rbp),%rdi
  call   <collapse@plt>
  xor    %eax,%eax
  jmp    L11
L37:
  mov    D30(%rip),%rax
  mov    (%rax),%rdx
  mov    D40(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L11
L252:
  mov    D67(%rip),%rax
  mov    (%rax),%rdx
  mov    D40(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L53
L56:
  mov    D30(%rip),%rax
  mov    (%rax),%rdx
  mov    D40(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0xffffffff,%eax
  jmp    L53
L143:
  call   <__stack_chk_fail@plt>
```

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;
    }
  }
}
```