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     L113
  mov    %rsi,%rbp
  mov    %rdi,%r14
  mov    %rdx,%r13
  xor    %esi,%esi
  jmp    L59
  nopl   0x0(%rax)
L72:
  mov    D3(%rip),%rdx
  cmp    (%rdx),%rax
  je     L117
L98:
  mov    %r12d,%esi
L59:
  mov    %r14,%rdi
  lea    0x1(%rsi),%r12d
  call   <get_s_header@plt>
  mov    %rax,%rbx
  test   %rax,%rax
  je     L111
  mov    D10(%rip),%rdx
  mov    (%rbx),%rax
  cmp    (%rdx),%rax
  jne    L72
  movslq 0x8(%rbx),%rax
  shr    $0x3,%rax
  test   %eax,%eax
  jle    L98
  mov    0x10(%rbx),%rcx
  lea    -0x1(%rax),%edx
  add    %r14,%rcx
  lea    0x8(%rcx),%rax
  lea    (%rax,%rdx,8),%rsi
  jmp    L164
  cs nopw 0x0(%rax,%rax,1)
L26:
  add    $0x8,%rax
L164:
  mov    (%rcx),%rdx
  cmp    %rbp,%rdx
  jb     L172
  cmp    %rdx,%r13
  jbe    L172
  add    (%rsp),%rdx
  mov    %rdx,(%rcx)
L172:
  mov    %rax,%rcx
  cmp    %rax,%rsi
  jne    L26
  jmp    L98
  nopw   0x0(%rax,%rax,1)
L117:
  movslq 0x8(%rbx),%rax
  shr    $0x4,%rax
  test   %eax,%eax
  jle    L98
  lea    -0x1(%rax),%ecx
  xor    %edx,%edx
  add    $0x1,%rcx
  shl    $0x4,%rcx
  jmp    L36
  nopw   0x0(%rax,%rax,1)
L146:
  add    $0x10,%rdx
  cmp    %rdx,%rcx
  je     L98
L36:
  mov    0x10(%rbx),%r15
  add    %r14,%r15
  add    %rdx,%r15
  mov    (%r15),%rax
  cmp    %rbp,%rax
  jb     L146
  cmp    %rax,%r13
  jbe    L146
  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    L68
  mov    %rdi,(%rax)
L68:
  mov    %rdi,(%r15)
  jmp    L146
  nopl   (%rax)
L111:
  add    $0x28,%rsp
  xor    %eax,%eax
  pop    %rbx
  pop    %rbp
  pop    %r12
  pop    %r13
  pop    %r14
  pop    %r15
  ret
  nopl   0x0(%rax)
L113:
  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;
}
```