// File: /workspace/github_c_makefile_star2_O1/deplinenoise[P]vlink/targets.c
// Function: addglobsym
bool addglobsym(struct GlobalVars *gv,struct Symbol *newsym)
/* insert symbol into global symbol hash table */
{
  struct Symbol **chain = &gv->symbols[elf_hash(newsym->name)%SYMHTABSIZE];
  struct Symbol *sym;
  struct ObjectUnit *newou = newsym->relsect ? newsym->relsect->obj : NULL;

  while (sym = *chain) {
    if (!strcmp(newsym->name,sym->name)) {

      if (newsym->type==SYM_ABS && sym->type==SYM_ABS &&
          newsym->value == sym->value)
        return FALSE;  /* absolute symbols with same value are ignored */

      if (newsym->relsect == NULL || sym->relsect == NULL) {
        /* redefined linker script symbol */
        if (newou!=NULL && newou->lnkfile->type<ID_LIBBASE) {
          static const char *objname = "ldscript";

          error(19,newou ? newou->lnkfile->pathname : objname,
                newsym->name, newou ? getobjname(newou) : objname,
                sym->relsect ? getobjname(sym->relsect->obj) : objname);
        }
        /* redefinitions in libraries are silently ignored */
        return FALSE;
      }

      if (sym->bind == SYMB_GLOBAL) {
        /* symbol already defined with global binding */

        if (newsym->bind == SYMB_GLOBAL) {
          if (newou->lnkfile->type < ID_LIBBASE) {
            if (newsym->type==SYM_COMMON && sym->type==SYM_COMMON) {
              if ((newsym->size>sym->size && newsym->value>=sym->value) ||
                  (newsym->size>=sym->size && newsym->value>sym->value)) {
                /* replace by common symbol with bigger size or alignment */
                newsym->glob_chain = sym->glob_chain;
                remove_obj_symbol(sym);  /* delete old symbol in object unit */
                break;
              }
            }
            else {
              /* Global symbol "x" is already defined in... */
              error(19,newou->lnkfile->pathname,newsym->name,
                    getobjname(newou),getobjname(sym->relsect->obj));
            }
            return FALSE;  /* ignore this symbol */
          }
          /* else: add global library symbol with same name to the chain -
             some targets may want to choose between them! */
        }
        else
          return FALSE;  /* don't replace global by nonglobal symbols */
      }

      else {
        if (newsym->bind == SYMB_WEAK)
          return FALSE;  /* don't replace weak by weak */

        /* replace weak symbol by a global one */
        newsym->glob_chain = sym->glob_chain;
        remove_obj_symbol(sym);  /* delete old symbol in object unit */
        break;
      }
    }

    chain = &sym->glob_chain;
  }

  *chain = newsym;
  if (newou) {
    if (trace_sym_access(gv,newsym->name))
      fprintf(stderr,"Symbol %s defined in section %s in %s\n",
              newsym->name,newsym->relsect->name,getobjname(newou));
  }
  return TRUE;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movq %rdi, 0x10(%rsp)
movq 0x180(%rdi), %r14
movq 0x20(%rsi), %rdi
callq 0x6e09
movzwl %ax, %eax
leaq (%r14,%rax,8), %r13
movq 0x38(%rbx), %r14
testq %r14, %r14
je 0xa975
movq 0x10(%r14), %rax
movq %rax, 0x8(%rsp)
jmp 0xa97e
movq $0x0, 0x8(%rsp)
movq (%r13), %r15
testq %r15, %r15
je 0xaa0c
movq 0x20(%rbx), %r12
xorl %ebp, %ebp
movq 0x20(%r15), %rsi
movq %r12, %rdi
callq 0x5160
testl %eax, %eax
jne 0xa9f9
movb 0x40(%rbx), %al
cmpb $0x1, %al
jne 0xa9bd
cmpb $0x1, 0x40(%r15)
jne 0xa9bd
movq 0x30(%rbx), %rcx
cmpq 0x30(%r15), %rcx
je 0xaaa2
testq %r14, %r14
je 0xaa54
cmpq $0x0, 0x38(%r15)
je 0xaa54
cmpb $0x2, 0x43(%r15)
jne 0xaa9c
cmpb $0x2, 0x43(%rbx)
jne 0xab45
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpb $0x3, 0x39(%rcx)
jbe 0xaaa9
movq %r15, %r13
movq 0x10(%r15), %rax
addq $0x10, %r13
movq %rax, %r15
testq %rax, %rax
jne 0xa991
movq %rbx, (%r13)
movl $0x1, %ebp
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0xab45
leaq 0x20(%rbx), %r12
movq (%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x730e
testl %eax, %eax
je 0xab45
addq $0x38, %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5454
jmp 0xab45
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xab45
movq 0x10(%rdi), %rax
cmpb $0x3, 0x39(%rax)
ja 0xab45
movq 0x10(%rax), %rbx
callq 0x7174
movq %rax, %r14
movq 0x38(%r15), %rax
testq %rax, %rax
je 0xab27
movq 0x10(%rax), %rdi
callq 0x7174
movq %rax, %r8
jmp 0xab2e
cmpb $0x3, 0x43(%rbx)
jne 0xaad7
xorl %ebp, %ebp
jmp 0xab45
cmpb $0x3, %al
jne 0xaaf4
cmpb $0x3, 0x40(%r15)
jne 0xaaf4
movl 0x44(%rbx), %eax
movl 0x44(%r15), %ecx
cmpl %ecx, %eax
jbe 0xaac9
movq 0x30(%rbx), %rdx
cmpq 0x30(%r15), %rdx
jge 0xaad7
cmpl %ecx, %eax
jb 0xab45
movq 0x30(%rbx), %rax
cmpq 0x30(%r15), %rax
jle 0xab45
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xcddb
movq %r15, %rdi
callq 0x5040
jmp 0xaa0c
movq 0x10(%rcx), %rbx
movq 0x8(%rsp), %rdi
callq 0x7174
movq %rax, %r14
movq 0x38(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x7174
xorl %ebp, %ebp
movl $0x13, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
movq %rax, %r8
jmp 0xab3e
leaq 0x17bf6(%rip), %r8      # 0x22724
xorl %ebp, %ebp
movl $0x13, %edi
movq %rbx, %rsi
movq %r12, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x6f84
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq