// File: /workspace/github_c_makefile_star2_O2/AK6DN[P]dec-utilities-for-pdp/palbart/palbart.c
// Function: defineSymbol
SYM_T *defineSymbol( char *name, WORD16 val, SYMTYP type, WORD16 start )
{
  SYM_T  *sym;
  int     xref_count;

  if( strlen( name ) < 1 )
  {
    return( &sym_undefined );   /* Protect against non-existent names.        */
  }
  sym = lookup( name );
  /* OS/8 PAL8 seems to allow permanent symbold to be redefined without error */
  if( ( M_FIXED( sym->type ) && pass == 1 && perm_redef_error ) || 
     (M_PERM_REDEFINED( sym->type ) && (sym->val != val)) )
  {
     type |= PERM_REDEFINED;
  }

  xref_count = 0;               /* Set concordance for normal defintion.      */

  if( M_DEFINED( sym->type ))
  {
    if( pass == 2 && ( (sym->val & 07777) != (val & 07777) || M_PERM_REDEFINED(sym->type)) )
    {
      /* Generate diagnostic if redefining a symbol.                          */
      if( M_PERM_REDEFINED( sym->type ) && (M_LABEL(sym->type) || M_LABEL(type)) )
      {
        errorSymbol( &illegal_redefine, sym->name, start );
      } else 
      {
        /* Generate diagnostic if redefining a symbol.                          */
        if( M_REDEFINED( sym->type ) && (M_LABEL(sym->type) || M_LABEL(type)) )
        {
          errorSymbol( &redefined_symbol, sym->name, start );
        }
      }
      type = type | REDEFINED;
      sym->xref_count++;      /* Referenced suymbol, count it.                */
      xref_count = sym->xref_count;
    }
  }

  if( pass == 2 && xref )
  {
    /* Put the definition line number in the concordance table.               */
    /* Defined symbols are not counted as references.                         */
    xreftab[sym->xref_index] = lineno;
    /* Put the line number in the concordance table.                          */
    xreftab[sym->xref_index + xref_count] = lineno;
  }

  /* Now set the value and the type.                                          */
  sym->val = ( M_LABEL(type) ) ? val : val & 07777;
  sym->type = ( pass == 1 ) ? ( type | CONDITION ) : type;
  return( sym );
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
cmpb $0x0, (%rdi)
je 0x2e0d
movl %ecx, %r15d
movl %edx, %ebx
movl %esi, %ebp
callq 0x3ed0
movq %rax, %r14
movl (%rax), %ecx
movl 0x85ee(%rip), %eax      # 0xb3e0
testb $0x2, %cl
je 0x2e19
cmpl $0x1, %eax
jne 0x2e19
cmpb $0x0, 0x8538(%rip)      # 0xb33b
je 0x2e19
orl $0x100, %ebx            # imm = 0x100
jmp 0x2e26
leaq 0x850c(%rip), %r14      # 0xb320
jmp 0x2f0c
btl $0x8, %ecx
jae 0x2e26
cmpw %bp, 0xc(%r14)
jne 0x2e05
cmpl $0x2, %eax
sete %sil
andb %cl, %sil
xorl %edx, %edx
cmpb $0x1, %sil
jne 0x2eb6
btl $0x8, %ecx
jb 0x2e52
movzwl 0xc(%r14), %eax
xorw %bp, %ax
andl $0xfff, %eax            # imm = 0xFFF
jne 0x2e52
pushq $0x2
popq %rax
jmp 0x2eb6
btl $0x8, %ecx
notl %ecx
movl %ebx, %eax
notl %eax
jae 0x2e78
testb $0x9, %cl
sete %dl
testb $0x9, %al
sete %sil
orb %dl, %sil
je 0x2e78
leaq 0x8362(%rip), %rdi      # 0xb1d8
jmp 0x2e93
testb $0x11, %cl
jne 0x2ea3
testb $0x9, %cl
setne %cl
testb $0x9, %al
setne %al
testb %al, %cl
jne 0x2ea3
leaq 0x8335(%rip), %rdi      # 0xb1c8
movq %r14, %rsi
addq $0x4, %rsi
movswl %r15w, %edx
callq 0x4045
orl $0x11, %ebx
movl 0x14(%r14), %edx
incl %edx
movl %edx, 0x14(%r14)
movl 0x852a(%rip), %eax      # 0xb3e0
cmpl $0x2, %eax
jne 0x2ee4
cmpb $0x0, 0x847f(%rip)      # 0xb341
je 0x2ee4
movzwl 0xa891(%rip), %ecx      # 0xd75c
movq 0x866e(%rip), %rsi      # 0xb540
movslq 0x10(%r14), %rdi
movw %cx, (%rsi,%rdi,2)
movslq %edx, %rdx
addq %rdi, %rdx
movw %cx, (%rsi,%rdx,2)
movl %ebx, %ecx
notl %ecx
movl %ebp, %edx
andl $0xfff, %edx            # imm = 0xFFF
testb $0x9, %cl
cmovel %ebp, %edx
movw %dx, 0xc(%r14)
movl %ebx, %ecx
orl $0x81, %ecx
cmpl $0x1, %eax
cmovnel %ebx, %ecx
movl %ecx, (%r14)
movq %r14, %rax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq