// File: /workspace/github_c_makefile_star2_O2/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, 0x14(%rsp)
movq %rsi, %rbx
movq %rdi, %r14
movq 0x1c0(%rdi), %r15
movq %rsi, %rdi
movl $0x3e7, %esi            # imm = 0x3E7
callq 0x6856
movq %r14, 0x8(%rsp)
movq 0x48(%r14), %rsi
movq %rbx, %rdi
callq 0x12552
movq (%r15), %rax
testq %rax, %rax
je 0x12520
testq %rax, %rax
je 0x12511
movq %rax, 0x20(%rsp)
movzbl 0x21(%r15), %ebp
andl $-0x40, %ebp
shll $0x18, %ebp
xorl %eax, %eax
movb %al, 0x21dd4(%rip)      # 0x33ca8
movb %al, 0x21dd2(%rip)      # 0x33cac
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x6856
movq 0x18(%r15), %rsi
movq %rbx, %rdi
callq 0x12552
movzbl 0x20(%r15), %esi
cmpl $0x3, %esi
je 0x11f26
cmpl $0x2, %esi
je 0x11f1e
cmpl $0x1, %esi
jne 0x11f2e
cmpl $0x0, 0x14(%rsp)
je 0x11f3e
movb 0x21(%r15), %al
andb $0x20, %al
je 0x11f3e
orl $0x4e9, %ebp            # imm = 0x4E9
jmp 0x11f44
orl $0x3ea, %ebp            # imm = 0x3EA
jmp 0x11f44
orl $0x3eb, %ebp            # imm = 0x3EB
jmp 0x11f44
leaq 0xf396(%rip), %rdi      # 0x212cb
xorl %eax, %eax
callq 0x6b2c
jmp 0x11f4e
orl $0x3e9, %ebp            # imm = 0x3E9
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6856
movq 0x8(%rsp), %rdi
movq %r15, %rsi
callq 0x12599
leaq 0x98(%r15), %r14
movq %r14, 0x28(%rsp)
movq (%r14), %r14
cmpq $0x0, (%r14)
je 0x11f8b
movq 0x78(%r15), %rsi
addq 0x20(%r14), %rsi
movq 0x28(%r14), %rcx
movq 0x8(%rsp), %rdi
movq %r14, %rdx
callq 0xaf7b
jmp 0x11f67
movq 0x48(%r15), %rsi
addq $0x3, %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x6856
testb $0x2, 0x21(%r15)
jne 0x11fc5
movq 0x48(%r15), %rdx
movq 0x78(%r15), %rsi
movq %rbx, %rdi
callq 0x6817
movl 0x48(%r15), %edx
movq %rbx, %rdi
pushq $0x2
popq %rsi
callq 0x693c
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x3ec, %ecx            # imm = 0x3EC
pushq $0x1
popq %r8
pushq $0x20
popq %r12
movl %r12d, %r9d
callq 0x125d3
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x3fd, %ecx            # imm = 0x3FD
pushq $0x2
popq %rbp
movl %ebp, %r8d
movl %r12d, %r9d
callq 0x125d3
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl %ebp, %r8d
pushq $0x10
popq %rbp
movl %ebp, %r9d
callq 0x125d3
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x3f8, %ecx            # imm = 0x3F8
pushq $0xa
popq %r8
movl %ebp, %r9d
callq 0x125d3
cmpl $0x0, 0x14(%rsp)
je 0x12085
movb 0x21(%r15), %al
andb $0x20, %al
je 0x12085
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x4ec, %ecx            # imm = 0x4EC
pushq $0x2
popq %rbp
movl %ebp, %r8d
pushq $0x18
popq %r9
callq 0x125d3
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl %ebp, %r8d
pushq $0xe
popq %r9
callq 0x125d3
movq %r15, 0x18(%rsp)
movq %r15, %rdi
callq 0x128ff
leaq 0x30(%rsp), %rdi
callq 0x63c8
movq 0x28(%rsp), %rdi
callq 0x642a
testq %rax, %rax
je 0x1235a
movq %rax, %r12
movq 0x10(%rax), %r13
movq 0x18(%rax), %rax
testq %rax, %rax
je 0x12146
cmpb $0x3, 0x40(%rax)
jne 0x12146
movq %r12, %rdi
pushq $0x1
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x7e, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x2
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x77, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x30, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x10
popq %rdx
callq 0xad23
movb $-0x2f, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x8
popq %rdx
callq 0xad23
movb $-0x2e, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x1
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x7f, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x1
popq %rsi
pushq $0x10
popq %rdx
callq 0xad23
movb $-0x76, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x1
popq %rsi
pushq $0x8
popq %rdx
callq 0xad23
movb $-0x75, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x2
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x78, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0x2
popq %rbp
movl %ebp, %esi
pushq $0x10
popq %rdx
callq 0xad23
movb $-0x7d, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
movl %ebp, %esi
pushq $0x8
popq %rdx
callq 0xad23
movb $-0x7c, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x20
popq %rdx
callq 0xad23
movb $-0x7b, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x10
popq %rdx
callq 0xad23
movb $-0x7a, %r15b
testl %eax, %eax
jne 0x122c6
movq %r12, %rdi
pushq $0xa
popq %rsi
pushq $0x8
popq %rdx
callq 0xad23
movb $-0x79, %r15b
testl %eax, %eax
jne 0x122c6
movb 0x38(%r12), %dl
movzbl %dl, %ecx
movq 0x30(%r12), %rax
cmpl $0x0, 0x14(%rsp)
je 0x12288
cmpb $0x2, %dl
jne 0x12288
movzwl 0x8(%rax), %edx
cmpw $0x6, %dx
jne 0x1226f
cmpw $0x18, 0xa(%rax)
pushq $0x2
popq %rcx
jne 0x12288
movl 0x10(%rax), %edx
movl $0x3ffffff, %ecx        # imm = 0x3FFFFFF
andl %ecx, %edx
movb $-0x1b, %r15b
pushq $0x2
popq %rcx
cmpl $0x3fffffc, %edx        # imm = 0x3FFFFFC
jne 0x12288
jmp 0x122c6
pushq $0x2
popq %rcx
testb $0xf, %dl
jne 0x12288
cmpw $0xe, 0xa(%rax)
jne 0x12288
cmpw $-0x4, 0x10(%rax)
movb $-0x7d, %r15b
je 0x122c6
movq 0x1d339(%rip), %rsi     # 0x2f5c8
leaq 0x1d06a(%rip), %rdx     # 0x2f300
movq (%rdx,%rcx,8), %rdx
movzwl 0x8(%rax), %ecx
movzwl 0xa(%rax), %r8d
movq 0x10(%rax), %r9
pushq $0x20
popq %rdi
xorl %eax, %eax
pushq 0x20(%r12)
movq 0x20(%rsp), %r10
pushq 0x18(%r10)
callq 0x6c19
addq $0x10, %rsp
movb $-0x7c, %r15b
movq 0x30(%rsp), %r14
movq %r14, %rbp
movq (%r14), %r14
testq %r14, %r14
je 0x122ee
movq 0x10(%rbp), %rsi
movq %r13, %rdi
callq 0x5160
testl %eax, %eax
jne 0x122cb
cmpb 0x18(%rbp), %r15b
jne 0x122cb
jmp 0x12346
pushq $0x40
popq %rdi
callq 0x6340
movq %rax, %rbp
movq %r13, 0x10(%rax)
movb %r15b, 0x18(%rax)
cmpb $-0x7e, %r15b
je 0x1231e
movzbl %r15b, %eax
cmpl $0x89, %eax
je 0x1231e
addb $0x30, %r15b
xorl %eax, %eax
cmpb $0x2, %r15b
ja 0x12326
movq 0x18(%r12), %rax
movl 0x44(%rax), %eax
movl %eax, 0x1c(%rbp)
andl $0x0, 0x20(%rbp)
movq %rbp, %rdi
addq $0x28, %rdi
callq 0x63c8
leaq 0x30(%rsp), %rdi
movq %rbp, %rsi
callq 0x6414
leaq 0x28(%rbp), %rdi
movq %r12, %rsi
callq 0x6414
incl 0x20(%rbp)
jmp 0x1209c
movq 0x30(%rsp), %rax
cmpq $0x0, (%rax)
movq 0x18(%rsp), %r15
je 0x12418
cmpb $0x0, 0x21937(%rip)     # 0x33cac
jne 0x12405
movb $0x1, 0x2192a(%rip)     # 0x33cac
movq %rbx, %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x6856
jmp 0x12405
movq %rax, %r14
movl 0x18(%rax), %ebp
shll $0x18, %ebp
movq 0x10(%rax), %rdi
callq 0x12c3a
orl %eax, %ebp
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6856
movq 0x10(%r14), %rsi
movq %rbx, %rdi
callq 0x12c48
movl 0x1c(%r14), %esi
testl %esi, %esi
je 0x123cb
movq %rbx, %rdi
callq 0x6856
movl 0x20(%r14), %esi
movq %rbx, %rdi
callq 0x6856
movq %r14, %r12
addq $0x28, %r12
movq %r12, %rdi
callq 0x642a
testq %rax, %rax
je 0x123f8
movl 0x20(%rax), %esi
movq %rbx, %rdi
callq 0x6856
jmp 0x123de
movq %r14, %rdi
callq 0x5040
movq 0x18(%rsp), %r15
leaq 0x30(%rsp), %rdi
callq 0x642a
testq %rax, %rax
jne 0x12391
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
pushq $0x2
popq %rbp
movl %ebp, %ecx
movl %ebp, %r8d
pushq $0x1
popq %r12
movl %r12d, %r9d
callq 0x12969
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %ebp, %ecx
movl %r12d, %r8d
movl %ebp, %r9d
callq 0x12969
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %ebp, %ecx
pushq $0x3
popq %r8
movl $0x100, %r9d            # imm = 0x100
callq 0x12969
cmpb $0x1, 0x2183b(%rip)     # 0x33cac
jne 0x1247d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6856
movq 0x8(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
pushq $0x1
popq %rbp
movl %ebp, %ecx
pushq $0x2
popq %r8
xorl %r9d, %r9d
callq 0x12969
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
movl %ebp, %ecx
movl %ebp, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x12969
cmpb $0x1, 0x217ec(%rip)     # 0x33ca8
jne 0x124c8
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6856
movq %r15, %rdi
callq 0x12adb
movq 0x8(%rsp), %rax
cmpb $0x0, 0x6c(%rax)
jne 0x124f7
movq %r15, %rdi
pushq $0x1
popq %rdx
movl %edx, %esi
callq 0xae5e
testl %eax, %eax
je 0x124f7
movq %rbx, %rdi
movq %r15, %rsi
callq 0x12b49
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
callq 0x6856
movq 0x20(%rsp), %r15
movq (%r15), %rax
jmp 0x11eb3
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 0x6856
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6856
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6856