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

```asm
<router_rewrite_metric>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x48,%rsp
  mov    %rdi,%r13
  mov    %rsi,0x18(%rsp)
  mov    %rdx,%r12
  mov    %rcx,(%rsp)
  mov    %r8,%rbx
  mov    %r9,0x8(%rsp)
  cmpq   $0x0,0x80(%rsp)
  setne  %dil
  movzbl %dil,%edi
  call   <assert@plt>
  mov    0x80(%rsp),%rax
  movslq (%rax),%rcx
  mov    $0x0,%eax
  cmp    $0x1fff,%rcx
  ja     L326
  lea    (%r12,%rcx,1),%rax
  cmp    %rax,%r12
  jae    L183
  mov    $0x0,%eax
L464:
  movzbl (%r12,%rax,1),%edx
  mov    %dl,0x0(%r13,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rcx
  jne    L464
  lea    0x0(%r13,%rcx,1),%r15
L293:
  mov    $0x0,%r14d
  mov    $0x0,%esi
  mov    $0x0,%ebp
  mov    %r12,0x10(%rsp)
  jmp    L314
L183:
  mov    %r13,%r15
  jmp    L293
L588:
  cmp    $0x1,%r14d
  je     L325
  cmp    $0x2,%r14d
  je     L294
  mov    $0x3,%r14d
  mov    $0x1,%ebp
  jmp    L60
L367:
  lea    (%rsi,%rsi,4),%edx
  movsbl %al,%eax
  lea    -0x30(%rax,%rdx,2),%esi
  mov    $0x2,%ebp
  jmp    L60
  lea    0x1(%r15),%rax
  mov    %rax,%rdi
  mov    $0x0,%esi
  cmp    %rcx,%r12
  jae    L201
  mov    %bpl,0x37(%rsp)
  mov    %r15,0x38(%rsp)
  mov    %rcx,%r15
  mov    %rdi,%rbp
  jmp    L586
  lea    0x1(%r15),%rax
  mov    %rax,%rsi
  cmp    %rcx,%r12
  jae    L400
  mov    %bpl,0x37(%rsp)
  mov    %r15,0x38(%rsp)
  mov    %rcx,%r15
  mov    %rsi,%rbp
  jmp    L194
L400:
  mov    $0x0,%esi
  jmp    L201
  lea    0x1(%r15),%rdx
  mov    $0x0,%esi
  cmp    %rcx,%r12
  jae    L201
L189:
  movzbl (%r12),%eax
  cmp    $0x2e,%al
  mov    $0x5f,%esi
  cmove  %esi,%eax
  mov    %al,-0x1(%rdx)
  add    $0x1,%r12
  add    $0x1,%rdx
  cmp    %r12,%rcx
  jne    L189
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  add    %rax,%r15
  mov    $0x0,%esi
  jmp    L201
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  add    %r15,%rax
  mov    %rax,0x20(%rsp)
  mov    $0x0,%esi
  cmp    %rcx,%r12
  jae    L201
  mov    %bpl,0x28(%rsp)
  mov    0x20(%rsp),%rbp
L581:
  add    $0x1,%r12
  movsbl -0x1(%r12),%edi
  call   <toupper@plt>
  add    $0x1,%r15
  mov    %al,-0x1(%r15)
  cmp    %rbp,%r15
  jne    L581
  movzbl 0x28(%rsp),%ebp
  mov    0x20(%rsp),%r15
  mov    $0x0,%esi
  jmp    L201
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  add    %r15,%rax
  mov    %rax,0x20(%rsp)
  mov    $0x0,%esi
  cmp    %rcx,%r12
  jae    L201
  mov    %bpl,0x28(%rsp)
  mov    0x20(%rsp),%rbp
L144:
  add    $0x1,%r12
  movsbl -0x1(%r12),%edi
  call   <tolower@plt>
  add    $0x1,%r15
  mov    %al,-0x1(%r15)
  cmp    %rbp,%r15
  jne    L144
  movzbl 0x28(%rsp),%ebp
  mov    0x20(%rsp),%r15
  mov    $0x0,%esi
  jmp    L201
  cmp    %rcx,%r12
  jae    L493
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  mov    $0x0,%edx
L70:
  movzbl (%r12,%rdx,1),%ecx
  mov    %cl,(%r15,%rdx,1)
  add    $0x1,%rdx
  cmp    %rdx,%rax
  jne    L70
  add    %rax,%r15
  mov    $0x0,%esi
  jmp    L201
L335:
  mov    %al,-0x1(%rbp)
  add    $0x1,%r12
  add    $0x1,%rbp
  cmp    %r12,%r15
  je     L124
L194:
  movzbl (%r12),%edx
  mov    $0x5f,%eax
  cmp    $0x2e,%dl
  je     L335
  movsbl %dl,%edi
  call   <tolower@plt>
  jmp    L335
L124:
  movzbl 0x37(%rsp),%ebp
  mov    0x38(%rsp),%r15
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  add    %rax,%r15
  mov    $0x0,%esi
  jmp    L201
L452:
  mov    %al,-0x1(%rbp)
  add    $0x1,%r12
  add    $0x1,%rbp
  cmp    %r12,%r15
  je     L644
L586:
  movzbl (%r12),%edx
  mov    $0x5f,%eax
  cmp    $0x2e,%dl
  je     L452
  movsbl %dl,%edi
  call   <toupper@plt>
  jmp    L452
L644:
  movzbl 0x37(%rsp),%ebp
  mov    0x38(%rsp),%r15
  mov    0x28(%rsp),%rax
  sub    0x20(%rsp),%rax
  add    %rax,%r15
  mov    $0x0,%esi
  jmp    L201
L86:
  mov    $0x0,%esi
L201:
  movzbl (%rbx),%edx
  cmp    $0x5c,%dl
  je     L60
  mov    %r15,%rax
  sub    %r13,%rax
  add    $0x1,%rax
  cmp    $0x1fff,%rax
  ja     L611
  mov    %dl,(%r15)
  lea    0x1(%r15),%r15
L611:
  cmpb   $0x0,(%rbx)
  je     L16
  mov    $0x0,%r14d
  mov    $0x0,%ebp
L60:
  add    $0x1,%rbx
L314:
  movzbl (%rbx),%eax
  test   %bpl,%bpl
  jne    L96
  cmp    $0x5c,%al
  je     L160
L96:
  cmp    $0x1,%bpl
  sete   %cl
  test   %r14d,%r14d
  sete   %dl
  and    %ecx,%edx
  cmp    $0x5f,%al
  jne    L595
  test   %dl,%dl
  jne    L162
L595:
  cmp    $0x5e,%al
  jne    L41
  test   %dl,%dl
  jne    L38
L41:
  cmp    $0x2e,%al
  jne    L273
  test   %cl,%cl
  jne    L588
L273:
  lea    -0x30(%rax),%edx
  cmp    $0x9,%dl
  ja     L271
  test   %bpl,%bpl
  jne    L367
L271:
  test   %bpl,%bpl
  je     L201
  test   %esi,%esi
  jle    L86
  movslq %esi,%rax
  mov    $0x0,%esi
  cmp    0x8(%rsp),%rax
  ja     L201
  mov    0x80(%rsp),%rsi
  lea    (%rsi,%rax,8),%rax
  mov    (%rax),%edx
  mov    $0x0,%esi
  test   %edx,%edx
  js     L201
  movslq %edx,%rdi
  mov    %rdi,%rsi
  mov    %rdi,0x20(%rsp)
  mov    0x10(%rsp),%rdi
  mov    %rdi,%r12
  add    %rsi,%r12
  movslq 0x4(%rax),%rax
  mov    %rax,0x28(%rsp)
  add    %rax,%rdi
  mov    %rdi,%rcx
  mov    %r15,%rax
  sub    %r13,%rax
  add    %rdi,%rax
  sub    %r12,%rax
  mov    $0x0,%esi
  cmp    $0x1fff,%rax
  ja     L201
  cmp    $0x5,%r14d
  ja     L546
  mov    %r14d,%eax
  lea    D0(%rip),%rdi
  movslq (%rdi,%rax,4),%rax
  add    %rdi,%rax
  notrack jmp *%rax
L546:
  mov    $0x0,%esi
  jmp    L201
L493:
  mov    $0x0,%esi
  jmp    L201
L16:
  mov    0x10(%rsp),%r12
  lea    -0x1(%r15),%rbx
  mov    0x80(%rsp),%rax
  movslq 0x4(%rax),%rax
  lea    (%r12,%rax,1),%rdx
  mov    %rbx,%rcx
  sub    %r13,%rcx
  mov    (%rsp),%rdi
  add    %rdi,%rcx
  sub    %rdx,%rcx
  mov    $0x0,%eax
  cmp    $0x1fff,%rcx
  ja     L326
  cmp    %rdi,%rdx
  jae    L604
  sub    %rdx,%rdi
  mov    %rdi,%rsi
L616:
  movzbl (%rdx,%rax,1),%ecx
  mov    %cl,-0x1(%r15,%rax,1)
  add    $0x1,%rax
  cmp    %rsi,%rax
  jne    L616
  add    %rsi,%rbx
L604:
  mov    0x18(%rsp),%rax
  mov    %rbx,(%rax)
  mov    %rbx,%rbp
  sub    %r13,%rbp
  mov    (%rsp),%rdi
  call   <strlen@plt>
  movslq %eax,%rdx
  add    %rbp,%rdx
  mov    $0x0,%eax
  cmp    $0x1fff,%rdx
  jbe    L457
L326:
  add    $0x48,%rsp
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
L457:
  mov    (%rsp),%rdx
  movzbl (%rdx),%eax
  test   %al,%al
  je     L39
L306:
  add    $0x1,%rbx
  mov    %al,-0x1(%rbx)
  add    $0x1,%rdx
  movzbl (%rdx),%eax
  test   %al,%al
  jne    L306
L39:
  movb   $0x0,(%rbx)
  lea    0x1(%rbx),%rax
  sub    %r13,%rax
  jmp    L326
L160:
  mov    $0x0,%r14d
  mov    $0x1,%ebp
  jmp    L60
L162:
  mov    $0x1,%r14d
  mov    $0x1,%ebp
  jmp    L60
L38:
  mov    $0x2,%r14d
  mov    $0x1,%ebp
  jmp    L60
L325:
  mov    $0x4,%r14d
  mov    $0x1,%ebp
  jmp    L60
L294:
  mov    $0x5,%r14d
  mov    $0x1,%ebp
  jmp    L60
```

assistant: ```c
size_t router_rewrite_metric(char (*newmetric)[8192], char **newfirstspace, const char *metric, const char *firstspace, const char *replacement, const size_t nmatch, const regmatch_t *pmatch) {
  char escape = 0;
  int ref = 0;
  char *s = *newmetric;
  const char *p;
  const char *q;
  const char *t;
  enum rewrite_case { RETAIN, LOWER, UPPER, RETAIN_DOT, LOWER_DOT, UPPER_DOT } rcase = RETAIN;
  assert(pmatch != NULL);
  q = metric;
  t = metric + pmatch[0].rm_so;
  if (s - *newmetric + t - q < sizeof(*newmetric)) {
    while (q < t)
      *s++ = *q++;
  } else {
    return 0;
  }
  for (p = replacement;; p++) {
    switch (*p) {
    case '\\':
      if (!escape) {
        escape = 1;
        rcase = RETAIN;
        break;
      }
    default:
      if (escape == 1 && rcase == RETAIN && *p == '_') {
        rcase = LOWER;
      } else if (escape == 1 && rcase == RETAIN && *p == '^') {
        rcase = UPPER;
      } else if (escape == 1 && *p == '.') {
        if (rcase == LOWER) {
          rcase = LOWER_DOT;
        } else if (rcase == UPPER) {
          rcase = UPPER_DOT;
        } else {
          rcase = RETAIN_DOT;
        }
      } else if (escape && *p >= '0' && *p <= '9') {
        escape = 2;
        ref *= 10;
        ref += *p - '0';
      } else {
        if (escape) {
          if (ref > 0 && ref <= nmatch && pmatch[ref].rm_so >= 0) {
            q = metric + pmatch[ref].rm_so;
            t = metric + pmatch[ref].rm_eo;
            if (s - *newmetric + t - q < sizeof(*newmetric)) {
              switch (rcase) {
              case RETAIN:
                while (q < t)
                  *s++ = *q++;
                break;
              case LOWER:
                while (q < t)
                  *s++ = (char)tolower(*q++);
                break;
              case UPPER:
                while (q < t)
                  *s++ = (char)toupper(*q++);
                break;
              case RETAIN_DOT:
                while (q < t) {
                  if (*q == '.')
                    *s++ = '_';
                  else
                    *s++ = *q;
                  q++;
                }
                break;
              case LOWER_DOT:
                while (q < t) {
                  if (*q == '.')
                    *s++ = '_';
                  else
                    *s++ = (char)tolower(*q);
                  q++;
                }
                break;
              case UPPER_DOT:
                while (q < t) {
                  if (*q == '.')
                    *s++ = '_';
                  else
                    *s++ = (char)toupper(*q);
                  q++;
                }
                break;
              }
            }
          }
          ref = 0;
        }
        if (*p != '\\') {
          escape = 0;
          rcase = RETAIN;
          if (s - *newmetric + 1 < sizeof(*newmetric))
            *s++ = *p;
        }
      }
      break;
    }
    if (*p == '\0')
      break;
  }
  s--;
  q = metric + pmatch[0].rm_eo;
  t = firstspace;
  if (s - *newmetric + t - q < sizeof(*newmetric)) {
    while (q < t)
      *s++ = *q++;
  } else {
    return 0;
  }
  *newfirstspace = s;
  if (s - *newmetric + strlen(firstspace) < sizeof(*newmetric)) {
    for (p = firstspace; *p != '\0'; p++)
      *s++ = *p;
    *s++ = '\0';
    return s - *newmetric;
  }
  return 0;
}
```