user: Converte this assembly snippet into its equivalent C code:

```asm
<path_within_dir>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r13
  push   %r12
  mov    %rdi,%r12
  push   %rbx
  sub    $0x18,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,-0x28(%rbp)
  xor    %eax,%eax
  test   %rdi,%rdi
  je     L124
  mov    D1(%rip),%rbx
  mov    %rsp,%rcx
  mov    %rsi,%rdi
  mov    (%rbx),%eax
  add    $0x1,%eax
  cltq
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L140
L137:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L137
L140:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L175
  mov    %rsp,%rsi
  mov    %rsp,%r13
  call   <realpath@plt>
  test   %rax,%rax
  je     L124
L15:
  cmpb   $0x2f,(%r12)
  jne    L201
  mov    %rsp,%rsi
  mov    %r12,%rdi
  call   <strstr@plt>
  cmp    %rax,%r12
  je     L201
L124:
  xor    %r13d,%r13d
L196:
  mov    -0x28(%rbp),%rax
  sub    %fs:0x28,%rax
  jne    L152
  lea    -0x18(%rbp),%rsp
  mov    %r13d,%eax
  pop    %rbx
  pop    %r12
  pop    %r13
  pop    %rbp
  ret
  nopw   0x0(%rax,%rax,1)
L201:
  mov    (%rbx),%eax
  mov    %rsp,%rcx
  add    $0x1,%eax
  cltq
  add    $0xf,%rax
  mov    %rax,%rdx
  and    $0xfffffffffffff000,%rax
  sub    %rax,%rcx
  and    $0xfffffffffffffff0,%rdx
  cmp    %rcx,%rsp
  je     L57
L122:
  sub    $0x1000,%rsp
  orq    $0x0,0xff8(%rsp)
  cmp    %rcx,%rsp
  jne    L122
L57:
  and    $0xfff,%edx
  sub    %rdx,%rsp
  test   %rdx,%rdx
  jne    L143
L114:
  mov    %r12,%rdi
  mov    %rsp,%rbx
  call   <xxstrdup@plt>
  mov    %rax,%r12
  jmp    L47
  nopw   0x0(%rax,%rax,1)
L170:
  movb   $0x0,(%rax)
  mov    %rbx,%rsi
  mov    %r12,%rdi
  call   <realpath@plt>
  test   %rax,%rax
  jne    L127
  mov    D10(%rip),%rax
  mov    D15(%rip),%rdx
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L28
L47:
  mov    $0x2f,%esi
  mov    %r12,%rdi
  call   <strrchr@plt>
  test   %rax,%rax
  jne    L170
  mov    $0x1,%r13d
L62:
  mov    %r12,%rdi
  call   <free@plt>
  jmp    L196
  xchg   %ax,%ax
L175:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  mov    %rsp,%rsi
  mov    %rsp,%r13
  call   <realpath@plt>
  test   %rax,%rax
  jne    L15
  jmp    L124
  nop
L127:
  mov    %r13,%rsi
  mov    %rbx,%rdi
  xor    %r13d,%r13d
  call   <strstr@plt>
  cmp    %rax,%rbx
  sete   %r13b
  jmp    L62
  nopw   0x0(%rax,%rax,1)
L28:
  xor    %r13d,%r13d
  jmp    L62
  nopl   (%rax)
L143:
  orq    $0x0,-0x8(%rsp,%rdx,1)
  jmp    L114
L152:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int path_within_dir(const char *path, const char *dir) {
  if (!path)
    return 0;
  char absolute_dir[PATH_MAX + 1];
  if (!realpath(dir, absolute_dir))
    return 0;
  char *p;
  if (path[0] == '/') {
    p = strstr(path, absolute_dir);
    if (p != path) {
      return 0;
    }
  }
  char absolute_path[PATH_MAX + 1];
  char *tmp_path = xxstrdup(path);
  int rv = 1;
  while ((p = strrchr(tmp_path, '/')) != NULL) {
    *p = '\0';
    if (realpath(tmp_path, absolute_path)) {
      p = strstr(absolute_path, absolute_dir);
      if (p != absolute_path) {
        rv = 0;
      }
      break;
    } else {
      if (errno != ENOENT) {
        rv = 0;
        break;
      }
    }
  }
  free(tmp_path);
  return rv;
}
```