// File: /workspace/github_c_makefile_star2_O3/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 $0x18, %rsp
movq %r8, 0x8(%rsp)
movl %ecx, %ebp
movq %rdx, %rbx
movq %rsi, %r13
movq %rdi, %r15
movl $0x20, %edi
callq 0x6638
movq %rax, %r12
movb 0x39(%rbx), %al
xorl %r14d, %r14d
testb $0x10, %al
jne 0x17c96
movq %r13, (%rsp)
movq %r15, %r13
movq 0x10(%rbx), %r15
testq %r15, %r15
movq %r12, 0x10(%rsp)
je 0x17b4a
movq %r15, %rdi
movl $0xfff2, %esi           # imm = 0xFFF2
movl %ebp, %edx
callq 0x18dc5
testl %eax, %eax
jne 0x17b42
movq %r15, %rdi
xorl %esi, %esi
movl %ebp, %edx
callq 0x18dc5
testl %eax, %eax
jne 0x17b42
leaq 0x17c00(%rip), %rdi     # 0x2f720
leaq 0x17c59(%rip), %rsi     # 0x2f780
movq %r15, %rdx
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, %r9d
xorl %eax, %eax
pushq %rax
pushq %rax
callq 0x15d58
addq $0x10, %rsp
movl %eax, %r14d
movq %r13, %r15
jmp 0x17b9a
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
movq %r13, %r15
jne 0x17b8f
cmpb $0x40, %al
jb 0x17c96
movzbl 0x38(%rbx), %esi
leaq 0x17787(%rip), %rax     # 0x2f2f0
movq (%rax,%rsi,8), %rdx
movq (%rsp), %rax
movq 0x18(%rax), %rcx
movq 0x20(%rbx), %r8
movq 0x28(%rbx), %r9
leaq 0xbdfc(%rip), %rdi      # 0x23980
xorl %eax, %eax
callq 0x52b0
movq 0x18(%rbx), %rcx
movl 0x1bd8e(%rip), %r14d    # 0x33924
addl 0x10(%rcx), %r14d
movl %ebp, %r12d
movq %rbx, %rdi
callq *0x8(%rsp)
movl %eax, %ebp
testb %al, %al
jne 0x17c0e
movq 0x30(%rbx), %rax
testq %rax, %rax
je 0x17c00
movzbl 0x50(%r15), %ecx
leaq 0x175c1(%rip), %rdx     # 0x2f180
movq (%rdx,%rcx,8), %rcx
movq (%rcx), %rsi
movzbl 0x38(%rbx), %ecx
leaq 0x1771f(%rip), %rdx     # 0x2f2f0
movq (%rdx,%rcx,8), %rdx
movzwl 0x8(%rax), %ecx
movzwl 0xa(%rax), %r8d
movq 0x10(%rax), %r9
movl $0x20, %edi
xorl %eax, %eax
pushq 0x20(%rbx)
movq 0x8(%rsp), %r10
pushq 0x18(%r10)
callq 0x6f14
addq $0x10, %rsp
jmp 0x17c0e
leaq 0xbdd2(%rip), %rdi      # 0x239d9
xorl %eax, %eax
callq 0x52b0
movq 0x10(%rsp), %r13
leaq 0x10(%r13), %rsi
movl 0x20(%rbx), %edx
movq %r15, 0x8(%rsp)
movq (%rsp), %r15
addl 0x40(%r15), %edx
movl %r12d, %edi
callq 0x69a0
leaq 0x18(%r13), %rsi
movl 0x28(%rbx), %edx
movl %r12d, %edi
callq 0x69a0
movq %r13, %rsi
addq $0x14, %rsi
shll $0x8, %r14d
movzbl %bpl, %edx
orl %r14d, %edx
movl %r12d, %edi
callq 0x69a0
leaq 0x1bd21(%rip), %rdi     # 0x33980
movq %r13, %rsi
callq 0x6729
movq 0x78(%r15), %rsi
movq 0x8(%rsp), %rdi
addq 0x20(%rbx), %rsi
cmpb $0x2, 0x6e(%rdi)
jne 0x17c84
xorl %ecx, %ecx
movl $0xc, %r14d
jmp 0x17c8e
movq 0x28(%rbx), %rcx
movl $0x8, %r14d
movq %rbx, %rdx
callq 0xb4ed
movl %r14d, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq