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

```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     L112
  test   %r15b,%r15b
  je     L112
  mov    D128(%rip),%rax
  mov    (%rax),%rdx
  mov    D55(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
L391:
  mov    0x18(%rsp),%rdx
  sub    %fs:0x28,%rdx
  jne    L461
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L112:
  mov    %r12,%rbp
  cmpb   $0x0,(%r12)
  je     L362
L90:
  add    $0x1,%rbp
  cmpb   $0x0,0x0(%rbp)
  jne    L90
L362:
  movslq %ecx,%rcx
  sub    %rcx,%rbp
  lea    -0x1(%rbp),%rbx
  cmp    %rbx,%r12
  jbe    L118
  mov    D128(%rip),%rax
  mov    (%rax),%rdx
  mov    D55(%rip),%rax
  mov    %rdx,(%rax)
  mov    $0x0,%eax
  jmp    L391
L118:
  mov    $0x0,%eax
  call   <getpid@plt>
  cmpb   $0x58,-0x1(%rbp)
  jne    L121
  test   %eax,%eax
  je     L121
  lea    -0x1(%r12),%rsi
L218:
  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     L195
  cmpb   $0x58,(%rbx)
  jne    L121
  test   %edx,%edx
  jne    L218
L121:
  cmpb   $0x58,(%rbx)
  jne    L352
  mov    $0x0,%eax
  call   <random@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    L121
L101:
  lea    0x1(%rbx),%rax
  mov    %rax,0x8(%rsp)
L123:
  lea    0x14(%rsp),%r14
L237:
  test   %r13,%r13
  je     L51
  mov    D42(%rip),%rax
  mov    (%rax),%esi
  mov    D44(%rip),%rax
  or     (%rax),%esi
  mov    D141(%rip),%rax
  or     (%rax),%esi
  mov    $0x180,%edx
  mov    %r12,%rdi
  call   <open@plt>
  mov    %eax,0x0(%r13)
  test   %eax,%eax
  jns    L340
  mov    D55(%rip),%rdx
  mov    D34(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  jne    L34
L70:
  mov    0x8(%rsp),%rbx
  movzbl (%rbx),%edi
  test   %dil,%dil
  je     L30
L163:
  cmp    $0x5a,%dil
  jne    L153
  cmp    %rbx,%rbp
  je     L139
  add    $0x1,%rbx
  movb   $0x61,-0x1(%rbx)
  movzbl (%rbx),%edi
  test   %dil,%dil
  jne    L163
  mov    $0x0,%eax
  jmp    L391
L352:
  lea    0x1(%rbx),%rax
  mov    %rax,0x8(%rsp)
  test   %r14b,%r14b
  jne    L180
  test   %r15b,%r15b
  je     L123
L180:
  cmp    %rbx,%r12
  jae    L123
L260:
  cmpb   $0x2f,(%rbx)
  je     L465
  sub    $0x1,%rbx
  cmp    %rbx,%r12
  jne    L260
  jmp    L123
L465:
  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    L391
  mov    0x14(%rsp),%edi
  call   <S_ISDIR@plt>
  test   %eax,%eax
  jne    L123
  mov    D89(%rip),%rdx
  mov    (%rdx),%rcx
  mov    D55(%rip),%rdx
  mov    %rcx,(%rdx)
  jmp    L391
L357:
  mov    $0x61,%eax
L146:
  mov    %al,(%rbx)
  jmp    L237
L13:
  mov    $0x41,%eax
  jmp    L146
L51:
  cmpl   $0x0,0x4(%rsp)
  je     L319
  mov    $0x1c0,%esi
  mov    %r12,%rdi
  call   <mkdir@plt>
  test   %rax,%rax
  je     L484
  mov    D55(%rip),%rdx
  mov    D34(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  je     L70
  mov    $0x0,%eax
  jmp    L391
L319:
  mov    %r14,%rsi
  mov    %r12,%rdi
  call   <lstat@plt>
  test   %rax,%rax
  je     L70
  mov    D55(%rip),%rdx
  mov    D31(%rip),%rax
  mov    (%rax),%rax
  cmp    %rax,(%rdx)
  sete   %al
  movzbl %al,%eax
  jmp    L391
L153:
  movsbl %dil,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  jne    L357
  movzbl (%rbx),%eax
  cmp    $0x7a,%al
  je     L13
  cmp    %rbx,%rbp
  je     L305
  add    $0x1,%eax
  jmp    L146
L340:
  mov    $0x1,%eax
  jmp    L391
L34:
  mov    $0x0,%eax
  jmp    L391
L30:
  mov    $0x0,%eax
  jmp    L391
L484:
  mov    $0x1,%eax
  jmp    L391
L139:
  mov    $0x0,%eax
  jmp    L391
L305:
  mov    $0x0,%eax
  jmp    L391
L195:
  mov    %rsi,%rbx
  jmp    L101
L461:
  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 = (random() & 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;
      }
    }
  }
}
```