// File: /workspace/github_c_makefile_star2_O0/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:
subq $0x38, %rsp
movq %rdi, 0x30(%rsp)
movq 0x30(%rsp), %rax
movq 0x1c0(%rax), %rax
movq %rax, 0x28(%rsp)
movq $0x0, 0x20(%rsp)
movq 0x30(%rsp), %rax
movl $0x0, 0x1d8(%rax)
movq 0x28(%rsp), %rax
movq (%rax), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0xea84
cmpq $0x0, 0x20(%rsp)
jne 0xe93b
movq 0x28(%rsp), %rax
movq %rax, 0x20(%rsp)
movq 0x28(%rsp), %rax
cmpq $0x0, 0x48(%rax)
jne 0xea57
movq 0x28(%rsp), %rax
movq 0x80(%rax), %rax
cmpq $0x0, (%rax)
jne 0xea57
movq 0x28(%rsp), %rax
movzwl 0x24(%rax), %eax
andl $0x2, %eax
cmpl $0x0, %eax
jne 0xea57
movq 0x28(%rsp), %rax
movq 0xb0(%rax), %rax
cmpq $0x0, (%rax)
jne 0xe9b6
movq 0x28(%rsp), %rdi
callq 0x7530
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
jne 0xe9a7
movq $0x0, 0x20(%rsp)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0xe912
movq 0x28(%rsp), %rax
cmpq 0x20(%rsp), %rax
je 0xea53
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x220(%rax), %rsi
callq 0x5130
cmpl $0x0, %eax
je 0xea04
movq 0x28(%rsp), %rax
movq 0x18(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x228(%rax), %rsi
callq 0x5130
cmpl $0x0, %eax
jne 0xea53
jmp 0xea06
movq 0x28(%rsp), %rdi
addq $0xb0, %rdi
callq 0x74d0
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0xea3a
movq 0x20(%rsp), %rdi
addq $0xb0, %rdi
movq 0x8(%rsp), %rsi
callq 0x7470
jmp 0xea06
movq 0x28(%rsp), %rdi
callq 0x7530
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0xe912
jmp 0xea55
jmp 0xea57
movq 0x30(%rsp), %rax
movl 0x1d8(%rax), %ecx
movl %ecx, %edx
addl $0x1, %edx
movl %edx, 0x1d8(%rax)
movq 0x28(%rsp), %rax
movl %ecx, 0x10(%rax)
movq 0x18(%rsp), %rax
movq %rax, 0x28(%rsp)
jmp 0xe912
movq 0x30(%rsp), %rax
cmpl $0x0, 0x110(%rax)
jne 0xebdd
movq 0x30(%rsp), %rax
cmpq $0x0, 0xa0(%rax)
je 0xeae1
movq 0x30(%rsp), %rax
movq 0xa0(%rax), %rdi
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rdx
movq 0x30(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x30f64(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq (%rax), %rcx
leaq 0x26956(%rip), %rsi     # 0x35430
movb $0x0, %al
callq 0x5150
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rdi
leaq 0x2695f(%rip), %rsi     # 0x35450
callq 0x5200
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0xebc6
movq 0x30(%rsp), %rax
cmpl $0x0, 0x58(%rax)
je 0xeb38
movq 0x30(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x30f0e(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq 0x78(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq *%rax
jmp 0xeb96
movq 0x30(%rsp), %rax
cmpl $0x0, 0x54(%rax)
je 0xeb6b
movq 0x30(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x30edb(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq 0x70(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq *%rax
jmp 0xeb94
movq 0x30(%rsp), %rax
movzbl 0x50(%rax), %eax
movl %eax, %ecx
leaq 0x30eb3(%rip), %rax     # 0x3fa30
movq (%rax,%rcx,8), %rax
movq 0x80(%rax), %rax
movq 0x30(%rsp), %rdi
movq 0x10(%rsp), %rsi
callq *%rax
jmp 0xeb96
movq 0x10(%rsp), %rdi
callq 0x50a0
movq 0x30(%rsp), %rax
cmpl $0x0, 0x58(%rax)
jne 0xebc4
movq 0x30(%rsp), %rax
cmpl $0x0, 0x54(%rax)
jne 0xebc4
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rdi
callq 0xf510
jmp 0xebdb
movq 0x30(%rsp), %rax
movq 0x48(%rax), %rsi
movl $0x1d, %edi
movb $0x0, %al
callq 0x8c00
jmp 0xebdd
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)