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

```asm
<serpent_convert_from_string>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  mov    %rsi,%rbp
  push   %rbx
  mov    %edi,%ebx
  mov    %rsi,%rdi
  lea    0x6(%rbx),%r12d
  sub    $0x48,%rsp
  mov    %rdx,0x10(%rsp)
  mov    %fs:0x28,%rax
  mov    %rax,0x38(%rsp)
  xor    %eax,%eax
  call   <strlen@plt>
  mov    %ebx,%edx
  add    $0x3,%edx
  cmovns %edx,%r12d
  sar    $0x2,%r12d
  cmp    %r12d,%eax
  jl     L5
L12:
  test   %ebx,%ebx
  js     L82
  lea    0x0(,%r12,4),%eax
  cmp    %ebx,%eax
  jl     L82
  sub    $0x3,%eax
  cmp    %ebx,%eax
  jg     L82
  test   %r12d,%r12d
  jle    L173
  lea    -0x1(%r12),%eax
  mov    %rbp,%rcx
  lea    0x1(%rbp,%rax,1),%rsi
  nopl   0x0(%rax,%rax,1)
L70:
  movzbl (%rcx),%eax
  mov    %eax,%edx
  and    $0xffffffdf,%edx
  sub    $0x41,%edx
  cmp    $0x5,%dl
  jbe    L8
  sub    $0x30,%eax
  cmp    $0x9,%al
  jbe    L8
L82:
  mov    $0xffffffff,%r12d
L163:
  mov    0x38(%rsp),%rax
  sub    %fs:0x28,%rax
  jne    L50
  add    $0x48,%rsp
  mov    %r12d,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax,%rax,1)
L8:
  add    $0x1,%rcx
  cmp    %rsi,%rcx
  jne    L70
  xor    %r13d,%r13d
  cmp    $0x7,%r12d
  jle    L35
  movslq %r12d,%rax
  mov    0x10(%rsp),%rdi
  lea    0x20(%rsp),%r13
  lea    -0x8(%rbp,%rax,1),%r14
  lea    -0x8(%r12),%eax
  mov    %eax,0x1c(%rsp)
  shr    $0x3,%eax
  mov    %rdi,%r15
  lea    D19(%rip),%r12
  mov    %eax,0x18(%rsp)
  lea    0x8(%rdi,%rax,8),%rax
  mov    %rax,0x8(%rsp)
  nopl   0x0(%rax)
L21:
  mov    %r14,%rdi
  mov    %r13,%rdx
  mov    %r12,%rsi
  sub    $0x8,%r14
  call   <sscanf@plt>
  mov    0x20(%rsp),%rax
  add    $0x8,%r15
  mov    %rax,-0x8(%r15)
  cmp    0x8(%rsp),%r15
  jne    L21
  mov    0x18(%rsp),%edi
  mov    0x1c(%rsp),%esi
  mov    %edi,%eax
  add    $0x1,%edi
  neg    %eax
  mov    %edi,%r13d
  lea    (%rsi,%rax,8),%r12d
L120:
  test   %r12d,%r12d
  jne    L35
L77:
  lea    0x1f(%rbx),%r12d
  sar    $0x5,%r12d
  cmp    %r12d,%r13d
  jge    L113
  lea    -0x1(%r12),%eax
  xor    %esi,%esi
  sub    %r13d,%eax
  movslq %r13d,%r13
  lea    0x8(,%rax,8),%rdx
  mov    0x10(%rsp),%rax
  lea    (%rax,%r13,8),%rdi
  call   <memset@plt>
  jmp    L163
  nopw   0x0(%rax,%rax,1)
L35:
  lea    0x2e(%rsp),%r14
  mov    %r12d,%edx
  mov    %rbp,%rsi
  movslq %r12d,%r12
  mov    %r14,%rdi
  call   <strncpy@plt>
  lea    0x20(%rsp),%rdx
  mov    %r14,%rdi
  lea    D19(%rip),%rsi
  movb   $0x0,0x2e(%rsp,%r12,1)
  call   <sscanf@plt>
  mov    0x20(%rsp),%rdx
  mov    0x10(%rsp),%rdi
  movslq %r13d,%rax
  add    $0x1,%r13d
  mov    %rdx,(%rdi,%rax,8)
  jmp    L77
  nopw   0x0(%rax,%rax,1)
L5:
  mov    %rbp,%rdi
  call   <strlen@plt>
  mov    %eax,%r12d
  jmp    L12
L113:
  mov    %r13d,%r12d
  jmp    L163
L173:
  xor    %r13d,%r13d
  jmp    L120
L50:
  call   <__stack_chk_fail@plt>
```

tool_calls: name: unpack_data
arguments: tag: D19
type_guessed: string

tool: D19: %08lX

assistant: ```c
int serpent_convert_from_string(int len, char *str, unsigned long *val) {
  int is, iv;
  int slen = (((strlen(str)) < ((len + 3) / 4)) ? (strlen(str)) : ((len + 3) / 4));
  if (len < 0)
    return -1;
  if (len > slen * 4 || len < slen * 4 - 3)
    return -1;
  for (is = 0; is < slen; is++)
    if (((str[is] < '0') || (str[is] > '9')) && ((str[is] < 'A') || (str[is] > 'F')) && ((str[is] < 'a') || (str[is] > 'f')))
      return -1;
  for (is = slen, iv = 0; is >= 8; is -= 8, iv++) {
    unsigned long t;
    sscanf(&str[is - 8], "%08lX", &t);
    val[iv] = t;
  }
  if (is > 0) {
    char tmp[10];
    unsigned long t;
    strncpy(tmp, str, is);
    tmp[is] = 0;
    sscanf(tmp, "%08lX", &t);
    val[iv++] = t;
  }
  for (; iv < (len + 31) / 32; iv++)
    val[iv] = 0;
  return iv;
}
```