// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/targets.c
// Function: write_constructors
static void write_constructors(struct GlobalVars *gv,struct ObjectUnit *ou,
                               struct Symbol *labelsym,int cnt,
                               lword offset,const char *secname)
{
  uint8_t *data = ou->lnkfile->data + offset;
  unsigned long asize = (unsigned long)fff[gv->dest_format]->addr_bits / 8;
  struct Section *sec;
  struct PriPointer *pp;

  /* create a new section, if required */
  for (sec=(struct Section *)ou->sections.first;
       sec->n.next!=NULL; sec=(struct Section *)sec->n.next) {
    if (!strcmp(secname,sec->name))
      break;
  }
  if (sec->n.next == NULL) {
    sec = add_xtor_section(gv,ou,secname,ou->lnkfile->data+offset,2*asize);
    offset = 0;
  }
  else
    sec->size += 2*asize;

  /* assign constructor/destructor label symbol to start of list */
  unlink_lnksymbol(gv,labelsym);
  labelsym->relsect = sec;
  labelsym->type = SYM_RELOC;
  labelsym->value = offset;
  labelsym->size = 2 * asize;
  add_objsymbol(ou,labelsym);
  addglobsym(gv,labelsym);  /* make it globally visible */
  data += writetaddr(gv,data,(lword)cnt);
  offset += asize;

  /* write con-/destructor pointers */
  for (pp=(struct PriPointer *)gv->pripointers.first;
       pp->n.next!=NULL; pp=(struct PriPointer *)pp->n.next) {
    if (!strcmp(pp->listname,labelsym->name)) {
      struct Reloc *r;

      data += writetaddr(gv,data,pp->addend);
      if (pp->xrefname) {
        r = newreloc(gv,sec,pp->xrefname,NULL,0,(unsigned long)offset,
                     R_ABS,pp->addend);
        addreloc(sec,r,0,asize<<3,-1);
      }
      sec->size += asize;
      labelsym->size += asize;
      offset += asize;
    }
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movq %r9, %r14
movl %ecx, 0x4(%rsp)
movq %rdx, %rbx
movq %rsi, %rbp
movq 0x10(%rsi), %rax
movq 0x20(%rsi), %r15
movq 0x28(%rax), %r13
movq %r8, 0x18(%rsp)
addq %r8, %r13
movq %rdi, 0x10(%rsp)
movzbl 0x50(%rdi), %eax
leaq 0x23126(%rip), %rcx     # 0x2f190
movq (%rcx,%rax,8), %rax
movsbq 0xab(%rax), %rax
movq %rax, 0x20(%rsp)
shrq $0x3, %rax
movq %rax, 0x8(%rsp)
movq %r15, %r12
movq (%r15), %r15
testq %r15, %r15
je 0xc0b4
movq 0x20(%r12), %rsi
movq %r14, %rdi
callq 0x5160
testl %eax, %eax
jne 0xc084
movq 0x8(%rsp), %rax
addq %rax, %rax
addq %rax, 0x48(%r12)
movq 0x18(%rsp), %r15
jmp 0xc0e7
movq 0x8(%rsp), %rax
leaq (%rax,%rax), %rcx
subq $0x8, %rsp
pushq $0x2
popq %r8
pushq $0x1
popq %r9
movq %rbp, %rdi
movq %r14, %rsi
movq %r13, %rdx
pushq $0x0
pushq $0x2
pushq $0x3
callq 0xbab3
addq $0x20, %rsp
movq %rax, %r12
xorl %r15d, %r15d
movq 0x10(%rsp), %rax
movq 0x188(%rax), %r14
testq %r14, %r14
je 0xc134
movq 0x20(%rbx), %rdi
callq 0x69ee
andl $0xf, %eax
leaq (%r14,%rax,8), %rdx
movq %rdx, %rax
movq (%rdx), %rcx
testq %rcx, %rcx
je 0xc11c
leaq 0x18(%rcx), %rdx
cmpq %rbx, %rcx
jne 0xc108
testq %rcx, %rcx
movq 0x8(%rsp), %r14
je 0xc150
movq 0x18(%rbx), %rcx
movq %rcx, (%rax)
andq $0x0, 0x18(%rbx)
jmp 0xc169
leaq 0x14894(%rip), %rdi     # 0x209cf
leaq 0x14849(%rip), %rsi     # 0x2098b
xorl %eax, %eax
callq 0x6b2c
movq 0x8(%rsp), %r14
jmp 0xc169
movq 0x20(%rbx), %rdx
leaq 0x14845(%rip), %rdi     # 0x209a0
leaq 0x14829(%rip), %rsi     # 0x2098b
xorl %eax, %eax
callq 0x6b2c
movq %r12, 0x38(%rbx)
movb $0x2, 0x40(%rbx)
movq %r15, 0x30(%rbx)
leal (%r14,%r14), %eax
movl %eax, 0x44(%rbx)
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xc601
movq 0x10(%rsp), %r14
movq %r14, %rdi
movq %rbx, %rsi
callq 0xa32a
movslq 0x4(%rsp), %rdx
movq %r14, %rdi
movq %r13, %rsi
callq 0x66c9
movslq %eax, %rbp
addq %r13, %rbp
movq %r15, %r13
leaq 0x1a8(%r14), %r15
movq 0x8(%rsp), %rcx
movswl 0x20(%rsp), %eax
andl $0xfff8, %eax           # imm = 0xFFF8
movzwl %ax, %eax
movl %eax, 0x4(%rsp)
addq %rcx, %r13
movq (%r15), %r15
cmpq $0x0, (%r15)
je 0xc24b
movq 0x18(%r15), %rdi
movq 0x20(%rbx), %rsi
callq 0x5160
testl %eax, %eax
jne 0xc1d0
movq 0x30(%r15), %rdx
movq 0x10(%rsp), %rdi
movq %rbp, %rsi
callq 0x66c9
movl %eax, %r14d
movq 0x28(%r15), %rdx
testq %rdx, %rdx
je 0xc236
movq %r12, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r13, %r9
pushq 0x30(%r15)
pushq $0x1
callq 0xabec
addq $0x10, %rsp
movq %r12, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl 0x4(%rsp), %ecx
pushq $-0x1
popq %r8
callq 0xac9f
movslq %r14d, %rax
movq 0x8(%rsp), %rcx
addq %rcx, 0x48(%r12)
addq %rax, %rbp
addl %ecx, 0x44(%rbx)
jmp 0xc1cd
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq