// File: /workspace/github_c_makefile_star2_O3/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 0x6d94
movzwl %ax, %eax
leaq (%r14,%rax,8), %r12
movq 0x38(%rbx), %r14
testq %r14, %r14
je 0xa86c
movq 0x10(%r14), %rax
movq %rax, 0x8(%rsp)
jmp 0xa875
movq $0x0, 0x8(%rsp)
movq (%r12), %r15
testq %r15, %r15
je 0xa905
movq 0x20(%rbx), %r13
xorl %ebp, %ebp
movq 0x20(%r15), %rsi
movq %r13, %rdi
callq 0x5160
testl %eax, %eax
jne 0xa8f2
movb 0x40(%rbx), %al
cmpb $0x1, %al
jne 0xa8b4
cmpb $0x1, 0x40(%r15)
jne 0xa8b4
movq 0x30(%rbx), %rcx
cmpq 0x30(%r15), %rcx
je 0xa9a4
testq %r14, %r14
je 0xa953
cmpq $0x0, 0x38(%r15)
je 0xa953
cmpb $0x2, 0x43(%r15)
movb 0x43(%rbx), %cl
jne 0xa99b
cmpb $0x2, %cl
jne 0xaa75
movq 0x8(%rsp), %rcx
movq 0x10(%rcx), %rcx
cmpb $0x3, 0x39(%rcx)
jbe 0xa9ab
movq %r15, %r12
movq 0x10(%r15), %rax
addq $0x10, %r12
movq %rax, %r15
testq %rax, %rax
jne 0xa888
movq %rbx, (%r12)
movq 0x8(%rsp), %r14
testq %r14, %r14
je 0xa949
leaq 0x20(%rbx), %r12
movq (%r12), %rsi
movq 0x10(%rsp), %rdi
callq 0x72df
movl $0x1, %ebp
testl %eax, %eax
je 0xaa75
addq $0x38, %rbx
movq %r12, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x5453
jmp 0xaa75
movl $0x1, %ebp
jmp 0xaa75
xorl %ebp, %ebp
movq 0x8(%rsp), %rdi
testq %rdi, %rdi
je 0xaa75
movq 0x10(%rdi), %rax
cmpb $0x3, 0x39(%rax)
ja 0xaa75
movq 0x10(%rax), %rbx
callq 0x7104
movq %rax, %r14
movq 0x38(%r15), %rax
testq %rax, %rax
je 0xaa57
movq 0x10(%rax), %rdi
callq 0x7104
movq %rax, %r8
jmp 0xaa5e
cmpb $0x3, %cl
jne 0xaa3a
xorl %ebp, %ebp
jmp 0xaa75
cmpb $0x3, %al
jne 0xaa07
cmpb $0x3, 0x40(%r15)
jne 0xaa07
movl 0x44(%rbx), %eax
movl 0x44(%r15), %ecx
cmpl %ecx, %eax
movq 0x8(%rsp), %r14
jbe 0xa9d0
movq 0x30(%rbx), %rdx
cmpq 0x30(%r15), %rdx
jge 0xa9e6
cmpl %ecx, %eax
jb 0xaa75
movq 0x30(%rbx), %rax
cmpq 0x30(%r15), %rax
jle 0xaa75
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xcd2c
movq %r15, %rdi
callq 0x5040
movq %rbx, (%r12)
jmp 0xa913
movq 0x10(%rcx), %rbx
movq 0x8(%rsp), %rdi
callq 0x7104
movq %rax, %r14
movq 0x38(%r15), %rax
movq 0x10(%rax), %rdi
callq 0x7104
xorl %ebp, %ebp
movl $0x13, %edi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
movq %rax, %r8
jmp 0xaa6e
movq 0x10(%r15), %rax
movq %rax, 0x10(%rbx)
movq %r15, %rdi
callq 0xcd2c
movq %r15, %rdi
callq 0x5040
jmp 0xa905
leaq 0x17cb6(%rip), %r8      # 0x22714
xorl %ebp, %ebp
movl $0x13, %edi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
xorl %eax, %eax
callq 0x6f14
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq