// File: /workspace/github_c_makefile_star2_O1/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), %r14
movq (%r14), %rax
testq %rax, %rax
je 0x8f69
movq %rdx, %r15
movq %rsi, %rbx
movq %rdi, %r12
movq %r14, %r13
movq %rax, %r14
cmpq %r15, %r13
je 0x8e77
movzbl 0x2d(%rbx), %edx
movq %r12, %rdi
movq %r13, %rsi
callq 0x8b09
cmpb $-0x1, %al
je 0x8e77
movl %eax, %ebp
xorl %eax, %eax
cmpl $0x0, 0x54(%r12)
jne 0x8e18
movzbl 0x50(%r12), %eax
leaq 0x26380(%rip), %rcx     # 0x2f180
movq (%rcx,%rax,8), %rax
movq %r12, %rdi
movq %r13, %rsi
movq %rbx, %rdx
callq *0x38(%rax)
testl %eax, %eax
jg 0x8fc9
testl %eax, %eax
jne 0x8e77
movl 0x54(%r12), %edx
testl %edx, %edx
je 0x8e88
testq %r15, %r15
jne 0x8e77
movq 0x20(%rbx), %rdi
movq %rdi, 0x8(%rsp)
movq 0x18(%r13), %rsi
movl %edx, 0x14(%rsp)
callq 0x5160
movq 0x8(%rsp), %rdx
movl 0x14(%rsp), %ecx
testl %eax, %eax
je 0x8e52
cmpb $0x0, (%rdx)
jne 0x8e6f
movb 0x20(%r13), %al
cmpb 0x2c(%rbx), %al
je 0x8fc9
cmpb $0x0, (%rdx)
jne 0x8e6f
cmpq $0x0, 0x48(%rbx)
je 0x8fdc
testl %ecx, %ecx
je 0x8f21
movq (%r14), %rax
testq %rax, %rax
jne 0x8dc1
jmp 0x8f69
cmpl $0x0, 0x70(%r12)
je 0x8ea1
cmpb $0x1, 0x20(%r13)
jne 0x8ea1
cmpb $0x1, 0x2c(%rbx)
je 0x8fc9
cmpl $0x0, 0x74(%r12)
je 0x8ec0
movb 0x20(%r13), %al
andb $-0x2, %al
cmpb $0x2, %al
jne 0x8ec0
movb 0x2c(%rbx), %al
andb $-0x2, %al
cmpb $0x2, %al
je 0x8fc9
movq 0x60(%r13), %rax
cmpq $0x0, (%rax)
je 0x8f01
movq 0x80(%rax), %rcx
testq %rcx, %rcx
je 0x8ee5
cmpq %rbx, 0x8(%rcx)
je 0x8f6e
movq (%rcx), %rcx
jmp 0x8ed1
movq 0x80(%rbx), %rcx
testq %rcx, %rcx
je 0x8efc
cmpq %rax, 0x8(%rcx)
je 0x8f6e
movq (%rcx), %rcx
jmp 0x8eec
movq (%rax), %rax
jmp 0x8ec4
cmpl $0x0, 0x78(%r12)
jne 0x8e25
movb 0x21(%r13), %al
andb 0x2d(%rbx), %al
testb $0x4, %al
je 0x8e25
jmp 0x8fc9
movq 0x220(%r12), %rsi
movq 0x8(%rsp), %rdi
callq 0x5160
movq 0x8(%rsp), %rdi
testl %eax, %eax
je 0x8f51
movq 0x228(%r12), %rsi
callq 0x5160
testl %eax, %eax
jne 0x8e77
cmpb $0x3, 0x20(%r13)
jne 0x8e77
testb $0x2, 0x21(%r13)
je 0x8e77
jmp 0x8fc9
xorl %r13d, %r13d
jmp 0x8fdc
movzbl 0x20(%r13), %eax
cmpq $0x1, %rax
je 0x8f7f
cmpb $0x1, 0x2c(%rbx)
jne 0x8fc9
movzbl 0x2c(%rbx), %ecx
cmpb %cl, %al
je 0x8fc9
leaq 0x25d52(%rip), %rdx     # 0x2ece0
movq (%rdx,%rax,8), %rax
movq %rax, 0x8(%rsp)
movq 0x18(%r13), %r12
movq (%rdx,%rcx,8), %r14
movq 0x10(%rbx), %rdi
movq 0x20(%rbx), %r15
callq 0x7174
movl $0x3a, %edi
movq 0x8(%rsp), %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %r15, %r8
movq %rax, %r9
xorl %eax, %eax
callq 0x6f84
andb $-0x20, %bpl
movzbl %bpl, %edx
movq %r13, %rdi
movq %rbx, %rsi
callq 0x8b48
movq %r13, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq