// File: /workspace/github_c_makefile_star2_O2/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movl %edx, 0x4(%rsp)
movq %rsi, %r12
movq %rdi, %r14
pushq $-0x1
popq %r13
xorl %ebp, %ebp
movq %rsi, %rbx
movq %r14, %rdi
callq 0x1ce4b
testq %rax, %rax
je 0x1cdfb
movq %rax, %r15
cmpq $0x0, 0x48(%rax)
je 0x1ccde
testb $0x1, 0x21(%r15)
je 0x1ccde
testb $0x1, 0x24(%r15)
jne 0x1ccde
testb $0x1, %bpl
je 0x1cd93
movq 0x38(%r15), %rsi
subq %r13, %rsi
je 0x1cdbb
cmpl $0x0, 0x4(%rsp)
jne 0x1cdb3
cmpq $0xf, %rsi
jbe 0x1cdb3
cmpq %r12, %rbx
je 0x1cd40
movq %rbx, %rdi
callq 0x50c0
movq 0x48(%r14), %rdi
callq 0x50e0
leaq 0x20(%rax), %rdi
callq 0x6340
movq %rax, %r13
movq 0x48(%r14), %rdx
movq 0x38(%r15), %rcx
movq %rax, %rdi
leaq 0x6992(%rip), %rsi      # 0x236f9
xorl %eax, %eax
callq 0x5260
movq %r13, %rdi
leaq 0x36f0(%rip), %rsi      # 0x20468
callq 0x5230
testq %rax, %rax
je 0x1ce30
movq %rax, %rbx
movq %r13, %rdi
callq 0x5040
jmp 0x1cdbb
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x1cdbb
movq 0x38(%r15), %rdx
leaq 0x6936(%rip), %rsi      # 0x236e0
xorl %eax, %eax
callq 0x5180
jmp 0x1cdbb
movq %rbx, %rdi
callq 0x698d
movq %r14, %rdi
movq %r15, %rsi
callq 0xb170
movq 0x50(%r15), %rdx
movq 0x78(%r15), %rsi
movq %rbx, %rdi
callq 0x6817
movq 0x48(%r15), %r13
movq %r13, %rsi
subq 0x50(%r15), %rsi
jbe 0x1cdef
movq %rbx, %rdi
callq 0x698d
movq 0x48(%r15), %r13
addq 0x38(%r15), %r13
movb $0x1, %bpl
jmp 0x1ccde
testq %rbx, %rbx
sete %al
cmpq %r12, %rbx
sete %cl
orb %al, %cl
je 0x1ce1a
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rbx, %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x50c0
pushq $0x1d
popq %rdi
movq %r13, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6c19