// File: /workspace/github_c_makefile_star2_O1/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, %r12d
movq %r8, 0x18(%rsp)
movq %rcx, 0x10(%rsp)
movq %rdx, %r14
movq %rsi, %rbp
movq %rdi, 0x20(%rsp)
movq 0x10(%rsi), %r13
movq 0x48(%r13), %rbx
movq %rdx, %rdi
callq 0x6e09
andl $0x1f, %eax
movq (%rbx,%rax,8), %rcx
testq %rcx, %rcx
je 0xac19
movl 0x80(%rsp), %r15d
movq %rcx, %rbx
movq 0x20(%rcx), %rsi
movq %r14, %rdi
callq 0x5160
testl %eax, %eax
je 0xad02
movq 0x18(%rbx), %rcx
testq %rcx, %rcx
jne 0xabee
movq %r13, 0x8(%rsp)
addq $0x18, %rbx
jmp 0xac22
movq %r13, 0x8(%rsp)
leaq (%rbx,%rax,8), %rbx
movb 0x70(%rsp), %r15b
movl $0x50, %edi
callq 0x66b6
movq %rax, %r13
movq %r14, 0x20(%rax)
movq 0x10(%rsp), %rax
movq %rax, 0x28(%r13)
movq 0x18(%rsp), %rdi
movq %rdi, 0x30(%r13)
movq %rbp, 0x38(%r13)
movb %r12b, 0x40(%r13)
movb 0x60(%rsp), %al
movb %al, 0x41(%r13)
movb 0x68(%rsp), %al
movb %al, 0x42(%r13)
movb %r15b, 0x43(%r13)
movl 0x78(%rsp), %eax
movl %eax, 0x44(%r13)
cmpb $0x3, %r12b
jne 0xac87
callq 0x6e9c
movzbl %al, %ecx
movzbl 0x2f(%rbp), %edx
cmpl %edx, %ecx
jbe 0xac87
movb %al, 0x2f(%rbp)
movq 0x20(%rsp), %rbp
leaq 0xb0(%rbp), %r12
movq (%r12), %r12
testq %r12, %r12
je 0xacb7
movq 0x8(%r12), %rdi
movq %r14, %rsi
callq 0x5160
testl %eax, %eax
jne 0xac93
testq %r12, %r12
je 0xacb7
orb $0x4, 0x41(%r13)
andb $-0x2, %r15b
cmpb $0x2, %r15b
jne 0xad4a
movq 0x8(%rsp), %rax
movq 0x10(%rax), %rax
movzwl 0x3a(%rax), %eax
testb $0x1, %al
jne 0xad2e
testb $0x2, %al
je 0xad3b
movq %r14, %rdi
callq 0x50e0
leaq 0x2(%rax), %rdi
callq 0x6668
movq %rax, %r15
movb $0x5f, (%rax)
leaq 0x1(%rax), %rdi
movq %r14, %rsi
callq 0x5080
movq %r15, %r14
jmp 0xad37
testl %r15d, %r15d
je 0xad4f
movq 0x10(%r13), %rax
movq 0x10(%rax), %r15
movq %r13, %rdi
callq 0x7174
movl $0x38, %edi
movq %r15, %rsi
movq %r14, %rdx
movq %rax, %rcx
xorl %eax, %eax
callq 0x6f84
jmp 0xad4f
cmpb $0x5f, (%r14)
jne 0xad3b
incq %r14
movq %r14, 0x20(%r13)
movq %rbp, %rdi
movq %r13, %rsi
callq 0xa934
testl %eax, %eax
je 0xad61
movq %r13, (%rbx)
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x28, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r13, %rdi
callq 0x5040
jmp 0xad4d