// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/linker.c
// Function: linker_write
void linker_write(struct GlobalVars *gv)
{
  struct LinkedSection *ls = (struct LinkedSection *)gv->lnksec.first;
  struct LinkedSection *firstls=NULL,*nextls;
  FILE *f;

  /* remove empty sections without symbols and relocs */
  gv->nsecs = 0;
  while (nextls = (struct LinkedSection *)ls->n.next) {
    if (firstls == NULL)
      firstls = ls;

    if (ls->size==0 && listempty(&ls->relocs)
        && !(ls->ld_flags & LSF_PRESERVE)) {
      if (listempty(&ls->symbols)) {
        remnode(&ls->n);
        if (ls == firstls)
          firstls = NULL;
        ls = nextls;
        continue;
      }
      else if (ls!=firstls && (!strcmp(ls->name,gv->common_sec_name) ||
                               !strcmp(ls->name,gv->scommon_sec_name))) {
        /* @@@ Attention! This is a big HACK!
           For the future it should be desirable to have a separate
           list for common symbols, instead of just putting them into
           the symbol list of the first section... @@@ */
        struct Symbol *sym;

        while (sym = (struct Symbol *)remhead(&ls->symbols)) {
          addtail(&firstls->symbols,&sym->n);
        }
        remnode(&ls->n);
        ls = nextls;
        continue;
      }
    }

    ls->index = gv->nsecs++;  /* reindex remaining sections */
    ls = nextls;
  }

  if (!gv->errflag) {  /* no error? */
    if (gv->trace_file)
      fprintf(gv->trace_file,"\nCreating output file %s (%s).\n",
              gv->dest_name,fff[gv->dest_format]->tname);

    /* write output file */
    if (f = fopen(gv->dest_name,"wb")) {
      if (gv->dest_sharedobj)
        fff[gv->dest_format]->writeshared(gv,f);
      else if (gv->dest_object)
        fff[gv->dest_format]->writeobject(gv,f);
      else
        fff[gv->dest_format]->writeexec(gv,f);
      fclose(f);
      if (!gv->dest_sharedobj && !gv->dest_object)
        set_exec(gv->dest_name);  /* set executable flag */
    }
    else  /* Can't create output file */
      error(29,gv->dest_name);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rdi, %rbx
movq 0x1c0(%rdi), %r13
movl $0x0, 0x1d8(%rdi)
movq (%r13), %rax
testq %rax, %rax
je 0xa1cd
xorl %ebp, %ebp
movq %r13, %r14
movq %rax, %r13
testq %rbp, %rbp
cmoveq %r14, %rbp
cmpq $0x0, 0x48(%r14)
jne 0xa15c
movq 0x80(%r14), %rax
cmpq $0x0, (%rax)
jne 0xa15c
testb $0x2, 0x24(%r14)
jne 0xa15c
movq 0xb0(%r14), %rax
cmpq $0x0, (%rax)
je 0xa17a
cmpq %rbp, %r14
je 0xa15c
movq 0x18(%r14), %r15
movq 0x220(%rbx), %rsi
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xa190
movq 0x228(%rbx), %rsi
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xa190
movl 0x1d8(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1d8(%rbx)
movl %eax, 0x10(%r14)
movq (%r13), %rax
testq %rax, %rax
jne 0xa0f8
jmp 0xa1cd
movq %r14, %rdi
callq 0x6759
cmpq %rbp, %r14
movl $0x0, %eax
cmoveq %rax, %rbp
jmp 0xa16f
leaq 0xb0(%r14), %r15
movq %r15, %rdi
callq 0x673f
testq %rax, %rax
je 0xa1c3
leaq 0xb0(%rbp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x6729
movq %r15, %rdi
callq 0x673f
testq %rax, %rax
jne 0xa1ab
movq %r14, %rdi
callq 0x6759
jmp 0xa16f
cmpl $0x0, 0x110(%rbx)
je 0xa1e5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa0(%rbx), %rdi
testq %rdi, %rdi
je 0xa215
movq 0x48(%rbx), %rdx
movzbl 0x50(%rbx), %eax
leaq 0x24f80(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movq (%rax), %rcx
leaq 0x1822a(%rip), %rsi     # 0x22438
xorl %eax, %eax
callq 0x5180
movq 0x48(%rbx), %rdi
leaq 0x18238(%rip), %rsi     # 0x22458
callq 0x5220
testq %rax, %rax
je 0xa248
movq %rax, %r14
cmpl $0x0, 0x58(%rbx)
je 0xa266
movzbl 0x50(%rbx), %eax
leaq 0x24f42(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
addq $0x78, %rax
jmp 0xa285
movq 0x48(%rbx), %rsi
movl $0x1d, %edi
xorl %eax, %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0x6f14
cmpl $0x0, 0x54(%rbx)
movzbl 0x50(%rbx), %eax
leaq 0x24f0b(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
je 0xa281
addq $0x70, %rax
jmp 0xa285
subq $-0x80, %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
movq %r14, %rdi
callq 0x50c0
cmpl $0x0, 0x58(%rbx)
jne 0xa1d6
cmpl $0x0, 0x54(%rbx)
jne 0xa1d6
movq 0x48(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa6f6