// File: /workspace/github_c_makefile_star2_O3/deplinenoise[P]vlink/linker.c
// Function: get_matching_lnksec
static struct LinkedSection *get_matching_lnksec(struct GlobalVars *gv,
                                                 struct Section *sec,
                                                 struct LinkedSection *myls)
/* find a LinkedSection node which fits the specified section,
   but which is different from 'myls' */
{
  struct LinkedSection *lsn = (struct LinkedSection *)gv->lnksec.first;
  struct LinkedSection *nextlsn;
  uint8_t f;
  int tl;

  while (nextlsn = (struct LinkedSection *)lsn->n.next) {
    if (lsn != myls && ((f = cmpsecflags(gv,lsn,sec->flags)) != 0xff)) {
      f &= ~SF_PORTABLE_MASK;

      if (!gv->dest_object) {
        /* target-specific linking */
        if ((tl = fff[gv->dest_format]->targetlink(gv,lsn,sec)) > 0) {
          /* target demands merge of sections */
          Dprintf("targetlink: %s(%s) -> %s\n",getobjname(sec->obj),
                  sec->name,lsn->name);
          merge_sec_attrs(lsn,sec,f);
          return (lsn);
        }
      }
      else
        tl = 0;

      if (tl == 0) {  /* target wants to use the default rules */

        if (!gv->dest_object) {
          /* for final executable only: */

          if (gv->small_code) {
            if (lsn->type==ST_CODE && sec->type==ST_CODE) {
              /* merge all code sections */
              Dprintf("smallcode: %s(%s) -> %s\n",getobjname(sec->obj),
                      sec->name,lsn->name);
              merge_sec_attrs(lsn,sec,f);
              return (lsn);
            }
          }

          if (gv->small_data) {
            if ((lsn->type==ST_DATA || lsn->type==ST_UDATA) &&
                (sec->type==ST_DATA || sec->type==ST_UDATA)) {
              /* merge all data and bss sections */
              Dprintf("smalldata: %s(%s) -> %s\n",getobjname(sec->obj),
                      sec->name,lsn->name);
              merge_sec_attrs(lsn,sec,f);
              return (lsn);
            }
          }

          if (checkrelrefs(lsn,sec)) {
            /* we must link them together, because there are rel. refs */
            if ((lsn->type==ST_CODE || sec->type==ST_CODE) &&
                lsn->type != sec->type)
              /* forces a maybe unwanted combination of code and data */
              error(58,sec_names[lsn->type],lsn->name,sec_names[sec->type],
                    sec->name,getobjname(sec->obj));
            Dprintf("relrefs: %s(%s) -> %s\n",getobjname(sec->obj),
                    sec->name,lsn->name);
            merge_sec_attrs(lsn,sec,f);
            return (lsn);
          }

          if (!gv->multibase && (lsn->flags & sec->flags & SF_SMALLDATA)) {
            Dprintf("sd-refs: %s(%s) -> %s\n",getobjname(sec->obj),
                    sec->name,lsn->name);
            merge_sec_attrs(lsn,sec,f);
            return (lsn);
          }
        }  /* final executable only */

        /* standard check, if sections could be merged */
        if (myls == NULL) {
          if (!strcmp(sec->name,lsn->name) || /* same name or no name */
              *(sec->name)==0) {
            if (lsn->type==sec->type) {   /* same type */
              Dprintf("name: %s(%s) -> %s\n",getobjname(sec->obj),
                      sec->name,lsn->name);
              merge_sec_attrs(lsn,sec,f);
              return (lsn);
            }
            else if (*(sec->name)==0 && sec->size==0) {
              /* no name and no contents - may contain abs symbols only */
              return (lsn);
            }
          }

          if (!gv->dest_object) {
            /* COMMON sections are merged with any BSS-type section */
            if (!strcmp(sec->name,gv->common_sec_name) ||
                !strcmp(sec->name,gv->scommon_sec_name)) {
              if (lsn->type==ST_UDATA && (lsn->flags & SF_UNINITIALIZED)) {
                Dprintf("common: %s(%s) -> %s\n",getobjname(sec->obj),
                        sec->name,lsn->name);
                merge_sec_attrs(lsn,sec,f);
                return (lsn);
              }
            }
          }
        }

      } /* default rules */
    }
    lsn = nextlsn;
  }
  return (NULL);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq 0x1c0(%rdi), %rbx
movq (%rbx), %rax
testq %rax, %rax
je 0x8f6c
movq %rdx, %r15
movq %rsi, %r8
movq %rdi, %r12
movq %rsi, 0x8(%rsp)
movq %rdx, 0x10(%rsp)
movq %rbx, %r14
movq %rax, %rbx
cmpq %r15, %r14
je 0x8eb0
movb 0x2d(%r8), %bpl
movb 0x21(%r14), %al
testb $0x1, 0x24(%r14)
jne 0x8d96
movl %eax, %ecx
xorb %bpl, %cl
testb $0x1, %cl
je 0x8d9a
jmp 0x8eb0
andb $-0x2, %bpl
movzbl 0x50(%r12), %ecx
leaq 0x263d9(%rip), %rdx     # 0x2f180
movq (%rdx,%rcx,8), %rcx
movq 0x30(%rcx), %rcx
testq %rcx, %rcx
je 0x8dc6
movzbl %al, %edi
movzbl %bpl, %esi
callq *%rcx
movq 0x8(%rsp), %r8
movl %eax, %ebp
jmp 0x8dc9
orb %al, %bpl
cmpb $-0x1, %bpl
je 0x8eb0
cmpl $0x0, 0x54(%r12)
je 0x8e84
xorl %ecx, %ecx
testq %r15, %r15
jne 0x8eb0
movq 0x20(%r8), %r13
movq 0x18(%r14), %rsi
movq %r13, %rdi
movq %r12, %r15
movl %ecx, %r12d
callq 0x5160
movl %r12d, %ecx
movq %r15, %r12
movq 0x10(%rsp), %r15
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x8e1b
cmpb $0x0, (%r13)
jne 0x8e3b
movb 0x20(%r14), %al
cmpb 0x2c(%r8), %al
je 0x8fd8
cmpb $0x0, (%r13)
jne 0x8e3b
cmpq $0x0, 0x48(%r8)
je 0x8feb
testb %cl, %cl
je 0x8eb0
movq 0x220(%r12), %rsi
movq %r13, %rdi
callq 0x5160
movq 0x8(%rsp), %r8
testl %eax, %eax
je 0x8e71
movq 0x228(%r12), %rsi
movq %r13, %rdi
callq 0x5160
movq 0x8(%rsp), %r8
testl %eax, %eax
jne 0x8eb0
cmpb $0x3, 0x20(%r14)
jne 0x8eb0
testb $0x2, 0x21(%r14)
je 0x8eb0
jmp 0x8fd8
movzbl 0x50(%r12), %eax
leaq 0x262ef(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movq %r12, %rdi
movq %r14, %rsi
movq %r8, %rdx
callq *0x38(%rax)
movq 0x8(%rsp), %r8
testl %eax, %eax
jg 0x8fd8
je 0x8ec1
movq (%rbx), %rax
testq %rax, %rax
jne 0x8d69
jmp 0x8f6c
cmpl $0x0, 0x54(%r12)
jne 0x8ddf
cmpl $0x0, 0x70(%r12)
je 0x8ee7
cmpb $0x1, 0x20(%r14)
jne 0x8ee7
cmpb $0x1, 0x2c(%r8)
je 0x8fd8
cmpl $0x0, 0x74(%r12)
je 0x8f07
movb 0x20(%r14), %al
andb $-0x2, %al
cmpb $0x2, %al
jne 0x8f07
movb 0x2c(%r8), %al
andb $-0x2, %al
cmpb $0x2, %al
je 0x8fd8
movq 0x60(%r14), %rax
movq (%rax), %rdx
testq %rdx, %rdx
je 0x8f4c
movq %rdx, %rcx
movq 0x80(%rax), %rdx
testq %rdx, %rdx
je 0x8f2d
cmpq %r8, 0x8(%rdx)
je 0x8f71
movq (%rdx), %rdx
jmp 0x8f1d
movq 0x80(%r8), %rdx
testq %rdx, %rdx
je 0x8f44
cmpq %rax, 0x8(%rdx)
je 0x8f71
movq (%rdx), %rdx
jmp 0x8f34
movq (%rcx), %rdx
movq %rcx, %rax
jmp 0x8f0e
movb $0x1, %cl
cmpl $0x0, 0x78(%r12)
jne 0x8de1
movb 0x21(%r14), %al
andb 0x2d(%r8), %al
testb $0x4, %al
je 0x8de1
jmp 0x8fd8
xorl %r14d, %r14d
jmp 0x8feb
movb 0x20(%r14), %al
cmpb $0x1, %al
setne %dl
movb 0x2c(%r8), %cl
cmpb $0x1, %cl
setne %sil
andb %dl, %sil
cmpb %cl, %al
sete %dl
orb %sil, %dl
jne 0x8fd8
movzbl %al, %eax
movzbl %cl, %ecx
leaq 0x25d41(%rip), %rdx     # 0x2ece0
movq (%rdx,%rax,8), %rbx
movq 0x18(%r14), %r12
movq (%rdx,%rcx,8), %r13
movq 0x10(%r8), %rdi
movq 0x20(%r8), %r15
callq 0x7104
movl $0x3a, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x6f14
movq 0x8(%rsp), %r8
andb $-0x20, %bpl
movzbl %bpl, %edx
movq %r14, %rdi
movq %r8, %rsi
callq 0x8adc
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq