// File: /workspace/github_c_makefile_star2_O1/AK6DN[P]dec-utilities-for-pdp/palbart/palbart.c
// Function: main
int main( int argc, char *argv[] )
{
  int     ix;
  int     space;

  /* Set the default values for global symbols.                               */
  binary_data_output = FALSE;
  fltg_input = FALSE;
  literals_ok = TRUE;
  perm_redef_error = FALSE;
  print_permanent_symbols = FALSE;
  rim_mode = FALSE;
  dollar_not_required = FALSE;
  additional_enabled = FALSE;
  symtab_print = FALSE;
  xref = FALSE;
  pathname = NULL;

  /* Get the options and pathnames                                            */
  getArgs( argc, argv );

  /* Setup the error file in case symbol table overflows while installing the */
  /* permanent symbols.                                                       */
  errorfile = fopen( errorpathname, "w" );
  if (errorfile == NULL) {
    fprintf( stderr, "Could not open error file %s: %s\n", errorpathname, strerror(errno));
    exit( -1 );

  }
  errors = 0;
  save_error_count = 0;
  pass = 0;             /* This is required for symbol table initialization.  */
  symtab = (SYM_T *) malloc( sizeof( SYM_T ) * SYMBOL_TABLE_SIZE );

  if( symtab == NULL )
  {
    fprintf( stderr, "Could not allocate memory for symbol table.\n");
    exit( -1 );
  }

  /* Place end marker in symbol table.                                        */
  symtab[0] = sym_undefined;
  symbol_top = 0;
  number_of_fixed_symbols = symbol_top;
  fixed_symbols = &symtab[symbol_top - 1];

  /* Enter the pseudo-ops into the symbol table                               */
  for( ix = 0; ix < DIM( pseudo ) - 
        (additional_enabled ? 0 : NUMBER_ADDITIONAL_PSEUDO) ; ix++ )
  {
    defineSymbol( pseudo[ix].name, pseudo[ix].val, pseudo[ix].type, 0 );
  }

  /* Enter the predefined symbols into the table.                             */
  /* Also make them part of the permanent symbol table.                       */
  for( ix = 0; ix < DIM( really_permanent_symbols ); ix++ )
  {
    defineSymbol( really_permanent_symbols[ix].name,
                  really_permanent_symbols[ix].val,
                  really_permanent_symbols[ix].type | DEFFIX , 0 );
  }

  /* Enter the predefined symbols into the table.                             */
  /* Also make them part of the permanent symbol table.                       */
  for( ix = 0; ix < DIM( permanent_symbols ); ix++ )
  {
    defineSymbol( permanent_symbols[ix].name,
                  permanent_symbols[ix].val,
                  permanent_symbols[ix].type | DEFFIX , 0 );
  }

  number_of_fixed_symbols = symbol_top;
  fixed_symbols = &symtab[symbol_top - 1];

  /* Do pass one of the assembly                                              */
  checksum = 0;
  pass = 1;
  page_lineno = LIST_LINES_PER_PAGE;
  onePass();
  errors_pass_1 = errors;

  /* Set up for pass two                                                      */
  rewind( infile );
  /*Opened in main errorfile = fopen( errorpathname, "w" );*/
  objectfile = fopen( objectpathname, "wb" );
  if (objectfile == NULL) {
    fprintf( stderr, "Could not open object file %s: %s\n", objectpathname, strerror(errno));
    exit( -1 );

  }
  objectsave = objectfile;

  listfile = fopen( listpathname, "w" );
  if (listfile == NULL) {
    fprintf( stderr, "Could not open list file %s: %s\n", listpathname, strerror(errno));
    exit( -1 );

  }
  listsave = NULL;

  punchLeader( 0 );
  checksum = 0;

  /* Do pass two of the assembly                                              */
  errors = 0;
  save_error_count = 0;
  page_lineno = LIST_LINES_PER_PAGE;

  if( xref )
  {
    /* Get the amount of space that will be required for the concordance.     */
    for( space = 0, ix = 0; ix < symbol_top; ix++ )
    {
      symtab[ix].xref_index = space;    /* Index into concordance table.      */
      space += symtab[ix].xref_count + 1;
      symtab[ix].xref_count = 0;        /* Clear the count for pass 2.        */

    }
    /* Allocate the necessary space.                                          */
    xreftab = (WORD16 *) malloc( sizeof( WORD16 ) * space );

    /* Clear the cross reference space.                                       */
    for( ix = 0; ix < space; ix++ )
    {
      xreftab[ix] = 0;
    }
  }
  pass = 2;
  onePass();

  /* Undo effects of NOPUNCH for any following checksum                       */
  objectfile = objectsave;
  punchChecksum();

  /* Works great for trailer.                                                 */
  punchLeader( 8 );

  /* undo effects of XLIST for any following output to listing file.          */
  if( listfile == NULL )
  {
    listfile = listsave;
  }

  /* Display value of error counter.                                          */
  if( errors == 0 )
  {
    fprintf( listfile, "\n      %s %s %s\n", s_no, s_detected, s_errors );
  }
  else
  {
    fprintf( errorfile, "\n      %d %s %s\n", errors, s_detected,
                                        ( errors == 1 ? s_error : s_errors ));
    fprintf( listfile, "\n      %d %s %s\n", errors, s_detected,
                                        ( errors == 1 ? s_error : s_errors ));
    fprintf( stderr,   "      %d %s %s\n", errors, s_detected,
                                        ( errors == 1 ? s_error : s_errors ));
  }
  /* Display value of link counter.                                          */
  if( links == 0 )
  {
    fprintf( listfile, "      %s %s %s\n", s_no, s_links, s_generated );
  }
  else
  {
    fprintf( errorfile, "      %d %s %s\n", links, 
                                        ( links == 1 ? s_link : s_links ), 
                                        s_generated);
    fprintf( listfile, "      %d %s %s\n", links, 
                                        ( links == 1 ? s_link : s_links ), 
                                        s_generated);
    fprintf( stderr, "      %d %s %s\n", links, 
                                        ( links == 1 ? s_link : s_links ), 
                                        s_generated);
  }

  if( symtab_print )
  {
    printSymbolTable();
  }

  if( print_permanent_symbols )
  {
    printPermanentSymbolTable();
  }

  if( xref )
  {
    printCrossReference();
  }

  fclose( objectfile );
  fclose( listfile );
  fclose( errorfile );
  if( errors == 0 && errors_pass_1 == 0 )
  {
    remove( errorpathname );
  }

  return( errors != 0 );
}

