// File: /workspace/github_c_makefile_star2_O2/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 %rdx, 0x10(%rsp)
movq %rsi, %r14
movq %rdi, %r12
movq 0x1c0(%rdi), %rbx
movq %rbx, %rbp
movq (%rbx), %rbx
testq %rbx, %rbx
je 0x8ac2
cmpq 0x10(%rsp), %rbp
je 0x890c
movzbl 0x2d(%r14), %edx
movq %r12, %rdi
movq %rbp, %rsi
callq 0x86c2
cmpb $-0x1, %al
je 0x890c
movl %eax, %r15d
cmpl $0x0, 0x54(%r12)
je 0x89f2
xorl %ecx, %ecx
cmpq $0x0, 0x10(%rsp)
jne 0x890c
movq 0x20(%r14), %r13
movq 0x18(%rbp), %rsi
movq %r13, %rdi
movb %r15b, 0xf(%rsp)
movq %r12, %r15
movq %r14, %r12
movl %ecx, %r14d
callq 0x5160
movl %r14d, %ecx
movq %r12, %r14
movq %r15, %r12
movb 0xf(%rsp), %r15b
testl %eax, %eax
je 0x8986
cmpb $0x0, (%r13)
jne 0x89a5
movb 0x20(%rbp), %al
cmpb 0x2c(%r14), %al
je 0x8b2f
cmpb $0x0, (%r13)
jne 0x89a5
cmpq $0x0, 0x48(%r14)
je 0x8b42
testb %cl, %cl
je 0x890c
movq 0x220(%r12), %rsi
movq %r13, %rdi
callq 0x5160
testl %eax, %eax
je 0x89d9
movq 0x228(%r12), %rsi
movq %r13, %rdi
callq 0x5160
testl %eax, %eax
jne 0x890c
cmpb $0x3, 0x20(%rbp)
jne 0x890c
testb $0x2, 0x21(%rbp)
je 0x890c
jmp 0x8b2f
movzbl 0x50(%r12), %eax
leaq 0x26791(%rip), %rcx     # 0x2f190
movq (%rcx,%rax,8), %rax
movq %r12, %rdi
movq %rbp, %rsi
movq %r14, %rdx
callq *0x38(%rax)
testl %eax, %eax
jg 0x8b2f
jne 0x890c
cmpl $0x0, 0x54(%r12)
jne 0x8945
cmpl $0x0, 0x70(%r12)
je 0x8a42
cmpb $0x1, 0x20(%rbp)
jne 0x8a42
cmpb $0x1, 0x2c(%r14)
je 0x8b2f
cmpl $0x0, 0x74(%r12)
je 0x8a61
movb 0x20(%rbp), %al
andb $-0x2, %al
cmpb $0x2, %al
jne 0x8a61
movb 0x2c(%r14), %al
andb $-0x2, %al
cmpb $0x2, %al
je 0x8b2f
movb %r15b, 0xf(%rsp)
movq 0x60(%rbp), %r13
movq (%r13), %r15
testq %r15, %r15
je 0x8a9e
movq 0x80(%r13), %rdi
movq %r14, %rsi
callq 0xa139
testl %eax, %eax
jne 0x8ac6
movq 0x80(%r14), %rdi
movq %r13, %rsi
callq 0xa139
movq %r15, %r13
testl %eax, %eax
je 0x8a6a
jmp 0x8ac6
movb $0x1, %cl
cmpl $0x0, 0x78(%r12)
movb 0xf(%rsp), %r15b
jne 0x8947
movb 0x21(%rbp), %al
andb 0x2d(%r14), %al
testb $0x4, %al
je 0x8947
jmp 0x8b2f
xorl %ebp, %ebp
jmp 0x8b42
movb 0x20(%rbp), %al
cmpb $0x1, %al
setne %dl
movb 0x2c(%r14), %cl
cmpb $0x1, %cl
setne %sil
andb %dl, %sil
cmpb %cl, %al
sete %dl
orb %sil, %dl
movb 0xf(%rsp), %r15b
jne 0x8b2f
movzbl %al, %eax
movzbl %cl, %ecx
leaq 0x261e8(%rip), %rdx     # 0x2ece0
movq (%rdx,%rax,8), %rbx
movq 0x18(%rbp), %r12
movq (%rdx,%rcx,8), %r13
movq 0x10(%r14), %rdi
movq 0x20(%r14), %r15
callq 0x6e1c
pushq $0x3a
popq %rdi
movq %rbx, %rsi
movq %r12, %rdx
movq %r13, %rcx
movq %r15, %r8
movb 0xf(%rsp), %r15b
movq %rax, %r9
xorl %eax, %eax
callq 0x6c19
andb $-0x20, %r15b
movzbl %r15b, %edx
movq %rbp, %rdi
movq %r14, %rsi
callq 0x8701
movq %rbp, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq