// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_elf32ppcbe.c
// Function: morphos_writeexec
static void morphos_writeexec(struct GlobalVars *gv,FILE *f)
/* creates a target-elf32morphos executable file, which in */
/* reality is a relocatable object too, but all symbol references have */
/* been resolved */
{
  struct LinkedSection *ls;
  int sdflag=0,sbflag=0;

  for (ls=(struct LinkedSection *)gv->lnksec.first; ls->n.next!=NULL;
       ls=(struct LinkedSection *)ls->n.next) {

    if (ls->flags & SF_SMALLDATA) {
      /* data sections should be called .sdata, and bss sections .sbss */

      if (ls->type == ST_DATA) {  /* .sdata */
        struct Section *bss_sec = find_first_bss_sec(ls);

        if (sdflag)
          error(124,fff[gv->dest_format]->tname);
        sdflag = 1;
        ls->name = sdata_name;

        if (bss_sec && (ls->filesize < ls->size)) {
          /* put bss-part of .sdata into an own section called .sbss */
          struct LinkedSection *sbss;
          struct Section *sec = bss_sec;
          struct Section *nextsec;
          struct Symbol *sym = (struct Symbol *)ls->symbols.first;
          struct Symbol *nextsym;
          unsigned long bss_offset = bss_sec->offset;
          lword bss_va = (lword)(ls->base + bss_offset);

          sbss = create_lnksect(gv,sbss_name,ST_UDATA,
                                ls->flags|SF_UNINITIALIZED,
                                ls->protection,ls->alignment);
          sbss->size = ls->size - bss_sec->offset;
          sbss->data = alloc(sbss->size);

          /* move bss sections from .sdata to .sbss */
          while (nextsec = (struct Section *)sec->n.next) {
            remnode(&sec->n);
            addtail(&sbss->sections,&sec->n);
            sec->lnksec = sbss;
            sec->offset -= bss_offset;
            sec = nextsec;
          }

          /* move symbols */
          while (nextsym = (struct Symbol *)sym->n.next) {
            /* move bss symbols to .sbss */
            if (sym->relsect->lnksec == sbss) {
              remnode(&sym->n);
              addtail(&sbss->symbols,&sym->n);
              sym->value -= bss_va;
            }
            sym = nextsym;
          }
          /* no relocs and no xrefs can occur in bss */

          ls->size -= sbss->size;  /* the bss part is gone */
        }
      }

      else if (ls->type == ST_UDATA) {
        if (sbflag)
          error(124,fff[gv->dest_format]->tname);
        sbflag = 1;
        ls->name = sbss_name;
      }
    }

    /* set filesize to memsize for all sections */
    if (!(ls->flags & SF_UNINITIALIZED))
      ls->filesize = ls->size;

    /* setup ddrelocs section, if present */
    if (!strcmp(ls->name,ddrelocs_name))
      make_ddrelocs(gv,ls);
  }

  elf32_writeobject(gv,f,EM_PPC,_BIG_ENDIAN_,ppc32_reloc_vlink2elf);
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x60(%rsp)
movq %rsi, 0x58(%rsp)
movl $0x0, 0x4c(%rsp)
movl $0x0, 0x48(%rsp)
movq 0x60(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x50(%rsp)
movq 0x50(%rsp), %rax
cmpq $0x0, (%rax)
je 0x2892a
movq 0x50(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x4, %eax
cmpl $0x0, %eax
je 0x288ca
movq 0x50(%rsp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x2, %eax
jne 0x28874
movq 0x50(%rsp), %rdi
callq 0x120b0
movq %rax, 0x40(%rsp)
cmpl $0x0, 0x4c(%rsp)
je 0x286a0
movq 0x60(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x173a3(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq (%rax), %rsi
movl $0x7c, %edi
movb $0x0, %al
callq 0x8c00
movl $0x1, 0x4c(%rsp)
movq 0x50(%rsp), %rax
leaq 0xcefd(%rip), %rcx      # 0x355b1
movq %rcx, 0x18(%rax)
cmpq $0x0, 0x40(%rsp)
je 0x28872
movq 0x50(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x50(%rsp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x28872
movq 0x40(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x50(%rsp), %rax
movq 0xb0(%rax), %rax
movq %rax, 0x20(%rsp)
movq 0x40(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x10(%rsp)
movq 0x50(%rsp), %rax
movq 0x40(%rax), %rax
addq 0x10(%rsp), %rax
movq %rax, 0x8(%rsp)
movq 0x60(%rsp), %rdi
movq 0x50(%rsp), %rax
movzbl 0x21(%rax), %eax
orl $0x2, %eax
movb %al, %cl
movq 0x50(%rsp), %rax
movb 0x22(%rax), %r8b
movq 0x50(%rsp), %rax
leaq 0xce78(%rip), %rsi      # 0x355b8
movl $0x3, %edx
movzbl %cl, %ecx
movzbl %r8b, %r8d
movzbl 0x23(%rax), %r9d
callq 0x12a60
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x40(%rsp), %rax
subq 0x38(%rax), %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x48(%rax)
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x71f0
movq %rax, %rcx
movq 0x38(%rsp), %rax
movq %rcx, 0x78(%rax)
movq 0x30(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, %rax
je 0x287ef
movq 0x30(%rsp), %rdi
callq 0x7530
movq 0x38(%rsp), %rdi
addq $0x60, %rdi
movq 0x30(%rsp), %rsi
callq 0x7470
movq 0x38(%rsp), %rcx
movq 0x30(%rsp), %rax
movq %rcx, 0x18(%rax)
movq 0x10(%rsp), %rdx
movq 0x30(%rsp), %rax
movq 0x38(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x38(%rax)
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x28790
jmp 0x287f1
movq 0x20(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x28859
movq 0x20(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x18(%rax), %rax
cmpq 0x38(%rsp), %rax
jne 0x2884d
movq 0x20(%rsp), %rdi
callq 0x7530
movq 0x38(%rsp), %rdi
addq $0xb0, %rdi
movq 0x20(%rsp), %rsi
callq 0x7470
movq 0x8(%rsp), %rdx
movq 0x20(%rsp), %rax
movq 0x30(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x30(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x20(%rsp)
jmp 0x287f1
movq 0x38(%rsp), %rax
movq 0x48(%rax), %rdx
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rcx
subq %rdx, %rcx
movq %rcx, 0x48(%rax)
jmp 0x288c8
movq 0x50(%rsp), %rax
movzbl 0x20(%rax), %eax
cmpl $0x3, %eax
jne 0x288c6
cmpl $0x0, 0x48(%rsp)
je 0x288ae
movq 0x60(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x17195(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq (%rax), %rsi
movl $0x7c, %edi
movb $0x0, %al
callq 0x8c00
movl $0x1, 0x48(%rsp)
movq 0x50(%rsp), %rax
leaq 0xccf6(%rip), %rcx      # 0x355b8
movq %rcx, 0x18(%rax)
jmp 0x288c8
jmp 0x288ca
movq 0x50(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0x288ed
movq 0x50(%rsp), %rax
movq 0x48(%rax), %rcx
movq 0x50(%rsp), %rax
movq %rcx, 0x50(%rax)
movq 0x50(%rsp), %rax
movq 0x18(%rax), %rdi
leaq 0x18191(%rip), %rsi     # 0x40a8e
callq 0x5130
cmpl $0x0, %eax
jne 0x28916
movq 0x60(%rsp), %rdi
movq 0x50(%rsp), %rsi
callq 0x29310
jmp 0x28918
movq 0x50(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x50(%rsp)
jmp 0x2862f
movq 0x60(%rsp), %rdi
movq 0x58(%rsp), %rsi
movl $0x14, %edx
movl $0x1, %ecx
leaq 0x3cb(%rip), %r8        # 0x28d10
callq 0x26a50
addq $0x68, %rsp
retq
nop