user: Converte this assembly snippet into its equivalent C code:

```asm
<router_rewrite_metric>:
  endbr64
  push   %rbp
  mov    %rsp,%rbp
  push   %rbx
  sub    $0x68,%rsp
  mov    %rdi,-0x48(%rbp)
  mov    %rsi,-0x50(%rbp)
  mov    %rdx,-0x58(%rbp)
  mov    %rcx,-0x60(%rbp)
  mov    %r8,-0x68(%rbp)
  mov    %r9,-0x70(%rbp)
  movb   $0x0,-0x39(%rbp)
  movl   $0x0,-0x38(%rbp)
  mov    -0x48(%rbp),%rax
  mov    %rax,-0x30(%rbp)
  movl   $0x0,-0x34(%rbp)
  cmpq   $0x0,0x10(%rbp)
  setne  %al
  movzbl %al,%eax
  mov    %eax,%edi
  call   <assert@plt>
  mov    -0x58(%rbp),%rax
  mov    %rax,-0x20(%rbp)
  mov    0x10(%rbp),%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  sub    -0x20(%rbp),%rax
  cmp    $0x1fff,%rax
  ja     L64
  jmp    L301
L365:
  mov    -0x20(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x30(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L301:
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L365
  jmp    L382
L64:
  mov    $0x0,%eax
  jmp    L336
L382:
  mov    -0x68(%rbp),%rax
  mov    %rax,-0x28(%rbp)
L586:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  cmp    $0x5c,%eax
  jne    L559
  cmpb   $0x0,-0x39(%rbp)
  jne    L559
  movb   $0x1,-0x39(%rbp)
  movl   $0x0,-0x34(%rbp)
  jmp    L271
L559:
  cmpb   $0x1,-0x39(%rbp)
  jne    L467
  cmpl   $0x0,-0x34(%rbp)
  jne    L467
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5f,%al
  jne    L467
  movl   $0x1,-0x34(%rbp)
  jmp    L86
L467:
  cmpb   $0x1,-0x39(%rbp)
  jne    L73
  cmpl   $0x0,-0x34(%rbp)
  jne    L73
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5e,%al
  jne    L73
  movl   $0x2,-0x34(%rbp)
  jmp    L86
L73:
  cmpb   $0x1,-0x39(%rbp)
  jne    L484
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L484
  cmpl   $0x1,-0x34(%rbp)
  jne    L135
  movl   $0x4,-0x34(%rbp)
  jmp    L86
L135:
  cmpl   $0x2,-0x34(%rbp)
  jne    L67
  movl   $0x5,-0x34(%rbp)
  jmp    L86
L67:
  movl   $0x3,-0x34(%rbp)
  jmp    L86
L484:
  cmpb   $0x0,-0x39(%rbp)
  je     L395
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2f,%al
  jle    L395
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x39,%al
  jg     L395
  movb   $0x2,-0x39(%rbp)
  mov    -0x38(%rbp),%edx
  mov    %edx,%eax
  shl    $0x2,%eax
  add    %edx,%eax
  add    %eax,%eax
  mov    %eax,-0x38(%rbp)
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  sub    $0x30,%eax
  add    %eax,-0x38(%rbp)
  jmp    L86
L395:
  cmpb   $0x0,-0x39(%rbp)
  je     L256
  cmpl   $0x0,-0x38(%rbp)
  jle    L453
  mov    -0x38(%rbp),%eax
  cltq
  cmp    %rax,-0x70(%rbp)
  jb     L453
  mov    -0x38(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  test   %eax,%eax
  js     L453
  mov    -0x38(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    0x10(%rbp),%rax
  add    %rdx,%rax
  mov    (%rax),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x38(%rbp),%eax
  cltq
  lea    0x0(,%rax,8),%rdx
  mov    0x10(%rbp),%rax
  add    %rdx,%rax
  mov    0x4(%rax),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  sub    -0x20(%rbp),%rax
  cmp    $0x1fff,%rax
  ja     L453
  cmpl   $0x5,-0x34(%rbp)
  ja     L453
  mov    -0x34(%rbp),%eax
  lea    0x0(,%rax,4),%rdx
  lea    D0(%rip),%rax
  mov    (%rdx,%rax,1),%eax
  cltq
  lea    D0(%rip),%rdx
  add    %rdx,%rax
  notrack jmp *%rax
L297:
  mov    -0x20(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x30(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L297
  jmp    L453
L423:
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <tolower@plt>
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L423
  jmp    L453
L381:
  mov    -0x20(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x20(%rbp)
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <toupper@plt>
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L381
  jmp    L453
L377:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L415
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  movb   $0x5f,(%rax)
  jmp    L488
L415:
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    -0x20(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L488:
  addq   $0x1,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L377
  jmp    L453
L137:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L427
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  movb   $0x5f,(%rax)
  jmp    L437
L427:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <tolower@plt>
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
L437:
  addq   $0x1,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L137
  jmp    L453
L49:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x2e,%al
  jne    L464
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  movb   $0x5f,(%rax)
  jmp    L50
L464:
  mov    -0x20(%rbp),%rax
  movzbl (%rax),%eax
  movsbl %al,%eax
  mov    %eax,%edi
  call   <toupper@plt>
  mov    %rax,%rcx
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    %ecx,%edx
  mov    %dl,(%rax)
L50:
  addq   $0x1,-0x20(%rbp)
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L49
  nop
L453:
  movl   $0x0,-0x38(%rbp)
L256:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  cmp    $0x5c,%al
  je     L86
  movb   $0x0,-0x39(%rbp)
  movl   $0x0,-0x34(%rbp)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  add    $0x1,%rax
  cmp    $0x1fff,%rax
  ja     L86
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    -0x28(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  jmp    L86
L86:
  nop
L271:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  je     L28
  addq   $0x1,-0x28(%rbp)
  jmp    L586
L28:
  nop
  subq   $0x1,-0x30(%rbp)
  mov    0x10(%rbp),%rax
  mov    0x4(%rax),%eax
  movslq %eax,%rdx
  mov    -0x58(%rbp),%rax
  add    %rdx,%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x60(%rbp),%rax
  mov    %rax,-0x18(%rbp)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  mov    %rax,%rdx
  mov    -0x18(%rbp),%rax
  add    %rdx,%rax
  sub    -0x20(%rbp),%rax
  cmp    $0x1fff,%rax
  ja     L424
  jmp    L407
L518:
  mov    -0x20(%rbp),%rdx
  lea    0x1(%rdx),%rax
  mov    %rax,-0x20(%rbp)
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rcx
  mov    %rcx,-0x30(%rbp)
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
L407:
  mov    -0x20(%rbp),%rax
  cmp    -0x18(%rbp),%rax
  jb     L518
  jmp    L140
L424:
  mov    $0x0,%eax
  jmp    L336
L140:
  mov    -0x50(%rbp),%rax
  mov    -0x30(%rbp),%rdx
  mov    %rdx,(%rax)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  mov    %rax,%rbx
  mov    -0x60(%rbp),%rax
  mov    %rax,%rdi
  call   <strlen@plt>
  cltq
  add    %rbx,%rax
  cmp    $0x1fff,%rax
  ja     L23
  mov    -0x60(%rbp),%rax
  mov    %rax,-0x28(%rbp)
  jmp    L317
L487:
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  mov    -0x28(%rbp),%rdx
  movzbl (%rdx),%edx
  mov    %dl,(%rax)
  addq   $0x1,-0x28(%rbp)
L317:
  mov    -0x28(%rbp),%rax
  movzbl (%rax),%eax
  test   %al,%al
  jne    L487
  mov    -0x30(%rbp),%rax
  lea    0x1(%rax),%rdx
  mov    %rdx,-0x30(%rbp)
  movb   $0x0,(%rax)
  mov    -0x30(%rbp),%rax
  sub    -0x48(%rbp),%rax
  jmp    L336
L23:
  mov    $0x0,%eax
L336:
  mov    -0x8(%rbp),%rbx
  leave
  ret
```

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