user: 请将以下的汇编代码转换成C语言代码：

```asm
<router_rewrite_metric>:
  endbr64
  push   %r15
  mov    %rdi,%r15
  xor    %edi,%edi
  push   %r14
  mov    %rcx,%r14
  push   %r13
  mov    %rdx,%r13
  push   %r12
  push   %rbp
  mov    %r8,%rbp
  push   %rbx
  sub    $0x48,%rsp
  cmpq   $0x0,0x80(%rsp)
  mov    %rsi,0x8(%rsp)
  setne  %dil
  mov    %r9,(%rsp)
  call   <assert@plt>
  mov    0x80(%rsp),%rax
  movslq (%rax),%rbx
  cmp    $0x1fff,%rbx
  ja     L528
  lea    0x0(%r13,%rbx,1),%rax
  cmp    %rax,%r13
  jae    L599
  xor    %eax,%eax
  nopl   0x0(%rax,%rax,1)
L325:
  movzbl 0x0(%r13,%rax,1),%edx
  mov    %dl,(%r15,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rbx
  jne    L325
  add    %r15,%rbx
L291:
  xor    %edx,%edx
  mov    %r13,%r8
  xor    %r10d,%r10d
  xor    %r12d,%r12d
  lea    D46(%rip),%rcx
  mov    %edx,%r13d
  mov    %r14,%r9
  cs nopw 0x0(%rax,%rax,1)
L497:
  mov    %rbx,%rdi
  movzbl 0x0(%rbp),%eax
  sub    %r15,%rdi
  test   %r12b,%r12b
  jne    L363
  cmp    $0x5c,%al
  je     L24
L363:
  cmp    $0x1,%r12b
  jne    L269
  test   %r13d,%r13d
  jne    L538
  cmp    $0x5f,%al
  je     L433
  cmp    $0x5e,%al
  je     L111
  cmp    $0x2e,%al
  je     L373
L3:
  lea    -0x30(%rax),%edx
  cmp    $0x9,%dl
  jbe    L577
L582:
  test   %r10d,%r10d
  je     L19
  movslq %r10d,%rdx
  xor    %r10d,%r10d
  cmp    (%rsp),%rdx
  jbe    L262
  nopl   0x0(%rax,%rax,1)
L19:
  cmp    $0x5c,%al
  je     L388
  add    $0x1,%rdi
  cmp    $0x1fff,%rdi
  ja     L106
  mov    %al,(%rbx)
  movzbl 0x0(%rbp),%eax
  add    $0x1,%rbx
L106:
  test   %al,%al
  je     L495
  xor    %r13d,%r13d
  xor    %r12d,%r12d
L388:
  add    $0x1,%rbp
  jmp    L497
  xchg   %ax,%ax
L538:
  cmp    $0x1,%r12b
  je     L49
  nopw   0x0(%rax,%rax,1)
L269:
  test   %r12b,%r12b
  je     L19
  lea    -0x30(%rax),%edx
  cmp    $0x9,%dl
  ja     L582
L577:
  lea    (%r10,%r10,4),%eax
  movsbl %dl,%edx
  mov    $0x2,%r12d
  lea    (%rdx,%rax,2),%r10d
  jmp    L388
L24:
  xor    %r13d,%r13d
  mov    $0x1,%r12d
  jmp    L388
  nopl   0x0(%rax,%rax,1)
L495:
  mov    0x80(%rsp),%rax
  lea    -0x1(%rbx),%rbp
  mov    %r8,%r13
  mov    %r9,%r14
  mov    %rbp,%r12
  movslq 0x4(%rax),%rax
  sub    %r15,%r12
  add    %rax,%r13
  lea    (%r9,%r12,1),%rax
  sub    %r13,%rax
  cmp    $0x1fff,%rax
  ja     L528
  cmp    %r9,%r13
  jae    L443
  mov    %r9,%rsi
  xor    %eax,%eax
  sub    %r13,%rsi
  nopl   0x0(%rax,%rax,1)
L522:
  movzbl 0x0(%r13,%rax,1),%edx
  mov    %dl,-0x1(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rsi
  jne    L522
  add    %rsi,%rbp
  mov    %rbp,%r12
  sub    %r15,%r12
L443:
  mov    0x8(%rsp),%rax
  mov    %r14,%rdi
  mov    %rbp,(%rax)
  call   <strlen@plt>
  cltq
  add    %r12,%rax
  cmp    $0x1fff,%rax
  jbe    L274
L528:
  add    $0x48,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  xchg   %ax,%ax
L433:
  mov    $0x1,%r13d
  mov    $0x1,%r12d
  jmp    L388
  nopl   0x0(%rax)
L111:
  mov    $0x2,%r13d
  mov    $0x1,%r12d
  jmp    L388
  nopl   0x0(%rax)
L262:
  mov    0x80(%rsp),%rsi
  lea    (%rsi,%rdx,8),%rsi
  movslq (%rsi),%rdx
  test   %edx,%edx
  js     L19
  movslq 0x4(%rsi),%rsi
  lea    (%r8,%rdx,1),%r14
  mov    %rsi,0x10(%rsp)
  add    %r8,%rsi
  lea    (%rsi,%rdi,1),%r11
  sub    %r14,%r11
  cmp    $0x1fff,%r11
  ja     L19
  cmp    $0x5,%r13d
  ja     L19
  mov    %r13d,%r10d
  movslq (%rcx,%r10,4),%r10
  add    %rcx,%r10
  notrack jmp *%r10
  nopl   0x0(%rax,%rax,1)
L583:
  mov    %al,0x0(%rbp)
  add    $0x1,%rbp
  add    $0x1,%r14
L274:
  movzbl (%r14),%eax
  test   %al,%al
  jne    L583
  movb   $0x0,0x0(%rbp)
  lea    0x1(%rbp),%rax
  add    $0x48,%rsp
  pop    %rbx
  sub    %r15,%rax
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   (%rax)
L373:
  mov    $0x3,%r13d
  mov    $0x1,%r12d
  jmp    L388
  nopl   0x0(%rax)
L599:
  mov    %r15,%rbx
  jmp    L291
  mov    %rbx,%r10
  cmp    %rsi,%r14
  jae    L96
  mov    %rdx,0x18(%rsp)
  mov    %r8,0x30(%rsp)
  mov    %r12b,0x20(%rsp)
  mov    %r10,%r12
  mov    %rbx,0x28(%rsp)
  mov    %rsi,%rbx
  mov    %rbp,0x38(%rsp)
  mov    %r14,%rbp
  mov    %r9,%r14
  nopl   0x0(%rax)
L279:
  movsbl 0x0(%rbp),%edi
  add    $0x1,%r12
  mov    $0x5f,%eax
  cmp    $0x2e,%dil
  je     L15
  call   <tolower@plt>
  lea    D46(%rip),%rcx
L15:
  add    $0x1,%rbp
  mov    %al,-0x1(%r12)
  cmp    %rbp,%rbx
  jne    L279
L403:
  mov    0x18(%rsp),%rdx
  movzbl 0x20(%rsp),%r12d
  mov    %r14,%r9
  mov    0x28(%rsp),%rbx
  mov    0x30(%rsp),%r8
L97:
  mov    0x10(%rsp),%rax
  mov    0x38(%rsp),%rbp
  xor    %r10d,%r10d
  sub    %rdx,%rax
  add    %rax,%rbx
  movzbl 0x0(%rbp),%eax
  mov    %rbx,%rdi
  sub    %r15,%rdi
  jmp    L19
  mov    0x10(%rsp),%r10
  sub    %rdx,%r10
  xor    %edx,%edx
  cmp    %rsi,%r14
  jae    L96
  nopw   0x0(%rax,%rax,1)
L237:
  movzbl (%r14,%rdx,1),%eax
  mov    $0x5f,%esi
  cmp    $0x2e,%al
  cmove  %esi,%eax
  mov    %al,(%rbx,%rdx,1)
  add    $0x1,%rdx
  cmp    %rdx,%r10
  jne    L237
  add    %r10,%rbx
  movzbl 0x0(%rbp),%eax
  xor    %r10d,%r10d
  mov    %rbx,%rdi
  sub    %r15,%rdi
  jmp    L19
  mov    0x10(%rsp),%r10
  sub    %rdx,%r10
  lea    (%rbx,%r10,1),%rdx
  cmp    %rsi,%r14
  jae    L96
  mov    %r8,0x10(%rsp)
  mov    %r9,0x18(%rsp)
  mov    %rbp,0x20(%rsp)
  mov    %r14,%rbp
  mov    %rdx,%r14
  nopw   0x0(%rax,%rax,1)
L469:
  movsbl 0x0(%rbp),%edi
  add    $0x1,%rbx
  add    $0x1,%rbp
  call   <toupper@plt>
  cmp    %r14,%rbx
  lea    D46(%rip),%rcx
  mov    %al,-0x1(%rbx)
  jne    L469
  mov    0x20(%rsp),%rbp
  mov    %rbx,%rdi
  mov    0x10(%rsp),%r8
  xor    %r10d,%r10d
  mov    0x18(%rsp),%r9
  sub    %r15,%rdi
  movzbl 0x0(%rbp),%eax
  jmp    L19
  mov    %rbx,%r10
  cmp    %rsi,%r14
  jae    L96
  mov    %rdx,0x18(%rsp)
  mov    %r8,0x28(%rsp)
  mov    %r9,0x30(%rsp)
  mov    %rbx,0x20(%rsp)
  mov    %r14,%rbx
  mov    %rsi,%r14
  mov    %rbp,0x38(%rsp)
  mov    %r10,%rbp
  nop
L327:
  movsbl (%rbx),%edi
  add    $0x1,%rbx
  add    $0x1,%rbp
  call   <tolower@plt>
  cmp    %rbx,%r14
  lea    D46(%rip),%rcx
  mov    %al,-0x1(%rbp)
  jne    L327
  mov    0x18(%rsp),%rdx
  mov    0x20(%rsp),%rbx
  mov    0x28(%rsp),%r8
  mov    0x30(%rsp),%r9
  jmp    L97
  mov    %rbx,%r10
  cmp    %rsi,%r14
  jae    L96
  mov    %rdx,0x18(%rsp)
  mov    %r8,0x30(%rsp)
  mov    %r12b,0x20(%rsp)
  mov    %r10,%r12
  mov    %rbx,0x28(%rsp)
  mov    %rsi,%rbx
  mov    %rbp,0x38(%rsp)
  mov    %r14,%rbp
  mov    %r9,%r14
  nopl   0x0(%rax)
L137:
  movsbl 0x0(%rbp),%edi
  add    $0x1,%r12
  mov    $0x5f,%eax
  cmp    $0x2e,%dil
  je     L570
  call   <toupper@plt>
  lea    D46(%rip),%rcx
L570:
  add    $0x1,%rbp
  mov    %al,-0x1(%r12)
  cmp    %rbp,%rbx
  jne    L137
  jmp    L403
  cmp    %rsi,%r14
  jae    L96
  mov    0x10(%rsp),%rsi
  xor    %eax,%eax
  sub    %rdx,%rsi
  nopl   0x0(%rax)
L557:
  movzbl (%r14,%rax,1),%edx
  mov    %dl,(%rbx,%rax,1)
  add    $0x1,%rax
  cmp    %rax,%rsi
  jne    L557
  add    %rsi,%rbx
  movzbl 0x0(%rbp),%eax
  xor    %r10d,%r10d
  mov    %rbx,%rdi
  sub    %r15,%rdi
  jmp    L19
L96:
  xor    %r10d,%r10d
  jmp    L19
L49:
  cmp    $0x2e,%al
  jne    L3
  cmp    $0x1,%r13d
  jne    L162
  mov    $0x4,%r13d
  jmp    L388
  nop
L162:
  cmp    $0x2,%r13d
  jne    L572
  mov    $0x5,%r13d
  jmp    L388
L572:
  mov    $0x3,%r13d
  jmp    L388
```

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;
}
```