// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/targets.c
// Function: addsymbol
struct Symbol *addsymbol(struct GlobalVars *gv,struct Section *s,
                         const char *name,const char *iname,lword val,
                         uint8_t type,uint8_t flags,uint8_t info,uint8_t bind,
                         uint32_t size,bool chkdef)
/* Define a new symbol. If defined twice in the same object unit, then */
/* return a pointer to its first definition. Defining the symbol twice */
/* globally is only allowed in different object units of a library. */
{
  struct Symbol *sym;
  struct ObjectUnit *ou = s->obj;
  struct Symbol **chain = &ou->objsyms[elf_hash(name)%OBJSYMHTABSIZE];

  while (sym = *chain) {
    if (!strcmp(name,sym->name)) {
      if (chkdef)  /* do we have to warn about multiple def. ourselves? */
        error(56,ou->lnkfile->pathname,name,getobjname(ou));
      return sym;  /* return first definition to caller */
    }
    chain = &sym->obj_chain;
  }

  sym = alloczero(sizeof(struct Symbol));
  sym->name = name;
  sym->indir_name = iname;
  sym->value = val;
  sym->relsect = s;
  sym->type = type;
  sym->flags = flags;
  sym->info = info;
  sym->bind = bind;
  sym->size = size;

  if (type == SYM_COMMON) {
    /* alignment of .common section must suit the biggest common-alignment */
    uint8_t com_alignment = lshiftcnt(val);

    if (com_alignment > s->alignment)
      s->alignment = com_alignment;
  }

  if (check_protection(gv,name))
    sym->flags |= SYMF_PROTECTED;

  if (bind==SYMB_GLOBAL || bind==SYMB_WEAK) {
    uint16_t flags = ou->lnkfile->flags;

    if (flags & IFF_DELUNDERSCORE) {
      if (*name == '_')
        sym->name = name + 1;  /* delete preceding underscore, if present */
    }
    else if (flags & IFF_ADDUNDERSCORE) {
      char *new_name = alloc(strlen(name) + 2);
      
      *new_name = '_';
      strcpy(new_name+1,name);
      sym->name = new_name;
    }

    if (!addglobsym(gv,sym)) {
      free(sym);
      return NULL;
    }
  }

  *chain = sym;
  return NULL;  /* ok, symbol exists only once in this object */
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x28, %rsp
movl %r9d, 0x4(%rsp)
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, 0x20(%rsp)
movl 0x80(%rsp), %r12d
movb 0x70(%rsp), %r13b
movq 0x10(%rsi), %rax
movq %rax, 0x8(%rsp)
movq 0x48(%rax), %rbx
movq %rdx, %rdi
callq 0x69ee
andl $0x1f, %eax
leaq (%rbx,%rax,8), %r15
movq (%r15), %rbx
testq %rbx, %rbx
je 0xa64b
movq 0x20(%rbx), %rsi
movq %r14, %rdi
callq 0x5160
testl %eax, %eax
je 0xa718
addq $0x18, %rbx
movq %rbx, %r15
jmp 0xa626
pushq $0x50
popq %rdi
callq 0x638a
movq %rax, %r12
movq %r14, 0x20(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r12)
movq 0x18(%rsp), %rdi
movq %rdi, 0x30(%r12)
movq %rbp, 0x38(%r12)
movl 0x4(%rsp), %eax
movb %al, 0x40(%r12)
movb 0x60(%rsp), %cl
movb %cl, 0x41(%r12)
movb 0x68(%rsp), %cl
movb %cl, 0x42(%r12)
movb %r13b, 0x43(%r12)
movl 0x78(%rsp), %ecx
movl %ecx, 0x44(%r12)
cmpb $0x3, %al
jne 0xa6b3
callq 0x6a69
movzbl %al, %ecx
movzbl 0x2f(%rbp), %edx
cmpl %edx, %ecx
jbe 0xa6b3
movb %al, 0x2f(%rbp)
movq 0x20(%rsp), %rbp
movq %rbp, %rdi
movq %r14, %rsi
callq 0xa2f1
testl %eax, %eax
je 0xa6cd
orb $0x4, 0x41(%r12)
andb $-0x2, %r13b
cmpb $0x2, %r13b
jne 0xa761
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movzwl 0x3a(%rax), %eax
testb $0x1, %al
jne 0xa744
testb $0x2, %al
je 0xa752
movq %r14, %rdi
callq 0x50e0
leaq 0x2(%rax), %rdi
callq 0x6340
movq %rax, %r13
movb $0x5f, (%rax)
leaq 0x1(%rax), %rdi
movq %r14, %rsi
callq 0x5080
movq %r13, %r14
jmp 0xa74d
testl %r12d, %r12d
je 0xa764
movq 0x8(%rsp), %rdi
movq 0x10(%rdi), %rax
movq 0x10(%rax), %r15
callq 0x6e1c
pushq $0x38
popq %rdi
movq %r15, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6c19
jmp 0xa764
cmpb $0x5f, (%r14)
jne 0xa752
incq %r14
movq %r14, 0x20(%r12)
movq %rbp, %rdi
movq %r12, %rsi
callq 0xa32a
testl %eax, %eax
je 0xa776
movq %r12, (%r15)
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r12, %rdi
callq 0x5040
jmp 0xa764