// File: /workspace/github_c_makefile_star2_O3/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 0x7a7b3(%rip), %rdi     # 0x85460
leaq 0x2abe(%rip), %rdx      # 0xd772
movl $0x50, %esi
movq %rax, %rcx
callq 0x2290
cmpl $0x2, %ebp
jl 0xb432
movl $0x1, %r15d
xorl %r14d, %r14d
leaq 0x4(%rsp), %r12
movslq %r15d, %rcx
movq (%rbx,%rcx,8), %rdi
movb (%rdi), %al
cmpb $0x2d, %al
jne 0xae9c
cmpb $0x78, 0x1(%rdi)
jne 0xacf9
cmpb $0x0, 0x2(%rdi)
je 0xad91
cmpb $0x64, 0x1(%rdi)
jne 0xad09
cmpb $0x0, 0x2(%rdi)
je 0xada0
cmpb $0x69, 0x1(%rdi)
jne 0xad19
cmpb $0x0, 0x2(%rdi)
je 0xadaf
cmpb $0x6d, 0x1(%rdi)
jne 0xad29
cmpb $0x0, 0x2(%rdi)
je 0xadbe
cmpb $0x6e, 0x1(%rdi)
jne 0xad39
cmpb $0x0, 0x2(%rdi)
je 0xadcd
cmpb $0x6f, 0x1(%rdi)
jne 0xad49
cmpb $0x0, 0x2(%rdi)
je 0xadf8
cmpb $0x79, 0x1(%rdi)
jne 0xad59
cmpb $0x0, 0x2(%rdi)
je 0xae07
cmpb $0x70, 0x1(%rdi)
jne 0xad69
cmpb $0x0, 0x2(%rdi)
je 0xae16
cmpb $0x71, 0x1(%rdi)
jne 0xad79
cmpb $0x0, 0x2(%rdi)
je 0xaec8
cmpb $0x49, 0x1(%rdi)
jne 0xaddc
incl %r15d
movq 0x8(%rbx,%rcx,8), %rdi
callq 0xac4c
jmp 0xaeba
movl $0x1, 0x19fb5(%rip)     # 0x24d50
jmp 0xaeba
movl $0x1, 0x19faa(%rip)     # 0x24d54
jmp 0xaeba
movl $0x1, 0x1ac6f(%rip)     # 0x25a28
jmp 0xaeba
movl $0x1, 0x7a18c(%rip)     # 0x84f54
jmp 0xaeba
movl $0x1, 0x19f85(%rip)     # 0x24d5c
jmp 0xaeba
cmpb $0x44, 0x1(%rdi)
jne 0xae25
addq $0x2, %rdi
movq %r12, %rsi
movl $0x44, %edx
callq 0x3852
jmp 0xaeba
movl $0x1, 0x7d2ae(%rip)     # 0x880b0
jmp 0xaeba
movl $0x1, 0x991b(%rip)      # 0x1472c
jmp 0xaeba
movl $0x1, 0x19f44(%rip)     # 0x24d64
jmp 0xaeba
cmpb $0x6c, 0x1(%rdi)
jne 0xae9c
incl %r15d
cmpl %ebp, %r15d
je 0xb49a
callq 0x2070
movq %rax, %r13
movl $0x0, (%rax)
movslq %r15d, %r12
movq (%rbx,%r12,8), %rdi
leaq 0x8(%rsp), %rsi
xorl %edx, %edx
callq 0x2240
movl %eax, 0x7a65a(%rip)     # 0x854b8
cmpl $0x0, (%r13)
jne 0xb48f
movq 0x8(%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0xb48f
cmpl $0x100, %eax            # imm = 0x100
jae 0xb48f
movl $0x10100, %edx          # imm = 0x10100
leaq 0x9dc2(%rip), %rdi      # 0x14c50
movl %eax, %esi
callq 0x2180
leaq 0x4(%rsp), %r12
jmp 0xaeba
testq %r14, %r14
jne 0xb42d
cmpb $0x30, %al
setge %cl
cmpb $0x2e, %al
sete %al
orb %cl, %al
movq %rdi, %r14
je 0xb42d
incl %r15d
cmpl %ebp, %r15d
jl 0xacd8
jmp 0xaed4
movl $0x1, 0x19e96(%rip)     # 0x24d68
jmp 0xaeba
testq %r14, %r14
je 0xb432
movq %r14, %rdi
callq 0x2110
movq %rax, %rbx
cmpl $0xfd, %ebx
jge 0xb443
cmpl $0x5, %ebx
jl 0xaf1d
leal -0x4(%rbx), %r15d
cmpb $0x2e, (%r14,%r15)
jne 0xaf1d
movq %r14, %rdi
movl %ebx, %esi
callq 0x2878
movq %rax, %r14
movq %rax, 0x7d1a0(%rip)     # 0x880b8
movl %r15d, %ebx
jmp 0xaf40
leal 0x4(%rbx), %esi
movq %r14, %rdi
callq 0x2878
movq %rax, 0x7d189(%rip)     # 0x880b8
movslq %ebx, %rcx
movl $0x3973612e, (%rax,%rcx) # imm = 0x3973612E
movq 0x7d178(%rip), %r14     # 0x880b8
movslq %ebx, %rbx
leaq 0x7d176(%rip), %r15     # 0x880c0
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d261(%rip), %r12     # 0x881c0
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d34c(%rip), %r13     # 0x882c0
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, 0x19dc2(%rip)     # 0x24d68
jne 0xb037
movl $0xa, %edi
callq 0x2050
leaq 0x2d1b(%rip), %rdi      # 0xdcd8
callq 0x20a0
leaq 0x2cb7(%rip), %rdi      # 0xdc80
callq 0x20a0
leaq 0x27f7(%rip), %rdi      # 0xd7cc
leaq 0x7a484(%rip), %rsi     # 0x85460
xorl %eax, %eax
callq 0x2130
leaq 0x2cc2(%rip), %rdi      # 0xdcac
callq 0x20a0
movq 0x7d0c2(%rip), %rsi     # 0x880b8
leaq 0x27f3(%rip), %rdi      # 0xd7f0
xorl %eax, %eax
callq 0x2130
leaq 0x27fb(%rip), %rdi      # 0xd806
leaq 0x7d1ae(%rip), %rsi     # 0x881c0
xorl %eax, %eax
callq 0x2130
cmpb $0x0, 0x7a160(%rip)     # 0x85180
je 0xb037
leaq 0x27f3(%rip), %rdi      # 0xd81c
leaq 0x7a150(%rip), %rsi     # 0x85180
xorl %eax, %eax
callq 0x2130
movq 0x7d07a(%rip), %rdi     # 0x880b8
leaq 0x1cf5(%rip), %rsi      # 0xcd3a
callq 0x22b0
movq %rax, 0x7a127(%rip)     # 0x85178
testq %rax, %rax
je 0xb448
movq %rax, 0x1a03f(%rip)     # 0x250a0
movq 0x7d050(%rip), %rax     # 0x880b8
movq %rax, 0x1a041(%rip)     # 0x250b0
leaq 0x7d14a(%rip), %rdi     # 0x881c0
leaq 0x27ca(%rip), %rsi      # 0xd847
callq 0x22b0
testq %rax, %rax
je 0xb467
movq %rax, 0x1a976(%rip)     # 0x25a08
cmpl $0x0, 0x19cbb(%rip)     # 0x24d54
je 0xb0be
leaq 0x27b6(%rip), %rdi      # 0xd858
leaq 0x279e(%rip), %rsi      # 0xd847
callq 0x22b0
testq %rax, %rax
je 0xb476
movq %rax, 0x1a952(%rip)     # 0x25a10
cmpl $0x0, 0x19c9f(%rip)     # 0x24d64
je 0xb0ea
leaq 0x7cff2(%rip), %rdi     # 0x880c0
leaq 0x2772(%rip), %rsi      # 0xd847
callq 0x22b0
testq %rax, %rax
je 0xb47b
movq %rax, 0x7c6ee(%rip)     # 0x877d8
cmpl $0x0, 0x963b(%rip)      # 0x1472c
je 0xb116
leaq 0x7d1c6(%rip), %rdi     # 0x882c0
leaq 0x2746(%rip), %rsi      # 0xd847
callq 0x22b0
testq %rax, %rax
je 0xb480
movq %rax, 0x7cf3a(%rip)     # 0x88050
movl $0x1, 0x1a8f8(%rip)     # 0x25a18
cmpl $0x0, 0x9609(%rip)      # 0x14730
jle 0xb197
leaq 0x276a(%rip), %rbx      # 0xd89a
leaq 0x278e(%rip), %r14      # 0xd8c5
callq 0x9e13
cmpl $0x0, 0x19c25(%rip)     # 0x24d68
jne 0xb172
movl 0x1a8cd(%rip), %esi     # 0x25a18
cmpl $0x1, %esi
jne 0xb162
movl 0x7c67a(%rip), %esi     # 0x877d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0xb172
movl 0x79ef8(%rip), %edx     # 0x85060
movq %r14, %rdi
xorl %eax, %eax
callq 0x2130
movl 0x1a8a0(%rip), %eax     # 0x25a18
cmpl $0x2, %eax
jl 0xb186
cmpl $0x0, 0x79edc(%rip)     # 0x85060
je 0xb197
leal 0x1(%rax), %ecx
movl %ecx, 0x1a889(%rip)     # 0x25a18
cmpl 0x959b(%rip), %eax      # 0x14730
jl 0xb137
movl $0x0, 0x1a877(%rip)     # 0x25a18
callq 0xa01d
callq 0xab2e
callq 0xa527
movslq 0x1a87d(%rip), %rsi     # 0x25a34
leaq 0x1a882(%rip), %rdi     # 0x25a40
leaq -0xc46(%rip), %rcx      # 0xa57f
movl $0x30, %edx
callq 0x20c0
cmpq $0x0, 0x7ce79(%rip)     # 0x88050
je 0xb1de
callq 0xa4aa
movq 0x1a823(%rip), %rdi     # 0x25a08
movl 0x1a849(%rip), %edx     # 0x25a34
leaq 0x26ff(%rip), %rsi      # 0xd8f1
xorl %eax, %eax
callq 0x2210
movq 0x1a808(%rip), %rcx     # 0x25a08
leaq 0x21d5(%rip), %rdi      # 0xd3dc
movl $0xe, %esi
movl $0x1, %edx
callq 0x2300
movq 0x1a7eb(%rip), %rdi     # 0x25a08
movl 0x1a811(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0xffff, %ecx           # imm = 0xFFFF
callq 0xa2dc
movslq 0x1a7fe(%rip), %rsi     # 0x25a34
leaq 0x1a803(%rip), %rdi     # 0x25a40
leaq -0xcb0(%rip), %rcx      # 0xa594
movl $0x30, %edx
callq 0x20c0
movq 0x1a7b3(%rip), %rdi     # 0x25a08
movl 0x1a7d9(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0xff, %ecx
callq 0xa2dc
movq 0x1a79a(%rip), %rdi     # 0x25a08
movl 0x1a7c0(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xa2dc
movq 0x79ef1(%rip), %rdi     # 0x85178
callq 0x2100
testl %eax, %eax
jne 0xb46c
movq 0x1a76d(%rip), %rdi     # 0x25a08
callq 0x2100
testl %eax, %eax
jne 0xb471
movq 0x7cda1(%rip), %rdi     # 0x88050
testq %rdi, %rdi
je 0xb2c1
callq 0x2100
testl %eax, %eax
jne 0xb485
movq 0x1a748(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0xb2da
callq 0x2100
testl %eax, %eax
jne 0xb48a
cmpl $0x0, 0x19a87(%rip)     # 0x24d68
jne 0xb3b2
cmpl $0x0, 0x19a66(%rip)     # 0x24d54
movq 0x9943(%rip), %rax      # 0x14c38
movq 0x9934(%rip), %r9       # 0x14c30
movq %r9, %rsi
cmoveq %rax, %rsi
cmpl $0x0, 0x1a71e(%rip)     # 0x25a28
movq %r9, %rdx
cmoveq %rax, %rdx
cmpl $0x0, 0x19a44(%rip)     # 0x24d5c
movq %r9, %rcx
cmoveq %rax, %rcx
cmpl $0x0, 0x7cd8a(%rip)     # 0x880b0
movq %r9, %r8
cmoveq %rax, %r8
cmpl $0x0, 0x19a1c(%rip)     # 0x24d50
cmoveq %rax, %r9
leaq 0x2606(%rip), %rdi      # 0xd945
xorl %eax, %eax
callq 0x2130
leaq 0x298b(%rip), %rdi      # 0xdcd8
callq 0x20a0
movl 0x19a08(%rip), %esi     # 0x24d60
leaq 0x260e(%rip), %rdi      # 0xd96d
xorl %eax, %eax
callq 0x2130
movl 0x1a6c8(%rip), %esi     # 0x25a34
leaq 0x2624(%rip), %rdi      # 0xd997
xorl %eax, %eax
callq 0x2130
movl 0x782c0(%rip), %esi     # 0x83640
leaq 0x263a(%rip), %rdi      # 0xd9c1
xorl %eax, %eax
callq 0x2130
movl 0x7a124(%rip), %esi     # 0x854b8
testl %esi, %esi
je 0xb3a6
leaq 0x264c(%rip), %rdi      # 0xd9eb
xorl %eax, %eax
callq 0x2130
leaq 0x292b(%rip), %rdi      # 0xdcd8
callq 0x20a0
movl 0x1a674(%rip), %esi     # 0x25a2c
testl %esi, %esi
je 0xb401
cmpl $0x1, %esi
leaq 0x2387(%rip), %rax      # 0xd74d
leaq 0x1011(%rip), %rdx      # 0xc3de
cmoveq %rax, %rdx
leaq 0x22de(%rip), %rcx      # 0xd6b6
cmovneq %rax, %rcx
leaq 0x2632(%rip), %rdi      # 0xda15
xorl %eax, %eax
callq 0x2130
cmpl $0x0, 0x19977(%rip)     # 0x24d68
jne 0xb40a
leaq 0x2936(%rip), %rdi      # 0xdd30
callq 0x20a0
jmp 0xb40a
cmpl $0x0, 0x19960(%rip)     # 0x24d68
je 0xb41f
movl 0x1a61c(%rip), %eax     # 0x25a2c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28de(%rip), %rdi      # 0xdd04
callq 0x20a0
jmp 0xb3ea
callq 0xab99
leaq 0x2814(%rip), %rdi      # 0xdc4d
callq 0x20a0
callq 0xab99
callq 0x261b
movq 0x7cc69(%rip), %rsi     # 0x880b8
leaq 0x23dc(%rip), %rdi      # 0xd832
xorl %eax, %eax
callq 0x2130
movl $0x1, %edi
callq 0x22f0
callq 0x2606
callq 0x25b2
callq 0x25c7
callq 0x2573
callq 0x2588
callq 0x259d
callq 0x25dc
callq 0x25f1
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2526
callq 0x254e