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

```asm
<strtoul>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %r12
  push   %rbx
  sub    $0x40,%rsp
  mov    %rdi,-0x38(%rbp)
  mov    %rsi,-0x40(%rbp)
  mov    %edx,-0x44(%rbp)
  movl   $0x0,-0x30(%rbp)
  movl   $0x0,-0x2c(%rbp)
  movq   $0x0,-0x28(%rbp)
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  jmp    L32
L309:
  addq   $0x1,-0x20(%rbp)
L32:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isspace@plt>
  test   %rax,%rax
  jne    L309
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2d,%al
  jne    L184
  movl   $0x1,-0x30(%rbp)
  addq   $0x1,-0x20(%rbp)
  jmp    L162
L184:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2b,%al
  jne    L162
  addq   $0x1,-0x20(%rbp)
L162:
  mov    -0x20(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  cmpl   $0x10,-0x44(%rbp)
  jne    L72
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  je     L275
L72:
  cmpl   $0x0,-0x44(%rbp)
  je     L51
  mov    -0x44(%rbp),%eax
  sub    $0x2,%eax
  mov    %eax,%ebx
  cmp    $0x22,%ebx
  jbe    L291
  mov    D56(%rip),%rax
  mov    (%rax),%edx
  mov    D0(%rip),%rax
  mov    %edx,(%rax)
  mov    $0x0,%eax
  jmp    L170
L51:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x30,%al
  jne    L312
  movl   $0x8,-0x44(%rbp)
  jmp    L109
L275:
  nop
L109:
  mov    -0x20(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x78,%al
  je     L85
  mov    -0x20(%rbp),%rax
  add    $0x1,%rax
  movzbl (%rax),%eax
  cmp    $0x58,%al
  jne    L291
L85:
  mov    -0x20(%rbp),%rax
  add    $0x2,%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <isxdigit@plt>
  test   %rax,%rax
  je     L291
  addq   $0x2,-0x20(%rbp)
  movl   $0x10,-0x44(%rbp)
  jmp    L291
L312:
  movl   $0xa,-0x44(%rbp)
  jmp    L291
L112:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  mov    %eax,%ebx
  cmp    $0x60,%bl
  jbe    L235
  cmp    $0x57,%bl
  setne  %al
  jmp    L161
L235:
  cmp    $0x40,%bl
  seta   %al
L161:
  test   %al,%al
  je     L68
  cmp    $0x37,%bl
  setne  %al
  jmp    L111
L68:
  cmp    $0x39,%bl
  setbe  %al
L111:
  test   %al,%al
  je     L318
  lea    -0x30(%rbx),%eax
  jmp    L265
L318:
  mov    $0xffffffff,%eax
L265:
  mov    %eax,%ebx
  movzbl %bl,%eax
  cmp    %eax,-0x44(%rbp)
  jle    L55
  mov    -0x28(%rbp),%rax
  movzbl %al,%edx
  mov    -0x44(%rbp),%eax
  cltq
  imul   %rax,%rdx
  movzbl %bl,%eax
  lea    (%rdx,%rax,1),%rbx
  mov    -0x28(%rbp),%rax
  shr    $0x8,%rax
  mov    %rax,%rdx
  mov    -0x44(%rbp),%eax
  cltq
  imul   %rdx,%rax
  mov    %rbx,%rdx
  shr    $0x8,%rdx
  lea    (%rax,%rdx,1),%r12
  mov    D43(%rip),%rax
  mov    (%rax),%eax
  sar    $0x8,%eax
  cltq
  cmp    %rax,%r12
  jbe    L86
  movl   $0x1,-0x2c(%rbp)
L86:
  mov    %r12,%rdx
  shl    $0x8,%rdx
  movzbl %bl,%eax
  add    %rdx,%rax
  mov    %rax,-0x28(%rbp)
  addq   $0x1,-0x20(%rbp)
L291:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L112
  jmp    L159
L55:
  nop
L159:
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jne    L310
  mov    -0x38(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  mov    D56(%rip),%rax
  mov    (%rax),%edx
  mov    D0(%rip),%rax
  mov    %edx,(%rax)
  movq   $0x0,-0x28(%rbp)
L310:
  cmpq   $0x0,-0x40(%rbp)
  je     L256
  mov    -0x40(%rbp),%rax
  mov    -0x20(%rbp),%rdx
  mov    %rdx,(%rax)
L256:
  cmpl   $0x0,-0x2c(%rbp)
  je     L104
  mov    D51(%rip),%rax
  mov    (%rax),%edx
  mov    D0(%rip),%rax
  mov    %edx,(%rax)
  mov    D43(%rip),%rax
  mov    (%rax),%eax
  cltq
  jmp    L170
L104:
  cmpl   $0x0,-0x30(%rbp)
  je     L139
  mov    -0x28(%rbp),%rax
  neg    %rax
  jmp    L170
L139:
  mov    -0x28(%rbp),%rax
L170:
  add    $0x40,%rsp
  pop    %rbx
  pop    %r12
  pop    %rbp
  ret
```

assistant: ```c
unsigned long int strtoul(const char *ptr, char **endptr, int base) {
  int neg = 0, overflow = 0;
  unsigned long int v = 0;
  const char *orig;
  const char *nptr = ptr;
  while (isspace(*nptr))
    ++nptr;
  if (*nptr == '-') {
    neg = 1;
    nptr++;
  } else if (*nptr == '+')
    ++nptr;
  orig = nptr;
  if (base == 16 && nptr[0] == '0')
    goto skip0x;
  if (base) {
    register unsigned int b = base - 2;
    if (b > 34) {
      errno = EINVAL;
      return 0;
    }
  } else {
    if (*nptr == '0') {
      base = 8;
    skip0x:
      if ((nptr[1] == 'x' || nptr[1] == 'X') && isxdigit(nptr[2])) {
        nptr += 2;
        base = 16;
      }
    } else
      base = 10;
  }
  while (*nptr) {
    register unsigned char c = *nptr;
    c = (((c >= 'a' ? (c - 'a' + 10) : (c >= 'A')) ? (c - 'A' + 10) : (c <= '9')) ? (c - '0') : 0xff);
    if (c >= base)
      break;
    {
      register unsigned long x = (v & 0xff) * base + c;
      register unsigned long w = (v >> 8) * base + (x >> 8);
      if (w > (ULONG_MAX >> 8))
        overflow = 1;
      v = (w << 8) + (x & 0xff);
    }
    ++nptr;
  }
  if (nptr == orig) {
    nptr = ptr;
    errno = EINVAL;
    v = 0;
  }
  if (endptr)
    *endptr = (char *)nptr;
  if (overflow) {
    errno = ERANGE;
    return ULONG_MAX;
  }
  return (neg ? -v : v);
}
```