// File: /workspace/github_c_makefile_star2_O1/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, %r13
movq %rdi, %r14
callq 0x1e98f
movq %r13, %rbx
testq %rax, %rax
je 0x1e95a
movq %rax, %r15
movq $-0x1, %r12
xorl %ebp, %ebp
movq %r13, %rbx
cmpq $0x0, 0x48(%r15)
je 0x1e83f
testb $0x1, 0x21(%r15)
je 0x1e83f
testb $0x1, 0x24(%r15)
je 0x1e854
movq %r14, %rdi
callq 0x1e98f
movq %rax, %r15
testq %rax, %rax
jne 0x1e82a
jmp 0x1e95a
testb $0x1, %bpl
je 0x1e8d4
movq 0x38(%r15), %rsi
subq %r12, %rsi
je 0x1e912
cmpl $0x0, 0x4(%rsp)
jne 0x1e8f4
cmpq $0xf, %rsi
jbe 0x1e8f4
cmpq %r13, %rbx
je 0x1e885
movq %rbx, %rdi
callq 0x50c0
movq 0x48(%r14), %rdi
callq 0x50e0
leaq 0x20(%rax), %rdi
callq 0x6668
movq %rax, %r12
movq 0x48(%r14), %rdx
movq 0x38(%r15), %rcx
movq %rax, %rdi
leaq 0x7249(%rip), %rsi      # 0x25af5
xorl %eax, %eax
callq 0x5250
movq %r12, %rdi
leaq 0x3bab(%rip), %rsi      # 0x22468
callq 0x5220
movq %rax, %rbx
testq %rax, %rax
je 0x1e8fe
movq %r12, %rdi
callq 0x5040
jmp 0x1e90d
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x1e912
movq 0x38(%r15), %rdx
leaq 0x71f1(%rip), %rsi      # 0x25adc
xorl %eax, %eax
callq 0x5180
jmp 0x1e912
movq %rbx, %rdi
callq 0x6da8
jmp 0x1e912
movl $0x1d, %edi
movq %r12, %rsi
xorl %eax, %eax
callq 0x6f84
testq %rbx, %rbx
je 0x1e95a
movq %r14, %rdi
movq %r15, %rsi
callq 0xb7c8
movq 0x50(%r15), %rdx
movq 0x78(%r15), %rsi
movq %rbx, %rdi
callq 0x6c1a
movq 0x48(%r15), %rsi
subq 0x50(%r15), %rsi
jbe 0x1e93f
movq %rbx, %rdi
callq 0x6da8
movq 0x48(%r15), %r12
addq 0x38(%r15), %r12
movq %r14, %rdi
callq 0x1e98f
movq %rax, %r15
movb $0x1, %bpl
jmp 0x1e84a
testq %rbx, %rbx
sete %al
cmpq %r13, %rbx
sete %cl
orb %al, %cl
je 0x1e979
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