// File: /workspace/github_c_makefile_star2_O3/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
xorl %r15d, %r15d
cmpb $0x1, 0x17ebe(%rip)     # 0x2f810
sete %al
movq 0x1c0(%rdi), %r12
cmpq $0x0, (%r12)
je 0x17a99
movq %rsi, %rbx
movq %rdi, %r14
movb %al, %r15b
xorl %eax, %eax
movl %eax, %r13d
movl %eax, 0xc(%rsp)
movq 0x80(%r12), %rbp
cmpq $0x0, (%rbp)
je 0x179af
movl 0xc(%rsp), %r13d
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x17aa8
addl %eax, %r13d
movq (%rbp), %rbp
cmpq $0x0, (%rbp)
jne 0x1798d
movq 0x98(%r12), %rbp
cmpq $0x0, (%rbp)
je 0x179db
movq %r14, %rdi
movq %r12, %rsi
movq %rbp, %rdx
movl %r15d, %ecx
movq %rbx, %r8
callq 0x17aa8
addl %eax, %r13d
movq (%rbp), %rbp
jmp 0x179b7
movl %r13d, %ebp
movl 0xc(%rsp), %eax
subl %eax, %ebp
je 0x17a87
movq 0x18(%r12), %rdi
callq 0x50e0
leaq 0x6(%rax), %rdi
callq 0x6638
movq %rax, %rdi
movq %rax, 0x10(%rsp)
cmpb $0x2, 0x6e(%r14)
leaq 0xbf6b(%rip), %rdx      # 0x2397c
leaq 0xbf5e(%rip), %rax      # 0x23976
cmoveq %rax, %rdx
movq 0x18(%r12), %rcx
leaq 0xbd86(%rip), %rsi      # 0x237ae
xorl %eax, %eax
callq 0x5250
leaq 0x17daa(%rip), %rdi     # 0x2f7e0
movq 0x10(%rsp), %rsi
callq 0x167f2
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 %ebp, %r9d
pushq %r15
pushq %r11
pushq $0x4
pushq %r10
pushq $0x0
callq 0x17ca8
addq $0x30, %rsp
movq (%r12), %r12
cmpq $0x0, (%r12)
movl %r13d, %eax
jne 0x17975
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq