// File: /workspace/github_c_makefile_star2_O1/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 $0x38, %rsp
movq %r9, %rbp
movl %ecx, 0x14(%rsp)
movq %rdx, %rbx
movq 0x10(%rsi), %rax
movq 0x20(%rsi), %r13
movq 0x28(%rax), %rax
movq %r8, %r12
addq %r8, %rax
movq %rax, (%rsp)
movq %rdi, %r14
movzbl 0x50(%rdi), %eax
leaq 0x22985(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movsbq 0xab(%rax), %rax
movq %rax, 0x20(%rsp)
shrq $0x3, %rax
movq %rax, 0x8(%rsp)
movq %rsi, 0x18(%rsp)
leaq 0x20(%rsi), %rax
movq %rax, 0x28(%rsp)
movq %r13, %r15
movq (%r13), %r13
testq %r13, %r13
je 0xc852
movq 0x20(%r15), %rsi
movq %rbp, %rdi
callq 0x5160
testl %eax, %eax
jne 0xc823
testq %r13, %r13
je 0xc852
movq 0x8(%rsp), %rax
addq %rax, %rax
addq %rax, 0x48(%r15)
jmp 0xc8a3
movq 0x8(%rsp), %rax
leaq (%rax,%rax), %rcx
movq 0x18(%rsp), %r12
movq %r12, %rdi
movq %rbp, %rsi
movq (%rsp), %rdx
callq 0xc156
movq %rax, %r15
movw $0x102, 0x2c(%rax)      # imm = 0x102
movb $0x3, 0x2e(%rax)
movzbl 0x82(%r12), %eax
cmpb $0x3, %al
movl $0x2, %ecx
cmovael %eax, %ecx
movb %cl, 0x2f(%r15)
movq 0x28(%rsp), %rdi
movq %r15, %rsi
callq 0x6759
xorl %r12d, %r12d
movq 0x188(%r14), %r13
testq %r13, %r13
je 0xc8f3
movq 0x20(%rbx), %rdi
callq 0x6e09
andl $0xf, %eax
leaq (,%rax,8), %rdx
addq %r13, %rdx
movq %rdx, %rax
movq (%rdx), %rcx
testq %rcx, %rcx
je 0xc8da
leaq 0x18(%rcx), %rdx
cmpq %rbx, %rcx
jne 0xc8c6
testq %rcx, %rcx
movq %r14, %r13
je 0xc90d
movq 0x18(%rbx), %rcx
movq %rcx, (%rax)
movq $0x0, 0x18(%rbx)
jmp 0xc926
leaq 0x160d5(%rip), %rdi     # 0x229cf
leaq 0x1608a(%rip), %rsi     # 0x2298b
xorl %eax, %eax
callq 0x52b0
movq %r14, %r13
jmp 0xc926
movq 0x20(%rbx), %rdx
leaq 0x16088(%rip), %rdi     # 0x229a0
leaq 0x1606c(%rip), %rsi     # 0x2298b
xorl %eax, %eax
callq 0x52b0
movq (%rsp), %r14
movq %r15, 0x38(%rbx)
movb $0x2, 0x40(%rbx)
movq %r12, 0x30(%rbx)
movq 0x8(%rsp), %rax
addl %eax, %eax
movl %eax, 0x44(%rbx)
movq 0x18(%rsp), %rdi
movq %rbx, %rsi
callq 0xce69
movq %r13, %rdi
movq %rbx, %rsi
callq 0xa934
movslq 0x14(%rsp), %rdx
movq %r13, %rdi
movq %r14, %rsi
callq 0x6ac0
movq 0x1a8(%r13), %rbp
cmpq $0x0, (%rbp)
je 0xca24
addq 0x8(%rsp), %r12
cltq
addq %rax, %r14
movswl 0x20(%rsp), %eax
andl $0xfff8, %eax           # imm = 0xFFF8
movzwl %ax, %eax
movl %eax, (%rsp)
movq %r13, 0x30(%rsp)
movq 0x18(%rbp), %rdi
movq 0x20(%rbx), %rsi
callq 0x5160
testl %eax, %eax
jne 0xca15
movq 0x30(%rbp), %rdx
movq %r13, %rdi
movq %r14, %r13
movq %r14, %rsi
callq 0x6ac0
movl %eax, %r14d
movq 0x28(%rbp), %rdx
testq %rdx, %rdx
je 0xc9f8
movq %r15, %rsi
xorl %ecx, %ecx
xorl %r8d, %r8d
movq %r12, %r9
pushq 0x30(%rbp)
pushq $0x1
callq 0xb202
addq $0x10, %rsp
movq %r15, %rdi
movq %rax, %rsi
xorl %edx, %edx
movl (%rsp), %ecx
movq $-0x1, %r8
callq 0xb2b7
movslq %r14d, %rax
movq %r13, %r14
addq %rax, %r14
movq 0x8(%rsp), %rax
addq %rax, 0x48(%r15)
addl %eax, 0x44(%rbx)
addq %rax, %r12
movq 0x30(%rsp), %r13
movq (%rbp), %rbp
cmpq $0x0, (%rbp)
jne 0xc999
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq