// File: /workspace/github_c_makefile_star2_O0/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
movq %rsp, %rbp
subq $0x40, %rsp
movw %cx, %ax
movw %si, %cx
movq %rdi, -0x10(%rbp)
movw %cx, -0x12(%rbp)
movl %edx, -0x18(%rbp)
movw %ax, -0x1a(%rbp)
movq -0x10(%rbp), %rdi
callq 0x20a0
cmpq $0x1, %rax
jae 0x328c
leaq 0xa10d(%rip), %rax      # 0xd390
movq %rax, -0x8(%rbp)
jmp 0x3495
movq -0x10(%rbp), %rdi
callq 0x4dd0
movq %rax, -0x28(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x2, %eax
cmpl $0x2, %eax
jne 0x32bc
cmpl $0x1, 0xa1a2(%rip)      # 0xd450
jne 0x32bc
movzbl 0xa0f4(%rip), %eax      # 0xd3ab
cmpl $0x0, %eax
jne 0x32de
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x100, %eax            # imm = 0x100
jne 0x32e9
movq -0x28(%rbp), %rax
movswl 0xc(%rax), %eax
movswl -0x12(%rbp), %ecx
cmpl %ecx, %eax
je 0x32e9
movl -0x18(%rbp), %eax
orl $0x100, %eax            # imm = 0x100
movl %eax, -0x18(%rbp)
movl $0x0, -0x2c(%rbp)
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x1, %eax
cmpl $0x1, %eax
jne 0x33e8
cmpl $0x2, 0xa147(%rip)      # 0xd450
jne 0x33e6
movq -0x28(%rbp), %rax
movswl 0xc(%rax), %eax
andl $0xfff, %eax            # imm = 0xFFF
movswl -0x12(%rbp), %ecx
andl $0xfff, %ecx            # imm = 0xFFF
cmpl %ecx, %eax
jne 0x3340
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x100, %eax            # imm = 0x100
jne 0x33e6
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x100, %eax            # imm = 0x100
cmpl $0x100, %eax            # imm = 0x100
jne 0x3385
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x9, %eax
cmpl $0x9, %eax
je 0x336b
movl -0x18(%rbp), %eax
andl $0x9, %eax
cmpl $0x9, %eax
jne 0x3385
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
movswl -0x1a(%rbp), %edx
leaq 0x9e5a(%rip), %rdi      # 0xd1d8
callq 0x5030
jmp 0x33c6
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x11, %eax
cmpl $0x11, %eax
jne 0x33c4
movq -0x28(%rbp), %rax
movl (%rax), %eax
andl $0x9, %eax
cmpl $0x9, %eax
je 0x33ac
movl -0x18(%rbp), %eax
andl $0x9, %eax
cmpl $0x9, %eax
jne 0x33c4
movq -0x28(%rbp), %rsi
addq $0x4, %rsi
movswl -0x1a(%rbp), %edx
leaq 0x9e09(%rip), %rdi      # 0xd1c8
callq 0x5030
jmp 0x33c6
movl -0x18(%rbp), %eax
orl $0x11, %eax
movl %eax, -0x18(%rbp)
movq -0x28(%rbp), %rax
movl 0x14(%rax), %ecx
addl $0x1, %ecx
movl %ecx, 0x14(%rax)
movq -0x28(%rbp), %rax
movl 0x14(%rax), %eax
movl %eax, -0x2c(%rbp)
jmp 0x33e8
cmpl $0x2, 0xa061(%rip)      # 0xd450
jne 0x343a
movzbl 0x9fb9(%rip), %eax      # 0xd3b1
cmpl $0x0, %eax
je 0x343a
movl 0xc3c9(%rip), %eax      # 0xf7cc
movw %ax, %dx
movq 0xa1a3(%rip), %rax      # 0xd5b0
movq -0x28(%rbp), %rcx
movslq 0x10(%rcx), %rcx
movw %dx, (%rax,%rcx,2)
movl 0xc3ad(%rip), %eax      # 0xf7cc
movw %ax, %dx
movq 0xa187(%rip), %rax      # 0xd5b0
movq -0x28(%rbp), %rcx
movl 0x10(%rcx), %ecx
addl -0x2c(%rbp), %ecx
movslq %ecx, %rcx
movw %dx, (%rax,%rcx,2)
movl -0x18(%rbp), %eax
andl $0x9, %eax
cmpl $0x9, %eax
jne 0x344e
movswl -0x12(%rbp), %eax
movl %eax, -0x30(%rbp)
jmp 0x345a
movswl -0x12(%rbp), %eax
andl $0xfff, %eax            # imm = 0xFFF
movl %eax, -0x30(%rbp)
movl -0x30(%rbp), %eax
movw %ax, %cx
movq -0x28(%rbp), %rax
movw %cx, 0xc(%rax)
cmpl $0x1, 0x9fe1(%rip)      # 0xd450
jne 0x347e
movl -0x18(%rbp), %eax
orl $0x81, %eax
movl %eax, -0x34(%rbp)
jmp 0x3484
movl -0x18(%rbp), %eax
movl %eax, -0x34(%rbp)
movl -0x34(%rbp), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
movq -0x28(%rbp), %rax
movq %rax, -0x8(%rbp)
movq -0x8(%rbp), %rax
addq $0x40, %rsp
popq %rbp
retq
nop