// File: /workspace/github_c_makefile_star2_O3/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 0x3e58
callq 0x2320
movq (%rax), %rax
decq %r15
movsbq 0x1(%r15), %rbx
incq %r15
testb $0x20, 0x1(%rax,%rbx,2)
jne 0x3e47
jmp 0x3e5a
xorl %ebx, %ebx
movq 0x21baf(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x3e77
leaq 0x871a(%rip), %rsi      # 0xc587
movq %r15, %rdx
xorl %eax, %eax
callq 0x2210
cmpb $0x2c, %bl
jne 0x3e84
movq %r15, %r14
jmp 0x4118
movsbl (%r15), %r14d
testl %r14d, %r14d
je 0x3ec7
leaq 0x86fd(%rip), %rdi      # 0xc591
movl $0x10, %edx
movl %r14d, %esi
callq 0x21b0
testq %rax, %rax
je 0x3ec7
movl $0x8, %eax
leaq 0x108ce(%rip), %rcx     # 0x14780
cmpb -0x8(%rax,%rcx), %r14b
je 0x3f1e
addq $0x10, %rax
cmpq $0xf8, %rax
jne 0x3eb2
jmp 0x3f2c
callq 0x2320
movq (%rax), %rax
movsbq %bl, %rcx
movzwl (%rax,%rcx,2), %eax
btl $0xb, %eax
jb 0x3f0f
movzbl %bl, %ecx
addl $-0x24, %ecx
cmpl $0x3b, %ecx
ja 0x3ef8
movabsq $0x800000000000401, %rdx # imm = 0x800000000000401
btq %rcx, %rdx
jb 0x3f00
testb $0x8, %al
je 0x412a
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x41db
jmp 0x3f29
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq 0x47b4
jmp 0x3f29
leaq 0x4(%rsp), %rsi
movq %r15, %rdi
callq *(%rax,%rcx)
movq %rax, %r15
cmpl $0x1, 0x81021(%rip)     # 0x84f54
movb (%r15), %al
jne 0x3f79
cmpb $0x20, %al
jne 0x3f79
movl 0x4(%rsp), %ebp
movl %ebp, (%r12)
movq %r15, %rdi
callq 0x2110
movq %rax, %r14
addq %r15, %r14
movq 0x21ab7(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x4118
leaq 0x8649(%rip), %rsi      # 0xc5b2
movl %ebp, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
jmp 0x4118
testb %al, %al
movq %r12, 0x10(%rsp)
je 0x3f9c
callq 0x2320
movq (%rax), %rax
decq %r15
movsbq 0x1(%r15), %rcx
incq %r15
testb $0x20, 0x1(%rax,%rcx,2)
jne 0x3f8d
leaq 0x861f(%rip), %r12      # 0xc5c2
leaq 0x108c6(%rip), %rbp     # 0x14870
movq %r15, %r14
movsbl (%r14), %esi
testl %esi, %esi
je 0x4073
movl $0xc, %edx
movq %r12, %rdi
callq 0x21b0
testq %rax, %rax
je 0x4073
movl $0x10, %r13d
movq -0x10(%r13,%rbp), %rbx
movq %rbx, %rdi
callq 0x2110
movslq %eax, %r15
movq %r14, %rdi
movq %rbx, %rsi
movq %r15, %rdx
callq 0x2080
testl %eax, %eax
je 0x4006
addq $0x18, %r13
cmpq $0x1a8, %r13            # imm = 0x1A8
jne 0x3fd5
jmp 0x4053
movl -0x8(%r13,%rbp), %edx
cmpl 0x8(%rsp), %edx
jle 0x40d9
addq %r15, %r14
movq %r14, %rdi
leaq 0xc(%rsp), %rsi
callq 0x3e17
movq %rax, %r14
movl 0xc(%rsp), %esi
movl $0xff0000, %eax         # imm = 0xFF0000
cmpl $0xff0000, %esi         # imm = 0xFF0000
je 0x4042
movl 0x4(%rsp), %edi
callq *(%r13,%rbp)
movl %eax, 0x4(%rsp)
cmpq $0x1a8, %r13            # imm = 0x1A8
jne 0x3fad
leaq 0x8574(%rip), %rdi      # 0xc5ce
xorl %eax, %eax
callq 0x2e72
movq %r14, %rdi
callq 0x2dde
movl $0x1, %edi
callq 0x22f0
movl 0x4(%rsp), %ebp
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
cmpl $0x1, 0x80ecf(%rip)     # 0x84f54
jne 0x4098
cmpb $0x20, (%r14)
jne 0x4098
movq %r14, %rdi
callq 0x2110
addq %rax, %r14
movq 0x21971(%rip), %rdi     # 0x25a10
testq %rdi, %rdi
je 0x4118
leaq 0x854b(%rip), %rsi      # 0xc5f6
movl %ebp, %edx
movl %ebp, %ecx
xorl %eax, %eax
callq 0x2210
cmpb $0x0, (%r14)
movq 0x2194f(%rip), %rax     # 0x25a10
je 0x410b
leaq 0x8537(%rip), %rsi      # 0xc601
movq %rax, %rdi
movq %r14, %rdx
xorl %eax, %eax
callq 0x2210
jmp 0x4118
movl 0x4(%rsp), %ebp
movq 0x10(%rsp), %rax
movl %ebp, (%rax)
cmpl $0x1, 0x80e69(%rip)     # 0x84f54
jne 0x3f52
cmpb $0x20, (%r14)
jne 0x3f52
movq %r14, %rdi
callq 0x2110
addq %rax, %r14
jmp 0x3f52
movl $0xa, %edi
movq %rax, %rsi
callq 0x21a0
movq %r14, %rax
addq $0x18, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r15, %rdi
callq 0x2dde
leaq 0x8468(%rip), %rdi      # 0xc5a1
xorl %eax, %eax
callq 0x2e72
jmp 0x4069