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

```asm
<scale>:
  endbr64
  push   %r13
  push   %r12
  movslq %esi,%r12
  push   %rbp
  push   %rbx
  mov    %rdx,%rbx
  sub    $0x8,%rsp
  movl   $0x0,(%rcx)
  cmp    %r12d,%edi
  je     L215
  mov    %edi,%r13d
  lea    D8(%rip),%rsi
  mov    %rdx,%rdi
  call   <strcmp@plt>
  test   %rax,%rax
  je     L215
  lea    -0x2(%r13),%eax
  cmp    $0x3e,%eax
  ja     L194
  lea    -0x2(%r12),%eax
  cmp    $0x3e,%eax
  ja     L194
  xor    %eax,%eax
  cmpb   $0x2d,(%rbx)
  sete   %al
  add    %rax,%rbx
  mov    %rbx,%rdi
  call   <strlen@plt>
  cltq
  lea    -0x1(%rbx,%rax,1),%rax
  cmp    %rax,%rbx
  ja     L68
  mov    $0x1,%ecx
  xor    %ebp,%ebp
  movslq %r13d,%rdi
  jmp    L88
  nopl   0x0(%rax)
L126:
  movzbl %sil,%esi
  mov    %esi,%edx
L129:
  cmp    %esi,%r13d
  jl     L194
L5:
  movsbq %dl,%rdx
  sub    $0x1,%rax
  imul   %rcx,%rdx
  imul   %rdi,%rcx
  add    %rdx,%rbp
  cmp    %rax,%rbx
  ja     L105
L88:
  movzbl (%rax),%edx
  lea    -0x30(%rdx),%esi
  cmp    $0x9,%sil
  jbe    L126
  lea    -0x41(%rdx),%esi
  cmp    $0x1a,%sil
  ja     L87
  sub    $0x37,%edx
  movzbl %dl,%esi
  cmp    %esi,%r13d
  jge    L5
L194:
  add    $0x8,%rsp
  xor    %r8d,%r8d
  pop    %rbx
  mov    %r8,%rax
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
L215:
  mov    %rbx,%r8
L4:
  add    $0x8,%rsp
  mov    %r8,%rax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  ret
  nopl   0x0(%rax)
L87:
  lea    -0x61(%rdx),%esi
  cmp    $0x19,%sil
  ja     L70
  sub    $0x3d,%edx
  movzbl %dl,%esi
  jmp    L129
  nopl   0x0(%rax)
L70:
  cmp    $0x40,%dl
  je     L78
  movsbl %dl,%esi
  cmp    $0x5f,%dl
  jne    L129
  mov    $0x3f,%esi
  mov    $0x3f,%edx
  jmp    L129
  nopl   0x0(%rax)
L105:
  mov    %ebp,%edi
L79:
  call   <log@plt>
  mov    %r12d,%edi
  mov    %eax,%ebx
  call   <log@plt>
  mov    $0x1,%esi
  mov    %eax,%r8d
  mov    %ebx,%eax
  cltd
  idiv   %r8d
  movslq %eax,%rbx
  lea    0x2(%rbx),%edi
  call   <calloc@plt>
  mov    $0x40,%edi
  mov    $0x5f,%esi
  mov    %rax,%r8
  lea    (%rax,%rbx,1),%rcx
  jmp    L74
  nopl   (%rax)
L160:
  add    $0x30,%edx
L134:
  mov    %dl,(%rcx)
  sub    $0x1,%rcx
  test   %rax,%rax
  jle    L4
L74:
  mov    %rbp,%rax
  cqto
  idiv   %r12
  mov    %rax,%rbp
  cmp    $0x9,%rdx
  jle    L160
  cmp    $0x23,%rdx
  jg     L62
  add    $0x37,%edx
  jmp    L134
  cs nopw 0x0(%rax,%rax,1)
L62:
  cmp    $0x3d,%dl
  jg     L80
  add    $0x3d,%edx
  jmp    L134
  nopw   0x0(%rax,%rax,1)
L80:
  cmp    $0x3e,%dl
  mov    %esi,%edx
  cmove  %edi,%edx
  jmp    L134
  nopw   0x0(%rax,%rax,1)
L78:
  mov    $0x3e,%esi
  mov    $0x3e,%edx
  jmp    L129
L68:
  xor    %edi,%edi
  xor    %ebp,%ebp
  jmp    L79
```

tool_calls: name: disassemble_data
arguments: data_label: D8
type_guessed: string

tool: D8: 0

assistant: ```c
char *scale(int cur, int res, char *num, bool *freeable) {
  bool caps = false, posi = true;
  *freeable = false;
  if (cur == res || strcmp(num, "0") == 0)
    return num;
  if (cur < 2 || cur > 64 || res < 2 || res > 64)
    return NULL;
  if (num[0] == '-') {
    posi = false;
    num++;
  }
  long iresult = 0, unit = 1;
  char *sresult = NULL, value;
  for (char *i = num + strlen(num) - 1; i >= num; i--) {
    value = *i;
    if (value > 47 && value < 58)
      value -= 48;
    else if (value > 64 && value < 92)
      value -= 55;
    else if (value > 96 && value < 123)
      value -= 61;
    else if (value == 64)
      value = 62;
    else if (value == 95)
      value = 63;
    if (value > cur)
      return NULL;
    iresult += value * unit;
    unit *= cur;
  }
  int len = (int)(log(iresult) / log(res)) + 1;
  sresult = calloc(len + 1, sizeof(char));
  char *ptr = sresult;
  ptr = len + sresult - 1;
  do {
    value = iresult % res;
    iresult /= res;
    if (value < 10)
      value += 48;
    else if (value < 36)
      value += 55;
    else if (value < 62)
      value += 61;
    else if (value == 62)
      value = 64;
    else if (value == 63)
      value = 95;
    *ptr = value;
    ptr--;
  } while (iresult > 0);
  return sresult;
}
```