// File: /workspace/github_c_makefile_star2_O3/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x48, %rsp
movl %edx, 0xc(%rsp)
movq %rsi, %rbx
movq %rdi, %r15
movq 0x1c0(%rdi), %r12
movq %rsi, %rdi
movl $0x3e7, %esi            # imm = 0x3E7
callq 0x6be8
movq 0x48(%r15), %rsi
movq %rbx, %rdi
callq 0x13575
movq (%r12), %r14
testq %r14, %r14
je 0x13543
movq %r15, 0x18(%rsp)
movzbl 0x21(%r12), %ebp
andl $-0x40, %ebp
shll $0x18, %ebp
xorl %eax, %eax
movb %al, 0x20a9b(%rip)      # 0x338b8
movb %al, 0x20a99(%rip)      # 0x338bc
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x6be8
movq 0x18(%r12), %rsi
movq %rbx, %rdi
callq 0x13575
movzbl 0x20(%r12), %esi
cmpl $0x3, %esi
movq %r14, 0x20(%rsp)
je 0x12e77
cmpl $0x2, %esi
je 0x12e6f
cmpl $0x1, %esi
jne 0x12e7f
cmpl $0x0, 0xc(%rsp)
je 0x12e8f
movb 0x21(%r12), %al
andb $0x20, %al
je 0x12e8f
orl $0x4e9, %ebp            # imm = 0x4E9
jmp 0x12e95
orl $0x3ea, %ebp            # imm = 0x3EA
jmp 0x12e95
orl $0x3eb, %ebp            # imm = 0x3EB
jmp 0x12e95
leaq 0x10435(%rip), %rdi     # 0x232bb
xorl %eax, %eax
callq 0x52b0
jmp 0x12e9f
orl $0x3e9, %ebp            # imm = 0x3E9
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6be8
movq %r15, %rdi
movq %r12, %rsi
callq 0x135be
movq 0x98(%r12), %r14
cmpq $0x0, (%r14)
je 0x12ed5
movq 0x78(%r12), %rsi
addq 0x20(%r14), %rsi
movq 0x28(%r14), %rcx
movq %r15, %rdi
movq %r14, %rdx
callq 0xb4ed
movq (%r14), %r14
jmp 0x12eb2
movq 0x48(%r12), %rsi
addq $0x3, %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x6be8
testb $0x2, 0x21(%r12)
jne 0x12f16
movq 0x48(%r12), %rdx
movq 0x78(%r12), %rsi
movq %rbx, %rdi
callq 0x6ba5
movl 0x48(%r12), %edx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x6ce0
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x3ec, %ecx            # imm = 0x3EC
movl $0x1, %r8d
movl $0x20, %r9d
callq 0x135fc
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x3fd, %ecx            # imm = 0x3FD
movl $0x2, %r8d
movl $0x20, %r9d
callq 0x135fc
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0x10, %r9d
callq 0x135fc
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x3f8, %ecx            # imm = 0x3F8
movl $0xa, %r8d
movl $0x10, %r9d
callq 0x135fc
cmpl $0x0, 0xc(%rsp)
je 0x12ffe
movb 0x21(%r12), %al
andb $0x20, %al
je 0x12ffe
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x4ec, %ecx            # imm = 0x4EC
movl $0x2, %r8d
movl $0x18, %r9d
callq 0x135fc
movq 0x80(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0xe, %r9d
callq 0x135fc
leaq 0x98(%r12), %r14
movq %r12, 0x10(%rsp)
movq %r12, %rdi
callq 0x1397c
leaq 0x30(%rsp), %rdi
callq 0x66da
movq %r14, 0x28(%rsp)
movq %r14, %rdi
callq 0x673f
testq %rax, %rax
je 0x13331
movq %rax, %rbp
movq 0x10(%rbp), %r12
movq 0x18(%rbp), %rax
testq %rax, %rax
je 0x130e2
cmpb $0x3, 0x40(%rax)
jne 0x130e2
movq %rbp, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x7e, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x77, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x30, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0xb27a
movb $-0x2f, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0xb27a
movb $-0x2e, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x7f, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x1, %esi
movl $0x10, %edx
callq 0xb27a
movb $-0x76, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0xb27a
movb $-0x75, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x78, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x2, %esi
movl $0x10, %edx
callq 0xb27a
movb $-0x7d, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0xb27a
movb $-0x7c, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0xb27a
movb $-0x7b, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0xb27a
movb $-0x7a, %r15b
testl %eax, %eax
jne 0x1327e
movq %rbp, %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0xb27a
movb $-0x79, %r15b
testl %eax, %eax
jne 0x1327e
movb 0x38(%rbp), %dl
movzbl %dl, %ecx
movq 0x30(%rbp), %rax
cmpl $0x0, 0xc(%rsp)
je 0x13240
cmpb $0x2, %dl
jne 0x13240
movzwl 0x8(%rax), %edx
movl $0x2, %ecx
cmpw $0x6, %dx
jne 0x1322a
cmpw $0x18, 0xa(%rax)
jne 0x13240
movl 0x10(%rax), %edx
movl $0x3ffffff, %esi        # imm = 0x3FFFFFF
andl %esi, %edx
movb $-0x1b, %r15b
cmpl $0x3fffffc, %edx        # imm = 0x3FFFFFC
jne 0x13240
jmp 0x1327e
testb $0xf, %dl
jne 0x13240
cmpw $0xe, 0xa(%rax)
jne 0x13240
cmpw $-0x4, 0x10(%rax)
movb $-0x7d, %r15b
je 0x1327e
movq 0x1c371(%rip), %rsi     # 0x2f5b8
leaq 0x1c0a2(%rip), %rdx     # 0x2f2f0
movq (%rdx,%rcx,8), %rdx
movzwl 0x8(%rax), %ecx
movzwl 0xa(%rax), %r8d
movq 0x10(%rax), %r9
movl $0x20, %edi
xorl %eax, %eax
pushq 0x20(%rbp)
movq 0x18(%rsp), %r10
pushq 0x18(%r10)
callq 0x6f14
addq $0x10, %rsp
movb $-0x7c, %r15b
movq 0x30(%rsp), %r13
movq (%r13), %rax
testq %rax, %rax
je 0x132ad
movq %rax, %r14
movq 0x10(%r13), %rsi
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
jne 0x132a5
cmpb 0x18(%r13), %r15b
je 0x1330b
movq (%r14), %rax
movq %r14, %r13
jmp 0x13287
movl $0x40, %edi
callq 0x6638
movq %rax, %r13
movq %r12, 0x10(%rax)
movb %r15b, 0x18(%rax)
cmpb $-0x7e, %r15b
je 0x132df
movzbl %r15b, %eax
cmpl $0x89, %eax
je 0x132df
addb $0x30, %r15b
xorl %eax, %eax
cmpb $0x2, %r15b
ja 0x132e6
movq 0x18(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, 0x1c(%r13)
movl $0x0, 0x20(%r13)
movq %r13, %rdi
addq $0x28, %rdi
callq 0x66da
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x6729
leaq 0x28(%r13), %rdi
movq %rbp, %rsi
callq 0x6729
incl 0x20(%r13)
movq 0x28(%rsp), %rdi
callq 0x673f
movq %rax, %rbp
testq %rax, %rax
jne 0x13036
movq 0x30(%rsp), %rax
cmpq $0x0, (%rax)
movq 0x18(%rsp), %r15
je 0x13402
cmpb $0x0, 0x20570(%rip)     # 0x338bc
jne 0x13362
movb $0x1, 0x20567(%rip)     # 0x338bc
movq %rbx, %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x6be8
leaq 0x30(%rsp), %rdi
callq 0x673f
testq %rax, %rax
je 0x13402
movq %rax, %r12
movl 0x18(%r12), %ebp
shll $0x18, %ebp
movq 0x10(%r12), %rdi
callq 0x50e0
leal 0x3(%rax), %esi
sarl $0x2, %esi
orl %ebp, %esi
movq %rbx, %rdi
callq 0x6be8
movq 0x10(%r12), %rsi
movq %rbx, %rdi
callq 0x13d0a
movl 0x1c(%r12), %esi
testl %esi, %esi
je 0x133b8
movq %rbx, %rdi
callq 0x6be8
movl 0x20(%r12), %esi
movq %rbx, %rdi
callq 0x6be8
leaq 0x28(%r12), %r14
movq %r14, %rdi
callq 0x673f
testq %rax, %rax
je 0x133e4
movl 0x20(%rax), %esi
movq %rbx, %rdi
callq 0x6be8
jmp 0x133ca
movq %r12, %rdi
callq 0x5040
leaq 0x30(%rsp), %rdi
callq 0x673f
movq %rax, %r12
testq %rax, %rax
jne 0x13378
movq 0x10(%rsp), %r12
movq 0xb0(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x2, %ecx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x139f0
movq 0xb0(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x2, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x139f0
movq 0xb0(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x2, %ecx
movl $0x3, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x139f0
cmpb $0x1, 0x20442(%rip)     # 0x338bc
jne 0x13486
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6be8
movq 0xb0(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
movl $0x2, %r8d
xorl %r9d, %r9d
callq 0x139f0
movq 0xb0(%r12), %rdx
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %ecx
movl $0x1, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x139f0
cmpb $0x1, 0x203e6(%rip)     # 0x338b8
movq 0x20(%rsp), %r14
jne 0x134e3
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6be8
movq %r12, %rdi
callq 0x13b8e
cmpb $0x0, 0x6c(%r15)
jne 0x13515
movq %r12, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xb3c5
testl %eax, %eax
je 0x13515
movq 0x60(%r12), %rsi
movq %rbx, %rdi
callq 0x13c0a
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
callq 0x6be8
movq %r14, %r12
movq (%r14), %rax
movq %rax, %r14
testq %rax, %rax
jne 0x12e09
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
movl $0x3e9, %esi            # imm = 0x3E9
callq 0x6be8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6be8
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6be8