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

```asm
<_gettemp>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  sub    $0x40,%rsp
  mov    %rdi,-0x28(%rbp)
  mov    %rsi,-0x30(%rbp)
  mov    %edx,-0x34(%rbp)
  mov    %fs:0x28,%rax
  mov    %rax,-0x8(%rbp)
  xor    %eax,%eax
  cmpq   $0x0,-0x30(%rbp)
  je     L53
  cmpl   $0x0,-0x34(%rbp)
  je     L53
  mov    D97(%rip),%rax
  mov    (%rax),%rdx
  mov    D129(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
  jmp    L353
L53:
  mov    $0x0,%eax
  call   <getpid@plt>
  mov    %eax,-0x1c(%rbp)
  mov    -0x28(%rbp),%rax
  mov    %rax,-0x10(%rbp)
  jmp    L170
L97:
  addq   $0x1,-0x10(%rbp)
L170:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L97
  jmp    L286
L31:
  mov    -0x1c(%rbp),%edx
  movslq %edx,%rax
  imul   $0x66666667,%rax,%rax
  shr    $0x20,%rax
  sar    $0x2,%eax
  mov    %edx,%esi
  sar    $0x1f,%esi
  sub    %esi,%eax
  mov    %eax,%ecx
  mov    %ecx,%eax
  shl    $0x2,%eax
  add    %ecx,%eax
  add    %eax,%eax
  mov    %edx,%ecx
  sub    %eax,%ecx
  mov    %ecx,%eax
  add    $0x30,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
  mov    -0x1c(%rbp),%eax
  movslq %eax,%rdx
  imul   $0x66666667,%rdx,%rdx
  shr    $0x20,%rdx
  sar    $0x2,%edx
  sar    $0x1f,%eax
  mov    %eax,%ecx
  mov    %edx,%eax
  sub    %ecx,%eax
  mov    %eax,-0x1c(%rbp)
L286:
  subq   $0x1,-0x10(%rbp)
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x58,%al
  je     L31
  cmpq   $0x0,-0x30(%rbp)
  jne    L301
  cmpl   $0x0,-0x34(%rbp)
  je     L194
L301:
  mov    -0x10(%rbp),%rax
  add    $0x1,%rax
  mov    %rax,-0x18(%rbp)
L342:
  mov    -0x10(%rbp),%rax
  cmp    -0x28(%rbp),%rax
  jbe    L99
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jne    L260
  mov    -0x10(%rbp),%rax
  movb   $0x0,(%rax)
  lea    -0x20(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <stat@plt>
  test   %rax,%rax
  je     L16
  mov    $0x0,%eax
  jmp    L353
L16:
  mov    -0x20(%rbp),%eax
  mov    %eax,%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  jne    L46
  mov    D16(%rip),%rax
  mov    (%rax),%rdx
  mov    D129(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
  jmp    L353
L46:
  mov    -0x10(%rbp),%rax
  movb   $0x2f,(%rax)
  jmp    L194
L260:
  subq   $0x1,-0x10(%rbp)
  jmp    L342
L99:
  nop
L194:
  cmpq   $0x0,-0x30(%rbp)
  je     L29
  mov    D100(%rip),%rax
  mov    (%rax),%edx
  mov    D12(%rip),%rax
  mov    (%rax),%eax
  or     %eax,%edx
  mov    D55(%rip),%rax
  mov    (%rax),%eax
  mov    %edx,%ecx
  or     %eax,%ecx
  mov    -0x28(%rbp),%rax
  mov    $0x180,%edx
  mov    %ecx,%esi
  mov    %rax,%rdi
  call   <open@plt>
  mov    -0x30(%rbp),%rdx
  mov    %eax,(%rdx)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%eax
  test   %eax,%eax
  js     L42
  mov    $0x1,%eax
  jmp    L353
L42:
  mov    D129(%rip),%rax
  mov    (%rax),%rdx
  mov    D66(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L18
  mov    $0x0,%eax
  jmp    L353
L29:
  cmpl   $0x0,-0x34(%rbp)
  je     L150
  mov    -0x28(%rbp),%rax
  mov    $0x1c0,%esi
  mov    %rax,%rdi
  call   <mkdir@plt>
  test   %rax,%rax
  jne    L62
  mov    $0x1,%eax
  jmp    L353
L62:
  mov    D129(%rip),%rax
  mov    (%rax),%rdx
  mov    D66(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  je     L18
  mov    $0x0,%eax
  jmp    L353
L150:
  lea    -0x20(%rbp),%rdx
  mov    -0x28(%rbp),%rax
  mov    %rdx,%rsi
  mov    %rax,%rdi
  call   <lstat@plt>
  test   %rax,%rax
  je     L18
  mov    D129(%rip),%rax
  mov    (%rax),%rdx
  mov    D81(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,%rdx
  sete   %al
  movzbl %al,%eax
  jmp    L353
L18:
  mov    -0x18(%rbp),%rax
  mov    %rax,-0x10(%rbp)
L57:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L358
  mov    $0x0,%eax
  jmp    L353
L358:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x7a,%al
  jne    L249
  mov    -0x10(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x10(%rbp)
  movb   $0x61,(%rax)
  jmp    L57
L249:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L11
  mov    -0x10(%rbp),%rax
  movb   $0x61,(%rax)
  jmp    L349
L11:
  mov    -0x10(%rbp),%rax
  movzbl (%rax),%eax
  add    $0x1,%eax
  mov    %eax,%edx
  mov    -0x10(%rbp),%rax
  mov    %dl,(%rax)
L349:
  jmp    L194
L353:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L191
  call   <__stack_chk_fail@plt>
L191:
  leave
  ret
```

assistant: ```c
int _gettemp(char *path, int *doopen, int domkdir) {
  char *start, *trv;
  struct stat sbuf;
  pid_t pid;
  if (doopen && domkdir) {
    errno = EINVAL;
    return (0);
  }
  pid = getpid();
  for (trv = path; *trv; ++trv)
    ;
  while (*--trv == 'X') {
    *trv = (pid % 10) + '0';
    pid /= 10;
  }
  if (doopen || domkdir) {
    for (start = trv + 1;; --trv) {
      if (trv <= path)
        break;
      if (*trv == '/') {
        *trv = '\0';
        if (stat(path, &sbuf))
          return (0);
        if (!S_ISDIR(sbuf.st_mode)) {
          errno = ENOTDIR;
          return (0);
        }
        *trv = '/';
        break;
      }
    }
  }
  for (;;) {
    if (doopen) {
      if ((*doopen = open(path, O_CREAT | O_EXCL | O_RDWR, 0600)) >= 0)
        return (1);
      if (errno != EEXIST)
        return (0);
    } else if (domkdir) {
      if (mkdir(path, 0700) == 0)
        return (1);
      if (errno != EEXIST)
        return (0);
    } else if (lstat(path, &sbuf))
      return (errno == ENOENT ? 1 : 0);
    for (trv = start;;) {
      if (!*trv)
        return (0);
      if (*trv == 'z')
        *trv++ = 'a';
      else {
        if (isdigit(*trv))
          *trv = 'a';
        else
          ++*trv;
        break;
      }
    }
  }
}
```