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

```asm
<strtoul>:
  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
  movq   $0x0,-0x10(%rbp)
  cmpq   $0x0,-0x30(%rbp)
  jne    L199
  lea    -0x18(%rbp),%rax
  mov    %rax,-0x30(%rbp)
L199:
  mov    -0x30(%rbp),%rax
  mov    -0x28(%rbp),%rdx
  mov    %rdx,(%rax)
  cmpl   $0x0,-0x34(%rbp)
  js     L69
  cmpl   $0x24,-0x34(%rbp)
  jle    L193
L69:
  mov    $0x0,%eax
  jmp    L253
L189:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
L193:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x20,%al
  je     L189
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x9,%al
  je     L189
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  je     L189
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0xd,%al
  je     L189
  cmpl   $0x0,-0x34(%rbp)
  jne    L39
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L132
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x78,%al
  jne    L132
  movl   $0x10,-0x34(%rbp)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
  jmp    L39
L132:
  movl   $0xa,-0x34(%rbp)
L39:
  cmpl   $0x10,-0x34(%rbp)
  jne    L91
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L91
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x78,%al
  jne    L91
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
  jmp    L91
L92:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jle    L243
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x39,%al
  jg     L243
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x30,%eax
  mov    %ax,-0x1a(%rbp)
  jmp    L94
L243:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x60,%al
  jle    L229
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x7a,%al
  jg     L229
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x57,%eax
  mov    %ax,-0x1a(%rbp)
  jmp    L94
L229:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x40,%al
  jle    L221
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x5a,%al
  jg     L221
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x37,%eax
  mov    %ax,-0x1a(%rbp)
L94:
  movswl -0x1a(%rbp),%eax
  cmp    %eax,-0x34(%rbp)
  jle    L164
  mov    -0x34(%rbp),%eax
  cltq
  imul   -0x10(%rbp),%rax
  mov    %rax,%rdx
  movswq -0x1a(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x10(%rbp)
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
L91:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L92
  jmp    L221
L164:
  nop
L221:
  mov    -0x10(%rbp),%rax
L253:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L277
  call   <__stack_chk_fail@plt>
L277:
  leave
  ret
```

assistant: ```c
unsigned long int strtoul(const char *S, char **PTR, int BASE) {
  unsigned long rval = 0;
  short int digit;
  char *ptr;
  if (PTR == 0) {
    PTR = &ptr;
  }
  *PTR = (char *)S;
  if ((BASE < 0) || BASE > 36) {
    return 0;
  }
  while ((**PTR == ' ') || (**PTR == '\t') || (**PTR == '\n') || (**PTR == '\r')) {
    (*PTR)++;
  }
  if (BASE == 0) {
    if ((**PTR == '0') && (*((*PTR) + 1) == 'x')) {
      BASE = 16;
      (*PTR)++;
      (*PTR)++;
    } else {
      BASE = 10;
    }
  }
  if (BASE == 16) {
    if ((**PTR == '0') && (*((*PTR) + 1) == 'x')) {
      (*PTR)++;
      (*PTR)++;
    }
  }
  while (**PTR) {
    if (((**PTR) >= '0') && ((**PTR) <= '9')) {
      digit = **PTR - '0';
    } else if (((**PTR) >= 'a') && ((**PTR) <= 'z')) {
      digit = (**PTR - 'a') + 10;
    } else if (((**PTR) >= 'A') && ((**PTR) <= 'Z')) {
      digit = (**PTR - 'A') + 10;
    } else {
      break;
    }
    if (digit < BASE) {
      rval = (rval * BASE) + digit;
    } else {
      break;
    }
    (*PTR)++;
  }
  return rval;
}
```