// File: /workspace/github_c_makefile_star2_O3/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 0x2f6c
movl %ecx, %r15d
movl %edx, %ebx
movl %esi, %ebp
callq 0x423f
movq %rax, %r14
movl (%rax), %ecx
movl 0x849f(%rip), %eax      # 0xb3f0
testb $0x2, %cl
je 0x2f78
cmpl $0x1, %eax
jne 0x2f78
cmpb $0x0, 0x83e9(%rip)      # 0xb34b
je 0x2f78
orl $0x100, %ebx            # imm = 0x100
jmp 0x2f85
leaq 0x83bd(%rip), %r14      # 0xb330
jmp 0x3074
btl $0x8, %ecx
jae 0x2f85
cmpw %bp, 0xc(%r14)
jne 0x2f64
cmpl $0x2, %eax
sete %sil
andb %cl, %sil
xorl %edx, %edx
cmpb $0x1, %sil
jne 0x301e
btl $0x8, %ecx
jb 0x2fb6
movzwl 0xc(%r14), %esi
xorw %bp, %si
movl $0x2, %eax
andl $0xfff, %esi            # imm = 0xFFF
je 0x301e
btl $0x8, %ecx
notl %ecx
jae 0x2fdb
testb $0x9, %cl
sete %al
movl %ebx, %edx
notl %edx
testb $0x9, %dl
sete %dl
orb %al, %dl
je 0x2fdb
leaq 0x820f(%rip), %rdi      # 0xb1e8
jmp 0x2ffb
testb $0x11, %cl
jne 0x300b
testb $0x9, %cl
setne %al
movl %ebx, %ecx
notl %ecx
testb $0x9, %cl
setne %cl
testb %cl, %al
jne 0x300b
leaq 0x81dd(%rip), %rdi      # 0xb1d8
movq %r14, %rsi
addq $0x4, %rsi
movswl %r15w, %edx
callq 0x43d8
orl $0x11, %ebx
movl 0x14(%r14), %edx
incl %edx
movl %edx, 0x14(%r14)
movl 0x83d2(%rip), %eax      # 0xb3f0
cmpl $0x2, %eax
jne 0x304c
cmpb $0x0, 0x8327(%rip)      # 0xb351
je 0x304c
movzwl 0xa739(%rip), %ecx      # 0xd76c
movq 0x8516(%rip), %rsi      # 0xb550
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