// File: /workspace/github_c_makefile_star2_O1/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 0xa2cd
xorl %ebp, %ebp
movq %r13, %r14
movq %rax, %r13
testq %rbp, %rbp
cmoveq %r14, %rbp
cmpq $0x0, 0x48(%r14)
jne 0xa25c
movq 0x80(%r14), %rax
cmpq $0x0, (%rax)
jne 0xa25c
testb $0x2, 0x24(%r14)
jne 0xa25c
movq 0xb0(%r14), %rax
cmpq $0x0, (%rax)
je 0xa27a
cmpq %rbp, %r14
je 0xa25c
movq 0x18(%r14), %r15
movq 0x220(%rbx), %rsi
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xa290
movq 0x228(%rbx), %rsi
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xa290
movl 0x1d8(%rbx), %eax
leal 0x1(%rax), %ecx
movl %ecx, 0x1d8(%rbx)
movl %eax, 0x10(%r14)
movq (%r13), %rax
testq %rax, %rax
jne 0xa1f8
jmp 0xa2cd
movq %r14, %rdi
callq 0x6789
cmpq %rbp, %r14
movl $0x0, %eax
cmoveq %rax, %rbp
jmp 0xa26f
leaq 0xb0(%r14), %r15
movq %r15, %rdi
callq 0x676f
testq %rax, %rax
je 0xa2c3
leaq 0xb0(%rbp), %r12
movq %r12, %rdi
movq %rax, %rsi
callq 0x6759
movq %r15, %rdi
callq 0x676f
testq %rax, %rax
jne 0xa2ab
movq %r14, %rdi
callq 0x6789
jmp 0xa26f
cmpl $0x0, 0x110(%rbx)
je 0xa2e5
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq 0xa0(%rbx), %rdi
testq %rdi, %rdi
je 0xa315
movq 0x48(%rbx), %rdx
movzbl 0x50(%rbx), %eax
leaq 0x24e80(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movq (%rax), %rcx
leaq 0x1813a(%rip), %rsi     # 0x22448
xorl %eax, %eax
callq 0x5180
movq 0x48(%rbx), %rdi
leaq 0x18148(%rip), %rsi     # 0x22468
callq 0x5220
testq %rax, %rax
je 0xa348
movq %rax, %r14
cmpl $0x0, 0x58(%rbx)
je 0xa366
movzbl 0x50(%rbx), %eax
leaq 0x24e42(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
addq $0x78, %rax
jmp 0xa385
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 0x6f84
cmpl $0x0, 0x54(%rbx)
movzbl 0x50(%rbx), %eax
leaq 0x24e0b(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
je 0xa381
addq $0x70, %rax
jmp 0xa385
subq $-0x80, %rax
movq %rbx, %rdi
movq %r14, %rsi
callq *(%rax)
movq %r14, %rdi
callq 0x50c0
cmpl $0x0, 0x58(%rbx)
jne 0xa2d6
cmpl $0x0, 0x54(%rbx)
jne 0xa2d6
movq 0x48(%rbx), %rdi
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xa7fa