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

```asm
<tidy_path>:
  endbr64
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  mov    %rdi,%rbp
  call   <strlen@plt>
  cltq
  lea    -0x1(%rbp,%rax,1),%rax
  cmpb   $0x2f,(%rax)
  je     L67
  movb   $0x2f,0x1(%rax)
  movb   $0x0,0x2(%rax)
L67:
  mov    $0x0,%ebx
  lea    D24(%rip),%r13
  lea    D21(%rip),%r12
  mov    $0x1,%r14d
  jmp    L127
L194:
  mov    %r14d,%ebx
L127:
  mov    %r13,%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <substr@plt>
  test   %rax,%rax
  jne    L194
  lea    D24(%rip),%r13
  lea    D4(%rip),%r12
  mov    $0x1,%r14d
  jmp    L49
L32:
  mov    %r14d,%ebx
L49:
  mov    %r13,%rdx
  mov    %r12,%rsi
  mov    %rbp,%rdi
  call   <substr@plt>
  test   %rax,%rax
  jne    L32
  lea    D5(%rip),%r13
  mov    $0x1,%r12d
  jmp    L74
L12:
  mov    $0x0,%ecx
L83:
  movzbl 0x3(%rax,%rcx,1),%esi
  mov    %sil,(%rdx,%rcx,1)
  add    $0x1,%rcx
  mov    %r12d,%ebx
  test   %sil,%sil
  jne    L83
L74:
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <strstr@plt>
  test   %rax,%rax
  je     L152
  lea    -0x1(%rax),%rdx
  cmp    %rdx,%rbp
  je     L207
L137:
  cmpb   $0x2f,(%rdx)
  je     L12
  sub    $0x1,%rdx
  cmp    %rdx,%rbp
  jne    L137
L207:
  cmpb   $0x2f,(%rdx)
  je     L12
L152:
  cmpb   $0x0,0x0(%rbp)
  je     L63
L210:
  mov    %rbp,%rdi
  call   <strlen@plt>
  cltq
  lea    -0x1(%rbp,%rax,1),%rdx
  cmp    %rdx,%rbp
  je     L29
  mov    %rdx,%rax
  cmpb   $0x2f,(%rdx)
  jne    L168
  lea    -0x1(%rdx),%rax
  movb   $0x0,(%rdx)
  cmp    %rax,%rbp
  je     L29
L168:
  mov    $0x1,%edx
L111:
  cmpb   $0x2f,(%rax)
  jne    L29
  sub    $0x1,%rax
  movb   $0x0,0x1(%rax)
  mov    %edx,%ebx
  cmp    %rax,%rbp
  jne    L111
  mov    $0x1,%ebx
L29:
  lea    D9(%rip),%r13
  mov    $0x1,%r12d
  jmp    L124
L63:
  lea    D24(%rip),%rsi
  mov    %rbp,%rdi
  call   <strcpy@plt>
  jmp    L210
L165:
  lea    0x2(%rbp),%rax
L84:
  add    $0x1,%rax
  movzbl -0x1(%rax),%edx
  mov    %dl,-0x3(%rax)
  mov    %r12d,%ebx
  test   %dl,%dl
  jne    L84
L124:
  mov    $0x2,%edx
  mov    %r13,%rsi
  mov    %rbp,%rdi
  call   <strncmp@plt>
  test   %eax,%eax
  je     L165
  mov    %ebx,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  ret
```

tool_calls: name: unpack_data
arguments: data_label: D24
datatype: string
name: unpack_data
arguments: data_label: D21
datatype: string
name: unpack_data
arguments: data_label: D4
datatype: string
name: unpack_data
arguments: data_label: D5
datatype: string
name: unpack_data
arguments: data_label: D9
datatype: string

tool: D24: /

tool: D21: /./

tool: D4: //

tool: D5: /../

tool: D9: ./

assistant: ```c
int tidy_path(char *path) {
  int tidied = 0;
  char *s, *p;
  s = path + strlen(path) - 1;
  if (s[0] != '/') {
    s[1] = '/';
    s[2] = '\0';
  }
  while (substr(path, "/./", "/"))
    tidied = 1;
  while (substr(path, "//", "/"))
    tidied = 1;
  while ((p = strstr(path, "/../")) != NULL) {
    s = p + 3;
    for (p--; p != path; p--)
      if (*p == '/')
        break;
    if (*p != '/')
      break;
    while ((*p++ = *s++))
      ;
    tidied = 1;
  }
  if (*path == '\0')
    strcpy(path, "/");
  p = path + strlen(path) - 1;
  if (p != path && *p == '/')
    *p-- = '\0';
  while (p != path && *p == '/') {
    *p-- = '\0';
    tidied = 1;
  }
  while (!strncmp(path, "./", 2)) {
    for (p = path, s = path + 2; (*p++ = *s++);)
      ;
    tidied = 1;
  }
  return tidied;
}
```