// File: /workspace/github_c_makefile_star2_O2/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 $0x28, %rsp
cmpl $0x0, 0x54(%rdi)
je 0xbda6
addq $0x28, %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 0xbe0e
testb $0x2, 0x41(%rax)
je 0xbe1c
leaq 0x1a8(%rbx), %r14
pushq $0x7d
popq %rbp
xorl %r15d, %r15d
movq (%r14), %r14
cmpq $0x0, (%r14)
je 0xbe24
movq 0x18(%r14), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
jne 0xbdc8
movq 0x10(%r14), %rsi
testq %r15, %r15
je 0xbe09
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xbdc8
movl %ebp, %edi
xorl %eax, %eax
callq 0x6c19
jmp 0xbdc8
movq %rsi, %r15
jmp 0xbdc8
cmpq $0x0, 0x218(%rbx)
je 0xbd97
xorl %r15d, %r15d
xorl %r14d, %r14d
jmp 0xbe3e
movb $0x1, %r14b
testq %r15, %r15
jne 0xbe3e
leaq 0x1479a(%rip), %rsi     # 0x205cd
movq %rbx, %rdi
callq 0xb557
movq %rax, %r15
movq 0x218(%rbx), %rax
testq %rax, %rax
je 0xbe50
testb $0x2, 0x41(%rax)
jne 0xbe6c
testb %r14b, %r14b
je 0xbd97
movq %r15, 0x18(%rsp)
xorl %r15d, %r15d
movq $0x0, 0x10(%rsp)
jmp 0xbee7
movq %r15, 0x18(%rsp)
leaq 0x1a8(%rbx), %r15
pushq $0x7d
popq %rbp
xorl %r12d, %r12d
movq (%r15), %r15
cmpq $0x0, (%r15)
je 0xbec4
movq 0x18(%r15), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
jne 0xbe7e
movq 0x10(%r15), %rsi
testq %r12, %r12
je 0xbebf
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xbe7e
movl %ebp, %edi
xorl %eax, %eax
callq 0x6c19
jmp 0xbe7e
movq %rsi, %r12
jmp 0xbe7e
movb $0x1, %r15b
testq %r12, %r12
je 0xbed3
movq %r12, 0x10(%rsp)
jmp 0xbee7
leaq 0x146fa(%rip), %rsi     # 0x205d4
movq %rbx, %rdi
callq 0xb557
movq %rax, 0x10(%rsp)
movq 0x1a8(%rbx), %r12
movq $0x0, 0x8(%rsp)
xorl %r13d, %r13d
movq %r12, %rbp
movq (%r12), %r12
testq %r12, %r12
je 0xbf51
testb %r14b, %r14b
je 0xbf26
movq 0x18(%rbp), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
adcl $0x0, %r13d
testb %r15b, %r15b
je 0xbefa
movq 0x18(%rbp), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
movq 0x8(%rsp), %rax
adcl $0x0, %eax
movq %rax, 0x8(%rsp)
jmp 0xbefa
movzbl 0x50(%rbx), %eax
leaq 0x23234(%rip), %rcx     # 0x2f190
movq (%rcx,%rax,8), %rax
movsbl 0xab(%rax), %eax
movb $0x8, %cl
idivb %cl
movsbq %al, %rdx
leal 0x2(%r13), %eax
movslq %eax, %rbp
xorl %eax, %eax
testb %r14b, %r14b
cmoveq %rax, %rbp
movq 0x8(%rsp), %rcx
leal 0x2(%rcx), %r12d
testb %r15b, %r15b
cmoveq %rax, %r12
addq %rbp, %r12
movq %rdx, 0x20(%rsp)
imulq %rdx, %r12
movq %r12, %rdi
callq 0x638a
leaq 0x14943(%rip), %rsi     # 0x208ed
movq %rbx, %rdi
movq %rax, %rdx
movq %r12, %rcx
callq 0xb906
movq %rax, %r12
testb %r14b, %r14b
je 0xbfdd
movq 0x210(%rbx), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movl %r13d, %ecx
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
callq 0xc02b
testb %r15b, %r15b
je 0xc007
imulq 0x20(%rsp), %rbp
movq 0x218(%rbx), %rdx
movq %rbx, %rdi
movq %r12, %rsi
movq 0x8(%rsp), %rcx
movq %rbp, %r8
movq 0x10(%rsp), %r9
callq 0xc02b
movq 0x10(%r12), %rax
movb $0x1, 0x39(%rax)
movq %rbx, %rdi
movq %r12, %rsi
xorl %edx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xb95b