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

```asm
<_gettemp>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,%r12
  mov    %rsi,%r13
  mov    %edx,0x4(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x18(%rsp)
  xor    %eax,%eax
  test   %rsi,%rsi
  setne  %r14b
  test   %edx,%edx
  setne  %r15b
  test   %r14b,%r14b
  je     L372
  test   %r15b,%r15b
  je     L372
  mov    D57(%rip),%rax
  mov    (%rax),%rdx
  mov    D10(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
L475:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L156
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L372:
  mov    %r12,%rbp
  cmpb   $0x0,(%r12)
  je     L270
L464:
  add    $0x1,%rbp
  cmpb   $0x0,0x0(%rbp)
  jne    L464
L270:
  movslq %ecx,%rcx
  sub    %rcx,%rbp
  lea    -0x1(%rbp),%rbx
  cmp    %rbx,%r12
  jbe    L409
  mov    D57(%rip),%rax
  mov    (%rax),%rdx
  mov    D10(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
  jmp    L475
L409:
  mov    $0x0,%eax
  call   <getpid@plt>
  cmpb   $0x58,-0x1(%rbp)
  jne    L260
  test   %eax,%eax
  je     L260
  lea    -0x1(%r12),%rsi
L91:
  sub    $0x1,%rbx
  movslq %eax,%rdx
  imul   $0x66666667,%rdx,%rdx
  sar    $0x22,%rdx
  mov    %eax,%ecx
  sar    $0x1f,%ecx
  sub    %ecx,%edx
  lea    (%rdx,%rdx,4),%ecx
  add    %ecx,%ecx
  sub    %ecx,%eax
  add    $0x30,%eax
  mov    %al,0x1(%rbx)
  mov    %edx,%eax
  cmp    %rsi,%rbx
  je     L144
  cmpb   $0x58,(%rbx)
  jne    L260
  test   %edx,%edx
  jne    L91
L260:
  cmpb   $0x58,(%rbx)
  jne    L406
  mov    $0x0,%eax
  call   <arc4random@plt>
  movzwl %ax,%ecx
  movzwl %ax,%eax
  imul   $0x4ec4ec4f,%rax,%rax
  sar    $0x24,%rax
  imul   $0x34,%eax,%edx
  mov    %ecx,%eax
  sub    %edx,%eax
  lea    0x41(%rax),%ecx
  lea    0x47(%rax),%edx
  cmp    $0x19,%eax
  mov    %ecx,%eax
  cmovg  %edx,%eax
  sub    $0x1,%rbx
  mov    %al,0x1(%rbx)
  cmp    %rbx,%r12
  jbe    L260
L374:
  lea    0x1(%rbx),%rax
  mov    %rax,0x8(%rsp)
L282:
  lea    0x14(%rsp),%r14
L366:
  test   %r13,%r13
  je     L6
  mov    D131(%rip),%rax
  mov    (%rax),%esi
  mov    D75(%rip),%rax
  or     (%rax),%esi
  mov    D87(%rip),%rax
  or     (%rax),%esi
  mov    $0x180,%edx
  mov    %r12,%rdi
  call   <open@plt>
  mov    %eax,0x0(%r13)
  test   %eax,%eax
  jns    L80
  mov    D10(%rip),%rdx
  mov    D103(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L269
L412:
  mov    0x8(%rsp),%rbx
  movzbl (%rbx),%edi
  test   %dil,%dil
  je     L287
L149:
  cmp    $0x5a,%dil
  jne    L41
  cmp    %rbx,%rbp
  je     L338
  add    $0x1,%rbx
  movb   $0x61,-0x1(%rbx)
  movzbl (%rbx),%edi
  test   %dil,%dil
  jne    L149
  mov    $0x0,%eax
  jmp    L475
L406:
  lea    0x1(%rbx),%rax
  mov    %rax,0x8(%rsp)
  test   %r14b,%r14b
  jne    L240
  test   %r15b,%r15b
  je     L282
L240:
  cmp    %rbx,%r12
  jae    L282
L397:
  cmpb   $0x2f,(%rbx)
  je     L152
  sub    $0x1,%rbx
  cmp    %rbx,%r12
  jne    L397
  jmp    L282
L152:
  movb   $0x0,(%rbx)
  lea    0x14(%rsp),%rsi
  mov    %r12,%rdi
  call   <stat@plt>
  mov    %eax,%edx
  movb   $0x2f,(%rbx)
  mov    $0x0,%eax
  test   %edx,%edx
  jne    L475
  mov    0x14(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  jne    L282
  mov    D11(%rip),%rdx
  mov    (%rdx),%rcx
  mov    D10(%rip),%rdx
  mov    %rcx,(%rdx)
  jmp    L475
L348:
  mov    $0x61,%eax
L493:
  mov    %al,(%rbx)
  jmp    L366
L131:
  mov    $0x41,%eax
  jmp    L493
L6:
  cmpl   $0x0,0x4(%rsp)
  je     L473
  mov    $0x1c0,%esi
  mov    %r12,%rdi
  call   <mkdir@plt>
  test   %rax,%rax
  je     L422
  mov    D10(%rip),%rdx
  mov    D103(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  je     L412
  mov    $0x0,%eax
  jmp    L475
L473:
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <lstat@plt>
  test   %rax,%rax
  je     L412
  mov    D10(%rip),%rdx
  mov    D70(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  sete   %al
  movzbl %al,%eax
  jmp    L475
L41:
  movsbl %dil,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L348
  movzbl (%rbx),%eax
  cmp    $0x7a,%al
  je     L131
  cmp    %rbx,%rbp
  je     L17
  add    $0x1,%eax
  jmp    L493
L80:
  mov    $0x1,%eax
  jmp    L475
L269:
  mov    $0x0,%eax
  jmp    L475
L287:
  mov    $0x0,%eax
  jmp    L475
L422:
  mov    $0x1,%eax
  jmp    L475
L338:
  mov    $0x0,%eax
  jmp    L475
L17:
  mov    $0x0,%eax
  jmp    L475
L144:
  mov    %rsi,%rbx
  jmp    L374
L156:
  call   <__stack_chk_fail@plt>
```

assistant: ```c
int _gettemp(char *path, int *doopen, int domkdir, int slen) {
  char *start, *trv, *suffp;
  struct stat sbuf;
  int rval;
  pid_t pid;
  if (doopen && domkdir) {
    errno = EINVAL;
    return (0);
  }
  for (trv = path; *trv; ++trv)
    ;
  trv -= slen;
  suffp = trv;
  --trv;
  if (trv < path) {
    errno = EINVAL;
    return (0);
  }
  pid = getpid();
  while (trv >= path && *trv == 'X' && pid != 0) {
    *trv-- = (pid % 10) + '0';
    pid /= 10;
  }
  while (trv >= path && *trv == 'X') {
    char c;
    pid = (arc4random() & 0xffff) % (26 + 26);
    if (pid < 26)
      c = pid + 'A';
    else
      c = (pid - 26) + 'a';
    *trv-- = c;
  }
  start = trv + 1;
  if (doopen || domkdir) {
    for (;; --trv) {
      if (trv <= path)
        break;
      if (*trv == '/') {
        *trv = '\0';
        rval = stat(path, &sbuf);
        *trv = '/';
        if (rval != 0)
          return (0);
        if (!S_ISDIR(sbuf.st_mode)) {
          errno = ENOTDIR;
          return (0);
        }
        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') {
        if (trv == suffp)
          return (0);
        *trv++ = 'a';
      } else {
        if (isdigit(*trv))
          *trv = 'a';
        else if (*trv == 'z')
          *trv = 'A';
        else {
          if (trv == suffp)
            return (0);
          ++*trv;
        }
        break;
      }
    }
  }
}
```