// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/t_amigahunk.c
// Function: ext_defs
static void ext_defs(struct GlobalVars *gv,FILE *f,struct LinkedSection *sec,
                     uint8_t bind,uint8_t stype,uint32_t xdeftype)
{
  struct Symbol *nextsym,*sym=(struct Symbol *)sec->symbols.first;
  bool xdefs = FALSE;

  while (nextsym = (struct Symbol *)sym->n.next) {
    if (sym->type==stype && sym->bind==bind && sym->info<=SYMI_FUNC) {
      remnode(&sym->n);

      if (!discard_symbol(gv,sym)) {
        if (xdeftype != EXT_IGNORE) {
          if (!xdefs) {
            xdefs = TRUE;
            if (xdeftype == EXT_SYMB) {
              if (!symhunk) {
                symhunk = TRUE;
                fwrite32be(f,HUNK_SYMBOL);
              }
            }
            else {
              if (!exthunk) {
                exthunk = TRUE;
                fwrite32be(f,HUNK_EXT);
              }
            }
          }
          /* generate xdef or symbol table entry */
          if (xdeftype==EXT_SYMB && strlen(sym->name)>124) {
            /* LoadSeg<=V40 doesn't allow more than 31 longwords per symbol,
               and will respond with "bad loadfile hunk" otherwise -
               so just strip the rest! */
            fwrite32be(f,(xdeftype << 24) | 31);
            fwritex(f,sym->name,124);
          }
          else {
            fwrite32be(f,(xdeftype << 24) | strlen32(sym->name));
            hunk_name(f,sym->name);           /* write symbol's name */
          }
          fwrite32be(f,(uint32_t)sym->value);  /* ... and its value */
        }

        else { /* EXT_IGNORE */
          if (stype==SYM_COMMON && !(sym->flags & SYMF_REFERENCED))
            /* Warning: unreferenced common symbol will disappear! */
            error(93,fff_amigahunk.tname,sym->name);
        }
      }
    }
    sym = nextsym;
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %r8d, %ebp
movl %ecx, %r14d
movq %rsi, 0x8(%rsp)
movq %rdi, %r12
movq 0xb0(%rdx), %rbx
movl %r9d, 0x4(%rsp)
shll $0x18, %r9d
movl %r9d, 0x14(%rsp)
xorl %r15d, %r15d
movq %rbx, %r13
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x12acc
cmpb %bpl, 0x40(%r13)
jne 0x1299d
cmpb %r14b, 0x43(%r13)
jne 0x1299d
cmpb $0x2, 0x42(%r13)
ja 0x1299d
movq %r13, %rdi
callq 0x6444
movq %r12, %rdi
movq %r13, %rsi
callq 0xc408
testl %eax, %eax
jne 0x1299d
cmpl $0x100, 0x4(%rsp)       # imm = 0x100
jne 0x12a04
cmpb $0x3, %bpl
jne 0x1299d
testb $0x2, 0x41(%r13)
jne 0x1299d
movq 0x1cbd4(%rip), %rsi     # 0x2f5c8
movq 0x20(%r13), %rdx
pushq $0x5d
popq %rdi
xorl %eax, %eax
callq 0x6c19
jmp 0x1299d
testl %r15d, %r15d
je 0x12a12
cmpl $0x0, 0x4(%rsp)
jne 0x12a38
jmp 0x12a5d
cmpl $0x0, 0x4(%rsp)
je 0x12a3e
cmpb $0x0, 0x2128c(%rip)     # 0x33cac
jne 0x12a38
movb $0x1, 0x21283(%rip)     # 0x33cac
movq 0x8(%rsp), %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x6856
movq 0x20(%r13), %r15
jmp 0x12a90
cmpb $0x0, 0x21263(%rip)     # 0x33ca8
jne 0x12a5d
movb $0x1, 0x2125a(%rip)     # 0x33ca8
movq 0x8(%rsp), %rdi
movl $0x3f0, %esi            # imm = 0x3F0
callq 0x6856
movq 0x20(%r13), %r15
movq %r15, %rdi
callq 0x50e0
cmpq $0x7d, %rax
jb 0x12a90
movq 0x8(%rsp), %r15
movq %r15, %rdi
pushq $0x1f
popq %rsi
callq 0x6856
movq 0x20(%r13), %rsi
movq %r15, %rdi
pushq $0x7c
popq %rdx
callq 0x6817
jmp 0x12ab7
movq %r15, %rdi
callq 0x12c3a
orl 0x14(%rsp), %eax
movq 0x8(%rsp), %r15
movq %r15, %rdi
movl %eax, %esi
callq 0x6856
movq 0x20(%r13), %rsi
movq %r15, %rdi
callq 0x12c48
movl 0x30(%r13), %esi
movq %r15, %rdi
callq 0x6856
pushq $0x1
popq %r15
jmp 0x1299d
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq