// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_amigahunk.c
// Function: ext_refs
static void ext_refs(FILE *f,struct LinkedSection *sec,bool ehf)
{
  struct list xnodelist;  /* xrefs with same ref. type and symbol name */
  struct XRefNode *xn,*nextxn;
  struct Reloc *xref;

  initlist(&xnodelist);
  while (xref = (struct Reloc *)remhead(&sec->xrefs)) {
    const char *name = xref->xrefname;  /* name of xref'ed symbol */
    uint8_t rtype = 0;

    if (xref->relocsect.symbol) {
      if (xref->relocsect.symbol->type == SYM_COMMON) {
        if (isstdreloc(xref,R_ABS,32)) {
          rtype = EXT_ABSCOMMON;
          goto rtype_done;
        }
        else if (isstdreloc(xref,R_PC,32)) {
          rtype = EXT_RELCOMMON;
          goto rtype_done;
        }
        else if (isstdreloc(xref,R_SD,32)) {
          rtype = EXT_DEXT32COMMON;
          goto rtype_done;
        }
        else if (isstdreloc(xref,R_SD,16)) {
          rtype = EXT_DEXT16COMMON;
          goto rtype_done;
        }
        else if (isstdreloc(xref,R_SD,8)) {
          rtype = EXT_DEXT8COMMON;
          goto rtype_done;
        }
      }
    }

    /* reference reloc type mapping */
    if (isstdreloc(xref,R_ABS,32)) rtype = EXT_ABSREF32;
    else if (isstdreloc(xref,R_ABS,16)) rtype = EXT_ABSREF16;
    else if (isstdreloc(xref,R_ABS,8)) rtype = EXT_ABSREF8;
    else if (isstdreloc(xref,R_PC,32)) rtype = EXT_RELREF32;
    else if (isstdreloc(xref,R_PC,16)) rtype = EXT_RELREF16;
    else if (isstdreloc(xref,R_PC,8)) rtype = EXT_RELREF8;
    else if (isstdreloc(xref,R_SD,32)) rtype = EXT_DEXT32;
    else if (isstdreloc(xref,R_SD,16)) rtype = EXT_DEXT16;
    else if (isstdreloc(xref,R_SD,8)) rtype = EXT_DEXT8;

    else if (ehf && xref->rtype==R_PC) {
      /* also check EHF/PowerPC relocation types */
      struct RelocInsert *ri;

      if (ri = xref->insert) {
        if (ri->bpos==6 && ri->bsiz==24 &&
            (ri->mask&0x3ffffff)==0x3fffffc) {
          rtype = EXT_RELREF26;
        }
        else if ((ri->bpos&15)==0 && ri->bsiz==14 &&
                 (ri->mask&0xffff)==0xfffc) {
          rtype = EXT_RELREF16;
        }
      }
    }

rtype_done:
    if (!rtype) {
      error(32,fff_amigahunk.tname,reloc_name[xref->rtype],
            (int)xref->insert->bpos,(int)xref->insert->bsiz,
            xref->insert->mask,sec->name,xref->offset);
      rtype = EXT_RELREF8;  /* @@@ to keep the loop running */
    }

    /* search appropriate XRefNode for referenced symbol and type */
    xn = (struct XRefNode *)xnodelist.first;
    while (nextxn = (struct XRefNode *)xn->n.next) {
      if (!strcmp(name,xn->sym_name) && rtype==xn->ref_type)
        break;
      xn = nextxn;
    }
    if (nextxn==NULL) {  /* we have to create a new XRefNode? */
      xn = alloc(sizeof(struct XRefNode));
      xn->sym_name = name;
      xn->ref_type = rtype;
      xn->com_size = (rtype==EXT_ABSCOMMON || rtype==EXT_RELCOMMON ||
                      (rtype>=EXT_DEXT32COMMON && rtype<=EXT_DEXT8COMMON)) ?
                     xref->relocsect.symbol->size : 0;
      xn->noffsets = 0;
      initlist(&xn->xreflist);
      addtail(&xnodelist,&xn->n);
    }

    /* add new offset to xreflist for same ref. type and symbol name */
    addtail(&xn->xreflist,&xref->n);
    xn->noffsets++;
  }

  if (xnodelist.first->next) {  /* at least one reference in this section? */
    if (!exthunk) {
      exthunk = TRUE;
      fwrite32be(f,HUNK_EXT);
    }
    while (xn = (struct XRefNode *)remhead(&xnodelist)) {
      fwrite32be(f,((uint32_t)xn->ref_type << 24) | strlen32(xn->sym_name));
      hunk_name(f,xn->sym_name);  /* symbol's name */
      if (xn->com_size)  /* store size of common block? */
        fwrite32be(f,xn->com_size);
      fwrite32be(f,(uint32_t)xn->noffsets);  /* number of references */
      while (xref = (struct Reloc *)remhead(&xn->xreflist)) {
        fwrite32be(f,(uint32_t)xref->offset);  /* offset */
      }
      free(xn);
    }
  }
}

// Assembly:
subq $0x88, %rsp
movq %rdi, 0x80(%rsp)
movq %rsi, 0x78(%rsp)
movl %edx, 0x74(%rsp)
leaq 0x58(%rsp), %rdi
callq 0x7330
movq 0x78(%rsp), %rdi
addq $0x98, %rdi
callq 0x74d0
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x1ea98
movq 0x40(%rsp), %rax
movq 0x10(%rax), %rax
movq %rax, 0x38(%rsp)
movb $0x0, 0x37(%rsp)
movq 0x40(%rsp), %rax
cmpq $0x0, 0x18(%rax)
je 0x1e6f6
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movzbl 0x40(%rax), %eax
cmpl $0x3, %eax
jne 0x1e6f4
movq 0x40(%rsp), %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e65e
movb $-0x7e, 0x37(%rsp)
jmp 0x1e8f1
movq 0x40(%rsp), %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e681
movb $-0x77, 0x37(%rsp)
jmp 0x1e8f1
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e6a4
movb $-0x30, 0x37(%rsp)
jmp 0x1e8f1
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e6c7
movb $-0x2f, 0x37(%rsp)
jmp 0x1e8f1
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e6ea
movb $-0x2e, 0x37(%rsp)
jmp 0x1e8f1
jmp 0x1e6ec
jmp 0x1e6ee
jmp 0x1e6f0
jmp 0x1e6f2
jmp 0x1e6f4
jmp 0x1e6f6
movq 0x40(%rsp), %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e719
movb $-0x7f, 0x37(%rsp)
jmp 0x1e8ef
movq 0x40(%rsp), %rdi
movl $0x1, %esi
movl $0x10, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e73c
movb $-0x76, 0x37(%rsp)
jmp 0x1e8ed
movq 0x40(%rsp), %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e75f
movb $-0x75, 0x37(%rsp)
jmp 0x1e8eb
movq 0x40(%rsp), %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e782
movb $-0x78, 0x37(%rsp)
jmp 0x1e8e9
movq 0x40(%rsp), %rdi
movl $0x2, %esi
movl $0x10, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e7a5
movb $-0x7d, 0x37(%rsp)
jmp 0x1e8e7
movq 0x40(%rsp), %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e7c8
movb $-0x7c, 0x37(%rsp)
jmp 0x1e8e5
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e7eb
movb $-0x7b, 0x37(%rsp)
jmp 0x1e8e3
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e80e
movb $-0x7a, 0x37(%rsp)
jmp 0x1e8e1
movq 0x40(%rsp), %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0x10ac0
cmpl $0x0, %eax
je 0x1e831
movb $-0x79, 0x37(%rsp)
jmp 0x1e8df
cmpl $0x0, 0x74(%rsp)
je 0x1e8dd
movq 0x40(%rsp), %rax
movzbl 0x38(%rax), %eax
cmpl $0x2, %eax
jne 0x1e8dd
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x1e8db
movq 0x28(%rsp), %rax
movzwl 0x8(%rax), %eax
cmpl $0x6, %eax
jne 0x1e89c
movq 0x28(%rsp), %rax
movzwl 0xa(%rax), %eax
cmpl $0x18, %eax
jne 0x1e89c
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
andq $0x3ffffff, %rax        # imm = 0x3FFFFFF
cmpq $0x3fffffc, %rax        # imm = 0x3FFFFFC
jne 0x1e89c
movb $-0x1b, 0x37(%rsp)
jmp 0x1e8d9
movq 0x28(%rsp), %rax
movzwl 0x8(%rax), %eax
andl $0xf, %eax
cmpl $0x0, %eax
jne 0x1e8d7
movq 0x28(%rsp), %rax
movzwl 0xa(%rax), %eax
cmpl $0xe, %eax
jne 0x1e8d7
movq 0x28(%rsp), %rax
movq 0x10(%rax), %rax
andq $0xffff, %rax           # imm = 0xFFFF
cmpq $0xfffc, %rax           # imm = 0xFFFC
jne 0x1e8d7
movb $-0x7d, 0x37(%rsp)
jmp 0x1e8d9
jmp 0x1e8db
jmp 0x1e8dd
jmp 0x1e8df
jmp 0x1e8e1
jmp 0x1e8e3
jmp 0x1e8e5
jmp 0x1e8e7
jmp 0x1e8e9
jmp 0x1e8eb
jmp 0x1e8ed
jmp 0x1e8ef
jmp 0x1e8f1
cmpb $0x0, 0x37(%rsp)
jne 0x1e969
movq 0x216d1(%rip), %rsi     # 0x3ffd0
movq 0x40(%rsp), %rax
movzbl 0x38(%rax), %eax
movl %eax, %ecx
leaq 0x2128f(%rip), %rax     # 0x3fba0
movq (%rax,%rcx,8), %rdx
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movzwl 0x8(%rax), %ecx
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movzwl 0xa(%rax), %r8d
movq 0x40(%rsp), %rax
movq 0x30(%rax), %rax
movq 0x10(%rax), %r9
movq 0x78(%rsp), %rax
movq 0x18(%rax), %r10
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movl $0x20, %edi
movq %r10, (%rsp)
movq %rax, 0x8(%rsp)
movb $0x0, %al
callq 0x8c00
movb $-0x7c, 0x37(%rsp)
movq 0x58(%rsp), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x48(%rsp)
cmpq $0x0, %rax
je 0x1e9be
movq 0x38(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x5130
cmpl $0x0, %eax
jne 0x1e9b2
movzbl 0x37(%rsp), %eax
movq 0x50(%rsp), %rcx
movzbl 0x18(%rcx), %ecx
cmpl %ecx, %eax
jne 0x1e9b2
jmp 0x1e9be
movq 0x48(%rsp), %rax
movq %rax, 0x50(%rsp)
jmp 0x1e973
cmpq $0x0, 0x48(%rsp)
jne 0x1ea72
movl $0x40, %edi
callq 0x71f0
movq %rax, 0x50(%rsp)
movq 0x38(%rsp), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x10(%rax)
movb 0x37(%rsp), %cl
movq 0x50(%rsp), %rax
movb %cl, 0x18(%rax)
movzbl 0x37(%rsp), %eax
cmpl $0x82, %eax
je 0x1ea23
movzbl 0x37(%rsp), %eax
cmpl $0x89, %eax
je 0x1ea23
movzbl 0x37(%rsp), %eax
cmpl $0xd0, %eax
jl 0x1ea35
movzbl 0x37(%rsp), %eax
cmpl $0xd2, %eax
jg 0x1ea35
movq 0x40(%rsp), %rax
movq 0x18(%rax), %rax
movl 0x44(%rax), %eax
movl %eax, 0x24(%rsp)
jmp 0x1ea3d
xorl %eax, %eax
movl %eax, 0x24(%rsp)
jmp 0x1ea3d
movl 0x24(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq 0x50(%rsp), %rax
movl $0x0, 0x20(%rax)
movq 0x50(%rsp), %rdi
addq $0x28, %rdi
callq 0x7330
movq 0x50(%rsp), %rsi
leaq 0x58(%rsp), %rdi
callq 0x7470
movq 0x50(%rsp), %rdi
addq $0x28, %rdi
movq 0x40(%rsp), %rsi
callq 0x7470
movq 0x50(%rsp), %rax
movl 0x20(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x20(%rax)
jmp 0x1e5e2
movq 0x58(%rsp), %rax
cmpq $0x0, (%rax)
je 0x1ebb1
cmpl $0x0, 0x261de(%rip)     # 0x44c8c
jne 0x1eacc
movl $0x1, 0x261d2(%rip)     # 0x44c8c
movq 0x80(%rsp), %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x84d0
jmp 0x1eace
leaq 0x58(%rsp), %rdi
callq 0x74d0
movq %rax, 0x50(%rsp)
cmpq $0x0, %rax
je 0x1ebaf
movq 0x80(%rsp), %rax
movq %rax, 0x18(%rsp)
movq 0x50(%rsp), %rax
movzbl 0x18(%rax), %eax
shll $0x18, %eax
movl %eax, 0x14(%rsp)
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rdi
callq 0x1f010
movl 0x14(%rsp), %esi
movq 0x18(%rsp), %rdi
orl %eax, %esi
callq 0x84d0
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rax
movq 0x10(%rax), %rsi
callq 0x1f050
movq 0x50(%rsp), %rax
cmpl $0x0, 0x1c(%rax)
je 0x1eb58
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x1c(%rax), %esi
callq 0x84d0
movq 0x80(%rsp), %rdi
movq 0x50(%rsp), %rax
movl 0x20(%rax), %esi
callq 0x84d0
movq 0x50(%rsp), %rdi
addq $0x28, %rdi
callq 0x74d0
movq %rax, 0x40(%rsp)
cmpq $0x0, %rax
je 0x1eba0
movq 0x80(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x20(%rax), %rax
movl %eax, %esi
callq 0x84d0
jmp 0x1eb6d
movq 0x50(%rsp), %rdi
callq 0x5030
jmp 0x1eace
jmp 0x1ebb1
addq $0x88, %rsp
retq
nopl (%rax)