// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_aout.c
// Function: aout_addrelocs
uint32_t aout_addrelocs(struct GlobalVars *gv,struct LinkedSection **ls,
                      int sec,struct list *rlst,
                      uint32_t (*getrinfo)(struct GlobalVars *,struct Reloc *,
                                          bool,const char *,uint32_t),
                      int be)
/* creates a.out relocations for a single section (.text or .data) */
{
  struct Reloc *rel;
  uint32_t rtabsize=0,rinfo;
  lword a;

  if (ls[sec]) {
    if (fff[gv->dest_format]->flags & AOUT_JAGRELOC) {
      /* Output is for Atari Jaguar, so search for possible MOVEI RISC
         relocations and flag them by the internal type R_AOUT_MOVEI. */
      detect_movei_relocs((struct Reloc *)ls[sec]->relocs.first);
      detect_movei_relocs((struct Reloc *)ls[sec]->xrefs.first);
    }

    /* relocations */
    for (rel=(struct Reloc *)ls[sec]->relocs.first; rel->n.next!=NULL;
         rel=(struct Reloc *)rel->n.next) {
      int rsec = aout_sectindex(ls,rel->relocsect.lnk);

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

      /* fix addend for a.out */
      a = (lword)ls[rsec]->base + rel->addend;
      /* @@@ calculation for other relocs: baserel,jmptab,load-relative? */

      if (rel->rtype == R_AOUT_MOVEI)
        a = sign_extend(SWAP16(a),32);

      if ((rinfo = getrinfo(gv,rel,FALSE,ls[sec]->name,rel->offset)) != ~0) {
        aout_addreloclist(rlst,rel->offset,(uint32_t)sectype[rsec],rinfo,be);
        writesection(gv,ls[sec]->data+rel->offset,rel,a);
        rtabsize += sizeof(struct relocation_info);
      }
    }

    /* external references */
    for (rel=(struct Reloc *)ls[sec]->xrefs.first; rel->n.next!=NULL;
         rel=(struct Reloc *)rel->n.next) {
      uint32_t symidx;

      if (rel->flags & RELF_INTERNAL)
        continue;  /* internal relocations will never be exported */
      if ((symidx = aout_findsym(rel->xrefname,be)) == -1)
        symidx = aout_addsym(rel->xrefname,0,0,0,N_UNDF|N_EXT,0,be);

      /* fix addend for a.out */
      if (rel->rtype == R_PC)
        a = rel->addend - (lword)(ls[sec]->base + rel->offset);
      else
        a = rel->addend;
      /* @@@ calculation for other relocs: baserel,jmptab,load-relative? */

      if (rel->rtype == R_AOUT_MOVEI)
        a = sign_extend(SWAP16(a),32);

      if ((rinfo = getrinfo(gv,rel,TRUE,ls[sec]->name,rel->offset)) != ~0) {
        aout_addreloclist(rlst,rel->offset,symidx,rinfo,be);
        writesection(gv,ls[sec]->data+rel->offset,rel,a);
        rtabsize += sizeof(struct relocation_info);
      }
    }
  }

  return (rtabsize);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x14(%rsp)
movq %r8, 0x20(%rsp)
movq %rcx, 0x18(%rsp)
movslq %edx, %r14
movq (%rsi,%r14,8), %r15
testq %r15, %r15
je 0x1b419
movq %rsi, %r12
movq %rdi, %r13
movzbl 0x50(%rdi), %eax
leaq 0x13f91(%rip), %rcx     # 0x2f190
movq (%rcx,%rax,8), %rax
testb $0x1, 0xaf(%rax)
je 0x1b22c
movq 0x80(%r15), %rdi
callq 0x1b42a
movq (%r12,%r14,8), %rax
movq 0x98(%rax), %rdi
callq 0x1b42a
movq (%r12,%r14,8), %r15
subq $-0x80, %r15
movl $0x0, 0x10(%rsp)
movq (%r15), %r15
cmpq $0x0, (%r15)
je 0x1b302
movq 0x18(%r15), %rax
xorl %ebp, %ebp
cmpq $0x3, %rbp
je 0x1b25c
cmpq %rax, (%r12,%rbp,8)
je 0x1b271
incq %rbp
jmp 0x1b24b
movq 0x18(%rax), %rsi
leaq 0x7570(%rip), %rdi      # 0x227d7
xorl %eax, %eax
callq 0x6b2c
pushq $0x3
popq %rbp
testb $0x10, 0x39(%r15)
jne 0x1b238
movq (%r12,%rbp,8), %rax
movq 0x28(%r15), %rbx
addq 0x40(%rax), %rbx
cmpb $0x11, 0x38(%r15)
jne 0x1b29c
roll $0x10, %ebx
movq %rbx, %rdi
pushq $0x20
popq %rsi
callq 0x6ad8
movq %rax, %rbx
movq (%r12,%r14,8), %rax
movq 0x18(%rax), %rcx
movl 0x20(%r15), %r8d
movq %r13, %rdi
movq %r15, %rsi
xorl %edx, %edx
callq *0x20(%rsp)
cmpl $-0x1, %eax
je 0x1b238
movl 0x20(%r15), %esi
leaq 0x7258(%rip), %rcx      # 0x22520
movzbl (%rbp,%rcx), %edx
movq 0x18(%rsp), %rdi
movl %eax, %ecx
movl 0x14(%rsp), %r8d
callq 0x1b4c5
movq (%r12,%r14,8), %rax
movq 0x78(%rax), %rsi
addq 0x20(%r15), %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %rbx, %rcx
callq 0xaf7b
addl $0x8, 0x10(%rsp)
jmp 0x1b238
movl $0x98, %r15d
addq (%r12,%r14,8), %r15
movq (%r15), %r15
cmpq $0x0, (%r15)
je 0x1b413
testb $0x10, 0x39(%r15)
jne 0x1b30c
movq 0x10(%r15), %rbx
movq 0x18c05(%rip), %rbp     # 0x33f30
movq %rbx, %rdi
callq 0x69ee
movzwl %ax, %eax
leaq (%rbp,%rax,8), %rbp
movq (%rbp), %rbp
testq %rbp, %rbp
je 0x1b362
movq 0x18(%rbp), %rsi
movq %rbx, %rdi
callq 0x5160
testl %eax, %eax
je 0x1b35a
addq $0x10, %rbp
jmp 0x1b33b
movl 0x2c(%rbp), %ebx
cmpl $-0x1, %ebx
jne 0x1b381
movq 0x10(%r15), %rdi
movl 0x14(%rsp), %eax
movl %eax, (%rsp)
xorl %esi, %esi
xorl %edx, %edx
xorl %ecx, %ecx
pushq $0x1
popq %r8
xorl %r9d, %r9d
callq 0x1b040
movl %eax, %ebx
movzbl 0x38(%r15), %eax
movq 0x28(%r15), %rbp
cmpl $0x11, %eax
je 0x1b3a5
cmpl $0x2, %eax
jne 0x1b3b6
movq (%r12,%r14,8), %rax
movq 0x40(%rax), %rax
addq 0x20(%r15), %rax
subq %rax, %rbp
jmp 0x1b3b6
roll $0x10, %ebp
movq %rbp, %rdi
pushq $0x20
popq %rsi
callq 0x6ad8
movq %rax, %rbp
movq (%r12,%r14,8), %rax
movq 0x18(%rax), %rcx
movl 0x20(%r15), %r8d
movq %r13, %rdi
movq %r15, %rsi
pushq $0x1
popq %rdx
callq *0x20(%rsp)
cmpl $-0x1, %eax
je 0x1b30c
movl 0x20(%r15), %esi
movq 0x18(%rsp), %rdi
movl %ebx, %edx
movl %eax, %ecx
movl 0x14(%rsp), %r8d
callq 0x1b4c5
movq (%r12,%r14,8), %rax
movq 0x78(%rax), %rsi
addq 0x20(%r15), %rsi
movq %r13, %rdi
movq %r15, %rdx
movq %rbp, %rcx
callq 0xaf7b
addl $0x8, 0x10(%rsp)
jmp 0x1b30c
movl 0x10(%rsp), %eax
jmp 0x1b41b
xorl %eax, %eax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq