// File: /workspace/github_c_makefile_star2_O0/Edilbert[P]BS9/bs9.c
// Function: EvalOperand
char *EvalOperand(char *p, int *v, int prio)
{
   int  i;    // loop index
   int  l;    // length of string
   int  o;    // priority of operator
   int  r;    // return value
   int  w;    // value of right operand
   char c;    // current character

   r = UNDEF; // preset result to UNDEF

   p = SkipSpace(p);
   c = *p;
   if (df) fprintf(df,"Eval <%s>",p);

   if (c == ',' )  return p; // comma separator

   // Start parsing unary operators
   // PC represents the current program counter

   if (*p && strchr("[(+-!~<>*&$'\"%?",*p))
   {
      for (i=0 ; i < UNAOPS ; ++i)
      if (*p == unaop[i].op)
      {
          p = unaop[i].foo(p,&r);
          break;
      }
   }
   else if (isdigit(c)) p = EvalDecValue(p,&r);    // decimal constant
   else if (isym(c))    p = EvalSymValue(p,&r);    // symbol or label
   else
   {
      ErrorLine(p);
      ErrorMsg("Illegal operand\n");
      exit(1);
   }

   // Left operand has been parsed successfully
   // now look for binary operators
   //  r is left  operand
   //  w is right operand

   // the left or right operand may be UNDEFINED in phase 1
   // in that case do not perform the operation, just parse

   if (CodeStyle == 1 && *p == ' ')
   {
      *v = r;
      p += strlen(p);
      if (df) fprintf(df,"Result: %4x %d\n",r,r);
      return p;
   }
   p = SkipSpace(p);

   while (*p && strchr("*/+-<>=!&^|",*p))
   {
      // loop through all binary operators

      for (i=0 ; i < BINOPS ; ++i)
      {
         l = strlen((binop[i].op));
         if (!strncmp(p,binop[i].op,l))
         {
            if ((o = binop[i].prio) <= prio)
            {
               *v = r;
               if (CodeStyle == 1 && *p == ' ') p += strlen(p);
               if (df) fprintf(df,"Result: %4x %d\n",r,r);
               return p;
            }
            p = EvalOperand(p+l,&w,o);
            if (w == UNDEF) r = UNDEF;
            else r = binop[i].foo(r,w);
            break;
         }
      }
      if (i == BINOPS)  // no valid operator
      {
         ErrorMsg("Syntax error: binary operator expected\n");
         ErrorLine(p);
         exit(1);
      }
   }
   *v = r;
   if (CodeStyle == 1 && *p == ' ') p += strlen(p);
   if (df)
   {
      fprintf(df," -> %4x %d",r,r);
      if (*p) fprintf(df,"  Rest:%s\n",p);
      else    fprintf(df,"\n");
   }
   return p;
}

// Assembly:
subq $0x38, %rsp
movq %rdi, 0x28(%rsp)
movq %rsi, 0x20(%rsp)
movl %edx, 0x1c(%rsp)
movl $0xff0000, 0xc(%rsp)    # imm = 0xFF0000
movq 0x28(%rsp), %rdi
callq 0x2830
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movb (%rax), %al
movb %al, 0x7(%rsp)
cmpq $0x0, 0x24274(%rip)     # 0x289f0
je 0x4798
movq 0x2426b(%rip), %rdi     # 0x289f0
movq 0x28(%rsp), %rdx
leaq 0xbcf3(%rip), %rsi      # 0x10484
movb $0x0, %al
callq 0x21e0
movsbl 0x7(%rsp), %eax
cmpl $0x2c, %eax
jne 0x47b1
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x4ba9
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x0, %eax
je 0x4848
movq 0x28(%rsp), %rax
movsbl (%rax), %esi
leaq 0xbcbd(%rip), %rdi      # 0x1048e
callq 0x2100
cmpq $0x0, %rax
je 0x4848
movl $0x0, 0x18(%rsp)
cmpl $0xf, 0x18(%rsp)
jge 0x4846
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
movslq 0x18(%rsp), %rdx
leaq 0x12f61(%rip), %rcx     # 0x17760
shlq $0x4, %rdx
addq %rdx, %rcx
movsbl (%rcx), %ecx
cmpl %ecx, %eax
jne 0x4837
movslq 0x18(%rsp), %rcx
leaq 0x12f47(%rip), %rax     # 0x17760
shlq $0x4, %rcx
addq %rcx, %rax
movq 0x8(%rax), %rax
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq *%rax
movq %rax, 0x28(%rsp)
jmp 0x4846
jmp 0x4839
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x47e4
jmp 0x48c7
callq 0x22e0
movq (%rax), %rax
movsbl 0x7(%rsp), %ecx
movslq %ecx, %rcx
movzwl (%rax,%rcx,2), %eax
andl $0x800, %eax            # imm = 0x800
cmpl $0x0, %eax
je 0x487c
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x5670
movq %rax, 0x28(%rsp)
jmp 0x48c5
movsbl 0x7(%rsp), %edi
callq 0x2a30
cmpl $0x0, %eax
je 0x48a1
movq 0x28(%rsp), %rdi
leaq 0xc(%rsp), %rsi
callq 0x4cd0
movq %rax, 0x28(%rsp)
jmp 0x48c3
movq 0x28(%rsp), %rdi
callq 0x3040
leaq 0xbbec(%rip), %rdi      # 0x1049e
movb $0x0, %al
callq 0x3150
movl $0x1, %edi
callq 0x22b0
jmp 0x48c5
jmp 0x48c7
cmpl $0x1, 0x83666(%rip)     # 0x87f34
jne 0x4932
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x4932
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
movq 0x28(%rsp), %rdi
callq 0x20f0
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x240ec(%rip)     # 0x289f0
je 0x4923
movq 0x240e3(%rip), %rdi     # 0x289f0
movl 0xc(%rsp), %edx
movl 0xc(%rsp), %ecx
leaq 0xbb93(%rip), %rsi      # 0x104af
movb $0x0, %al
callq 0x21e0
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x4ba9
movq 0x28(%rsp), %rdi
callq 0x2830
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
movsbl (%rax), %ecx
xorl %eax, %eax
cmpl $0x0, %ecx
movb %al, 0x6(%rsp)
je 0x4973
movq 0x28(%rsp), %rax
movsbl (%rax), %esi
leaq 0xbb5c(%rip), %rdi      # 0x104bf
callq 0x2100
cmpq $0x0, %rax
setne %al
movb %al, 0x6(%rsp)
movb 0x6(%rsp), %al
testb $0x1, %al
jne 0x4980
jmp 0x4b06
movl $0x0, 0x18(%rsp)
cmpl $0x11, 0x18(%rsp)
jge 0x4ad8
movslq 0x18(%rsp), %rcx
leaq 0x12eb1(%rip), %rax     # 0x17850
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rdi
callq 0x20f0
movl %eax, 0x14(%rsp)
movq 0x28(%rsp), %rdi
movslq 0x18(%rsp), %rcx
leaq 0x12e8d(%rip), %rax     # 0x17850
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq (%rax), %rsi
movslq 0x14(%rsp), %rdx
callq 0x2060
cmpl $0x0, %eax
jne 0x4ac6
movslq 0x18(%rsp), %rcx
leaq 0x12e64(%rip), %rax     # 0x17850
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movl 0x8(%rax), %eax
movl %eax, 0x10(%rsp)
cmpl 0x1c(%rsp), %eax
jg 0x4a6b
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
cmpl $0x1, 0x83522(%rip)     # 0x87f34
jne 0x4a35
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x4a35
movq 0x28(%rsp), %rdi
callq 0x20f0
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x23fb3(%rip)     # 0x289f0
je 0x4a5c
movq 0x23faa(%rip), %rdi     # 0x289f0
movl 0xc(%rsp), %edx
movl 0xc(%rsp), %ecx
leaq 0xba5a(%rip), %rsi      # 0x104af
movb $0x0, %al
callq 0x21e0
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
jmp 0x4ba9
movq 0x28(%rsp), %rdi
movslq 0x14(%rsp), %rax
addq %rax, %rdi
movl 0x10(%rsp), %edx
leaq 0x8(%rsp), %rsi
callq 0x4740
movq %rax, 0x28(%rsp)
cmpl $0xff0000, 0x8(%rsp)    # imm = 0xFF0000
jne 0x4a9f
movl $0xff0000, 0xc(%rsp)    # imm = 0xFF0000
jmp 0x4ac4
movslq 0x18(%rsp), %rcx
leaq 0x12da5(%rip), %rax     # 0x17850
imulq $0x18, %rcx, %rcx
addq %rcx, %rax
movq 0x10(%rax), %rax
movl 0xc(%rsp), %edi
movl 0x8(%rsp), %esi
callq *%rax
movl %eax, 0xc(%rsp)
jmp 0x4ad8
jmp 0x4ac8
movl 0x18(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x18(%rsp)
jmp 0x4988
cmpl $0x11, 0x18(%rsp)
jne 0x4b01
leaq 0xb9e5(%rip), %rdi      # 0x104cb
movb $0x0, %al
callq 0x3150
movq 0x28(%rsp), %rdi
callq 0x3040
movl $0x1, %edi
callq 0x22b0
jmp 0x4941
movl 0xc(%rsp), %ecx
movq 0x20(%rsp), %rax
movl %ecx, (%rax)
cmpl $0x1, 0x8341c(%rip)     # 0x87f34
jne 0x4b3b
movq 0x28(%rsp), %rax
movsbl (%rax), %eax
cmpl $0x20, %eax
jne 0x4b3b
movq 0x28(%rsp), %rdi
callq 0x20f0
addq 0x28(%rsp), %rax
movq %rax, 0x28(%rsp)
cmpq $0x0, 0x23ead(%rip)     # 0x289f0
je 0x4b9f
movq 0x23ea4(%rip), %rdi     # 0x289f0
movl 0xc(%rsp), %edx
movl 0xc(%rsp), %ecx
leaq 0xb998(%rip), %rsi      # 0x104f3
movb $0x0, %al
callq 0x21e0
movq 0x28(%rsp), %rax
cmpb $0x0, (%rax)
je 0x4b88
movq 0x23e7d(%rip), %rdi     # 0x289f0
movq 0x28(%rsp), %rdx
leaq 0xb97f(%rip), %rsi      # 0x104fe
movb $0x0, %al
callq 0x21e0
jmp 0x4b9d
movq 0x23e61(%rip), %rdi     # 0x289f0
leaq 0xd13b(%rip), %rsi      # 0x11cd1
movb $0x0, %al
callq 0x21e0
jmp 0x4b9f
movq 0x28(%rsp), %rax
movq %rax, 0x30(%rsp)
movq 0x30(%rsp), %rax
addq $0x38, %rsp
retq
nopw %cs:(%rax,%rax)