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

```asm
<rearrange_relocs>:
  endbr64
  push   %r15
  push   %r14
  push   %r13
  push   %r12
  push   %rbp
  push   %rbx
  sub    $0x28,%rsp
  mov    %rcx,(%rsp)
  test   %rdi,%rdi
  je     L157
  mov    %rsi,%rbp
  mov    %rdi,%r14
  mov    %rdx,%r13
  xor    %esi,%esi
  jmp    L16
  nopl   0x0(%rax)
L138:
  mov    D13(%rip),%rdx
  cmp    (%rdx),%rax
  je     L11
L170:
  mov    %r12d,%esi
L16:
  mov    %r14,%rdi
  lea    0x1(%rsi),%r12d
  call   <get_s_header@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L174
  mov    D10(%rip),%rdx
  mov    (%rbx),%rax
  cmp    (%rdx),%rax
  jne    L138
  movslq 0x8(%rbx),%rax
  shr    $0x3,%rax
  test   %eax,%eax
  jle    L170
  mov    0x10(%rbx),%rcx
  lea    -0x1(%rax),%edx
  add    %r14,%rcx
  lea    0x8(%rcx),%rax
  lea    (%rax,%rdx,8),%rsi
  jmp    L162
  cs nopw 0x0(%rax,%rax,1)
L5:
  add    $0x8,%rax
L162:
  mov    (%rcx),%rdx
  cmp    %rbp,%rdx
  jb     L102
  cmp    %rdx,%r13
  jbe    L102
  add    (%rsp),%rdx
  mov    %rdx,(%rcx)
L102:
  mov    %rax,%rcx
  cmp    %rax,%rsi
  jne    L5
  jmp    L170
  nopw   0x0(%rax,%rax,1)
L11:
  movslq 0x8(%rbx),%rax
  shr    $0x4,%rax
  test   %eax,%eax
  jle    L170
  lea    -0x1(%rax),%ecx
  xor    %edx,%edx
  add    $0x1,%rcx
  shl    $0x4,%rcx
  jmp    L92
  nopw   0x0(%rax,%rax,1)
L65:
  add    $0x10,%rdx
  cmp    %rdx,%rcx
  je     L170
L92:
  mov    0x10(%rbx),%r15
  add    %r14,%r15
  add    %rdx,%r15
  mov    (%r15),%rax
  cmp    %rbp,%rax
  jb     L65
  cmp    %rax,%r13
  jbe    L65
  mov    0x1c(%rbx),%esi
  mov    %r14,%rdi
  mov    %rdx,0x18(%rsp)
  mov    %rcx,0x10(%rsp)
  call   <get_s_header@plt>
  mov    0x8(%r15),%edi
  mov    %rax,0x8(%rsp)
  call   <ELF64_R_SYM@plt>
  mov    0x8(%rsp),%rsi
  mov    %r14,%rdi
  mov    0x10(%rsp),%rcx
  mov    0x18(%rsp),%rdx
  imul   0x18(%rsi),%eax
  add    0x10(%rsi),%rdi
  mov    (%r15),%rsi
  cltq
  add    %rdi,%rax
  mov    (%rsp),%rdi
  add    %rsi,%rdi
  cmp    (%rax),%rsi
  jne    L134
  mov    %rdi,(%rax)
L134:
  mov    %rdi,(%r15)
  jmp    L65
  nopl   (%rax)
L174:
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L157:
  add    $0x28,%rsp
  mov    $0x1,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
```

assistant: ```c
int rearrange_relocs(char *elf, void *base, void *top, size_t n) {
  if (!elf)
    return 1;
  int sh_num;
  sh_num = 0;
  Elf64_Shdr *shdr;
  Elf64_Shdr *linked;
  while ((shdr = get_s_header(elf, sh_num++))) {
    int num, i;
    unsigned long long addr;
    if (shdr->sh_type == SHT_RELA) {
      num = shdr->sh_size / sizeof(Elf64_Rela);
      Elf64_Rela *rel;
      for (i = 0; i < num; i++) {
        addr = ((unsigned long long)elf + shdr->sh_offset + (i * sizeof(Elf64_Rela)));
        rel = (Elf64_Rela *)addr;
        if ((unsigned long long)rel->r_offset >= (unsigned long long)base && (unsigned long long)rel->r_offset < (unsigned long long)top) {
          rel->r_offset += n;
        }
      }
    } else if (shdr->sh_type == SHT_REL) {
      num = shdr->sh_size / sizeof(Elf64_Rel);
      Elf64_Rel *rel;
      for (i = 0; i < num; i++) {
        addr = ((unsigned long long)elf + shdr->sh_offset + (i * sizeof(Elf64_Rel)));
        rel = (Elf64_Rel *)addr;
        if ((unsigned long long)rel->r_offset >= (unsigned long long)base && (unsigned long long)rel->r_offset < (unsigned long long)top) {
          linked = get_s_header(elf, shdr->sh_link);
          unsigned long long sym_addr;
          Elf64_Sym *sym;
          int sym_ind = ELF64_R_SYM(rel->r_info);
          sym_addr = (unsigned long long)elf + linked->sh_offset;
          sym_addr += linked->sh_entsize * sym_ind;
          sym = (Elf64_Sym *)sym_addr;
          if (rel->r_offset == sym->st_value)
            sym->st_value += n;
          rel->r_offset += n;
        }
      }
    }
  }
  return 0;
}
```