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

```asm
<_gettemp>:
  endbr64
  push   %r15
  push   %r14
  mov    %rdi,%r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %edx,%ebp
  push   %rbx
  mov    %rsi,%rbx
  sub    $0x28,%rsp
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  setne  %cl
  test   %edx,%edx
  setne  %sil
  test   %cl,%cl
  je     L107
  test   %sil,%sil
  je     L107
  mov    D36(%rip),%rax
  mov    (%rax),%rdx
  mov    D6(%rip),%rax
  mov    %rdx,(%rax)
  xor    %eax,%eax
L79:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L142
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L107:
  xor    %eax,%eax
  mov    %sil,0xf(%rsp)
  mov    %cl,0xe(%rsp)
  call   <getpid@plt>
  movzbl 0xe(%rsp),%ecx
  movzbl 0xf(%rsp),%esi
  mov    %eax,%edx
  movzbl (%r14),%eax
  test   %al,%al
  je     L132
  mov    %r14,%r13
  nopl   0x0(%rax,%rax,1)
L58:
  mov    %r13,%r15
  add    $0x1,%r13
  mov    %eax,%edi
  movzbl 0x0(%r13),%eax
  test   %al,%al
  jne    L58
L176:
  cmp    $0x58,%dil
  jne    L150
  nopl   0x0(%rax,%rax,1)
L272:
  movslq %edx,%rax
  mov    %edx,%edi
  mov    %r15,%r13
  sub    $0x1,%r15
  imul   $0x66666667,%rax,%rax
  sar    $0x1f,%edi
  sar    $0x22,%rax
  sub    %edi,%eax
  lea    (%rax,%rax,4),%edi
  add    %edi,%edi
  sub    %edi,%edx
  add    $0x30,%edx
  mov    %dl,0x1(%r15)
  cmpb   $0x58,(%r15)
  mov    %eax,%edx
  je     L272
L150:
  test   %cl,%cl
  jne    L147
  test   %sil,%sil
  jne    L147
L221:
  lea    0x14(%rsp),%r15
  test   %rbx,%rbx
  je     L45
L173:
  mov    D99(%rip),%rax
  mov    $0x180,%edx
  mov    %r14,%rdi
  mov    (%rax),%esi
  mov    D19(%rip),%rax
  or     (%rax),%esi
  mov    D106(%rip),%rax
  or     (%rax),%esi
  call   <open@plt>
  mov    %eax,(%rbx)
  test   %eax,%eax
  jns    L29
L348:
  mov    D79(%rip),%rax
  mov    D6(%rip),%rdx
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L41
L50:
  movsbl (%r12),%edi
  test   %dil,%dil
  je     L41
  mov    %r12,%r13
  jmp    L127
  nopl   0x0(%rax)
L198:
  movsbl 0x1(%r13),%edi
  add    $0x1,%r13
  movb   $0x61,-0x1(%r13)
  test   %dil,%dil
  je     L41
L127:
  cmp    $0x7a,%dil
  je     L198
  call   <isdigit@plt>
  mov    %rax,%r8
  mov    $0x61,%eax
  test   %r8,%r8
  je     L100
  mov    %al,0x0(%r13)
L235:
  test   %rbx,%rbx
  jne    L173
L45:
  test   %ebp,%ebp
  je     L160
  mov    $0x1c0,%esi
  mov    %r14,%rdi
  call   <mkdir@plt>
  test   %rax,%rax
  jne    L348
L29:
  mov    $0x1,%eax
  jmp    L79
  nopl   0x0(%rax,%rax,1)
L41:
  xor    %eax,%eax
  jmp    L79
  nopw   0x0(%rax,%rax,1)
L147:
  cmp    %r15,%r14
  jb     L145
  jmp    L241
  nopw   0x0(%rax,%rax,1)
L16:
  sub    $0x1,%r15
  cmp    %r15,%r14
  je     L241
L145:
  cmpb   $0x2f,(%r15)
  jne    L16
  movb   $0x0,(%r15)
  lea    0x14(%rsp),%rsi
  mov    %r14,%rdi
  call   <stat@plt>
  test   %rax,%rax
  jne    L41
  mov    0x14(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  je     L136
  movb   $0x2f,(%r15)
  mov    %r13,%r12
  jmp    L221
  nopw   0x0(%rax,%rax,1)
L100:
  movzbl 0x0(%r13),%eax
  add    $0x1,%eax
  mov    %al,0x0(%r13)
  jmp    L235
  nopl   0x0(%rax)
L160:
  mov    %r15,%rsi
  mov    %r14,%rdi
  call   <lstat@plt>
  test   %rax,%rax
  je     L50
  mov    D6(%rip),%rdx
  mov    D89(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  sete   %al
  movzbl %al,%eax
  jmp    L79
  nopl   0x0(%rax,%rax,1)
L241:
  mov    %r13,%r12
  jmp    L221
L132:
  movzbl -0x1(%r14),%edi
  lea    -0x1(%r14),%r15
  mov    %r14,%r13
  jmp    L176
L136:
  mov    D88(%rip),%rdx
  mov    (%rdx),%rcx
  mov    D6(%rip),%rdx
  mov    %rcx,(%rdx)
  jmp    L79
L142:
  call   <__stack_chk_fail@plt>
```

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