// File: /workspace/github_c_makefile_star2_O0/deplinenoise[P]vlink/t_rawbin.c
// Function: rawbin_writeexec
static void rawbin_writeexec(struct GlobalVars *gv,FILE *f,bool singlefile)
/* creates executable raw-binary files (with absolute addresses) */
{
  FILE *firstfile = f;
  bool firstsec = TRUE;
  unsigned long addr = ~0;
  struct LinkedSection *ls;

  while (ls = get_next_section(gv)) {
    if (ls->size == 0 || !(ls->flags & SF_ALLOC) || (ls->ld_flags & LSF_NOLOAD))
      continue;  /* ignore empty sections */

    if (firstsec) {
      if (gv->trace_file)
        fprintf(gv->trace_file,"Base address = 0x%08lx.\n",ls->copybase);
      firstsec = FALSE;
    }
    else {
      if (ls->copybase != addr) {
        if (ls->copybase-addr < MAXGAP || singlefile) {
          fwritegap(f,ls->copybase-addr);
        }
        else {  /* open a new file for this section */
          char *name;

          if (f != firstfile)
            fclose(f);
          name = alloc(strlen(gv->dest_name)+32);
          sprintf(name,"%s.%lx",gv->dest_name,ls->copybase);
          if (!(f = fopen(name,"wb"))) {
            error(29,name);
            break;
          }
          free(name);
        }
      }
    }

    /* resolve all relocations and write section contents */
    calc_relocs(gv,ls);
    fwritex(f,ls->data,ls->filesize);
    if (ls->filesize < ls->size)
      fwritegap(f,ls->size - ls->filesize);

    addr = ls->copybase + ls->size;
  }

  if (f && f!=firstfile)
    fclose(f);
}

// Assembly:
subq $0x48, %rsp
movq %rdi, 0x40(%rsp)
movq %rsi, 0x38(%rsp)
movl %edx, 0x34(%rsp)
movq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movl $0x1, 0x24(%rsp)
movq $-0x1, 0x18(%rsp)
movq 0x40(%rsp), %rdi
callq 0x30ef0
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x30ec9
movq 0x10(%rsp), %rax
cmpq $0x0, 0x48(%rax)
je 0x30d24
movq 0x10(%rsp), %rax
movzbl 0x21(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x30d24
movq 0x10(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
je 0x30d26
jmp 0x30cdd
cmpl $0x0, 0x24(%rsp)
je 0x30d6c
movq 0x40(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0x30d5f
movq 0x40(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rdx
leaq 0x73b8(%rip), %rsi      # 0x38110
movb $0x0, %al
callq 0x5150
movl $0x0, 0x24(%rsp)
jmp 0x30e52
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
cmpq 0x18(%rsp), %rax
je 0x30e50
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
subq 0x18(%rsp), %rax
cmpq $0x10, %rax
jb 0x30d9b
cmpl $0x0, 0x34(%rsp)
je 0x30db8
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rsi
subq 0x18(%rsp), %rsi
callq 0x86c0
jmp 0x30e4e
movq 0x38(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x30dce
movq 0x38(%rsp), %rdi
callq 0x50a0
movq 0x40(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0x50c0
movq %rax, %rdi
addq $0x20, %rdi
callq 0x71f0
movq %rax, 0x8(%rsp)
movq 0x8(%rsp), %rdi
movq 0x40(%rsp), %rax
movq 0x48(%rax), %rdx
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rcx
leaq 0x731e(%rip), %rsi      # 0x38129
movb $0x0, %al
callq 0x5230
movq 0x8(%rsp), %rdi
leaq 0x4632(%rip), %rsi      # 0x35450
callq 0x5200
movq %rax, 0x38(%rsp)
cmpq $0x0, %rax
jne 0x30e44
movq 0x8(%rsp), %rsi
movl $0x1d, %edi
movb $0x0, %al
callq 0x8c00
jmp 0x30ec9
movq 0x8(%rsp), %rdi
callq 0x5030
jmp 0x30e50
jmp 0x30e52
movq 0x40(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq 0x114f0
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x78(%rax), %rsi
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rdx
callq 0x8470
movq 0x10(%rsp), %rax
movq 0x50(%rax), %rax
movq 0x10(%rsp), %rcx
cmpq 0x48(%rcx), %rax
jae 0x30ead
movq 0x38(%rsp), %rdi
movq 0x10(%rsp), %rax
movq 0x48(%rax), %rsi
movq 0x10(%rsp), %rax
subq 0x50(%rax), %rsi
callq 0x86c0
movq 0x10(%rsp), %rax
movq 0x38(%rax), %rax
movq 0x10(%rsp), %rcx
addq 0x48(%rcx), %rax
movq %rax, 0x18(%rsp)
jmp 0x30cdd
cmpq $0x0, 0x38(%rsp)
je 0x30ee7
movq 0x38(%rsp), %rax
cmpq 0x28(%rsp), %rax
je 0x30ee7
movq 0x38(%rsp), %rdi
callq 0x50a0
addq $0x48, %rsp
retq
nopl (%rax)