// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x58, %rsp
movq %rdi, 0x50(%rsp)
movq %rsi, 0x48(%rsp)
movl %edx, 0x44(%rsp)
movq %rcx, 0x38(%rsp)
movq %r8, 0x30(%rsp)
movl %r9d, 0x2c(%rsp)
movl $0x0, 0x1c(%rsp)
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
cmpq $0x0, (%rax,%rcx,8)
je 0x2dc5a
movq 0x50(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x12150(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movl 0xac(%rax), %eax
andl $0x1000000, %eax        # imm = 0x1000000
cmpl $0x0, %eax
je 0x2d928
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x80(%rax), %rdi
callq 0x2dc70
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x98(%rax), %rdi
callq 0x2dc70
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x80(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
je 0x2da98
movq 0x48(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x2dde0
movl %eax, 0xc(%rsp)
movq 0x20(%rsp), %rax
movzbl 0x39(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x2d97e
jmp 0x2da86
movq 0x48(%rsp), %rax
movslq 0xc(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x40(%rax), %rax
movq 0x20(%rsp), %rcx
addq 0x28(%rcx), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x11, %eax
jne 0x2d9e1
movq 0x10(%rsp), %rdi
andq $0xffff, %rdi           # imm = 0xFFFF
shlq $0x10, %rdi
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq 0x10(%rsp), %rax
sarq $0x10, %rax
orq %rax, %rdi
movl $0x20, %esi
callq 0x89f0
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x48(%rsp), %rcx
movslq 0x44(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rsp), %rdx
movq 0x20(%rdx), %rdx
movl %edx, %r8d
xorl %edx, %edx
callq *%rax
movl %eax, 0x18(%rsp)
cmpl $-0x1, %eax
je 0x2da84
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movl %eax, %esi
movslq 0xc(%rsp), %rcx
leaq 0x13801(%rip), %rax     # 0x41238
movzbl (%rax,%rcx), %edx
movl 0x18(%rsp), %ecx
movl 0x2c(%rsp), %r8d
callq 0x2de50
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x78(%rax), %rsi
movq 0x20(%rsp), %rax
addq 0x20(%rax), %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x110c0
movl 0x1c(%rsp), %eax
addq $0x8, %rax
movl %eax, 0x1c(%rsp)
jmp 0x2da86
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x2d942
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x98(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x20(%rsp), %rax
cmpq $0x0, (%rax)
je 0x2dc58
movq 0x20(%rsp), %rax
movzbl 0x39(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0x2dad7
jmp 0x2dc46
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x2c(%rsp), %esi
callq 0x2def0
movl %eax, 0x8(%rsp)
cmpl $-0x1, %eax
jne 0x2db1d
movq 0x20(%rsp), %rax
movq 0x10(%rax), %rdi
movl 0x2c(%rsp), %eax
xorl %r9d, %r9d
movl $0x1, %r8d
movl %r9d, %esi
movl %r9d, %edx
movl %r9d, %ecx
movl %eax, (%rsp)
callq 0x2d6e0
movl %eax, 0x8(%rsp)
movq 0x20(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x2, %eax
jne 0x2db59
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movq 0x48(%rsp), %rcx
movslq 0x44(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x40(%rcx), %rcx
movq 0x20(%rsp), %rdx
addq 0x20(%rdx), %rcx
subq %rcx, %rax
movq %rax, 0x10(%rsp)
jmp 0x2db67
movq 0x20(%rsp), %rax
movq 0x28(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x20(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x11, %eax
jne 0x2dbaa
movq 0x10(%rsp), %rdi
andq $0xffff, %rdi           # imm = 0xFFFF
shlq $0x10, %rdi
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq 0x10(%rsp), %rax
sarq $0x10, %rax
orq %rax, %rdi
movl $0x20, %esi
callq 0x89f0
movq %rax, 0x10(%rsp)
movq 0x30(%rsp), %rax
movq 0x50(%rsp), %rdi
movq 0x20(%rsp), %rsi
movq 0x48(%rsp), %rcx
movslq 0x44(%rsp), %rdx
movq (%rcx,%rdx,8), %rcx
movq 0x18(%rcx), %rcx
movq 0x20(%rsp), %rdx
movq 0x20(%rdx), %rdx
movl %edx, %r8d
movl $0x1, %edx
callq *%rax
movl %eax, 0x18(%rsp)
cmpl $-0x1, %eax
je 0x2dc44
movq 0x38(%rsp), %rdi
movq 0x20(%rsp), %rax
movq 0x20(%rax), %rax
movl %eax, %esi
movl 0x8(%rsp), %edx
movl 0x18(%rsp), %ecx
movl 0x2c(%rsp), %r8d
callq 0x2de50
movq 0x50(%rsp), %rdi
movq 0x48(%rsp), %rax
movslq 0x44(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movq 0x78(%rax), %rsi
movq 0x20(%rsp), %rax
addq 0x20(%rax), %rsi
movq 0x20(%rsp), %rdx
movq 0x10(%rsp), %rcx
callq 0x110c0
movl 0x1c(%rsp), %eax
addq $0x8, %rax
movl %eax, 0x1c(%rsp)
jmp 0x2dc46
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x20(%rsp)
jmp 0x2dab2
jmp 0x2dc5a
movl 0x1c(%rsp), %eax
addq $0x58, %rsp
retq
nopw %cs:(%rax,%rax)