// Assembly:
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
movb %bl, 0x8c30(%rip)       # 0xb348
movb %bl, 0x8c2b(%rip)       # 0xb349
movb $0x1, 0x8c25(%rip)      # 0xb34a
movb %bl, 0x8c20(%rip)       # 0xb34b
movb %bl, 0x8c1b(%rip)       # 0xb34c
movb %bl, 0x8c16(%rip)       # 0xb34d
movb %bl, 0x8c11(%rip)       # 0xb34e
movb %bl, 0x8c0c(%rip)       # 0xb34f
movb %bl, 0x8c07(%rip)       # 0xb350
movb %bl, 0x8c02(%rip)       # 0xb351
movq $0x0, 0x8bfe(%rip) # 0xb358
callq 0x2b31
leaq 0x8bfa(%rip), %rdi      # 0xb360
leaq 0x4c9d(%rip), %rsi      # 0x740a
callq 0x2160
movq %rax, 0x8c67(%rip)      # 0xb3e0
testq %rax, %rax
je 0x2b1d
movl %ebx, 0x8c60(%rip)      # 0xb3e8
movl %ebx, 0x8c5e(%rip)      # 0xb3ec
movl %ebx, 0x8c5c(%rip)      # 0xb3f0
movl $0x18000, %edi          # imm = 0x18000
callq 0x2140
movq %rax, 0x8c53(%rip)      # 0xb3f8
testq %rax, %rax
je 0x2b22
movq 0x8b8b(%rip), %rcx      # 0xb340
movq %rcx, 0x10(%rax)
movups 0x8b70(%rip), %xmm0     # 0xb330
movups %xmm0, (%rax)
xorl %ebx, %ebx
movl %ebx, 0x8c35(%rip)      # 0xb400
movl %ebx, 0x8c33(%rip)      # 0xb404
addq $-0x18, %rax
movq %rax, 0x8c2c(%rip)      # 0xb408
leaq 0x792d(%rip), %r14      # 0xa110
leaq 0x4(%r14), %rdi
movswl 0xc(%r14), %esi
movl (%r14), %edx
xorl %ecx, %ecx
callq 0x2f0e
incq %rbx
xorl %eax, %eax
cmpb $0x0, 0x8b4d(%rip)      # 0xb34f
setne %al
leaq 0x1c(,%rax,2), %rax
addq $0x18, %r14
cmpq %rbx, %rax
ja 0x27e3
xorl %ebx, %ebx
leaq 0x7bc1(%rip), %r14      # 0xa3e0
leaq (%rbx,%r14), %rdi
addq $0x4, %rdi
movswl 0x8(%rdi), %esi
movl -0x4(%rdi), %edx
orl $0x3, %edx
xorl %ecx, %ecx
callq 0x2f0e
addq $0x18, %rbx
cmpq $0x18, %rbx
je 0x281f
xorl %ebx, %ebx
leaq 0x7bc5(%rip), %r14      # 0xa410
leaq (%rbx,%r14), %rdi
addq $0x4, %rdi
movswl 0x8(%rdi), %esi
movl -0x4(%rdi), %edx
orl $0x3, %edx
xorl %ecx, %ecx
callq 0x2f0e
addq $0x18, %rbx
cmpq $0xca8, %rbx            # imm = 0xCA8
jne 0x284b
movslq 0x8b88(%rip), %rax      # 0xb400
movl %eax, 0x8b86(%rip)      # 0xb404
movq 0x8b73(%rip), %rcx      # 0xb3f8
leaq (%rax,%rax,2), %rax
leaq (%rcx,%rax,8), %rax
addq $-0x18, %rax
movq %rax, 0x8b70(%rip)      # 0xb408
movw $0x0, 0x8b6f(%rip)      # 0xb410
movl $0x1, 0x8b45(%rip)      # 0xb3f0
movl $0x37, 0x8b5f(%rip)     # 0xb414
callq 0x3052
movl 0x8b28(%rip), %eax      # 0xb3e8
movl %eax, 0x8b52(%rip)      # 0xb418
movq 0x8b53(%rip), %rdi      # 0xb420
callq 0x20b0
leaq 0x8b57(%rip), %rdi      # 0xb430
leaq 0x4d29(%rip), %rsi      # 0x7609
callq 0x2160
movq %rax, 0x8bc4(%rip)      # 0xb4b0
testq %rax, %rax
je 0x2b27
movq %rax, 0x8bbc(%rip)      # 0xb4b8
leaq 0x8bbd(%rip), %rdi      # 0xb4c0
leaq 0x4b00(%rip), %rsi      # 0x740a
callq 0x2160
movq %rax, 0x8c2a(%rip)      # 0xb540
testq %rax, %rax
je 0x2b2c
movq $0x0, 0x8c1e(%rip) # 0xb548
cmpq $0x0, 0x8b7e(%rip)      # 0xb4b0
je 0x294e
movl $0xf0, %ebx
movq 0x8b70(%rip), %rsi      # 0xb4b0
movl $0x80, %edi
callq 0x20e0
decl %ebx
jne 0x2939
movw $0x0, 0x8ab9(%rip)      # 0xb410
xorl %ebx, %ebx
movl %ebx, 0x8a89(%rip)      # 0xb3e8
movl %ebx, 0x8a87(%rip)      # 0xb3ec
movl $0x37, 0x8aa5(%rip)     # 0xb414
cmpb $0x0, 0x89db(%rip)      # 0xb351
je 0x29d9
cmpl $0x0, 0x8a81(%rip)      # 0xb400
jle 0x29b2
movq 0x8a70(%rip), %rax      # 0xb3f8
addq $0x14, %rax
xorl %ecx, %ecx
xorl %ebx, %ebx
movl %ebx, -0x4(%rax)
movl (%rax), %edx
addl %edx, %ebx
incl %ebx
movl $0x0, (%rax)
incq %rcx
movslq 0x8a57(%rip), %rdx      # 0xb400
addq $0x18, %rax
cmpq %rdx, %rcx
jl 0x2990
movslq %ebx, %r14
leaq (%r14,%r14), %rdi
callq 0x2140
movq %rax, 0x8b8b(%rip)      # 0xb550
testl %r14d, %r14d
jle 0x29d9
addl %ebx, %ebx
movq %rax, %rdi
xorl %esi, %esi
movq %rbx, %rdx
callq 0x20d0
movl $0x2, 0x8a0d(%rip)      # 0xb3f0
callq 0x3052
movq 0x8ac9(%rip), %rax      # 0xb4b8
movq %rax, 0x8aba(%rip)      # 0xb4b0
callq 0x34d4
movl $0x8, %edi
callq 0x349e
cmpq $0x0, 0x8b33(%rip)      # 0xb540
jne 0x2a1d
movq 0x8b32(%rip), %rax      # 0xb548
movq %rax, 0x8b23(%rip)      # 0xb540
movl 0x89c5(%rip), %edi      # 0xb3e8
testl %edi, %edi
jne 0x2b09
movq 0x8b0e(%rip), %rdi      # 0xb540
leaq 0x4c17(%rip), %rsi      # 0x7650
leaq 0x868e(%rip), %rdx      # 0xb0ce
leaq 0x8671(%rip), %rcx      # 0xb0b8
leaq 0x8679(%rip), %r8       # 0xb0c7
xorl %eax, %eax
callq 0x2120
movl 0x8afd(%rip), %edi      # 0xb558
testl %edi, %edi
jne 0x2b13
movq 0x8ad6(%rip), %rdi      # 0xb540
leaq 0x4be0(%rip), %rsi      # 0x7651
leaq 0x8656(%rip), %rdx      # 0xb0ce
leaq 0x8690(%rip), %rcx      # 0xb10f
leaq 0x867a(%rip), %r8       # 0xb100
xorl %eax, %eax
callq 0x2120
cmpb $0x0, 0x88bc(%rip)      # 0xb350
je 0x2a9b
callq 0x350a
cmpb $0x0, 0x88aa(%rip)      # 0xb34c
je 0x2aa9
callq 0x36a0
cmpb $0x0, 0x88a1(%rip)      # 0xb351
je 0x2ab7
callq 0x37fd
movq 0x89f2(%rip), %rdi      # 0xb4b0
callq 0x2090
movq 0x8a76(%rip), %rdi      # 0xb540
callq 0x2090
movq 0x890a(%rip), %rdi      # 0xb3e0
callq 0x2090
movl 0x8937(%rip), %eax      # 0xb418
orl 0x8901(%rip), %eax      # 0xb3e8
jne 0x2af5
leaq 0x8870(%rip), %rdi      # 0xb360
callq 0x2060
xorl %eax, %eax
cmpl $0x0, 0x88ea(%rip)      # 0xb3e8
setne %al
addq $0x8, %rsp
popq %rbx
popq %r14
retq
callq 0x21e0
jmp 0x2a55
callq 0x227e
jmp 0x2a8d
callq 0x23b1
callq 0x238c
callq 0x2352
callq 0x2318