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

```asm
<strtoul>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rdi,0x8(%rsp)
  mov    %rsi,(%rsp)
  cmp    $0x1,%edx
  je     L16
  mov    %edx,%r13d
  mov    %rdi,%rbp
  cmp    $0x24,%edx
  ja     L16
L86:
  mov    %rbp,%r12
  add    $0x1,%rbp
  movzbl -0x1(%rbp),%ebx
  mov    %ebx,%edi
  call   <isspace@plt>
  test   %rax,%rax
  jne    L86
  cmp    $0x2d,%ebx
  je     L213
  movl   $0x0,0x1c(%rsp)
  cmp    $0x2b,%ebx
  je     L305
L8:
  test   $0xffffffef,%r13d
  jne    L248
  cmp    $0x30,%ebx
  je     L252
L248:
  test   %r13d,%r13d
  jne    L158
  cmp    $0x30,%ebx
  setne  %r13b
  movzbl %r13b,%r13d
  lea    0x8(%r13,%r13,1),%r13d
L158:
  mov    D14(%rip),%rax
  mov    (%rax),%rax
  movslq %r13d,%rcx
  mov    %rcx,0x10(%rsp)
  mov    $0x0,%edx
  div    %rcx
  mov    %rax,%r15
  mov    %edx,0x18(%rsp)
  mov    $0x0,%r14d
  mov    $0x0,%r12d
  jmp    L276
L16:
  mov    (%rsp),%rax
  test   %rax,%rax
  je     L150
  mov    0x8(%rsp),%rsi
  mov    %rsi,(%rax)
L150:
  mov    D31(%rip),%rax
  mov    (%rax),%edx
  mov    D57(%rip),%rax
  mov    %edx,(%rax)
  mov    $0x0,%r12d
L196:
  mov    %r12,%rax
  add    $0x28,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L213:
  movsbl 0x0(%rbp),%ebx
  lea    0x2(%r12),%rbp
  movl   $0x1,0x1c(%rsp)
  jmp    L8
L305:
  movsbl 0x0(%rbp),%ebx
  lea    0x2(%r12),%rbp
  jmp    L8
L252:
  movzbl 0x0(%rbp),%eax
  and    $0xffffffdf,%eax
  cmp    $0x58,%al
  jne    L94
  movsbl 0x1(%rbp),%ebx
  add    $0x2,%rbp
  mov    $0x10,%r13d
  jmp    L158
L94:
  mov    $0x30,%ebx
  jmp    L248
L208:
  mov    %ebx,%edi
  call   <isalpha@plt>
  test   %rax,%rax
  je     L72
  mov    %ebx,%edi
  call   <isupper@plt>
  cmp    $0x1,%rax
  sbb    %eax,%eax
  and    $0x20,%eax
  add    $0x37,%eax
  sub    %eax,%ebx
  jmp    L2
L161:
  mov    D14(%rip),%rax
  mov    (%rax),%r12
  mov    D10(%rip),%rax
  mov    (%rax),%edx
  mov    D57(%rip),%rax
  mov    %edx,(%rax)
  mov    $0xffffffff,%r14d
L34:
  add    $0x1,%rbp
  movzbl -0x1(%rbp),%ebx
L276:
  mov    %ebx,%edi
  call   <isdigit@plt>
  test   %rax,%rax
  je     L208
  sub    $0x30,%ebx
L2:
  cmp    %ebx,%r13d
  jle    L72
  test   %r14d,%r14d
  js     L34
  cmp    %r15,%r12
  ja     L161
  jne    L294
  cmp    0x18(%rsp),%ebx
  jg     L161
L294:
  imul   0x10(%rsp),%r12
  movslq %ebx,%rbx
  add    %rbx,%r12
  mov    $0x1,%r14d
  jmp    L34
L72:
  cmpl   $0x0,0x1c(%rsp)
  je     L156
  test   %r14d,%r14d
  jle    L156
  neg    %r12
  cmpq   $0x0,(%rsp)
  je     L196
L57:
  lea    -0x1(%rbp),%rax
  mov    %rax,0x8(%rsp)
  jmp    L115
L156:
  cmpq   $0x0,(%rsp)
  je     L196
  test   %r14d,%r14d
  jne    L57
L115:
  mov    (%rsp),%rax
  mov    0x8(%rsp),%rcx
  mov    %rcx,(%rax)
  jmp    L196
```

assistant: ```c
unsigned long strtoul(const char *nptr, char **endptr, int base) {
  const char *s;
  unsigned long acc, cutoff;
  int c;
  int neg, any, cutlim;
  if (base < 0 || base == 1 || base > 36) {
    if (endptr != 0)
      *endptr = (char *)nptr;
    errno = EINVAL;
    return 0;
  }
  s = nptr;
  do {
    c = (unsigned char)*s++;
  } while (isspace(c));
  if (c == '-') {
    neg = 1;
    c = *s++;
  } else {
    neg = 0;
    if (c == '+')
      c = *s++;
  }
  if ((base == 0 || base == 16) && c == '0' && (*s == 'x' || *s == 'X')) {
    c = s[1];
    s += 2;
    base = 16;
  }
  if (base == 0)
    base = c == '0' ? 8 : 10;
  cutoff = ULONG_MAX / (unsigned long)base;
  cutlim = ULONG_MAX % (unsigned long)base;
  for (acc = 0, any = 0;; c = (unsigned char)*s++) {
    if (isdigit(c))
      c -= '0';
    else if (isalpha(c))
      c -= isupper(c) ? 'A' - 10 : 'a' - 10;
    else
      break;
    if (c >= base)
      break;
    if (any < 0)
      continue;
    if (acc > cutoff || (acc == cutoff && c > cutlim)) {
      any = -1;
      acc = ULONG_MAX;
      errno = ERANGE;
    } else {
      any = 1;
      acc *= (unsigned long)base;
      acc += c;
    }
  }
  if (neg && any > 0)
    acc = -acc;
  if (endptr != 0)
    *endptr = (char *)(any ? s - 1 : nptr);
  return (acc);
}
```