// File: /workspace/github_c_makefile_star2_O1/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)
jne 0xc698
movq %rdi, %rbx
movq 0x210(%rdi), %rax
testq %rax, %rax
je 0xc563
testb $0x2, 0x41(%rax)
jne 0xc508
xorl %r15d, %r15d
xorl %ebp, %ebp
jmp 0xc595
movq 0x1a8(%rbx), %r14
cmpq $0x0, (%r14)
je 0xc578
xorl %r15d, %r15d
movq 0x18(%r14), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
je 0xc53b
movq (%r14), %r14
cmpq $0x0, (%r14)
jne 0xc518
jmp 0xc57b
movq 0x10(%r14), %rsi
testq %r15, %r15
je 0xc55e
movq %r15, %rdi
callq 0x5160
testl %eax, %eax
je 0xc530
movl $0x7d, %edi
xorl %eax, %eax
callq 0x6f84
jmp 0xc530
movq %rsi, %r15
jmp 0xc530
cmpq $0x0, 0x218(%rbx)
je 0xc698
testq %rax, %rax
jne 0xc4f8
jmp 0xc4fe
xorl %r15d, %r15d
movb $0x1, %bpl
testq %r15, %r15
jne 0xc595
leaq 0x16043(%rip), %rsi     # 0x225cd
movq %rbx, %rdi
callq 0xbbe9
movq %rax, %r15
movq 0x218(%rbx), %rax
testq %rax, %rax
je 0xc5a7
testb $0x2, 0x41(%rax)
jne 0xc5af
xorl %r12d, %r12d
xorl %r14d, %r14d
jmp 0xc627
movq 0x1a8(%rbx), %r14
cmpq $0x0, (%r14)
je 0xc60a
xorl %r12d, %r12d
movq 0x18(%r14), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
testl %eax, %eax
je 0xc5e2
movq (%r14), %r14
cmpq $0x0, (%r14)
jne 0xc5bf
jmp 0xc60d
movq 0x10(%r14), %rsi
testq %r12, %r12
je 0xc605
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
je 0xc5d7
movl $0x7d, %edi
xorl %eax, %eax
callq 0x6f84
jmp 0xc5d7
movq %rsi, %r12
jmp 0xc5d7
xorl %r12d, %r12d
movb $0x1, %r14b
testq %r12, %r12
jne 0xc627
leaq 0x15fb8(%rip), %rsi     # 0x225d4
movq %rbx, %rdi
callq 0xbbe9
movq %rax, %r12
movl %ebp, %eax
orb %r14b, %al
cmpb $0x1, %al
jne 0xc698
movq %r12, 0x10(%rsp)
movq %r15, 0x18(%rsp)
movq 0x1a8(%rbx), %r15
cmpq $0x0, (%r15)
je 0xc6a7
xorl %r13d, %r13d
xorl %r12d, %r12d
testb %bpl, %bpl
je 0xc66d
movq 0x18(%r15), %rdi
movq 0x210(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
adcl $0x0, %r13d
testb %r14b, %r14b
je 0xc68d
movq 0x18(%r15), %rdi
movq 0x218(%rbx), %rax
movq 0x20(%rax), %rsi
callq 0x5160
cmpl $0x1, %eax
adcl $0x0, %r12d
movq (%r15), %r15
cmpq $0x0, (%r15)
jne 0xc64d
jmp 0xc6ad
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
xorl %r12d, %r12d
xorl %r13d, %r13d
movzbl 0x50(%rbx), %eax
leaq 0x22ac8(%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
testb %bpl, %bpl
cmoveq %rax, %rdx
movsbq %cl, %rsi
leal 0x2(%r12), %ecx
movslq %ecx, %r15
testb %r14b, %r14b
cmoveq %rax, %r15
movq %rdx, 0x8(%rsp)
addq %rdx, %r15
movq %rsi, (%rsp)
imulq %rsi, %r15
movq %r15, %rdi
callq 0x66b6
movq %rax, 0x20(%rsp)
movl $0x40, %edi
callq 0x66b6
leaq 0x161cd(%rip), %rdx     # 0x228ed
movq %rdx, 0x20(%rax)
movq %rdx, 0x18(%rax)
movq %rdx, 0x10(%rax)
movq 0x20(%rsp), %rcx
movq %rcx, 0x28(%rax)
movq %r15, 0x30(%rax)
movb 0x50(%rbx), %cl
movb %cl, 0x38(%rax)
movb $0x3, 0x39(%rax)
movq %rbx, %rdi
movq %rax, %rsi
callq 0xbf5e
movq %rax, %r15
testb %bpl, %bpl
je 0xc773
movq 0x210(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movl %r13d, %ecx
xorl %r8d, %r8d
movq 0x18(%rsp), %r9
callq 0xc7bf
testb %r14b, %r14b
je 0xc79c
movq 0x8(%rsp), %r8
imulq (%rsp), %r8
movq 0x218(%rbx), %rdx
movq %rbx, %rdi
movq %r15, %rsi
movl %r12d, %ecx
movq 0x10(%rsp), %r9
callq 0xc7bf
movq 0x10(%r15), %rax
movb $0x1, 0x39(%rax)
movq %rbx, %rdi
movq %r15, %rsi
xorl %edx, %edx
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
jmp 0xc040