user: 请将这段汇编代码片段转换成等效的C代码：

```asm
<strtoul>:
  endbr64
  push   %r12
  push   %rbp
  push   %rbx
  cmp    $0x1,%edx
  je     L51
  mov    %rdi,%rbx
  mov    %rsi,%r12
  mov    %edx,%ebp
  cmp    $0x24,%edx
  jbe    L149
L51:
  mov    D2(%rip),%rax
  mov    (%rax),%edx
  mov    D23(%rip),%rax
  mov    %edx,(%rax)
  mov    $0x0,%esi
L118:
  mov    %rsi,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  ret
L5:
  add    $0x1,%rbx
L149:
  movsbl (%rbx),%edi
  call   <isspace@plt>
  test   %rax,%rax
  jne    L5
  movzbl (%rbx),%eax
  cmp    $0x2b,%al
  je     L35
  mov    $0x0,%r10d
  cmp    $0x2d,%al
  je     L143
L4:
  test   $0xffffffef,%ebp
  jne    L11
  cmpb   $0x30,(%rbx)
  je     L115
  test   %ebp,%ebp
  mov    $0xa,%eax
  cmove  %eax,%ebp
L11:
  mov    D35(%rip),%rax
  mov    (%rax),%r8
  mov    D55(%rip),%rax
  mov    (%rax),%r9d
  mov    $0x0,%esi
  movslq %ebp,%rdi
  jmp    L54
L35:
  add    $0x1,%rbx
  mov    $0x0,%r10d
  jmp    L4
L143:
  add    $0x1,%rbx
  mov    $0x1,%r10d
  jmp    L4
L115:
  cmpb   $0x78,0x1(%rbx)
  je     L71
  test   %ebp,%ebp
  jne    L11
  add    $0x1,%rbx
  mov    $0x8,%ebp
  jmp    L11
L71:
  add    $0x2,%rbx
  mov    $0x10,%ebp
  jmp    L11
L213:
  movsbl %al,%eax
  lea    -0x37(%rax),%ecx
L136:
  cmp    %ebp,%ecx
  jge    L73
  mov    %rdi,%r11
  imul   %rsi,%r11
  mov    %r11,%rax
  mov    $0x0,%edx
  div    %rdi
  cmp    %rsi,%rax
  je     L168
L221:
  mov    D23(%rip),%rax
  mov    %r9d,(%rax)
  mov    %r8,%rsi
L1:
  add    $0x1,%rbx
L54:
  movzbl (%rbx),%eax
  lea    -0x41(%rax),%edx
  cmp    $0x19,%dl
  jbe    L213
  lea    -0x61(%rax),%edx
  cmp    $0x19,%dl
  ja     L235
  movsbl %al,%eax
  lea    -0x57(%rax),%ecx
  jmp    L136
L235:
  lea    -0x30(%rax),%edx
  cmp    $0x9,%dl
  ja     L73
  movsbl %al,%eax
  lea    -0x30(%rax),%ecx
  jmp    L136
L73:
  test   %r12,%r12
  je     L36
  mov    %rbx,(%r12)
L36:
  test   %r10d,%r10d
  je     L118
  mov    %rsi,%rax
  neg    %rax
  mov    D35(%rip),%rdx
  cmp    %rsi,(%rdx)
  cmovne %rax,%rsi
  jmp    L118
L168:
  movslq %ecx,%rcx
  add    %r11,%rcx
  jb     L221
  cmp    %rsi,%r8
  je     L221
  mov    %rcx,%rsi
  jmp    L1
```

assistant: ```c
unsigned long strtoul(const char *nptr, char **endptr, int base) {
  int neg = 0;
  unsigned long ret = 0;
  if (base < 0 || base == 1 || base > 36) {
    errno = EINVAL;
    return 0;
  }
  while (isspace(*nptr)) {
    nptr++;
  }
  if (*nptr == '+') {
    nptr++;
  } else if (*nptr == '-') {
    neg = 1;
    nptr++;
  }
  if ((base == 0 || base == 16) && nptr[0] == '0' && nptr[1] == 'x') {
    base = 16;
    nptr += 2;
  } else if (base == 0 && nptr[0] == '0') {
    base = 8;
    nptr++;
  } else if (base == 0) {
    base = 10;
  }
  for (;;) {
    char c = *nptr;
    int v = -1;
    unsigned long new_ret;
    if (c >= 'A' && c <= 'Z') {
      v = c - 'A' + 10;
    } else if (c >= 'a' && c <= 'z') {
      v = c - 'a' + 10;
    } else if (c >= '0' && c <= '9') {
      v = c - '0';
    }
    if (v < 0 || v >= base) {
      if (endptr) {
        *endptr = (char *)nptr;
      }
      break;
    }
    new_ret = ret * base;
    if (new_ret / base != ret || new_ret + v < new_ret || ret == ULONG_MAX) {
      ret = ULONG_MAX;
      errno = ERANGE;
    } else {
      ret = new_ret + v;
    }
    nptr++;
  }
  if (neg && ret != ULONG_MAX) {
    ret = -ret;
  }
  return ret;
}
```