// File: /workspace/github_c_makefile_star2_O1/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 %r9d, 0x8(%rsp)
movq %rsi, 0x10(%rsp)
movq 0xb0(%rdx), %r15
movq (%r15), %rax
testq %rax, %rax
je 0x13ced
movl %r8d, %ebp
movl %ecx, %r14d
movq %rdi, %r12
movl 0x8(%rsp), %ecx
shll $0x18, %ecx
movl %ecx, 0xc(%rsp)
xorl %ebx, %ebx
movq %r15, %r13
movq %rax, %r15
cmpb %bpl, 0x40(%r13)
jne 0x13cc1
cmpb %r14b, 0x43(%r13)
jne 0x13cc1
cmpb $0x2, 0x42(%r13)
ja 0x13cc1
movq %r13, %rdi
callq 0x6789
movq %r12, %rdi
movq %r13, %rsi
callq 0xcbff
testl %eax, %eax
jne 0x13cc1
cmpl $0x100, 0x8(%rsp)       # imm = 0x100
jne 0x13c1f
cmpb $0x3, %bpl
jne 0x13cc1
testb $0x2, 0x41(%r13)
jne 0x13cc1
movq 0x1b9ae(%rip), %rsi     # 0x2f5b8
movq 0x20(%r13), %rdx
movl $0x5d, %edi
xorl %eax, %eax
callq 0x6f84
jmp 0x13cc1
testl %ebx, %ebx
movq 0x10(%rsp), %rbx
jne 0x13c53
cmpl $0x0, 0x8(%rsp)
je 0x13ccf
movl $0x3ef, %esi            # imm = 0x3EF
cmpb $0x0, 0x1fc7d(%rip)     # 0x338bc
leaq 0x1fc76(%rip), %rax     # 0x338bc
jne 0x13c53
movb $0x1, (%rax)
movq %rbx, %rdi
callq 0x6c5d
cmpl $0x0, 0x8(%rsp)
jne 0x13c89
movq 0x20(%r13), %rdi
callq 0x50e0
cmpq $0x7d, %rax
jb 0x13c89
movq %rbx, %rdi
movl $0x1f, %esi
callq 0x6c5d
movq 0x20(%r13), %rsi
movl $0x7c, %edx
movq %rbx, %rdi
callq 0x6c1a
jmp 0x13cb0
movq 0x20(%r13), %rdi
callq 0x50e0
leal 0x3(%rax), %esi
sarl $0x2, %esi
orl 0xc(%rsp), %esi
movq %rbx, %rdi
callq 0x6c5d
movq 0x20(%r13), %rsi
movq %rbx, %rdi
callq 0x13e79
movl 0x30(%r13), %esi
movq %rbx, %rdi
callq 0x6c5d
movl $0x1, %ebx
movq (%r15), %rax
testq %rax, %rax
jne 0x13ba4
jmp 0x13ced
movl $0x3f0, %esi            # imm = 0x3F0
cmpb $0x0, 0x1fbdd(%rip)     # 0x338b8
leaq 0x1fbd6(%rip), %rax     # 0x338b8
je 0x13c48
jmp 0x13c53
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq