// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_elf32.c
// Function: elf32_addrela
static int elf32_addrela(struct GlobalVars *gv,struct LinkedSection *ls,
                         struct Reloc *rel,bool be,
                         uint8_t (*reloc_vlink2elf)(struct Reloc *))
{
  struct RelaNode *rn = alloc(sizeof(struct RelaNode));
  uint32_t symidx;
  uint8_t rtype;

  if (rel->flags & RELF_INTERNAL)
    return 0;  /* internal relocations will never be exported */

  if (rel->xrefname) {
    symidx = elf32_symidx(&elf32symlist,&elf32stringlist,rel->xrefname,be);
  }
  else {
    if (rel->relocsect.lnk == NULL) {
      if (!(rel->flags & RELF_DYNLINK))
        return 0;  /* ignore, because it was resolved by a shared object */
      else
        ierror("elf32_addrela: Reloc type %d (%s) at %s+0x%lx (addend 0x%llx)"
               " is missing a relocsect.lnk",(int)rel->rtype,
               reloc_name[rel->rtype],ls->name,rel->offset,rel->addend);
    }
    symidx = (uint32_t)(rel->relocsect.lnk->index + secsyms);
  }

  if (!(rtype = reloc_vlink2elf(rel))) {
    struct RelocInsert *ri;

    if (ri = rel->insert)
      error(32,fff[gv->dest_format]->tname,reloc_name[rel->rtype],
            (int)ri->bpos,(int)ri->bsiz,ri->mask,ls->name,rel->offset);
    else
      ierror("elf32_addrela(): Reloc without insert-field");
  }

  write32(be,rn->r.r_offset,(uint32_t)(ls->base + rel->offset));
  write32(be,rn->r.r_addend,(uint32_t)rel->addend);
  write32(be,rn->r.r_info,ELF32_R_INFO(symidx,(uint32_t)rtype));
  addtail(&relalist,&rn->n);

  if (gv->reloctab_format != RTAB_ADDEND) {
    writesection(gv,ls->data+rel->offset,rel,rel->addend);
    return sizeof(struct Elf32_Rel);
  }
  writesection(gv,ls->data+rel->offset,rel,0);
  return sizeof(struct Elf32_Rela);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r8, 0x18(%rsp)
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
pushq $0x20
popq %rdi
callq 0x6340
movq %rax, %r12
movb 0x39(%rbx), %al
xorl %r14d, %r14d
testb $0x10, %al
jne 0x1691f
movq %r13, 0x10(%rsp)
movq %r15, %r13
movq 0x10(%rbx), %r15
testq %r15, %r15
movq %r12, 0x20(%rsp)
je 0x167d3
movq %r15, %rdi
movl $0xfff2, %esi           # imm = 0xFFF2
movl %ebp, %edx
callq 0x178cc
testl %eax, %eax
jne 0x167cb
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x178cc
testl %eax, %eax
jne 0x167cb
andl $0x0, 0x8(%rsp)
andl $0x0, (%rsp)
leaq 0x18f7d(%rip), %rdi     # 0x2f730
leaq 0x18fd6(%rip), %rsi     # 0x2f790
pushq $0x1
popq %r9
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
callq 0x14bb2
movl %eax, %r14d
movq %r13, %r15
jmp 0x16824
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
movq %r13, %r15
jne 0x16819
cmpb $0x40, %al
jb 0x1691f
movzbl 0x38(%rbx), %esi
leaq 0x18b0e(%rip), %rax     # 0x2f300
movq (%rax,%rsi,8), %rdx
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rbx), %r8
movq 0x28(%rbx), %r9
leaq 0xb192(%rip), %rdi      # 0x219a0
xorl %eax, %eax
callq 0x6b2c
movq 0x18(%rbx), %rcx
movl 0x1d4f4(%rip), %r14d    # 0x33d14
addl 0x10(%rcx), %r14d
movl %ebp, %r12d
movq %rbx, %rdi
callq *0x18(%rsp)
movl %eax, %ebp
testb %al, %al
jne 0x1689c
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x1688e
movzbl 0x50(%r15), %ecx
leaq 0x18947(%rip), %rdx     # 0x2f190
movq (%rdx,%rcx,8), %rcx
movq (%rcx), %rsi
movzbl 0x38(%rbx), %ecx
leaq 0x18aa5(%rip), %rdx     # 0x2f300
movq (%rdx,%rcx,8), %rdx
movzwl 0x8(%rax), %ecx
movzwl 0xa(%rax), %r8d
movq 0x10(%rax), %r9
movq 0x10(%rsp), %rax
movq 0x18(%rax), %rax
movq 0x20(%rbx), %rdi
movq %rdi, 0x8(%rsp)
movq %rax, (%rsp)
pushq $0x20
popq %rdi
xorl %eax, %eax
callq 0x6c19
jmp 0x1689c
leaq 0xb164(%rip), %rdi      # 0x219f9
xorl %eax, %eax
callq 0x6b2c
movq 0x20(%rsp), %r13
leaq 0x10(%r13), %rsi
movl 0x20(%rbx), %edx
movq %r15, 0x18(%rsp)
movq 0x10(%rsp), %r15
addl 0x40(%r15), %edx
movl %r12d, %edi
callq 0x6681
leaq 0x18(%r13), %rsi
movl 0x28(%rbx), %edx
movl %r12d, %edi
callq 0x6681
movq %r13, %rsi
addq $0x14, %rsi
shll $0x8, %r14d
movzbl %bpl, %edx
orl %r14d, %edx
movl %r12d, %edi
callq 0x6681
leaq 0x1d482(%rip), %rdi     # 0x33d70
movq %r13, %rsi
callq 0x6414
movq 0x78(%r15), %rsi
movq 0x18(%rsp), %rdi
addq 0x20(%rbx), %rsi
cmpb $0x2, 0x6e(%rdi)
jne 0x1690f
xorl %ecx, %ecx
pushq $0xc
jmp 0x16915
movq 0x28(%rbx), %rcx
pushq $0x8
popq %r14
movq %rbx, %rdx
callq 0xaf7b
movl %r14d, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq