// File: /workspace/github_c_makefile_star2_O1/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:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x18, %rsp
movl %edx, 0x8(%rsp)
movq %rsi, %r12
movq %rdi, %r15
movl $0xff0000, 0x4(%rsp)    # imm = 0xFF0000
cmpb $0x0, (%rdi)
je 0x3de9
callq 0x2320
movq (%rax), %rax
decq %r15
movsbq 0x1(%r15), %rcx
incq %r15
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x3dda
movsbq (%r15), %rbx
movq 0x21c1c(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x3e0a
leaq 0x879b(%rip), %rsi      # 0xc59b
movq %r15, %rdx
xorl %eax, %eax
callq 0x2210
cmpb $0x2c, %bl
jne 0x3e24
movq %r15, %r14
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movsbl (%r15), %r14d
testl %r14d, %r14d
je 0x3e67
leaq 0x8771(%rip), %rdi      # 0xc5a5
movl $0x10, %edx
movl %r14d, %esi
callq 0x21b0
testq %rax, %rax
je 0x3e67
movl $0x8, %eax
leaq 0x1092e(%rip), %rcx     # 0x14780
cmpb -0x8(%rax,%rcx), %r14b
je 0x3eba
addq $0x10, %rax
cmpq $0xf8, %rax
jne 0x3e52
jmp 0x3ec8
callq 0x2320
movq (%rax), %rax
movzwl (%rax,%rbx,2), %eax
btl $0xb, %eax
jb 0x3eab
movzbl %bl, %ecx
addl $-0x24, %ecx
cmpl $0x3b, %ecx
ja 0x3e94
movabsq $0x800000000000401, %rdx # imm = 0x800000000000401
btq %rcx, %rdx
jb 0x3e9c
testb $0x8, %al
je 0x40b8
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x4169
jmp 0x3ec5
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x4756
jmp 0x3ec5
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq *(%rax,%rcx)
movq %rax, %r15
cmpl $0x1, 0x81085(%rip)     # 0x84f54
jne 0x3ef2
cmpb $0x20, (%r15)
jne 0x3ef2
movl 0x4(%rsp), %ebp
movl %ebp, (%r12)
movq %r15, %rdi
callq 0x2110
movq %rax, %r14
addq %r15, %r14
jmp 0x407f
cmpb $0x0, (%r15)
movq %r12, 0x10(%rsp)
je 0x3f17
callq 0x2320
movq (%rax), %rax
decq %r15
movsbq 0x1(%r15), %rcx
incq %r15
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x3f08
leaq 0x86b8(%rip), %r12      # 0xc5d6
movq %r15, %r14
movsbl (%r14), %esi
testl %esi, %esi
je 0x3fed
movl $0xc, %edx
movq %r12, %rdi
callq 0x21b0
testq %rax, %rax
je 0x3fed
leaq 0x10936(%rip), %r13     # 0x14880
xorl %ebp, %ebp
movq -0x10(%r13), %rbx
movq %rbx, %rdi
callq 0x2110
movslq %eax, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2080
testl %eax, %eax
je 0x3f81
incq %rbp
addq $0x18, %r13
cmpq $0x11, %rbp
jne 0x3f4c
movl $0x11, %ebp
jmp 0x3fc4
movl -0x8(%r13), %edx
cmpl 0x8(%rsp), %edx
jle 0x405a
addq %r15, %r14
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x3daa
movq %rax, %r14
movl 0xc(%rsp), %esi
cmpl $0xff0000, %esi         # imm = 0xFF0000
jne 0x3fb8
movl $0xff0000, 0x4(%rsp)    # imm = 0xFF0000
jmp 0x3fc4
movl 0x4(%rsp), %edi
callq *(%r13)
movl %eax, 0x4(%rsp)
cmpl $0x11, %ebp
jne 0x3f21
leaq 0x860e(%rip), %rdi      # 0xc5e2
xorl %eax, %eax
callq 0x2e63
movq %r14, %rdi
callq 0x2dcf
movl $0x1, %edi
callq 0x22f0
movl 0x4(%rsp), %ebp
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
cmpl $0x1, 0x80f55(%rip)     # 0x84f54
jne 0x4012
cmpb $0x20, (%r14)
jne 0x4012
movq %r14, %rdi
callq 0x2110
addq %rax, %r14
movq 0x219f7(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x3e12
leaq 0x85e1(%rip), %rsi      # 0xc60a
movl %ebp, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
cmpb $0x0, (%r14)
movq 0x219d1(%rip), %rax     # 0x25a10
je 0x40a6
leaq 0x85cd(%rip), %rsi      # 0xc615
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2210
jmp 0x3e12
movl 0x4(%rsp), %ebp
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
cmpl $0x1, 0x80ee8(%rip)     # 0x84f54
jne 0x407f
cmpb $0x20, (%r14)
jne 0x407f
movq %r14, %rdi
callq 0x2110
addq %rax, %r14
movq 0x2198a(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x3e12
leaq 0x8530(%rip), %rsi      # 0xc5c6
movl %ebp, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
jmp 0x3e12
movl $0xa, %edi
movq %rax, %rsi
callq 0x21a0
jmp 0x3e12
movq %r15, %rdi
callq 0x2dcf
leaq 0x84ee(%rip), %rdi      # 0xc5b5
xorl %eax, %eax
callq 0x2e63
jmp 0x3fe3