// File: /workspace/github_c_makefile_star2_O0/simh[P]simtools/crossassemblers/macro11/symbols.c
// Function: add_sym
SYMBOL         *add_sym(
    char *labelraw,
    unsigned value,
    unsigned flags,
    SECTION *section,
    SYMBOL_TABLE *table)
{
    SYMBOL         *sym;
    char            label[SYMMAX_MAX + 1];      // big size

    if (isdigit((unsigned char)labelraw[0])) {
        // Don't truncate local labels
        strncpy(label, labelraw, SYMMAX_MAX);
        label[SYMMAX_MAX] = 0;
    } else {
        //JH: truncate symbol to SYMMAX
        strncpy(label, labelraw, symbol_len);
        label[symbol_len] = 0;
    }

    sym = lookup_sym(label, table);
    if (sym != NULL) {
        // A symbol registered as "undefined" can be changed.

        if ((sym->flags & SYMBOLFLAG_UNDEFINED) && !(flags & SYMBOLFLAG_UNDEFINED)) {
            sym->flags &= ~(SYMBOLFLAG_PERMANENT | SYMBOLFLAG_UNDEFINED);
        }

        /* Check for compatible definition */
        else if (sym->section == section && sym->value == value) {
            sym->flags |= flags;       /* Merge flags quietly */
            return sym;                /* 's okay */
        }

        if (!(sym->flags & SYMBOLFLAG_PERMANENT)) {
            /* permit redefinition */
            sym->value = value;
            sym->flags |= flags;
            sym->section = section;
            return sym;
        }

        return NULL;                   /* Bad symbol redefinition */
    }

    sym = new_sym(label);
    sym->flags = flags;
    sym->stmtno = stmtno;
    sym->section = section;
    sym->value = value;

    add_table(sym, table);

    return sym;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x80, %rsp
movq %rdi, -0x10(%rbp)
movl %esi, -0x14(%rbp)
movl %edx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq %r8, -0x28(%rbp)
callq 0x22e0
movq (%rax), %rax
movq -0x10(%rbp), %rcx
movzbl (%rcx), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0xe235
leaq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
movl $0x40, %edx
callq 0x2060
movb $0x0, -0x40(%rbp)
jmp 0xe255
leaq -0x80(%rbp), %rdi
movq -0x10(%rbp), %rsi
movslq 0xb894(%rip), %rdx      # 0x19ad8
callq 0x2060
movslq 0xb888(%rip), %rax      # 0x19ad8
movb $0x0, -0x80(%rbp,%rax)
leaq -0x80(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe040
movq %rax, -0x30(%rbp)
cmpq $0x0, -0x30(%rbp)
je 0xe316
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x10, %eax
cmpl $0x0, %eax
je 0xe29a
movl -0x18(%rbp), %eax
andl $0x10, %eax
cmpl $0x0, %eax
jne 0xe29a
movq -0x30(%rbp), %rax
movl 0x10(%rax), %ecx
andl $-0x12, %ecx
movl %ecx, 0x10(%rax)
jmp 0xe2d0
movq -0x30(%rbp), %rax
movq 0x18(%rax), %rax
cmpq -0x20(%rbp), %rax
jne 0xe2ce
movq -0x30(%rbp), %rax
movl 0x8(%rax), %eax
cmpl -0x14(%rbp), %eax
jne 0xe2ce
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
orl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe368
jmp 0xe2d0
movq -0x30(%rbp), %rax
movl 0x10(%rax), %eax
andl $0x1, %eax
cmpl $0x0, %eax
jne 0xe30c
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
orl 0x10(%rax), %ecx
movl %ecx, 0x10(%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
jmp 0xe368
movq $0x0, -0x8(%rbp)
jmp 0xe368
leaq -0x80(%rbp), %rdi
callq 0xe380
movq %rax, -0x30(%rbp)
movl -0x18(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x10(%rax)
leaq 0xb850(%rip), %rax      # 0x19b84
movl (%rax), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0xc(%rax)
movq -0x20(%rbp), %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x18(%rax)
movl -0x14(%rbp), %ecx
movq -0x30(%rbp), %rax
movl %ecx, 0x8(%rax)
movq -0x30(%rbp), %rdi
movq -0x28(%rbp), %rsi
callq 0xe190
movq -0x30(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x80, %rsp
popq %rbp
retq
nopw %cs:(%rax,%rax)