// File: /workspace/github_c_makefile_star2_O1/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 0x7a872(%rip), %rdi     # 0x85460
leaq 0x2b97(%rip), %rdx      # 0xd78c
movl $0x50, %esi
movq %rax, %rcx
callq 0x2290
cmpl $0x2, %ebp
jl 0xae8b
movl $0x1, %r12d
xorl %r15d, %r15d
movslq %r12d, %r14
movq (%rbx,%r14,8), %r13
movq %r13, %rdi
leaq 0x2b70(%rip), %rsi      # 0xd795
callq 0x21f0
testl %eax, %eax
je 0xad62
movq %r13, %rdi
leaq 0x2b5c(%rip), %rsi      # 0xd798
callq 0x21f0
testl %eax, %eax
je 0xad71
movq %r13, %rdi
leaq 0x2b48(%rip), %rsi      # 0xd79b
callq 0x21f0
testl %eax, %eax
je 0xad80
movq %r13, %rdi
leaq 0x2b34(%rip), %rsi      # 0xd79e
callq 0x21f0
testl %eax, %eax
je 0xad8f
movq %r13, %rdi
leaq 0x2b20(%rip), %rsi      # 0xd7a1
callq 0x21f0
testl %eax, %eax
je 0xad9e
movq %r13, %rdi
leaq 0x2b0c(%rip), %rsi      # 0xd7a4
callq 0x21f0
testl %eax, %eax
je 0xadad
movq %r13, %rdi
leaq 0x2af8(%rip), %rsi      # 0xd7a7
callq 0x21f0
testl %eax, %eax
je 0xadbc
movq %r13, %rdi
leaq 0x2ae4(%rip), %rsi      # 0xd7aa
callq 0x21f0
testl %eax, %eax
je 0xadcb
movq %r13, %rdi
leaq 0x2ad0(%rip), %rsi      # 0xd7ad
callq 0x21f0
testl %eax, %eax
je 0xadda
movl $0x2, %edx
movq %r13, %rdi
leaq 0x2ab7(%rip), %rsi      # 0xd7b0
callq 0x2080
testl %eax, %eax
je 0xade9
movl $0x2, %edx
movq %r13, %rdi
leaq 0x2a9e(%rip), %rsi      # 0xd7b3
callq 0x2080
testl %eax, %eax
je 0xadf8
movl $0x2, %edx
movq %r13, %rdi
leaq 0x2a85(%rip), %rsi      # 0xd7b6
callq 0x2080
testl %eax, %eax
je 0xae10
testq %r15, %r15
jne 0xb440
movb (%r13), %al
cmpb $0x30, %al
setge %cl
cmpb $0x2e, %al
sete %al
orb %cl, %al
jne 0xae7a
jmp 0xb440
movl $0x1, 0x19fe4(%rip)     # 0x24d50
jmp 0xae77
movl $0x1, 0x19fd9(%rip)     # 0x24d54
jmp 0xae77
movl $0x1, 0x1ac9e(%rip)     # 0x25a28
jmp 0xae77
movl $0x1, 0x7a1bb(%rip)     # 0x84f54
jmp 0xae77
movl $0x1, 0x19fb4(%rip)     # 0x24d5c
jmp 0xae77
movl $0x1, 0x7d2f9(%rip)     # 0x880b0
jmp 0xae77
movl $0x1, 0x9966(%rip)      # 0x1472c
jmp 0xae77
movl $0x1, 0x19f8f(%rip)     # 0x24d64
jmp 0xae77
movl $0x1, 0x19f84(%rip)     # 0x24d68
jmp 0xae77
incl %r12d
movq 0x8(%rbx,%r14,8), %rdi
callq 0xab8d
jmp 0xae77
addq $0x2, %r13
movq %r13, %rdi
leaq 0xc(%rsp), %rsi
movl $0x44, %edx
callq 0x380d
jmp 0xae77
incl %r12d
cmpl %ebp, %r12d
je 0xb450
callq 0x2070
movq %rax, %r13
movl $0x0, (%rax)
movslq %r12d, %r14
movq (%rbx,%r14,8), %rdi
movq %rsp, %rsi
xorl %edx, %edx
callq 0x2240
movl %eax, 0x7a677(%rip)     # 0x854b8
cmpl $0x0, (%r13)
jne 0xb445
movq (%rsp), %rcx
cmpb $0x0, (%rcx)
jne 0xb445
cmpl $0x100, %eax            # imm = 0x100
jae 0xb445
movl $0x10100, %edx          # imm = 0x10100
leaq 0x9de0(%rip), %rdi      # 0x14c50
movl %eax, %esi
callq 0x2180
movq %r15, %r13
incl %r12d
movq %r13, %r15
cmpl %ebp, %r12d
jl 0xac14
jmp 0xae8e
xorl %r13d, %r13d
testq %r13, %r13
je 0xb3e3
movq %r13, %rdi
callq 0x2110
movq %rax, %rbx
cmpl $0xfd, %ebx
jge 0xb3f4
cmpl $0x5, %ebx
jl 0xaed5
leal -0x4(%rbx), %r14d
cmpb $0x2e, (%r13,%r14)
jne 0xaed5
movq %r13, %rdi
movl %ebx, %esi
callq 0x2878
movq %rax, 0x7d1e8(%rip)     # 0x880b8
movl %r14d, %ebx
jmp 0xaef1
leal 0x4(%rbx), %esi
movq %r13, %rdi
callq 0x2878
movq %rax, 0x7d1d1(%rip)     # 0x880b8
movslq %ebx, %rcx
movl $0x3973612e, (%rax,%rcx) # imm = 0x3973612E
movq 0x7d1c0(%rip), %r14     # 0x880b8
movslq %ebx, %rbx
leaq 0x7d1be(%rip), %r15     # 0x880c0
movq %r15, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d2a9(%rip), %r12     # 0x881c0
movq %r12, %rdi
movq %r14, %rsi
movq %rbx, %rdx
callq 0x22a0
leaq 0x7d394(%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, 0x19e0a(%rip)     # 0x24d68
jne 0xafef
movl $0xa, %edi
callq 0x2050
leaq 0x2da1(%rip), %rdi      # 0xdd16
callq 0x20a0
leaq 0x2d3d(%rip), %rdi      # 0xdcbe
callq 0x20a0
leaq 0x287d(%rip), %rdi      # 0xd80a
leaq 0x7a4cc(%rip), %rsi     # 0x85460
xorl %eax, %eax
callq 0x2130
leaq 0x2d48(%rip), %rdi      # 0xdcea
callq 0x20a0
movq 0x7d10a(%rip), %rsi     # 0x880b8
leaq 0x2879(%rip), %rdi      # 0xd82e
xorl %eax, %eax
callq 0x2130
leaq 0x2881(%rip), %rdi      # 0xd844
leaq 0x7d1f6(%rip), %rsi     # 0x881c0
xorl %eax, %eax
callq 0x2130
cmpb $0x0, 0x7a1a8(%rip)     # 0x85180
je 0xafef
leaq 0x2879(%rip), %rdi      # 0xd85a
leaq 0x7a198(%rip), %rsi     # 0x85180
xorl %eax, %eax
callq 0x2130
movq 0x7d0c2(%rip), %rdi     # 0x880b8
leaq 0x1d51(%rip), %rsi      # 0xcd4e
callq 0x22b0
movq %rax, 0x7a16f(%rip)     # 0x85178
testq %rax, %rax
je 0xb3f9
movq %rax, 0x1a087(%rip)     # 0x250a0
movq 0x7d098(%rip), %rax     # 0x880b8
movq %rax, 0x1a089(%rip)     # 0x250b0
leaq 0x7d192(%rip), %rdi     # 0x881c0
leaq 0x2850(%rip), %rsi      # 0xd885
callq 0x22b0
testq %rax, %rax
je 0xb418
movq %rax, 0x1a9be(%rip)     # 0x25a08
cmpl $0x0, 0x19d03(%rip)     # 0x24d54
je 0xb076
leaq 0x283c(%rip), %rdi      # 0xd896
leaq 0x2824(%rip), %rsi      # 0xd885
callq 0x22b0
testq %rax, %rax
je 0xb427
movq %rax, 0x1a99a(%rip)     # 0x25a10
cmpl $0x0, 0x19ce7(%rip)     # 0x24d64
je 0xb0a2
leaq 0x7d03a(%rip), %rdi     # 0x880c0
leaq 0x27f8(%rip), %rsi      # 0xd885
callq 0x22b0
testq %rax, %rax
je 0xb42c
movq %rax, 0x7c736(%rip)     # 0x877d8
cmpl $0x0, 0x9683(%rip)      # 0x1472c
je 0xb0ce
leaq 0x7d20e(%rip), %rdi     # 0x882c0
leaq 0x27cc(%rip), %rsi      # 0xd885
callq 0x22b0
testq %rax, %rax
je 0xb431
movq %rax, 0x7cf82(%rip)     # 0x88050
movl $0x1, 0x1a940(%rip)     # 0x25a18
cmpl $0x0, 0x9651(%rip)      # 0x14730
jle 0xb14f
leaq 0x27f0(%rip), %rbx      # 0xd8d8
leaq 0x2814(%rip), %r14      # 0xd903
callq 0x9d83
cmpl $0x0, 0x19c6d(%rip)     # 0x24d68
jne 0xb12a
movl 0x1a915(%rip), %esi     # 0x25a18
cmpl $0x1, %esi
jne 0xb11a
movl 0x7c6c2(%rip), %esi     # 0x877d0
movq %rbx, %rdi
xorl %eax, %eax
callq 0x2130
jmp 0xb12a
movl 0x79f40(%rip), %edx     # 0x85060
movq %r14, %rdi
xorl %eax, %eax
callq 0x2130
movl 0x1a8e8(%rip), %eax     # 0x25a18
cmpl $0x2, %eax
jl 0xb13e
cmpl $0x0, 0x79f24(%rip)     # 0x85060
je 0xb14f
leal 0x1(%rax), %ecx
movl %ecx, 0x1a8d1(%rip)     # 0x25a18
cmpl 0x95e3(%rip), %eax      # 0x14730
jl 0xb0ef
movl $0x0, 0x1a8bf(%rip)     # 0x25a18
callq 0x9f89
callq 0xaa6f
callq 0xa469
movslq 0x1a8c5(%rip), %rsi     # 0x25a34
leaq 0x1a8ca(%rip), %rdi     # 0x25a40
leaq -0xcbf(%rip), %rcx      # 0xa4be
movl $0x30, %edx
callq 0x20c0
cmpq $0x0, 0x7cec1(%rip)     # 0x88050
je 0xb196
callq 0xa3ed
movq 0x1a86b(%rip), %rdi     # 0x25a08
movl 0x1a891(%rip), %edx     # 0x25a34
leaq 0x2785(%rip), %rsi      # 0xd92f
xorl %eax, %eax
callq 0x2210
movq 0x1a850(%rip), %rcx     # 0x25a08
leaq 0x2231(%rip), %rdi      # 0xd3f0
movl $0xe, %esi
movl $0x1, %edx
callq 0x2300
movq 0x1a833(%rip), %rdi     # 0x25a08
movl 0x1a859(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0xffff, %ecx           # imm = 0xFFFF
callq 0xa237
movslq 0x1a846(%rip), %rsi     # 0x25a34
leaq 0x1a84b(%rip), %rdi     # 0x25a40
leaq -0xd29(%rip), %rcx      # 0xa4d3
movl $0x30, %edx
callq 0x20c0
movq 0x1a7fb(%rip), %rdi     # 0x25a08
movl 0x1a821(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0xff, %ecx
callq 0xa237
movq 0x1a7e2(%rip), %rdi     # 0x25a08
movl 0x1a808(%rip), %esi     # 0x25a34
xorl %edx, %edx
movl $0x4000, %ecx           # imm = 0x4000
callq 0xa237
movq 0x79f39(%rip), %rdi     # 0x85178
callq 0x2100
testl %eax, %eax
jne 0xb41d
movq 0x1a7b5(%rip), %rdi     # 0x25a08
callq 0x2100
testl %eax, %eax
jne 0xb422
movq 0x7cde9(%rip), %rdi     # 0x88050
testq %rdi, %rdi
je 0xb279
callq 0x2100
testl %eax, %eax
jne 0xb436
movq 0x1a790(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0xb292
callq 0x2100
testl %eax, %eax
jne 0xb43b
cmpl $0x0, 0x19acf(%rip)     # 0x24d68
jne 0xb36a
cmpl $0x0, 0x19aae(%rip)     # 0x24d54
movq 0x998b(%rip), %rax      # 0x14c38
movq 0x997c(%rip), %r9       # 0x14c30
movq %r9, %rsi
cmoveq %rax, %rsi
cmpl $0x0, 0x1a766(%rip)     # 0x25a28
movq %r9, %rdx
cmoveq %rax, %rdx
cmpl $0x0, 0x19a8c(%rip)     # 0x24d5c
movq %r9, %rcx
cmoveq %rax, %rcx
cmpl $0x0, 0x7cdd2(%rip)     # 0x880b0
movq %r9, %r8
cmoveq %rax, %r8
cmpl $0x0, 0x19a64(%rip)     # 0x24d50
cmoveq %rax, %r9
leaq 0x268c(%rip), %rdi      # 0xd983
xorl %eax, %eax
callq 0x2130
leaq 0x2a11(%rip), %rdi      # 0xdd16
callq 0x20a0
movl 0x19a50(%rip), %esi     # 0x24d60
leaq 0x2694(%rip), %rdi      # 0xd9ab
xorl %eax, %eax
callq 0x2130
movl 0x1a710(%rip), %esi     # 0x25a34
leaq 0x26aa(%rip), %rdi      # 0xd9d5
xorl %eax, %eax
callq 0x2130
movl 0x78308(%rip), %esi     # 0x83640
leaq 0x26c0(%rip), %rdi      # 0xd9ff
xorl %eax, %eax
callq 0x2130
movl 0x7a16c(%rip), %esi     # 0x854b8
testl %esi, %esi
je 0xb35e
leaq 0x26d2(%rip), %rdi      # 0xda29
xorl %eax, %eax
callq 0x2130
leaq 0x29b1(%rip), %rdi      # 0xdd16
callq 0x20a0
movl 0x1a6bc(%rip), %esi     # 0x25a2c
testl %esi, %esi
je 0xb3a4
cmpl $0x1, %esi
leaq 0x23e9(%rip), %rax      # 0xd767
leaq 0x106d(%rip), %rdx      # 0xc3f2
cmoveq %rax, %rdx
leaq 0x2340(%rip), %rcx      # 0xd6d0
cmovneq %rax, %rcx
leaq 0x26b8(%rip), %rdi      # 0xda53
xorl %eax, %eax
callq 0x2130
jmp 0xb3b9
cmpl $0x0, 0x199bd(%rip)     # 0x24d68
jne 0xb3b9
leaq 0x298e(%rip), %rdi      # 0xdd42
callq 0x20a0
cmpl $0x0, 0x199a8(%rip)     # 0x24d68
jne 0xb3ce
leaq 0x29a5(%rip), %rdi      # 0xdd6e
callq 0x20a0
movl 0x1a658(%rip), %eax     # 0x25a2c
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x28a1(%rip), %rdi      # 0xdc8b
callq 0x20a0
callq 0xaada
callq 0x261b
movq 0x7ccb8(%rip), %rsi     # 0x880b8
leaq 0x2469(%rip), %rdi      # 0xd870
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
callq 0xaada
movq %rbx, %rdi
movq %r14, %rsi
callq 0x2526
callq 0x254e