// File: /workspace/github_c_makefile_star2_O2/Edilbert[P]BS9/bs9.c
// Function: main
int main(int argc, char *argv[])
{
   int ic,l,v;
   char *EndPtr;
   char *argsrc = NULL; // argument filename;
   time_t rawtime;
   struct tm * timeinfo;

   time (&rawtime);
   timeinfo = localtime (&rawtime);
   strftime (datebuffer,80,"%e-%b-%Y",timeinfo);

   for (ic=1 ; ic < argc ; ++ic)
   {
           if (!strcmp(argv[ic],"-x")) SkipHex    = 1;
      else if (!strcmp(argv[ic],"-d")) Debug      = 1;
      else if (!strcmp(argv[ic],"-i")) IgnoreCase = 1;
      else if (!strcmp(argv[ic],"-m")) CodeStyle  = 1;
      else if (!strcmp(argv[ic],"-n")) WithLiNo   = 1;
      else if (!strcmp(argv[ic],"-o")) Optimize   = 1;
      else if (!strcmp(argv[ic],"-y")) Symbols    = 1;
      else if (!strcmp(argv[ic],"-p")) Preprocess = 1;
      else if (!strcmp(argv[ic],"-q")) Quiet      = 1;
      else if (!strncmp(argv[ic],"-I",2)) DefineIncludePath(argv[++ic]);
      else if (!strncmp(argv[ic],"-D",2)) DefineLabel(argv[ic]+2,&v,'D');
      else if (!strncmp(argv[ic],"-l",2))
      {
         if (++ic == argc)
         {
            fprintf(stderr, "Missing value for -l\n");
            exit(1);
         }
         errno = 0;
         Preset = strtol(argv[ic], &EndPtr,0);
         if (errno != 0 || *EndPtr != '\0' || Preset < 0 || Preset > 0xff)
         {
            fprintf(stderr, "Illegal value '%s' for -l\n",argv[ic]);
            exit(1);
         }
         memset(ROM,Preset,sizeof(ROM));
      }
      else if (argsrc == NULL && (argv[ic][0] >= '0' || argv[ic][0] == '.'))
      {
         argsrc = argv[ic];
      }
      else
      {
         usage();
      }
   }
   if (!argsrc)
   {
      printf("*** missing filename for assembler source file ***\n");
      usage();
   }

   // default file names if only source file specified:
   // prog.as9   prog.pp   prog.lst   prog.opt

   l = strlen(argsrc);
   if (l > FNSIZE - 4)
   {
      fprintf(stderr,"\n*** filename too long ***\n");
      exit(1);
   }

   // check extension of form ".xxx"

   if (l > 4 && argsrc[l-4] == '.')
   {
      Src = (char *)StrNDup(argsrc,l);
      l -= 4; // length of basename
   }
   else
   {
      Src = StrNDup(argsrc,l+4);
      memmove(Src+l,".as9",4); // add default extension
   }

   // set static filenames

   memmove(Pre,Src,l);
   memmove(Lst,Src,l);
   memmove(Sym,Src,l);

   // add extensions

   memmove(Pre+l,".pp" ,3);
   memmove(Lst+l,".ls9",4);
   memmove(Sym+l,".sym",4);

   if (!Quiet)
   {
      printf("\n");
      printf("*******************************************\n");
      printf("* Bit Shift Assembler 21-Apr-2025         *\n");
      printf("* Today is            %s         *\n",datebuffer);
      printf("* --------------------------------------- *\n");
      printf("* Source: %-31.31s *\n",Src);
      printf("* List  : %-31.31s *\n",Lst);
      if (Ipa[0]) printf("* Incl. : %-31.31s *\n",Ipa);
   }

   sf = fopen(Src,"r");
   if (!sf)
   {
      printf("Could not open <%s>\n",Src);
      exit(1);
   }
   IncludeStack[0].fp = sf;
   IncludeStack[0].Src = Src;
                   lf = AssertFileOp(fopen(Lst,"w"), "Open list file");
   if (Debug)      df = AssertFileOp(fopen("Debug.lst","w"), "Open Debug file");
   if (Preprocess) pf = AssertFileOp(fopen(Pre,"w"), "Open preprocessor file");
   if (Symbols)    yf = AssertFileOp(fopen(Sym,"w"), "Open symbol file");

   for (Pass = 1 ; Pass <= MaxPass ; ++Pass)
   {
      Phase1();
      if (!Quiet)
      {
         if (Pass == 1) printf("* Pass 1: %5d Unresolved branches       *\n",Unresolved);
         else           printf("* Pass%2d: %5d Labels changed            *\n",Pass,Changes);
      }
      if (Pass > 1 && Changes == 0) break;
   }
   Pass = 0;
   Phase2();
   WriteBinaries();
   ListUndefinedSymbols();
   qsort(lab,Labels,sizeof(struct LabelStruct),CmpAddress);
   if (yf) PrintSymbols();
   fprintf(lf,"\n\n%5d Symbols\n",Labels);
   fprintf(lf,"-------------\n");
   ListSymbols(lf,Labels,0,0xffff);
   qsort(lab,Labels,sizeof(struct LabelStruct),CmpRefs);
   ListSymbols(lf,Labels,0,0xff);
   ListSymbols(lf,Labels,0,0x4000);
   if (fclose(sf)) AssertFileOp(NULL, "Close source file");
   if (fclose(lf)) AssertFileOp(NULL, "Close list file");
   if (yf) if (fclose(yf)) AssertFileOp(NULL, "Close symbol file");
   if (df) if (fclose(df)) AssertFileOp(NULL, "Close debug file");
   if (!Quiet)
   {
      printf("* -d:%s  -i:%s  -n:%s  -o:%s  -x:%s  *\n",
            Stat(Debug),Stat(IgnoreCase),Stat(WithLiNo),
            Stat(Optimize),Stat(SkipHex));
      printf("*******************************************\n");
      printf("* Source Lines: %6d                    *\n",TotalLiNo);
      printf("* Symbols     : %6d                    *\n",Labels);
      printf("* Macros      : %6d                    *\n",Macros);
      if (Preset)
      printf("* Preset      : %6d                    *\n",Preset);
      printf("*******************************************\n");
   }
   if (ErrNum)
      printf("* %3d ERROR%s occured%s                      *\n",
             ErrNum, ErrNum == 1 ? "" : "S", ErrNum == 1 ? " " : "");
   else if (!Quiet) printf("* OK, no errors                           *\n");
   if (!Quiet) printf("*******************************************\n\n");
   // MneStat();
   return ErrNum;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
movl %edi, %ebp
leaq 0x10(%rsp), %r14
movq %r14, %rdi
callq 0x2260
movq %r14, %rdi
callq 0x2060
leaq 0x7a988(%rip), %rdi     # 0x84460
leaq 0x2c23(%rip), %rdx      # 0xc702
pushq $0x50
popq %rsi
movq %rax, %rcx
callq 0x2290
pushq $0x1
popq %r14
xorl %r12d, %r12d
leaq 0x4(%rsp), %r15
pushq $0x44
popq %r13
cmpl %ebp, %r14d
jge 0x9cfd
movslq %r14d, %rcx
movq (%rbx,%rcx,8), %rdi
movb (%rdi), %al
cmpb $0x2d, %al
jne 0x9cc9
cmpb $0x78, 0x1(%rdi)
jne 0x9b24
cmpb $0x0, 0x2(%rdi)
je 0x9bbc
cmpb $0x64, 0x1(%rdi)
jne 0x9b34
cmpb $0x0, 0x2(%rdi)
je 0x9bcb
cmpb $0x69, 0x1(%rdi)
jne 0x9b44
cmpb $0x0, 0x2(%rdi)
je 0x9bda
cmpb $0x6d, 0x1(%rdi)
jne 0x9b54
cmpb $0x0, 0x2(%rdi)
je 0x9be9
cmpb $0x6e, 0x1(%rdi)
jne 0x9b64
cmpb $0x0, 0x2(%rdi)
je 0x9bf8
cmpb $0x6f, 0x1(%rdi)
jne 0x9b74
cmpb $0x0, 0x2(%rdi)
je 0x9c21
cmpb $0x79, 0x1(%rdi)
jne 0x9b84
cmpb $0x0, 0x2(%rdi)
je 0x9c30
cmpb $0x70, 0x1(%rdi)
jne 0x9b94
cmpb $0x0, 0x2(%rdi)
je 0x9c3f
cmpb $0x71, 0x1(%rdi)
jne 0x9ba4
cmpb $0x0, 0x2(%rdi)
je 0x9ce5
cmpb $0x49, 0x1(%rdi)
jne 0x9c07
incl %r14d
movq 0x8(%rbx,%rcx,8), %rdi
callq 0x9a77
jmp 0x9cef
movl $0x1, 0x1a18a(%rip)     # 0x23d50
jmp 0x9cef
movl $0x1, 0x1a17f(%rip)     # 0x23d54
jmp 0x9cef
movl $0x1, 0x1ae44(%rip)     # 0x24a28
jmp 0x9cef
movl $0x1, 0x7a361(%rip)     # 0x83f54
jmp 0x9cef
movl $0x1, 0x1a15a(%rip)     # 0x23d5c
jmp 0x9cef
cmpb $0x44, 0x1(%rdi)
jne 0x9c4e
addq $0x2, %rdi
movq %r15, %rsi
movl %r13d, %edx
callq 0x32ce
jmp 0x9cef
movl $0x1, 0x7d485(%rip)     # 0x870b0
jmp 0x9cef
movl $0x1, 0x9af2(%rip)      # 0x1372c
jmp 0x9cef
movl $0x1, 0x1a11b(%rip)     # 0x23d64
jmp 0x9cef
cmpb $0x6c, 0x1(%rdi)
jne 0x9cc9
incl %r14d
cmpl %ebp, %r14d
je 0xa2e5
callq 0x2070
movq %rax, %r13
andl $0x0, (%rax)
movslq %r14d, %r15
movq (%rbx,%r15,8), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x2240
movl %eax, 0x7a834(%rip)     # 0x844b8
cmpl $0x0, (%r13)
jne 0xa2c7
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0xa2c7
cmpl $0x100, %eax            # imm = 0x100
jae 0xa2c7
movl $0x10100, %edx          # imm = 0x10100
leaq 0x9f9c(%rip), %rdi      # 0x13c50
movl %eax, %esi
callq 0x2180
movq %r12, %rdi
leaq 0x4(%rsp), %r15
pushq $0x44
popq %r13
jmp 0x9cf2
testq %r12, %r12
jne 0xa285
cmpb $0x30, %al
setge %cl
cmpb $0x2e, %al
sete %al
orb %cl, %al
jne 0x9cf2
jmp 0xa285
movl $0x1, 0x1a079(%rip)     # 0x23d68
movq %r12, %rdi
incl %r14d
movq %rdi, %r12
jmp 0x9afa
testq %r12, %r12
je 0xa28a
movq %r12, %rdi
callq 0x2110
movq %rax, %rbx
cmpl $0xfd, %ebx
jge 0xa29b
cmpl $0x5, %ebx
jl 0x9d46
leal -0x4(%rbx), %r15d
cmpb $0x2e, (%r12,%r15)
jne 0x9d46
movq %r12, %rdi
movl %ebx, %esi
callq 0x258f
movq %rax, %r14
movq %rax, 0x7d377(%rip)     # 0x870b8
movl %r15d, %ebx
jmp 0x9d69
leal 0x4(%rbx), %esi
movq %r12, %rdi
callq 0x258f
movq %rax, 0x7d360(%rip)     # 0x870b8
movslq %ebx, %rcx
movl $0x3973612e, (%rax,%rcx) # imm = 0x3973612E
movq 0x7d34f(%rip), %r14     # 0x870b8
movslq %ebx, %rbx
leaq 0x7d34d(%rip), %r15     # 0x870c0
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d438(%rip), %r12     # 0x871c0
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d523(%rip), %r13     # 0x872c0
movq %r13, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
movw $0x702e, (%rbx,%r15)    # imm = 0x702E
movb $0x70, 0x2(%rbx,%r15)
movl $0x39736c2e, (%rbx,%r12) # imm = 0x39736C2E
movl $0x6d79732e, (%rbx,%r13) # imm = 0x6D79732E
cmpl $0x0, 0x19f99(%rip)     # 0x23d68
jne 0x9e5e
pushq $0xa
popq %rdi
callq 0x2050
leaq 0x2e84(%rip), %rdi      # 0xcc68
callq 0x20a0
leaq 0x2e20(%rip), %rdi      # 0xcc10
callq 0x20a0
leaq 0x2960(%rip), %rdi      # 0xc75c
leaq 0x7a65d(%rip), %rsi     # 0x84460
xorl %eax, %eax
callq 0x2130
leaq 0x2e2b(%rip), %rdi      # 0xcc3c
callq 0x20a0
movq 0x7d29b(%rip), %rsi     # 0x870b8
leaq 0x295c(%rip), %rdi      # 0xc780
xorl %eax, %eax
callq 0x2130
leaq 0x2964(%rip), %rdi      # 0xc796
leaq 0x7d387(%rip), %rsi     # 0x871c0
xorl %eax, %eax
callq 0x2130
cmpb $0x0, 0x7a339(%rip)     # 0x84180
je 0x9e5e
leaq 0x295c(%rip), %rdi      # 0xc7ac
leaq 0x7a329(%rip), %rsi     # 0x84180
xorl %eax, %eax
callq 0x2130
movq 0x7d253(%rip), %rdi     # 0x870b8
leaq 0x1e5e(%rip), %rsi      # 0xbcca
callq 0x22b0
movq %rax, 0x7a300(%rip)     # 0x84178
testq %rax, %rax
je 0xa2b0
movq %rax, 0x1a218(%rip)     # 0x240a0
movq 0x7d229(%rip), %rax     # 0x870b8
movq %rax, 0x1a21a(%rip)     # 0x240b0
leaq 0x7d323(%rip), %rdi     # 0x871c0
leaq 0x2933(%rip), %rsi      # 0xc7d7
callq 0x22b0
movq %rax, %rbx
leaq 0x2926(%rip), %rsi      # 0xc7d9
movq %rax, %rdi
callq 0x2575
movq %rbx, 0x1ab46(%rip)     # 0x24a08
cmpl $0x0, 0x19e8b(%rip)     # 0x23d54
je 0x9ef7
leaq 0x2916(%rip), %rdi      # 0xc7e8
leaq 0x28fe(%rip), %rsi      # 0xc7d7
callq 0x22b0
movq %rax, %rbx
leaq 0x290a(%rip), %rsi      # 0xc7f2
movq %rax, %rdi
callq 0x2575
movq %rbx, 0x1ab19(%rip)     # 0x24a10
cmpl $0x0, 0x19e66(%rip)     # 0x23d64
je 0x9f2c
leaq 0x7d1b9(%rip), %rdi     # 0x870c0
leaq 0x28c9(%rip), %rsi      # 0xc7d7
callq 0x22b0
movq %rax, %rbx
leaq 0x28e5(%rip), %rsi      # 0xc802
movq %rax, %rdi
callq 0x2575
movq %rbx, 0x7c8ac(%rip)     # 0x867d8
cmpl $0x0, 0x97f9(%rip)      # 0x1372c
je 0x9f61
leaq 0x7d384(%rip), %rdi     # 0x872c0
leaq 0x2894(%rip), %rsi      # 0xc7d7
callq 0x22b0
movq %rax, %rbx
leaq 0x28c7(%rip), %rsi      # 0xc819
movq %rax, %rdi
callq 0x2575
movq %rbx, 0x7d0ef(%rip)     # 0x87050
pushq $0x1
popq %rax
leaq 0x28bf(%rip), %rbx      # 0xc82a
leaq 0x28e3(%rip), %r14      # 0xc855
movl %eax, 0x1aaa0(%rip)     # 0x24a18
cmpl 0x97b2(%rip), %eax      # 0x13730
jg 0x9fd2
callq 0x8da8
cmpl $0x0, 0x19ddc(%rip)     # 0x23d68
jne 0x9fbb
movl 0x1aa84(%rip), %esi     # 0x24a18
cmpl $0x1, %esi
jne 0x9fab
movl 0x7c831(%rip), %esi     # 0x867d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0x9fbb
movl 0x7a0af(%rip), %edx     # 0x84060
movq %r14, %rdi
xorl %eax, %eax
callq 0x2130
movl 0x1aa57(%rip), %ecx     # 0x24a18
leal 0x1(%rcx), %eax
cmpl $0x2, %ecx
jl 0x9f72
cmpl $0x0, 0x7a090(%rip)     # 0x84060
jne 0x9f72
andl $0x0, 0x1aa3f(%rip)     # 0x24a18
callq 0x8ef2
callq 0x9962
callq 0x92fe
movslq 0x1aa45(%rip), %rsi     # 0x24a34
leaq 0x1aa4a(%rip), %rdi     # 0x24a40
leaq -0xca9(%rip), %rcx      # 0x9354
pushq $0x30
popq %rdx
callq 0x20c0
cmpq $0x0, 0x7d043(%rip)     # 0x87050
je 0xa014
callq 0x9288
movq 0x1a9ed(%rip), %rdi     # 0x24a08
movl 0x1aa13(%rip), %edx     # 0x24a34
leaq 0x2859(%rip), %rsi      # 0xc881
xorl %eax, %eax
callq 0x2210
movq 0x1a9d2(%rip), %rcx     # 0x24a08
leaq 0x232f(%rip), %rdi      # 0xc36c
pushq $0xe
popq %rsi
pushq $0x1
popq %rdx
callq 0x2300
movq 0x1a9b9(%rip), %rdi     # 0x24a08
movl 0x1a9df(%rip), %esi     # 0x24a34
xorl %edx, %edx
movl $0xffff, %ecx           # imm = 0xFFFF
callq 0x90f9
movslq 0x1a9cc(%rip), %rsi     # 0x24a34
leaq 0x1a9d1(%rip), %rdi     # 0x24a40
leaq -0xd0d(%rip), %rcx      # 0x9369
pushq $0x30
popq %rdx
callq 0x20c0
movq 0x1a983(%rip), %rdi     # 0x24a08
movl 0x1a9a9(%rip), %esi     # 0x24a34
xorl %edx, %edx
movl $0xff, %ecx
callq 0x90f9
movq 0x1a96a(%rip), %rdi     # 0x24a08
movl 0x1a990(%rip), %esi     # 0x24a34
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0x90f9
movq 0x7a0c1(%rip), %rdi     # 0x84178
callq 0x2100
testl %eax, %eax
je 0xa0ce
leaq 0x27c9(%rip), %rsi      # 0xc890
xorl %edi, %edi
callq 0x2575
movq 0x1a933(%rip), %rdi     # 0x24a08
callq 0x2100
testl %eax, %eax
je 0xa0ec
leaq 0x27bd(%rip), %rsi      # 0xc8a2
xorl %edi, %edi
callq 0x2575
movq 0x7cf5d(%rip), %rdi     # 0x87050
testq %rdi, %rdi
je 0xa10f
callq 0x2100
testl %eax, %eax
je 0xa10f
leaq 0x27aa(%rip), %rsi      # 0xc8b2
xorl %edi, %edi
callq 0x2575
movq 0x1a8fa(%rip), %rdi     # 0x24a10
testq %rdi, %rdi
je 0xa132
callq 0x2100
testl %eax, %eax
je 0xa132
leaq 0x2799(%rip), %rsi      # 0xc8c4
xorl %edi, %edi
callq 0x2575
cmpl $0x0, 0x19c2f(%rip)     # 0x23d68
jne 0xa20a
cmpl $0x0, 0x19c0e(%rip)     # 0x23d54
movq 0x9aeb(%rip), %rax      # 0x13c38
movq 0x9adc(%rip), %r9       # 0x13c30
movq %r9, %rsi
cmoveq %rax, %rsi
cmpl $0x0, 0x1a8c6(%rip)     # 0x24a28
movq %r9, %rdx
cmoveq %rax, %rdx
cmpl $0x0, 0x19bec(%rip)     # 0x23d5c
movq %r9, %rcx
cmoveq %rax, %rcx
cmpl $0x0, 0x7cf32(%rip)     # 0x870b0
movq %r9, %r8
cmoveq %rax, %r8
cmpl $0x0, 0x19bc4(%rip)     # 0x23d50
cmoveq %rax, %r9
leaq 0x273e(%rip), %rdi      # 0xc8d5
xorl %eax, %eax
callq 0x2130
leaq 0x2ac3(%rip), %rdi      # 0xcc68
callq 0x20a0
movl 0x19bb0(%rip), %esi     # 0x23d60
leaq 0x2746(%rip), %rdi      # 0xc8fd
xorl %eax, %eax
callq 0x2130
movl 0x1a870(%rip), %esi     # 0x24a34
leaq 0x275c(%rip), %rdi      # 0xc927
xorl %eax, %eax
callq 0x2130
movl 0x78468(%rip), %esi     # 0x82640
leaq 0x2772(%rip), %rdi      # 0xc951
xorl %eax, %eax
callq 0x2130
movl 0x7a2cc(%rip), %esi     # 0x844b8
testl %esi, %esi
je 0xa1fe
leaq 0x2784(%rip), %rdi      # 0xc97b
xorl %eax, %eax
callq 0x2130
leaq 0x2a63(%rip), %rdi      # 0xcc68
callq 0x20a0
movl 0x1a81c(%rip), %esi     # 0x24a2c
testl %esi, %esi
je 0xa259
cmpl $0x1, %esi
leaq 0x24bf(%rip), %rax      # 0xc6dd
leaq 0x1149(%rip), %rdx      # 0xb36e
cmoveq %rax, %rdx
leaq 0x2416(%rip), %rcx      # 0xc646
cmovneq %rax, %rcx
leaq 0x276a(%rip), %rdi      # 0xc9a5
xorl %eax, %eax
callq 0x2130
cmpl $0x0, 0x19b1f(%rip)     # 0x23d68
jne 0xa262
leaq 0x2a6e(%rip), %rdi      # 0xccc0
callq 0x20a0
jmp 0xa262
cmpl $0x0, 0x19b08(%rip)     # 0x23d68
je 0xa277
movl 0x1a7c4(%rip), %eax     # 0x24a2c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2a16(%rip), %rdi      # 0xcc94
callq 0x20a0
jmp 0xa242
callq 0x99c6
leaq 0x294c(%rip), %rdi      # 0xcbdd
callq 0x20a0
callq 0x99c6
movq 0x6d56(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x2490(%rip), %rdi      # 0xc73c
pushq $0x1b
jmp 0xa2f8
movq 0x7ce01(%rip), %rsi     # 0x870b8
leaq 0x2504(%rip), %rdi      # 0xc7c2
xorl %eax, %eax
callq 0x2130
jmp 0xa301
movq 0x6d2a(%rip), %rax      # 0x10ff8
movq (%rax), %rdi
movq (%rbx,%r15,8), %rdx
leaq 0x2445(%rip), %rsi      # 0xc721
xorl %eax, %eax
callq 0x2210
jmp 0xa301
movq 0x6d0c(%rip), %rax      # 0x10ff8
movq (%rax), %rcx
leaq 0x2415(%rip), %rdi      # 0xc70b
pushq $0x15
popq %rsi
pushq $0x1
popq %rdx
callq 0x2300
pushq $0x1
popq %rdi
callq 0x22f0