// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_amigahunk.c
// Function: writeobject
static void writeobject(struct GlobalVars *gv,FILE *f,bool ehf)
/* creates a target-amigahunk relocatable object file */
{
  struct LinkedSection *ls = (struct LinkedSection *)gv->lnksec.first;
  struct LinkedSection *nextls;

  fwrite32be(f,HUNK_UNIT);
  hunk_name_len(f,gv->dest_name);  /* unit name is output file name */

  if (ls->n.next == NULL) {
    /* special case: no sections, create dummy section */
    fwrite32be(f,HUNK_CODE);
    fwrite32be(f,0);
    fwrite32be(f,HUNK_END);
    return;
  }

  /* section loop */
  while (nextls = (struct LinkedSection *)ls->n.next) {
    uint32_t memflags = (ls->flags&(SF_FAST|SF_CHIP))<<24;

    exthunk = symhunk = FALSE;
    fwrite32be(f,HUNK_NAME);
    hunk_name_len(f,ls->name);  /* section name */

    switch (ls->type) {  /* section type */
      case ST_CODE:
        if ((ls->flags & SF_EHFPPC) && ehf)
          fwrite32be(f,HUNK_PPC_CODE|memflags);
        else
          fwrite32be(f,HUNK_CODE|memflags);
        break;
      case ST_DATA:
        fwrite32be(f,HUNK_DATA|memflags);
        break;
      case ST_UDATA:
        fwrite32be(f,HUNK_BSS|memflags);
        break;
      default:
        ierror("writeobject(): Illegal section type %u",ls->type);
        break;
    }

    fix_reloc_addends(gv,ls);
    fix_xref_addends(gv,ls);
    fwrite32be(f,(ls->size+3)>>2);  /* section size */
    if (!(ls->flags & SF_UNINITIALIZED)) {
      fwritex(f,ls->data,ls->size);  /* write section contents */
      fwrite_align(f,2,ls->size);
    }

    /* relocation hunks */
    reloc_hunk(gv,f,ls,HUNK_ABSRELOC32,R_ABS,32);
    reloc_hunk(gv,f,ls,HUNK_RELRELOC32,R_PC,32);
    reloc_hunk(gv,f,ls,HUNK_RELRELOC16,R_PC,16);
    reloc_hunk(gv,f,ls,HUNK_DREL16,R_SD,16);
    if ((ls->flags & SF_EHFPPC) && ehf) {
      reloc_hunk(gv,f,ls,HUNK_RELRELOC26,R_PC,24);
      reloc_hunk(gv,f,ls,HUNK_RELRELOC16,R_PC,14);
    }
    unsupp_relocs(ls);  /* print unsupported relocations */

    /* external references and global definitions */
    ext_refs(f,ls,ehf);
    ext_defs(gv,f,ls,SYMB_GLOBAL,SYM_RELOC,EXT_DEF);
    ext_defs(gv,f,ls,SYMB_GLOBAL,SYM_ABS,EXT_ABS);
    ext_defs(gv,f,ls,SYMB_GLOBAL,SYM_COMMON,EXT_IGNORE);
    if (exthunk)
      fwrite32be(f,0);  /* close HUNK_EXT block, if required */

    /* symbol table */
    ext_defs(gv,f,ls,SYMB_LOCAL,SYM_RELOC,EXT_SYMB);
    ext_defs(gv,f,ls,SYMB_LOCAL,SYM_ABS,EXT_IGNORE);
    if (symhunk)
      fwrite32be(f,0);  /* close HUNK_SYMBOL block, if required */
    unsupp_symbols(ls);  /* print unsupported symbol definitions */

    /* line debug hunks */
    if (gv->strip_symbols < STRIP_DEBUG) {
      if (checktargetext(ls,TGEXT_AMIGAOS,SUBID_LINE))
        linedebug_hunks(gv,f,ls);
    }

    fwrite32be(f,HUNK_END);  /* end of this section */
    ls = nextls;
  }
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq %rsi, 0x28(%rsp)
movl %edx, 0x24(%rsp)
movq 0x30(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x28(%rsp), %rdi
movl $0x3e7, %esi            # imm = 0x3E7
callq 0x84d0
movq 0x28(%rsp), %rdi
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rsi
callq 0x1de00
movq 0x18(%rsp), %rax
cmpq $0x0, (%rax)
jne 0x1da0f
movq 0x28(%rsp), %rdi
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x84d0
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x84d0
movq 0x28(%rsp), %rdi
movl $0x3f2, %esi            # imm = 0x3F2
callq 0x84d0
jmp 0x1ddf3
jmp 0x1da11
movq 0x18(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x1ddf3
movq 0x18(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $-0x40, %eax
shll $0x18, %eax
movl %eax, 0xc(%rsp)
movl $0x0, 0x27243(%rip)     # 0x44c88
movl $0x0, 0x2723d(%rip)     # 0x44c8c
movq 0x28(%rsp), %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x84d0
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x18(%rax), %rsi
callq 0x1de00
movq 0x18(%rsp), %rax
movzbl 0x20(%rax), %eax
movl %eax, 0x8(%rsp)
subl $0x1, %eax
je 0x1da9b
jmp 0x1da85
movl 0x8(%rsp), %eax
subl $0x2, %eax
je 0x1dadf
jmp 0x1da90
movl 0x8(%rsp), %eax
subl $0x3, %eax
je 0x1daf5
jmp 0x1db0b
movq 0x18(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x1dac9
cmpl $0x0, 0x24(%rsp)
je 0x1dac9
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
orl $0x4e9, %esi            # imm = 0x4E9
callq 0x84d0
jmp 0x1dadd
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
orl $0x3e9, %esi            # imm = 0x3E9
callq 0x84d0
jmp 0x1db22
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
orl $0x3ea, %esi            # imm = 0x3EA
callq 0x84d0
jmp 0x1db22
movq 0x28(%rsp), %rdi
movl 0xc(%rsp), %esi
orl $0x3eb, %esi            # imm = 0x3EB
callq 0x84d0
jmp 0x1db22
movq 0x18(%rsp), %rax
movzbl 0x20(%rax), %esi
leaq 0x185b4(%rip), %rdi     # 0x360cf
movb $0x0, %al
callq 0x8ae0
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x1de90
movq 0x30(%rsp), %rdi
movq 0x18(%rsp), %rsi
callq 0x1df00
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
addq $0x3, %rax
shrq $0x2, %rax
movl %eax, %esi
callq 0x84d0
movq 0x18(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x1dba4
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x78(%rax), %rsi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rdx
callq 0x8470
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rax
movq 0x48(%rax), %rax
movl %eax, %edx
movl $0x2, %esi
callq 0x8640
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x3ec, %ecx            # imm = 0x3EC
movl $0x1, %r8d
movl $0x20, %r9d
callq 0x1df70
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x3fd, %ecx            # imm = 0x3FD
movl $0x2, %r8d
movl $0x20, %r9d
callq 0x1df70
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0x10, %r9d
callq 0x1df70
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x3f8, %ecx            # imm = 0x3F8
movl $0xa, %r8d
movl $0x10, %r9d
callq 0x1df70
movq 0x18(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x20, %eax
cmpl $0x0, %eax
je 0x1dc9a
cmpl $0x0, 0x24(%rsp)
je 0x1dc9a
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x4ec, %ecx            # imm = 0x4EC
movl $0x2, %r8d
movl $0x18, %r9d
callq 0x1df70
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0xe, %r9d
callq 0x1df70
movq 0x18(%rsp), %rdi
callq 0x1e520
movq 0x28(%rsp), %rdi
movq 0x18(%rsp), %rsi
movl 0x24(%rsp), %edx
callq 0x1e5c0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x2, %r8d
movl $0x1, %r9d
movl %r8d, %ecx
callq 0x1ebc0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x2, %r9d
movl $0x1, %r8d
movl %r9d, %ecx
callq 0x1ebc0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x2, %ecx
movl $0x3, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x1ebc0
cmpl $0x0, 0x26f63(%rip)     # 0x44c8c
je 0x1dd37
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x84d0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x1, %ecx
movl $0x2, %r8d
xorl %r9d, %r9d
callq 0x1ebc0
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
movl $0x1, %r8d
movl $0x100, %r9d            # imm = 0x100
movl %r8d, %ecx
callq 0x1ebc0
cmpl $0x0, 0x26f05(%rip)     # 0x44c88
je 0x1dd91
movq 0x28(%rsp), %rdi
xorl %esi, %esi
callq 0x84d0
movq 0x18(%rsp), %rdi
callq 0x1ede0
movq 0x30(%rsp), %rax
movzbl 0x6c(%rax), %eax
cmpl $0x1, %eax
jge 0x1ddd5
movq 0x18(%rsp), %rdi
movl $0x1, %edx
movl %edx, %esi
callq 0x10df0
cmpl $0x0, %eax
je 0x1ddd3
movq 0x30(%rsp), %rdi
movq 0x28(%rsp), %rsi
movq 0x18(%rsp), %rdx
callq 0x1ee70
jmp 0x1ddd5
movq 0x28(%rsp), %rdi
movl $0x3f2, %esi            # imm = 0x3F2
callq 0x84d0
movq 0x10(%rsp), %rax
movq %rax, 0x18(%rsp)
jmp 0x1da11
addq $0x38, %rsp
retq
nopl (%rax,%rax)