// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_aout.c
// Function: aout_newreloc
static void aout_newreloc(struct GlobalVars *gv,struct aout_hdr *hdr,
                          struct Section *sec,uint32_t saddr,uint32_t symidx,
                          bool xtern,uint8_t rtype,uint16_t size,
                          uint32_t offs,int be)
{
  const char *fn = "aout_newreloc(): ";
  struct ObjectUnit *ou = sec->obj;
  struct LinkFile *lf = ou->lnkfile;
  lword mask = -1;
  lword a = readsection(gv,rtype,sec->data+offs,0,size,mask);

  if (rtype == R_AOUT_MOVEI)
    a = sign_extend(SWAP16(a),32);  /* swap 16-bit words */

  if (xtern) {
    /* relocation by an external reference to an unknown symbol */
    char *strtab = ((char *)hdr) + aout_stroffset(hdr,be);
    struct nlist32 *nlst = (struct nlist32 *)(((char *)hdr) +
                                              aout_symoffset(hdr,be));
    char *xrefname = strtab + read32(be,&nlst[symidx].n_strx);

    if (rtype == R_PC) {
      /* fix a.out specific PC-relative relocs */
      a += (lword)saddr + (lword)offs;
    }

    if (nlst[symidx].n_type == N_EXT|N_UNDF) {
      if (rtype == R_AOUT_MOVEI) {
        addreloc(sec,newreloc(gv,sec,xrefname,NULL,0,offs,R_ABS,a),
                 0,16,0xffff);
        addreloc(sec,newreloc(gv,sec,xrefname,NULL,0,offs+2,R_ABS,a),
                 0,16,0xffff0000);
      }
      else
        addreloc(sec,newreloc(gv,sec,xrefname,NULL,0,offs,rtype,a),
                 0,size,mask);
    }
    else
      error(91,lf->pathname,xrefname,sec->name);  /* illegal ext. ref. */
  }

  else {
    /* local relocation */
    struct Section *rsec = NULL;
    uint32_t rsaddr = 0; /* reloc section base address in object file */

    if (symidx & ~N_TYPE)  /* illegal nlist type in relocation */
      error(92,lf->pathname,symidx,sec->name,lf->objname,offs);

    switch (symidx & N_TYPE) {
      case N_TEXT:
        if (!(rsec = find_sect_type(ou,ST_CODE,SP_READ|SP_EXEC)))
          ierror("%sno .text for reloc found",fn);
        rsaddr = 0;
        break;

      case N_DATA:
        if (!(rsec = find_sect_type(ou,ST_DATA,SP_READ|SP_WRITE)))
          ierror("%sno .data for reloc found",fn);
        rsaddr = read32(be,hdr->a_text);
        break;

      case N_BSS:
        if (!(rsec = find_sect_type(ou,ST_UDATA,SP_READ|SP_WRITE)))
          ierror("%sno .bss for reloc found",fn);
        rsaddr = read32(be,hdr->a_text) + read32(be,&hdr->a_data);
        break;

      default:
        ierror("%slocal reloc with nlist type %lu is not supported",
               fn,symidx&N_TYPE);
        break;
    }

    /* fix addend for a.out */
    switch (rtype) {
      case R_ABS:
      case R_AOUT_MOVEI:
        a -= (lword)rsaddr;
        break;
      case R_PC:
        a += (lword)offs;
        break;
    }

    if (rtype == R_AOUT_MOVEI) {
      addreloc(sec,newreloc(gv,sec,NULL,rsec,0,offs,R_ABS,a),
               0,16,0xffff);
      addreloc(sec,newreloc(gv,sec,NULL,rsec,0,offs+2,R_ABS,a),
               0,16,0xffff0000);
    }
    else
      addreloc(sec,newreloc(gv,sec,NULL,rsec,0,offs,rtype,a),0,size,mask);
  }
}

// Assembly:
subq $0xe8, %rsp
movl 0x108(%rsp), %eax
movl 0x100(%rsp), %eax
movw 0xf8(%rsp), %ax
movb 0xf0(%rsp), %al
movq %rdi, 0xe0(%rsp)
movq %rsi, 0xd8(%rsp)
movq %rdx, 0xd0(%rsp)
movl %ecx, 0xcc(%rsp)
movl %r8d, 0xc8(%rsp)
movl %r9d, 0xc4(%rsp)
leaq 0xb9c1(%rip), %rax      # 0x3704b
movq %rax, 0xb8(%rsp)
movq 0xd0(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xb0(%rsp)
movq 0xb0(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0xa8(%rsp)
movq $-0x1, 0xa0(%rsp)
movq 0xe0(%rsp), %rdi
movb 0xf0(%rsp), %sil
movq 0xd0(%rsp), %rax
movq 0x40(%rax), %rdx
movl 0x100(%rsp), %eax
addq %rax, %rdx
movw 0xf8(%rsp), %ax
movq 0xa0(%rsp), %r9
xorl %ecx, %ecx
movzbl %sil, %esi
movzwl %ax, %r8d
callq 0x10eb0
movq %rax, 0x98(%rsp)
movzbl 0xf0(%rsp), %eax
cmpl $0x11, %eax
jne 0x2b75e
movq 0x98(%rsp), %rdi
andq $0xffff, %rdi           # imm = 0xFFFF
shlq $0x10, %rdi
movabsq $0xffff0000, %rax       # imm = 0xFFFF0000
andq 0x98(%rsp), %rax
sarq $0x10, %rax
orq %rax, %rdi
movl $0x20, %esi
callq 0x89f0
movq %rax, 0x98(%rsp)
cmpl $0x0, 0xc4(%rsp)
je 0x2ba09
movq 0xd8(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0xd8(%rsp), %rdi
movl 0x108(%rsp), %esi
callq 0x2efb0
movl %eax, %ecx
movq 0x58(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x90(%rsp)
movq 0xd8(%rsp), %rax
movq %rax, 0x60(%rsp)
movq 0xd8(%rsp), %rdi
movl 0x108(%rsp), %esi
callq 0x2eff0
movl %eax, %ecx
movq 0x60(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x88(%rsp)
movq 0x90(%rsp), %rax
movq %rax, 0x68(%rsp)
movl 0x108(%rsp), %edi
movq 0x88(%rsp), %rsi
movl 0xc8(%rsp), %eax
imulq $0xc, %rax, %rax
addq %rax, %rsi
callq 0x8060
movl %eax, %ecx
movq 0x68(%rsp), %rax
movl %ecx, %ecx
addq %rcx, %rax
movq %rax, 0x80(%rsp)
movzbl 0xf0(%rsp), %eax
cmpl $0x2, %eax
jne 0x2b847
movl 0xcc(%rsp), %eax
movl 0x100(%rsp), %ecx
addq %rcx, %rax
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
movq 0x88(%rsp), %rax
movl 0xc8(%rsp), %ecx
imulq $0xc, %rcx, %rcx
addq %rcx, %rax
movzbl 0x4(%rax), %eax
cmpl $0x1, %eax
sete %al
andb $0x1, %al
movzbl %al, %eax
orl $0x0, %eax
cmpl $0x0, %eax
je 0x2b9d8
movzbl 0xf0(%rsp), %eax
cmpl $0x11, %eax
jne 0x2b95e
movq 0xd0(%rsp), %rax
movq %rax, 0x48(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl 0x100(%rsp), %eax
movl %eax, %r9d
movq 0x98(%rsp), %rax
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x48(%rsp), %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
movl $0xffff, %r8d           # imm = 0xFFFF
callq 0x109b0
movq 0xd0(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl 0x100(%rsp), %eax
addl $0x2, %eax
movl %eax, %eax
movl %eax, %r9d
movq 0x98(%rsp), %rax
xorl %ecx, %ecx
xorl %r8d, %r8d
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x50(%rsp), %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
movl $0xffff0000, %r8d       # imm = 0xFFFF0000
callq 0x109b0
jmp 0x2b9d6
movq 0xd0(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x80(%rsp), %rdx
movl 0x100(%rsp), %eax
movl %eax, %r9d
movb 0xf0(%rsp), %r10b
movq 0x98(%rsp), %rax
xorl %ecx, %ecx
xorl %r8d, %r8d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x40(%rsp), %rdi
movq %rax, %rsi
movw 0xf8(%rsp), %ax
movq 0xa0(%rsp), %r8
xorl %edx, %edx
movzwl %ax, %ecx
callq 0x109b0
jmp 0x2ba04
movq 0xa8(%rsp), %rax
movq 0x10(%rax), %rsi
movq 0x80(%rsp), %rdx
movq 0xd0(%rsp), %rax
movq 0x20(%rax), %rcx
movl $0x5b, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x2bd81
movq $0x0, 0x78(%rsp)
movl $0x0, 0x74(%rsp)
movl 0xc8(%rsp), %eax
andl $-0x1f, %eax
cmpl $0x0, %eax
je 0x2ba68
movq 0xa8(%rsp), %rax
movq 0x10(%rax), %rsi
movl 0xc8(%rsp), %edx
movq 0xd0(%rsp), %rax
movq 0x20(%rax), %rcx
movq 0xa8(%rsp), %rax
movq 0x20(%rax), %r8
movl 0x100(%rsp), %r9d
movl $0x5c, %edi
movb $0x0, %al
callq 0x8c00
movl 0xc8(%rsp), %eax
andl $0x1e, %eax
movl %eax, 0x3c(%rsp)
subl $0x4, %eax
je 0x2ba9a
jmp 0x2ba7d
movl 0x3c(%rsp), %eax
subl $0x6, %eax
je 0x2badf
jmp 0x2ba88
movl 0x3c(%rsp), %eax
subl $0x8, %eax
je 0x2bb38
jmp 0x2bbaf
movq 0xb0(%rsp), %rdi
movl $0x1, %esi
movl $0x5, %edx
callq 0x11f40
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
jne 0x2bad2
movq 0xb8(%rsp), %rsi
leaq 0xb592(%rip), %rdi      # 0x3705d
movb $0x0, %al
callq 0x8ae0
movl $0x0, 0x74(%rsp)
jmp 0x2bbcf
movq 0xb0(%rsp), %rdi
movl $0x2, %esi
movl $0x3, %edx
callq 0x11f40
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
jne 0x2bb17
movq 0xb8(%rsp), %rsi
leaq 0xb568(%rip), %rdi      # 0x37078
movb $0x0, %al
callq 0x8ae0
movl 0x108(%rsp), %edi
movq 0xd8(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movl %eax, 0x74(%rsp)
jmp 0x2bbcf
movq 0xb0(%rsp), %rdi
movl $0x3, %edx
movl %edx, %esi
callq 0x11f40
movq %rax, 0x78(%rsp)
cmpq $0x0, %rax
jne 0x2bb6d
movq 0xb8(%rsp), %rsi
leaq 0xb52d(%rip), %rdi      # 0x37093
movb $0x0, %al
callq 0x8ae0
movl 0x108(%rsp), %edi
movq 0xd8(%rsp), %rsi
addq $0x4, %rsi
callq 0x8060
movl %eax, 0x38(%rsp)
movl 0x108(%rsp), %edi
movq 0xd8(%rsp), %rsi
addq $0x8, %rsi
callq 0x8060
movl %eax, %ecx
movl 0x38(%rsp), %eax
addl %ecx, %eax
movl %eax, 0x74(%rsp)
jmp 0x2bbcf
movq 0xb8(%rsp), %rsi
movl 0xc8(%rsp), %edx
andl $0x1e, %edx
leaq 0xb4e5(%rip), %rdi      # 0x370ad
movb $0x0, %al
callq 0x8ae0
movzbl 0xf0(%rsp), %eax
movl %eax, 0x34(%rsp)
subl $0x1, %eax
je 0x2bbf8
jmp 0x2bbe2
movl 0x34(%rsp), %eax
subl $0x2, %eax
je 0x2bc13
jmp 0x2bbed
movl 0x34(%rsp), %eax
subl $0x11, %eax
jne 0x2bc2a
jmp 0x2bbf8
movl 0x74(%rsp), %eax
movl %eax, %ecx
movq 0x98(%rsp), %rax
subq %rcx, %rax
movq %rax, 0x98(%rsp)
jmp 0x2bc2a
movl 0x100(%rsp), %eax
addq 0x98(%rsp), %rax
movq %rax, 0x98(%rsp)
movzbl 0xf0(%rsp), %eax
cmpl $0x11, %eax
jne 0x2bd0a
movq 0xd0(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x78(%rsp), %rcx
movl 0x100(%rsp), %eax
movl %eax, %r9d
movq 0x98(%rsp), %rax
xorl %edx, %edx
xorl %r8d, %r8d
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x20(%rsp), %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
movl $0xffff, %r8d           # imm = 0xFFFF
callq 0x109b0
movq 0xd0(%rsp), %rax
movq %rax, 0x28(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x78(%rsp), %rcx
movl 0x100(%rsp), %eax
addl $0x2, %eax
movl %eax, %eax
movl %eax, %r9d
movq 0x98(%rsp), %rax
xorl %edx, %edx
xorl %r8d, %r8d
movl $0x1, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x28(%rsp), %rdi
movq %rax, %rsi
xorl %edx, %edx
movl $0x10, %ecx
movl $0xffff0000, %r8d       # imm = 0xFFFF0000
callq 0x109b0
jmp 0x2bd7f
movq 0xd0(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0xe0(%rsp), %rdi
movq 0xd0(%rsp), %rsi
movq 0x78(%rsp), %rcx
movl 0x100(%rsp), %eax
movl %eax, %r9d
movb 0xf0(%rsp), %r10b
movq 0x98(%rsp), %rax
xorl %edx, %edx
xorl %r8d, %r8d
movzbl %r10b, %r10d
movl %r10d, (%rsp)
movq %rax, 0x8(%rsp)
callq 0x10850
movq 0x18(%rsp), %rdi
movq %rax, %rsi
movw 0xf8(%rsp), %ax
movq 0xa0(%rsp), %r8
xorl %edx, %edx
movzwl %ax, %ecx
callq 0x109b0
jmp 0x2bd81
addq $0xe8, %rsp
retq
nopl (%rax)