// File: /workspace/github_c_makefile_star2_O1/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 0x6c5d
movq 0x48(%r15), %rsi
movq %rbx, %rdi
callq 0x136bf
cmpq $0x0, (%r12)
je 0x1368d
movq (%r12), %rax
testq %rax, %rax
je 0x1367e
movq %r15, 0x18(%rsp)
movq %r12, %r14
movq %rax, %r12
movzbl 0x21(%r14), %ebp
andl $-0x40, %ebp
shll $0x18, %ebp
xorl %eax, %eax
movb %al, 0x20920(%rip)      # 0x338b8
movb %al, 0x2091e(%rip)      # 0x338bc
movq %rbx, %rdi
movl $0x3e8, %esi            # imm = 0x3E8
callq 0x6c5d
movq 0x18(%r14), %rsi
movq %rbx, %rdi
callq 0x136bf
movq %r14, 0x10(%rsp)
movzbl 0x20(%r14), %esi
cmpl $0x3, %esi
je 0x12ff3
cmpl $0x2, %esi
je 0x12feb
cmpl $0x1, %esi
jne 0x12ffb
cmpl $0x0, 0xc(%rsp)
je 0x1300b
movq 0x10(%rsp), %rax
movb 0x21(%rax), %al
andb $0x20, %al
je 0x1300b
orl $0x4e9, %ebp            # imm = 0x4E9
jmp 0x13011
orl $0x3ea, %ebp            # imm = 0x3EA
jmp 0x13011
orl $0x3eb, %ebp            # imm = 0x3EB
jmp 0x13011
leaq 0x102d9(%rip), %rdi     # 0x232db
xorl %eax, %eax
callq 0x52b0
jmp 0x1301b
orl $0x3e9, %ebp            # imm = 0x3E9
movq %rbx, %rdi
movl %ebp, %esi
callq 0x6c5d
movq %r15, %rdi
movq 0x10(%rsp), %r13
movq %r13, %rsi
callq 0x13708
movq 0x98(%r13), %r14
cmpq $0x0, (%r14)
je 0x13054
movq 0x78(%r13), %rsi
addq 0x20(%r14), %rsi
movq 0x28(%r14), %rcx
movq %r15, %rdi
movq %r14, %rdx
callq 0xb5b0
movq (%r14), %r14
jmp 0x13032
movq 0x48(%r13), %rsi
addq $0x3, %rsi
shrq $0x2, %rsi
movq %rbx, %rdi
callq 0x6c5d
testb $0x2, 0x21(%r13)
jne 0x13090
movq 0x48(%r13), %rdx
movq 0x78(%r13), %rsi
movq %rbx, %rdi
callq 0x6c1a
movl 0x48(%r13), %edx
movq %rbx, %rdi
movl $0x2, %esi
callq 0x6d55
movq %r12, 0x20(%rsp)
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x3ec, %ecx            # imm = 0x3EC
movl $0x1, %r8d
movl $0x20, %r9d
callq 0x13746
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x3fd, %ecx            # imm = 0x3FD
movl $0x2, %r8d
movl $0x20, %r9d
callq 0x13746
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0x10, %r9d
callq 0x13746
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x3f8, %ecx            # imm = 0x3F8
movl $0xa, %r8d
movl $0x10, %r9d
callq 0x13746
cmpl $0x0, 0xc(%rsp)
je 0x1315e
movb 0x21(%r13), %al
andb $0x20, %al
je 0x1315e
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x4ec, %ecx            # imm = 0x4EC
movl $0x2, %r8d
movl $0x18, %r9d
callq 0x13746
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movl $0x3ed, %ecx            # imm = 0x3ED
movl $0x2, %r8d
movl $0xe, %r9d
callq 0x13746
leaq 0x98(%r13), %r14
movq %r13, %rdi
callq 0x13aef
leaq 0x30(%rsp), %rdi
callq 0x670a
movq %r14, 0x28(%rsp)
movq %r14, %rdi
callq 0x676f
testq %rax, %rax
je 0x134a5
movq %rax, %rbp
movq 0x10(%rbp), %r15
movq 0x18(%rbp), %rax
testq %rax, %rax
je 0x1323c
cmpb $0x3, 0x40(%rax)
jne 0x1323c
movq %rbp, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x7e, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x77, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x30, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0xb340
movb $-0x2f, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0xb340
movb $-0x2e, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x1, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x7f, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x1, %esi
movl $0x10, %edx
callq 0xb340
movb $-0x76, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x1, %esi
movl $0x8, %edx
callq 0xb340
movb $-0x75, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x2, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x78, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x2, %esi
movl $0x10, %edx
callq 0xb340
movb $-0x7d, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0x2, %esi
movl $0x8, %edx
callq 0xb340
movb $-0x7c, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x20, %edx
callq 0xb340
movb $-0x7b, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x10, %edx
callq 0xb340
movb $-0x7a, %r12b
testl %eax, %eax
jne 0x133a7
movq %rbp, %rdi
movl $0xa, %esi
movl $0x8, %edx
callq 0xb340
testl %eax, %eax
movl $0x87, %r12d
cmovel %eax, %r12d
cmpl $0x0, 0xc(%rsp)
je 0x133a7
testl %eax, %eax
jne 0x133a7
cmpb $0x2, 0x38(%rbp)
jne 0x133a4
movq 0x30(%rbp), %rax
testq %rax, %rax
je 0x133a4
movzwl 0x8(%rax), %ecx
cmpw $0x6, %cx
jne 0x13382
cmpw $0x18, 0xa(%rax)
jne 0x13382
movl 0x10(%rax), %edx
movl $0x3ffffff, %esi        # imm = 0x3FFFFFF
andl %esi, %edx
movb $-0x1b, %r12b
cmpl $0x3fffffc, %edx        # imm = 0x3FFFFFC
je 0x133a7
testb $0xf, %cl
jne 0x133a4
cmpw $0xe, 0xa(%rax)
jne 0x133a4
cmpw $-0x4, 0x10(%rax)
movl $0x0, %r12d
movl $0x83, %eax
cmovel %eax, %r12d
jmp 0x133a7
xorl %r12d, %r12d
testb %r12b, %r12b
jne 0x133f2
movq 0x1c205(%rip), %rsi     # 0x2f5b8
movzbl 0x38(%rbp), %eax
leaq 0x1bf32(%rip), %rcx     # 0x2f2f0
movq (%rcx,%rax,8), %rdx
movq 0x30(%rbp), %rax
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 0x6f84
addq $0x10, %rsp
movb $-0x7c, %r12b
movq 0x30(%rsp), %r13
movq (%r13), %rax
testq %rax, %rax
je 0x13421
movq %rax, %r14
movq 0x10(%r13), %rsi
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
jne 0x13419
cmpb 0x18(%r13), %r12b
je 0x1347f
movq (%r14), %rax
movq %r14, %r13
jmp 0x133fb
movl $0x40, %edi
callq 0x6668
movq %rax, %r13
movq %r15, 0x10(%rax)
movb %r12b, 0x18(%rax)
cmpb $-0x7e, %r12b
je 0x13453
movzbl %r12b, %eax
cmpl $0x89, %eax
je 0x13453
addb $0x30, %r12b
xorl %eax, %eax
cmpb $0x2, %r12b
ja 0x1345a
movq 0x18(%rbp), %rax
movl 0x44(%rax), %eax
movl %eax, 0x1c(%r13)
movl $0x0, 0x20(%r13)
movq %r13, %rdi
addq $0x28, %rdi
callq 0x670a
leaq 0x30(%rsp), %rdi
movq %r13, %rsi
callq 0x6759
leaq 0x28(%r13), %rdi
movq %rbp, %rsi
callq 0x6759
incl 0x20(%r13)
movq 0x28(%rsp), %rdi
callq 0x676f
movq %rax, %rbp
testq %rax, %rax
jne 0x13190
movq 0x30(%rsp), %rax
cmpq $0x0, (%rax)
movq 0x20(%rsp), %r12
je 0x1356c
cmpb $0x0, 0x203fc(%rip)     # 0x338bc
jne 0x134d6
movb $0x1, 0x203f3(%rip)     # 0x338bc
movq %rbx, %rdi
movl $0x3ef, %esi            # imm = 0x3EF
callq 0x6c5d
leaq 0x30(%rsp), %rdi
callq 0x676f
testq %rax, %rax
je 0x1356c
movq %rax, %r15
movl 0x18(%r15), %ebp
shll $0x18, %ebp
movq 0x10(%r15), %rdi
callq 0x50e0
leal 0x3(%rax), %esi
sarl $0x2, %esi
orl %ebp, %esi
movq %rbx, %rdi
callq 0x6c5d
movq 0x10(%r15), %rsi
movq %rbx, %rdi
callq 0x13e79
movl 0x1c(%r15), %esi
testl %esi, %esi
je 0x13528
movq %rbx, %rdi
callq 0x6c5d
movl 0x20(%r15), %esi
movq %rbx, %rdi
callq 0x6c5d
leaq 0x28(%r15), %r14
movq %r14, %rdi
callq 0x676f
testq %rax, %rax
je 0x13552
movl 0x20(%rax), %esi
movq %rbx, %rdi
callq 0x6c5d
jmp 0x13538
movq %r15, %rdi
callq 0x5040
leaq 0x30(%rsp), %rdi
callq 0x676f
movq %rax, %r15
testq %rax, %rax
jne 0x134ec
movq 0x18(%rsp), %r15
movq %r15, %rdi
movq %rbx, %rsi
movq 0x10(%rsp), %r14
movq %r14, %rdx
movl $0x2, %ecx
movl $0x2, %r8d
movl $0x1, %r9d
callq 0x13b63
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x2, %ecx
movl $0x1, %r8d
movl $0x2, %r9d
callq 0x13b63
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x2, %ecx
movl $0x3, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x13b63
cmpb $0x1, 0x202e2(%rip)     # 0x338bc
jne 0x135e6
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6c5d
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x1, %ecx
movl $0x2, %r8d
xorl %r9d, %r9d
callq 0x13b63
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
movl $0x1, %ecx
movl $0x1, %r8d
movl $0x100, %r9d            # imm = 0x100
callq 0x13b63
cmpb $0x1, 0x20290(%rip)     # 0x338b8
jne 0x13634
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6c5d
movq %r14, %rdi
callq 0x13cfc
cmpb $0x0, 0x6c(%r15)
jne 0x13664
movq %r14, %rdi
movl $0x1, %esi
movl $0x1, %edx
callq 0xb488
testl %eax, %eax
je 0x13664
movq %rbx, %rdi
movq %r14, %rsi
callq 0x13d78
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
callq 0x6c5d
movq (%r12), %rax
testq %rax, %rax
jne 0x12f7f
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 0x6c5d
movq %rbx, %rdi
xorl %esi, %esi
callq 0x6c5d
movq %rbx, %rdi
movl $0x3f2, %esi            # imm = 0x3F2
addq $0x48, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c5d