// File: /workspace/github_c_makefile_star2_O3/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, %ebx
movq %rsi, %r12
movq %rdi, %r14
movq 0x1c0(%rdi), %rdi
callq 0x1e849
testq %rax, %rax
je 0x1e807
movq %rax, %r15
movl %ebx, 0x4(%rsp)
movq $-0x1, %r13
xorl %ebp, %ebp
movq %r12, %rbx
cmpq $0x0, 0x48(%r15)
je 0x1e6db
testb $0x1, 0x21(%r15)
je 0x1e6db
testb $0x1, 0x24(%r15)
je 0x1e6f4
movq 0x1c0(%r14), %rdi
callq 0x1e849
movq %rax, %r15
testq %rax, %rax
jne 0x1e6c6
jmp 0x1e7f7
testb $0x1, %bpl
je 0x1e780
movq 0x38(%r15), %rsi
subq %r13, %rsi
je 0x1e7a8
cmpl $0x0, 0x4(%rsp)
jne 0x1e7a0
cmpq $0xf, %rsi
jbe 0x1e7a0
cmpq %r12, %rbx
je 0x1e72d
movq %rbx, %rdi
callq 0x50c0
movq 0x48(%r14), %rdi
callq 0x50e0
leaq 0x20(%rax), %rdi
callq 0x6638
movq %rax, %r13
movq 0x48(%r14), %rdx
movq 0x38(%r15), %rcx
movq %rax, %rdi
leaq 0x7381(%rip), %rsi      # 0x25ad5
xorl %eax, %eax
callq 0x5250
movq %r13, %rdi
leaq 0x3cf3(%rip), %rsi      # 0x22458
callq 0x5220
testq %rax, %rax
je 0x1e82c
movq %rax, %rbx
movq %r13, %rdi
callq 0x5040
jmp 0x1e7a8
movq 0xa0(%r14), %rdi
testq %rdi, %rdi
je 0x1e7a8
movq 0x38(%r15), %rdx
leaq 0x7325(%rip), %rsi      # 0x25abc
xorl %eax, %eax
callq 0x5180
jmp 0x1e7a8
movq %rbx, %rdi
callq 0x6d33
movq %r14, %rdi
movq %r15, %rsi
callq 0xb6e6
movq 0x50(%r15), %rdx
movq 0x78(%r15), %rsi
movq %rbx, %rdi
callq 0x6ba5
movq 0x48(%r15), %r13
movq %r13, %rsi
subq 0x50(%r15), %rsi
jbe 0x1e7dc
movq %rbx, %rdi
callq 0x6d33
movq 0x48(%r15), %r13
addq 0x38(%r15), %r13
movq 0x1c0(%r14), %rdi
callq 0x1e849
movq %rax, %r15
movb $0x1, %bpl
jmp 0x1e6ea
testq %rbx, %rbx
sete %al
cmpq %r12, %rbx
sete %cl
orb %al, %cl
je 0x1e816
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
movl $0x1d, %edi
movq %r13, %rsi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6f14