// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_addrelocs
void elf32_addrelocs(struct GlobalVars *gv,
                     uint8_t (*reloc_vlink2elf)(struct Reloc *))
/* creates relocations for all sections */
{
  bool be = elf32_endianess == _BIG_ENDIAN_;
  struct LinkedSection *ls;
  struct Reloc *rel;
  uint32_t sroffs=0,roffs=0;

  for (ls=(struct LinkedSection *)gv->lnksec.first;
       ls->n.next!=NULL; ls=(struct LinkedSection *)ls->n.next) {
    sroffs = roffs;

    /* relocations */
    for (rel=(struct Reloc *)ls->relocs.first;
         rel->n.next!=NULL; rel=(struct Reloc *)rel->n.next) {
      roffs += elf32_addrela(gv,ls,rel,be,reloc_vlink2elf);
    }

    /* external references */
    for (rel=(struct Reloc *)ls->xrefs.first;
         rel->n.next!=NULL; rel=(struct Reloc *)rel->n.next) {
      roffs += elf32_addrela(gv,ls,rel,be,reloc_vlink2elf);
    }

    if (roffs != sroffs) {
      /* create ".rel(a).name" header */
      char *relname = (char *)alloc(strlen(ls->name)+6);

      sprintf(relname,".%s%s",
              gv->reloctab_format==RTAB_ADDEND ? "rela" : "rel",
              ls->name);
      elf32_addshdr(elf32_addshdrstr(relname),
                    gv->reloctab_format==RTAB_ADDEND ? SHT_RELA : SHT_REL,
                    0,0,sroffs,roffs-sroffs,0,(uint32_t)ls->index,4,
                    gv->reloctab_format==RTAB_ADDEND ?
                      sizeof(struct Elf32_Rela) : sizeof(struct Elf32_Rel),
                    be);
      /* sroffs is relative and will be corrected later */
      /* sh_link will be initialized, when .symtab exists */
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, %r14
xorl %r15d, %r15d
cmpb $0x1, 0x19219(%rip)     # 0x2f820
sete %r15b
leaq 0x1c0(%rdi), %r12
xorl %ebp, %ebp
movq (%r12), %r12
cmpq $0x0, (%r12)
je 0x16724
leaq 0x80(%r12), %r13
movl %ebp, 0xc(%rsp)
movq (%r13), %r13
cmpq $0x0, (%r13)
je 0x16652
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x16733
addl %eax, %ebp
jmp 0x1662f
leaq 0x98(%r12), %r13
movq (%r13), %r13
cmpq $0x0, (%r13)
je 0x1667d
movq %r14, %rdi
movq %r12, %rsi
movq %r13, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x16733
addl %eax, %ebp
jmp 0x1665a
movl %ebp, %r13d
movl 0xc(%rsp), %eax
subl %eax, %r13d
je 0x16614
movq 0x18(%r12), %rdi
callq 0x50e0
leaq 0x6(%rax), %rdi
callq 0x6340
movq %rax, %rdi
movq %rax, 0x10(%rsp)
cmpb $0x2, 0x6e(%r14)
leaq 0xb2ec(%rip), %rdx      # 0x2199c
leaq 0xb2df(%rip), %rax      # 0x21996
cmoveq %rax, %rdx
movq 0x18(%r12), %rcx
leaq 0xb107(%rip), %rsi      # 0x217ce
xorl %eax, %eax
callq 0x5260
movq 0x10(%rsp), %rdi
callq 0x169fe
xorl %ecx, %ecx
xorl %edx, %edx
cmpb $0x2, 0x6e(%r14)
sete %cl
setne %dl
leal (%rdx,%rdx,4), %esi
addl $0x4, %esi
movl 0x10(%r12), %r10d
leal 0x8(,%rcx,4), %r11d
subq $0x8, %rsp
movl %eax, %edi
xorl %edx, %edx
xorl %ecx, %ecx
movl 0x14(%rsp), %r8d
movl %r13d, %r9d
pushq %r15
pushq %r11
pushq $0x4
pushq %r10
pushq $0x0
callq 0x16931
addq $0x30, %rsp
jmp 0x16614
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq