// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/targets.c
// Function: make_constructors
void make_constructors(struct GlobalVars *gv)
/* Create an artificial object for constructor/destructor lists
   and fill them will entries from the PriPointer list. */
{
  if (!gv->dest_object && (gv->ctor_symbol || gv->dtor_symbol)) {
    int nctors=0,ndtors=0;
    bool ctors=FALSE,dtors=FALSE;
    const char *csecname=NULL,*dsecname=NULL;
    unsigned long clen,dlen;
    struct PriPointer *pp;
    uint8_t *data;
    struct ObjectUnit *ou;

    /* check if constructors or destructors are needed (referenced) */
    if (gv->ctor_symbol) {
      if (gv->ctor_symbol->flags & SYMF_REFERENCED) {
        ctors = TRUE;
        for (pp=(struct PriPointer *)gv->pripointers.first;
             pp->n.next!=NULL; pp=(struct PriPointer *)pp->n.next) {
          if (!strcmp(pp->listname,gv->ctor_symbol->name)) {
            if (csecname) {
              if (strcmp(csecname,pp->secname))
                error(125);  /* CTORS/DTORS spread over multiple sections */
            }
            else
              csecname = pp->secname;
          }
        }
        if (!csecname)
          csecname = xtors_secname(gv,ctors_name);
      }
    }
    if (gv->dtor_symbol) {
      if (gv->dtor_symbol->flags & SYMF_REFERENCED) {
        dtors = TRUE;
        for (pp=(struct PriPointer *)gv->pripointers.first;
             pp->n.next!=NULL; pp=(struct PriPointer *)pp->n.next) {
          if (!strcmp(pp->listname,gv->dtor_symbol->name)) {
            if (dsecname) {
              if (strcmp(dsecname,pp->secname))
                error(125);  /* CTORS/DTORS spread over multiple sections */
            }
            else
              dsecname = pp->secname;
          }
        }
        if (!dsecname)
          dsecname = xtors_secname(gv,dtors_name);
      }
    }
    if (!ctors && !dtors)
      return;

    /* count number of constructor and destructor pointers */
    for (pp=(struct PriPointer *)gv->pripointers.first;
         pp->n.next!=NULL; pp=(struct PriPointer *)pp->n.next) {
      if (ctors) {
        if (!strcmp(pp->listname,gv->ctor_symbol->name))
          nctors++;
      }
      if (dtors) {
        if (!strcmp(pp->listname,gv->dtor_symbol->name))
          ndtors++;
      }
    }

    /* create artificial object */
    clen = (unsigned long)(fff[gv->dest_format]->addr_bits / 8) *
            (ctors ? nctors+2 : 0);
    dlen = (unsigned long)(fff[gv->dest_format]->addr_bits / 8) *
            (dtors ? ndtors+2 : 0);
    data = alloczero(clen + dlen);
    ou = art_objunit(gv,"INITEXIT",data,clen+dlen);

    /* write constructors/destructors */
    if (ctors)
      write_constructors(gv,ou,gv->ctor_symbol,nctors,0,csecname);
    if (dtors)
      write_constructors(gv,ou,gv->dtor_symbol,ndtors,clen,dsecname);

    /* enqueue artificial object unit into linking process */
    ou->lnkfile->type = ID_OBJECT;
    add_objunit(gv,ou,FALSE);
  }
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x38, %rsp
cmpl $0x0, 0x54(%rdi)
je 0xc447
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rdi, %rbx
movq 0x210(%rdi), %rax
testq %rax, %rax
je 0xc4be
testb $0x2, 0x41(%rax)
je 0xc4cc
movq 0x1a8(%rbx), %r15
movq (%r15), %r14
testq %r14, %r14
je 0xc4e6
xorl %r12d, %r12d
movq 0x18(%r15), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
je 0xc493
movq %r14, %r15
movq (%r14), %r14
testq %r14, %r14
jne 0xc46e
jmp 0xc4da
movq 0x10(%r15), %rsi
testq %r12, %r12
je 0xc4b9
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xc486
movl $0x7d, %edi
xorl %eax, %eax
callq 0x6f14
movq (%r15), %r14
jmp 0xc486
movq %rsi, %r12
jmp 0xc486
cmpq $0x0, 0x218(%rbx)
je 0xc438
xorl %r12d, %r12d
movq $0x0, 0x8(%rsp)
jmp 0xc503
movb $0x1, %al
movq %rax, 0x8(%rsp)
testq %r12, %r12
jne 0xc503
movq 0x208(%rbx), %rdi
leaq 0x160c9(%rip), %rsi     # 0x225bd
callq 0xbb26
movq %rax, %r12
movb $0x1, %al
movq %rax, 0x8(%rsp)
movq 0x218(%rbx), %rax
testq %rax, %rax
je 0xc515
testb $0x2, 0x41(%rax)
jne 0xc52b
cmpb $0x0, 0x8(%rsp)
je 0xc438
xorl %r15d, %r15d
xorl %r13d, %r13d
jmp 0xc5ae
movq 0x1a8(%rbx), %r15
movq (%r15), %r14
testq %r14, %r14
je 0xc595
xorl %r13d, %r13d
movq 0x18(%r15), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
je 0xc562
movq %r14, %r15
movq (%r14), %r14
testq %r14, %r14
jne 0xc53d
jmp 0xc58d
movq 0x10(%r15), %rsi
testq %r13, %r13
je 0xc588
movq %r13, %rdi
callq 0x5160
testl %eax, %eax
je 0xc555
movl $0x7d, %edi
xorl %eax, %eax
callq 0x6f14
movq (%r15), %r14
jmp 0xc555
movq %rsi, %r13
jmp 0xc555
movb $0x1, %r15b
testq %r13, %r13
jne 0xc5ae
movq 0x208(%rbx), %rdi
leaq 0x16021(%rip), %rsi     # 0x225c4
callq 0xbb26
movq %rax, %r13
movb $0x1, %r15b
movq %r13, 0x20(%rsp)
movq %r12, 0x28(%rsp)
movq 0x1a8(%rbx), %r14
movq (%r14), %rax
testq %rax, %rax
je 0xc620
xorl %r13d, %r13d
xorl %r12d, %r12d
movq %rax, %rbp
cmpb $0x0, 0x8(%rsp)
je 0xc5f2
movq 0x18(%r14), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
adcl $0x0, %r13d
testb %r15b, %r15b
je 0xc612
movq 0x18(%r14), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
adcl $0x0, %r12d
movq (%rbp), %rax
movq %rbp, %r14
testq %rax, %rax
jne 0xc5cd
jmp 0xc626
xorl %r12d, %r12d
xorl %r13d, %r13d
movzbl 0x50(%rbx), %eax
leaq 0x22b4f(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movb 0xab(%rax), %al
movl %eax, %ecx
sarb $0x7, %cl
shrb $0x5, %cl
addb %al, %cl
sarb $0x3, %cl
leal 0x2(%r13), %eax
movslq %eax, %rdx
xorl %eax, %eax
movq 0x8(%rsp), %rbp
testb %bpl, %bpl
cmoveq %rax, %rdx
movsbq %cl, %rsi
leal 0x2(%r12), %ecx
movslq %ecx, %r14
testb %r15b, %r15b
cmoveq %rax, %r14
movq %rdx, 0x18(%rsp)
addq %rdx, %r14
movq %rsi, 0x10(%rsp)
imulq %rsi, %r14
movq %r14, %rdi
callq 0x6686
movq %rax, 0x30(%rsp)
movl $0x40, %edi
callq 0x6686
leaq 0x1623e(%rip), %rdx     # 0x228dd
movq %rdx, 0x20(%rax)
movq %rdx, 0x18(%rax)
movq %rdx, 0x10(%rax)
movq 0x30(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq %r14, 0x30(%rax)
movb 0x50(%rbx), %cl
movb %cl, 0x38(%rax)
movb $0x3, 0x39(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbeac
movq %rax, %r14
testb %bpl, %bpl
je 0xc6f2
movq 0x210(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %r13d, %ecx
xorl %r8d, %r8d
movq 0x28(%rsp), %r9
callq 0xc73f
testb %r15b, %r15b
je 0xc71c
movq 0x18(%rsp), %r8
imulq 0x10(%rsp), %r8
movq 0x218(%rbx), %rdx
movq %rbx, %rdi
movq %r14, %rsi
movl %r12d, %ecx
movq 0x20(%rsp), %r9
callq 0xc73f
movq 0x10(%r14), %rax
movb $0x1, 0x39(%rax)
movq %rbx, %rdi
movq %r14, %rsi
xorl %edx, %edx
addq $0x38, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xbf8e