// File: /workspace/github_c_makefile_star2_O2/simh[P]simtools/crossassemblers/macro8x/macro8x.c
// Function: main
int main( int argc, char *argv[] )
{
  int     ix;
  int     space;

  save_argc = argc;
  save_argv = argv;

  /* Set the default values for global symbols.                               */
  binary_data_output = FALSE;
  fltg_input = FALSE;
  nomac_exp = TRUE;
  print_permanent_symbols = FALSE;
  rim_mode = FALSE;
  symtab_print = FALSE;
  xref = FALSE;
  pathname = NULL;
  for( ix = 0; ix < MAC_TABLE_LENGTH; ix++ )
  {
    mac_bodies[ix] = 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" );
  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 ); 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( 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;
  onePass();
  errors_pass_1 = errors;
  fclose ( errorfile );

  /* Set up for pass two                                                      */
  errorfile = fopen( errorpathname, "w" );
  objectfile = fopen( objectpathname, "wb" );
  objectsave = objectfile;

  listfile = fopen( listpathname, "w" );
  listsave = listfile;

  punchLeader( 0 );
  checksum = 0;

  /* Do pass two of the assembly                                              */
  errors = 0;
  save_error_count = 0;

  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 = (WORD32 *) malloc( sizeof( WORD32 ) * 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( 1 );

  /* undo effects of NOLIST for any following output to listing file.         */
  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 ));
  }

  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 %r15
pushq %r14
pushq %r12
pushq %rbx
pushq %rax
movl %edi, 0x8ed6(%rip)      # 0xb180
movq %rsi, 0x8ed7(%rip)      # 0xb188
xorl %eax, %eax
movb %al, 0x8ed7(%rip)       # 0xb190
movb %al, 0x8ed2(%rip)       # 0xb191
movb $0x1, 0x8ecc(%rip)      # 0xb192
movb %al, 0x8ec7(%rip)       # 0xb193
movb %al, 0x8ec2(%rip)       # 0xb194
movb %al, 0x8ebd(%rip)       # 0xb195
movb %al, 0x8eb8(%rip)       # 0xb196
andq $0x0, 0x8eb2(%rip)      # 0xb198
leaq 0x8eb3(%rip), %rcx      # 0xb1a0
cmpq $0x2000, %rax           # imm = 0x2000
je 0x2300
andq $0x0, (%rax,%rcx)
addq $0x8, %rax
jmp 0x22ed
callq 0x26a8
leaq 0xae94(%rip), %rdi      # 0xd1a0
leaq 0x5116(%rip), %rsi      # 0x7429
callq 0x2150
andl $0x0, 0xaf09(%rip)      # 0xd228
andl $0x0, 0xaf06(%rip)      # 0xd22c
movq %rax, 0xaef3(%rip)      # 0xd220
andl $0x0, 0xaefc(%rip)      # 0xd230
movl $0x30000, %edi          # imm = 0x30000
callq 0x2130
movq %rax, 0xaef3(%rip)      # 0xd238
testq %rax, %rax
je 0x2684
movq 0x8e23(%rip), %rcx      # 0xb178
movq %rcx, 0x10(%rax)
movups 0x8e08(%rip), %xmm0     # 0xb168
andl $0x0, 0xaed9(%rip)      # 0xd240
movups %xmm0, (%rax)
andl $0x0, 0xaed3(%rip)      # 0xd244
addq $-0x18, %rax
movq %rax, 0xaecc(%rip)      # 0xd248
xorl %ebx, %ebx
leaq 0x7d5b(%rip), %r14      # 0xa0e0
cmpq $0x2e8, %rbx            # imm = 0x2E8
je 0x23a9
leaq (%rbx,%r14), %rdi
addq $0x4, %rdi
movl -0x4(%rdi), %edx
movl 0x8(%rdi), %esi
xorl %ecx, %ecx
callq 0x29d7
addq $0x18, %rbx
jmp 0x2385
xorl %ebx, %ebx
leaq 0x801e(%rip), %r14      # 0xa3d0
cmpq $0xa98, %rbx            # imm = 0xA98
je 0x23d9
leaq (%rbx,%r14), %rdi
addq $0x4, %rdi
movl -0x4(%rdi), %edx
movl 0x8(%rdi), %esi
orl $0x3, %edx
xorl %ecx, %ecx
callq 0x29d7
addq $0x18, %rbx
jmp 0x23b2
movslq 0xae60(%rip), %rax      # 0xd240
movl %eax, 0xae5e(%rip)      # 0xd244
movq 0xae4b(%rip), %rcx      # 0xd238
imulq $0x18, %rax, %rax
addq %rcx, %rax
addq $-0x18, %rax
movq %rax, 0xae49(%rip)      # 0xd248
andl $0x0, 0xae4a(%rip)      # 0xd250
movl $0x1, 0xae20(%rip)      # 0xd230
callq 0x2a94
movl 0xae0d(%rip), %eax      # 0xd228
movl %eax, 0xae33(%rip)      # 0xd254
movq 0xadf8(%rip), %rdi      # 0xd220
callq 0x20a0
leaq 0xad6c(%rip), %rdi      # 0xd1a0
leaq 0x4fee(%rip), %rbx      # 0x7429
movq %rbx, %rsi
callq 0x2150
movq %rax, 0xadd6(%rip)      # 0xd220
leaq 0xae0f(%rip), %rdi      # 0xd260
leaq 0x5257(%rip), %rsi      # 0x76af
callq 0x2150
movq %rax, 0xae7c(%rip)      # 0xd2e0
movq %rax, 0xae7d(%rip)      # 0xd2e8
leaq 0xae7e(%rip), %rdi      # 0xd2f0
movq %rbx, %rsi
callq 0x2150
movq %rax, 0xaeef(%rip)      # 0xd370
movq %rax, 0xaef0(%rip)      # 0xd378
xorl %ebx, %ebx
xorl %edi, %edi
callq 0x2f56
andl $0x0, 0xadb8(%rip)      # 0xd250
andl $0x0, 0xad89(%rip)      # 0xd228
andl $0x0, 0xad86(%rip)      # 0xd22c
cmpb $0x0, 0x8ce9(%rip)      # 0xb196
je 0x250a
movq 0xad82(%rip), %rax      # 0xd238
addq $0x14, %rax
xorl %ecx, %ecx
movslq 0xad7d(%rip), %rdx      # 0xd240
cmpq %rdx, %rcx
jge 0x24dd
movl %ebx, -0x4(%rax)
movl (%rax), %edx
andl $0x0, (%rax)
addl %edx, %ebx
incl %ebx
incq %rcx
addq $0x18, %rax
jmp 0x24bc
movslq %ebx, %r14
leaq (,%r14,4), %rdi
callq 0x2130
movq %rax, 0xae8c(%rip)      # 0xd380
xorl %ecx, %ecx
testl %r14d, %r14d
cmovlel %ecx, %ebx
cmpq %rcx, %rbx
je 0x250a
andl $0x0, (%rax,%rcx,4)
incq %rcx
jmp 0x24fc
movl $0x2, 0xad1c(%rip)      # 0xd230
callq 0x2a94
movq 0xadc8(%rip), %rax      # 0xd2e8
movq %rax, 0xadb9(%rip)      # 0xd2e0
callq 0x2f8a
pushq $0x1
popq %rdi
callq 0x2f56
movq 0xae3d(%rip), %rdi      # 0xd378
movq %rdi, 0xae2e(%rip)      # 0xd370
movl 0xace0(%rip), %edx      # 0xd228
testl %edx, %edx
jne 0x25f6
leaq 0x515b(%rip), %rsi      # 0x76b2
leaq 0x8920(%rip), %rdx      # 0xae7e
leaq 0x8903(%rip), %rcx      # 0xae68
leaq 0x890b(%rip), %r8       # 0xae77
xorl %eax, %eax
callq 0x2120
cmpb $0x0, 0x8c1b(%rip)      # 0xb195
je 0x2581
callq 0x2fbd
cmpb $0x0, 0x8c0b(%rip)      # 0xb193
je 0x258f
callq 0x3142
cmpb $0x0, 0x8c00(%rip)      # 0xb196
je 0x259d
callq 0x328e
movq 0xad3c(%rip), %rdi      # 0xd2e0
callq 0x20a0
movq 0xadc0(%rip), %rdi      # 0xd370
callq 0x20a0
movq 0xac64(%rip), %rdi      # 0xd220
callq 0x20a0
movl 0xac61(%rip), %ecx      # 0xd228
movl 0xac87(%rip), %eax      # 0xd254
orl %ecx, %eax
jne 0x25e3
leaq 0xabc8(%rip), %rdi      # 0xd1a0
callq 0x2060
movl 0xac45(%rip), %ecx      # 0xd228
xorl %eax, %eax
testl %ecx, %ecx
setne %al
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r14
popq %r15
retq
movq 0xac23(%rip), %rdi      # 0xd220
cmpl $0x1, %edx
leaq 0x886a(%rip), %r12      # 0xae71
leaq 0x8869(%rip), %rbx      # 0xae77
movq %rbx, %r8
cmoveq %r12, %r8
leaq 0x50a7(%rip), %r15      # 0x76c3
leaq 0x8845(%rip), %r14      # 0xae68
movq %r15, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2120
movq 0xad39(%rip), %rdi      # 0xd370
movl 0xabeb(%rip), %edx      # 0xd228
cmpl $0x1, %edx
movq %rbx, %r8
cmoveq %r12, %r8
movq %r15, %rsi
movq %r14, %rcx
xorl %eax, %eax
callq 0x2120
movq 0x799d(%rip), %rax      # 0x9ff8
movq (%rax), %rdi
movl 0xabc4(%rip), %edx      # 0xd228
cmpl $0x1, %edx
cmoveq %r12, %rbx
leaq 0x5052(%rip), %rsi      # 0x76c4
movq %r14, %rcx
movq %rbx, %r8
xorl %eax, %eax
callq 0x2120
jmp 0x2573
movq 0x796d(%rip), %rax      # 0x9ff8
movq (%rax), %rcx
leaq 0x4fed(%rip), %rdi      # 0x7682
pushq $0x2c
popq %rsi
pushq $0x1
popq %rdx
callq 0x2180
pushq $-0x1
popq %rdi
callq 0x2170