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

```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    L254
  lea    -0x18(%rbp),%rax
  mov    %rax,-0x30(%rbp)
L254:
  mov    -0x30(%rbp),%rax
  mov    -0x28(%rbp),%rdx
  mov    %rdx,(%rax)
  cmpl   $0x0,-0x34(%rbp)
  js     L245
  cmpl   $0x24,-0x34(%rbp)
  jle    L250
L245:
  mov    $0x0,%eax
  jmp    L101
L179:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  lea    0x1(%rax),%rdx
  mov    -0x30(%rbp),%rax
  mov    %rdx,(%rax)
L250:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x20,%al
  je     L179
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x9,%al
  je     L179
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0xa,%al
  je     L179
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0xd,%al
  je     L179
  cmpl   $0x0,-0x34(%rbp)
  jne    L38
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L17
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x78,%al
  jne    L17
  movl   $0x10,-0x34(%rbp)
  jmp    L38
L17:
  movl   $0xa,-0x34(%rbp)
L38:
  cmpl   $0x10,-0x34(%rbp)
  jne    L40
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L40
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x78,%al
  jne    L40
  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    L40
L18:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jle    L249
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x39,%al
  jg     L249
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x30,%eax
  mov    %ax,-0x1a(%rbp)
  jmp    L5
L249:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x60,%al
  jle    L50
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x7a,%al
  jg     L50
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x57,%eax
  mov    %ax,-0x1a(%rbp)
  jmp    L5
L50:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x40,%al
  jle    L62
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cmp    $0x5a,%al
  jg     L62
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  cbtw
  sub    $0x37,%eax
  mov    %ax,-0x1a(%rbp)
L5:
  movswl -0x1a(%rbp),%eax
  cmp    %eax,-0x34(%rbp)
  jle    L51
  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)
L40:
  mov    -0x30(%rbp),%rax
  mov    (%rax),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L18
  jmp    L62
L51:
  nop
L62:
  mov    -0x10(%rbp),%rax
L101:
  mov    -0x8(%rbp),%rdx
  sub    %fs:0x28,%rdx
  je     L78
  call   <__stack_chk_fail@plt>
L78:
  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 == NULL) {
    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;
    } 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;
}
```