// File: /workspace/github_c_makefile_star2_O1/Edilbert[P]BS9/bs9.c
// Function: RecordMacro
void RecordMacro(char *p)
{
   char Macro[ML];
   int i,j,l,al,an,bl,mf;
   int ap[10];
   char args[ML];
   char Buf[ML];
   char *b;
   char *at;

   if (Macros > MAXMAC -2)
   {
      ++ErrNum;
      ErrorMsg("Too many macros (> %d)\n",MAXMAC);
      exit(1);
   }

   bl = 1;
   mf = strcmpword(p,"MACRO") != 0; // 1 : name MACRO
   if (!mf) p += 5;                 // 0 : MACRO name
   if (df) fprintf(df,"macro type = %d\n",mf);

   p = NextSymbol(p,Macro);
   l = strlen(Macro);
   if (mf) p = StrMatch(p,"MACRO") + 5;
   p = SkipSpace(p);

   if (df)
   {
      fprintf(df,"Macro name: <%s>\n",Macro);
      fprintf(df,"Arglist: <%s>\n",p);
   }

   if (*p == '(') ++p;
   if (mf) an = ScanArgs(p,args,ap);
   else    an = ScanArguments(p,args,ap,MAXARGS);
   if (df)
   {
      fprintf(df,"RecordMacro: %s(",Macro);
      for (i=0 ; i < an ; ++i)
      {
         at = args + ap[i];
         al = strlen(at);
         fprintf(df,"%s[%d]",at,al);
         if (i < an-1) fprintf(df,",");
      }
      fprintf(df,")\n");
   }
   j = MacroIndex(Macro);
   if (j < 0)  // create new entry in macro table
   {
      j = Macros;
      Mac[j].Name = (char *)StrNDup(Macro,l);
      Mac[j].Narg = an;
      Mac[j].Type = mf;
      fgets(Line,sizeof(Line),sf);
      while (!feof(sf) && !StrCaseStr(Line,"ENDM"))
      {
         ++LiNo;
         l = strlen(Line);
         if (l && Line[l-1] == 10) Line[--l] = 0; // Remove linefeed
         if (l && Line[l-1] == 13) Line[--l] = 0; // Remove return

         // parse line and substitute arguments

         p = Line;
         b = Buf;
         while (*p)
         {
            for (i=0 ; i < an ; ++i)
            {
               at = args + ap[i];
               al = strlen(at);
               if (al && !StrnCmp(p,at,al))
               {
                  *b++ = CHAMAC;
                  *b++ = '0' + i;
                  p += al;
                  break;
               }
            }
            if (i == an) *b++ = *p++;
         }
         *b++ = '\n';
         *b = 0;

         if (df)
         {
            fprintf(df,"MAC line  :%s\n",Line);
            fprintf(df,"MAC parsed:%s\n",Buf);
         }
         l = strlen(Buf);
         if (bl == 1)
         {
            bl = l+1;
            Mac[j].Body = (char *)StrNDup(Buf,l);
         }
         else
         {
            bl += l;
            Mac[j].Body = (char *)ReallocOrDie(Mac[j].Body,bl);
            strcat(Mac[j].Body,Buf);
         }
         fgets(Line,sizeof(Line),sf);
      }
      Macros++;
      if (df) fprintf(df,"finished macro %d\n",Macros);
   }
   else  // Skip macro
   {
      if (!Pass) PrintLiNo();
      ++LiNo;
      if (ListOn && !Pass) fprintf(lf,"            %s\n",Line);
      do
      {
         fgets(Line,sizeof(Line),sf);
         if (!Pass)
         {
            PrintLiNo();
            if (ListOn) fprintf(lf,"            %s",Line);
            if (pf) fprintf(pf,"%s",Line);
         }
         ++LiNo;
      } while (!feof(sf) && !StrCaseStr(Line,"ENDM"));
      LiNo-=2;
   }
   if (df) MacroInfo(j);
   ++LiNo;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x358, %rsp            # imm = 0x358
cmpl $0xc7, 0x7a886(%rip)    # 0x83640
jge 0x9339
movq %rdi, %r14
leaq 0x4685(%rip), %rsi      # 0xd44f
callq 0x2cc9
movl %eax, %ebx
xorl %eax, %eax
xorl %ebp, %ebp
testl %ebx, %ebx
sete %al
setne %bpl
leaq (%rax,%rax,4), %r15
addq %r14, %r15
movq 0x1cc24(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x8e01
leaq 0x465d(%rip), %rsi      # 0xd455
movl %ebp, %edx
xorl %eax, %eax
callq 0x2210
leaq 0x50(%rsp), %r12
movq %r15, %rdi
movq %r12, %rsi
callq 0x2baa
movq %rax, %r14
movq %r12, %rdi
callq 0x2110
movq %rax, %r15
testl %ebx, %ebx
je 0x8e39
leaq 0x4625(%rip), %rsi      # 0xd44f
movq %r14, %rdi
callq 0x2969
movq %rax, %r14
addq $0x5, %r14
cmpb $0x0, (%r14)
je 0x8e59
callq 0x2320
movq (%rax), %rax
decq %r14
movsbq 0x1(%r14), %rcx
incq %r14
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x8e4a
movq 0x1cbb0(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x8e90
leaq 0x45fa(%rip), %rsi      # 0xd466
leaq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x2210
movq 0x1cb91(%rip), %rdi     # 0x25a10
leaq 0x45f2(%rip), %rsi      # 0xd478
movq %r14, %rdx
xorl %eax, %eax
callq 0x2210
xorl %edi, %edi
cmpb $0x28, (%r14)
sete %dil
addq %r14, %rdi
leaq 0x150(%rsp), %rsi
leaq 0x20(%rsp), %rdx
testl %ebx, %ebx
je 0x8eb5
callq 0x8bb8
jmp 0x8ebf
movl $0xa, %ecx
callq 0x8a16
movl %eax, %r12d
movq 0x1cb47(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
movq %r12, 0x8(%rsp)
je 0x8f7d
movq %r15, (%rsp)
leaq 0x45a5(%rip), %rsi      # 0xd487
leaq 0x50(%rsp), %rdx
xorl %eax, %eax
callq 0x2210
testl %r12d, %r12d
jle 0x8f57
movq 0x8(%rsp), %rcx
leal -0x1(%rcx), %eax
movslq %eax, %r14
movl %ecx, %r13d
leaq 0x4590(%rip), %rbx      # 0xd498
xorl %r15d, %r15d
movslq 0x20(%rsp,%r15,4), %rax
leaq (%rsp,%rax), %r12
addq $0x150, %r12            # imm = 0x150
movq %r12, %rdi
callq 0x2110
movq 0x1cae6(%rip), %rdi     # 0x25a10
movq %rbx, %rsi
movq %r12, %rdx
movl %eax, %ecx
xorl %eax, %eax
callq 0x2210
cmpq %r14, %r15
jge 0x8f4f
movq 0x1cacb(%rip), %rsi     # 0x25a10
movl $0x2c, %edi
callq 0x21a0
incq %r15
cmpq %r15, %r13
jne 0x8f0b
movq 0x1cab2(%rip), %rcx     # 0x25a10
leaq 0x3603(%rip), %rdi      # 0xc568
movl $0x2, %esi
movl $0x1, %edx
callq 0x2300
movq 0x8(%rsp), %r12
movq (%rsp), %r15
leaq 0x50(%rsp), %rdi
callq 0x35ff
testl %eax, %eax
js 0x90b2
movl %eax, %ebx
cmpl $0x0, 0x1ca80(%rip)     # 0x25a18
jne 0x8fbe
cmpl $0x0, 0x1bdbb(%rip)     # 0x24d5c
je 0x8fbe
movq 0x1ca5e(%rip), %rdi     # 0x25a08
movl 0x1bda8(%rip), %edx     # 0x24d58
leaq 0x32c7(%rip), %rsi      # 0xc27e
xorl %eax, %eax
callq 0x2210
incl 0x1bd94(%rip)           # 0x24d58
cmpl $0x0, 0x91ed(%rip)      # 0x121b8
je 0x8ff2
cmpl $0x0, 0x1ca44(%rip)     # 0x25a18
jne 0x8ff2
movq 0x1ca2b(%rip), %rdi     # 0x25a08
leaq 0x32b5(%rip), %rsi      # 0xc299
leaq 0x1beb5(%rip), %rdx     # 0x24ea0
xorl %eax, %eax
callq 0x2210
leaq 0x1bea7(%rip), %r14     # 0x24ea0
leaq 0x3737(%rip), %r15      # 0xc737
leaq 0x3277(%rip), %r12      # 0xc27e
leaq 0x4491(%rip), %r13      # 0xd49f
movq 0x7c163(%rip), %rdx     # 0x85178
movq %r14, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x21c0
cmpl $0x0, 0x1c9ef(%rip)     # 0x25a18
jne 0x907c
cmpl $0x0, 0x1bd2a(%rip)     # 0x24d5c
je 0x904b
movq 0x1c9cd(%rip), %rdi     # 0x25a08
movl 0x1bd17(%rip), %edx     # 0x24d58
movq %r12, %rsi
xorl %eax, %eax
callq 0x2210
cmpl $0x0, 0x9166(%rip)      # 0x121b8
je 0x9068
movq 0x1c9ad(%rip), %rdi     # 0x25a08
movq %r15, %rsi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2210
movq 0x7e769(%rip), %rsi     # 0x877d8
testq %rsi, %rsi
je 0x907c
movq %r14, %rdi
callq 0x2170
incl 0x1bcd6(%rip)           # 0x24d58
movq 0x7c0ef(%rip), %rdi     # 0x85178
callq 0x2230
testl %eax, %eax
jne 0x90a6
movq %r14, %rdi
movq %r13, %rsi
callq 0x274e
testq %rax, %rax
je 0x900e
addl $-0x2, 0x1bcab(%rip)    # 0x24d58
jmp 0x9310
movslq 0x7a587(%rip), %rbx     # 0x83640
leaq 0x50(%rsp), %rdi
movl %r15d, %esi
callq 0x2878
movq %rbx, 0x18(%rsp)
shlq $0x5, %rbx
leaq 0x7a57a(%rip), %rcx     # 0x83650
movq %rax, (%rbx,%rcx)
movl %r12d, 0x10(%rbx,%rcx)
movq %rcx, 0x10(%rsp)
movl %ebp, 0x18(%rbx,%rcx)
movq 0x7c089(%rip), %rdx     # 0x85178
leaq 0x1bdaa(%rip), %r15     # 0x24ea0
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x21c0
movq 0x7c06e(%rip), %rdi     # 0x85178
callq 0x2230
testl %eax, %eax
jne 0x92e3
addq %rbx, 0x10(%rsp)
movl %r12d, %r13d
movl $0x1, (%rsp)
leaq 0x250(%rsp), %rbp
movq %r15, %rdi
leaq 0x4367(%rip), %rsi      # 0xd49f
callq 0x274e
testq %rax, %rax
jne 0x92e3
incl 0x1bc0c(%rip)           # 0x24d58
movq %r15, %rdi
callq 0x2110
testl %eax, %eax
je 0x9173
movl %eax, %ecx
decl %ecx
movslq %ecx, %rcx
cmpb $0xa, (%rcx,%r15)
jne 0x9175
cltq
movb $0x0, -0x1(%rax,%r15)
decq %rax
jmp 0x9175
xorl %eax, %eax
testl %eax, %eax
je 0x9189
cltq
cmpb $0xd, -0x1(%rax,%r15)
jne 0x9189
movb $0x0, -0x1(%rax,%r15)
cmpb $0x0, 0x1bd10(%rip)     # 0x24ea0
je 0x9216
leaq 0x250(%rsp), %rbp
leaq 0x1bcfb(%rip), %r15     # 0x24ea0
xorl %r14d, %r14d
testl %r12d, %r12d
jle 0x91ff
movslq 0x20(%rsp,%r14,4), %rax
leaq (%rsp,%rax), %rbx
addq $0x150, %rbx            # imm = 0x150
movq %rbx, %rdi
callq 0x2110
testl %eax, %eax
je 0x91de
movslq %eax, %r12
movq %r15, %rdi
movq %rbx, %rsi
movq %r12, %rdx
callq 0x356b
testl %eax, %eax
je 0x91e8
incq %r14
cmpq %r14, %r13
jne 0x91ad
jmp 0x91fa
movb $0x60, (%rbp)
leal 0x30(%r14), %eax
movb %al, 0x1(%rbp)
addq $0x2, %rbp
addq %r12, %r15
movq 0x8(%rsp), %r12
cmpl %r12d, %r14d
jne 0x9210
movb (%r15), %al
incq %r15
movb %al, (%rbp)
incq %rbp
cmpb $0x0, (%r15)
jne 0x91a5
movw $0xa, (%rbp)
movq 0x1c7ed(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
leaq 0x1bc73(%rip), %r15     # 0x24ea0
leaq 0x250(%rsp), %rbp
je 0x9260
leaq 0x4266(%rip), %rsi      # 0xd4a4
movq %r15, %rdx
xorl %eax, %eax
callq 0x2210
movq 0x1c7c1(%rip), %rdi     # 0x25a10
leaq 0x425d(%rip), %rsi      # 0xd4b3
movq %rbp, %rdx
xorl %eax, %eax
callq 0x2210
movq %rbp, %rdi
callq 0x2110
movl (%rsp), %ecx
cmpl $0x1, %ecx
jne 0x928b
leal 0x1(%rax), %ecx
movl %ecx, (%rsp)
movq %rbp, %rdi
movl %eax, %esi
callq 0x2878
movq 0x10(%rsp), %rcx
movq %rax, 0x8(%rcx)
jmp 0x92bb
addl %eax, %ecx
movq 0x10(%rsp), %r14
movq 0x8(%r14), %rdi
movl %ecx, (%rsp)
movslq %ecx, %rsi
callq 0x2280
movq %rax, %rbx
movq %rax, %rdi
callq 0x2834
movq %rbx, 0x8(%r14)
movq %rbx, %rdi
movq %rbp, %rsi
callq 0x22e0
movq 0x7beb6(%rip), %rdx     # 0x85178
movq %r15, %rdi
movl $0x100, %esi            # imm = 0x100
callq 0x21c0
movq 0x7bea2(%rip), %rdi     # 0x85178
callq 0x2230
testl %eax, %eax
je 0x912e
movl 0x7a357(%rip), %edx     # 0x83640
incl %edx
movl %edx, 0x7a34f(%rip)     # 0x83640
movq 0x1c718(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x930b
leaq 0x41be(%rip), %rsi      # 0xd4c2
xorl %eax, %eax
callq 0x2210
movq 0x18(%rsp), %rbx
cmpq $0x0, 0x1c6f8(%rip)     # 0x25a10
je 0x9321
movl %ebx, %edi
callq 0x8cc4
incl 0x1ba31(%rip)           # 0x24d58
addq $0x358, %rsp            # imm = 0x358
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
incl 0x1c6ed(%rip)           # 0x25a2c
leaq 0x40f1(%rip), %rdi      # 0xd437
movl $0xc8, %esi
xorl %eax, %eax
callq 0x2e63
movl $0x1, %edi
callq 0x22f0