// File: /workspace/github_c_makefile_star2_O1/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 0x2f4b
movl %ecx, %r15d
movl %edx, %ebx
movl %esi, %ebp
callq 0x41de
movq %rax, %r14
movl (%rax), %eax
movl 0x84bf(%rip), %ecx      # 0xb3f0
testb $0x2, %al
je 0x2f57
cmpl $0x1, %ecx
jne 0x2f57
cmpb $0x0, 0x840a(%rip)      # 0xb34b
je 0x2f57
orl $0x100, %ebx            # imm = 0x100
jmp 0x2f64
leaq 0x83de(%rip), %r14      # 0xb330
jmp 0x3044
btl $0x8, %eax
jae 0x2f64
cmpw %bp, 0xc(%r14)
jne 0x2f43
cmpl $0x2, %ecx
sete %dl
andb %al, %dl
xorl %ecx, %ecx
cmpb $0x1, %dl
jne 0x2fe8
btl $0x8, %eax
jb 0x2f89
movzwl 0xc(%r14), %edx
xorw %bp, %dx
andl $0xfff, %edx            # imm = 0xFFF
je 0x2fe8
btl $0x8, %eax
notl %eax
jae 0x2fad
testb $0x9, %al
sete %cl
movl %ebx, %edx
notl %edx
testb $0x9, %dl
sete %dl
orb %cl, %dl
je 0x2fad
leaq 0x823d(%rip), %rdi      # 0xb1e8
jmp 0x2fcb
testb $0x11, %al
jne 0x2fdb
testb $0x9, %al
setne %al
movl %ebx, %ecx
notl %ecx
testb $0x9, %cl
setne %cl
testb %cl, %al
jne 0x2fdb
leaq 0x820d(%rip), %rdi      # 0xb1d8
movq %r14, %rsi
addq $0x4, %rsi
movswl %r15w, %edx
callq 0x4382
orl $0x11, %ebx
movl 0x14(%r14), %ecx
incl %ecx
movl %ecx, 0x14(%r14)
movl 0x8402(%rip), %eax      # 0xb3f0
cmpl $0x2, %eax
jne 0x301c
cmpb $0x0, 0x8357(%rip)      # 0xb351
je 0x301c
movzwl 0xa769(%rip), %edx      # 0xd76c
movq 0x8546(%rip), %rsi      # 0xb550
movslq 0x10(%r14), %rdi
movw %dx, (%rsi,%rdi,2)
movslq %ecx, %rcx
addq %rdi, %rcx
movw %dx, (%rsi,%rcx,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