// File: /workspace/github_c_makefile_star2_O2/deplinenoise[P]vlink/expr.c
// Function: eval_expr
static int eval_expr(struct Expr *tree,lword *result)
/* evaluate expression tree, returns !0 when result is absolute */
{
  const char *fn = "eval_expr: ";
  int abs = 1;
  int labs=0,rabs=0;
  lword val=0,lval,rval;

  if (tree) {
    if (tree->left) {
      if (!(labs = eval_expr(tree->left,&lval)))
        abs = 0;
    }
    if (tree->right) {
      if (!(rabs = eval_expr(tree->right,&rval)))
        abs = 0;
    }

    switch(tree->type) {
      case ADD:
        val = lval + rval;
        break;
      case SUB:
        val = lval - rval;
        if (!labs && !rabs)
          abs = 1;  /* result is absolute, when both are reloc */
        break;
      case MUL:
        val = lval * rval;
        break;
      case DIV:
        if (rval == 0) {
          error(103,scriptname,line);  /* Division by zero */
          val = 0;
        }
        else
          val = lval / rval;
        break;
      case MOD:
        if (rval == 0) {
          error(103,scriptname,line);  /* Division by zero */
          val = 0;
        }
        else
          val = lval % rval;
        break;
      case NEG:
        val = -lval;
        break;
      case CPL:
        val = ~lval;
        break;
      case LAND:
        val = lval && rval;
        break;
      case LOR:
        val = lval || rval;
        break;
      case BAND:
        val = lval & rval;
        break;
      case BOR:
        val = lval | rval;
        break;
      case XOR:
        val = lval ^ rval;
        break;
      case NOT:
        val = !lval;
        break;
      case LSH:
        val = lval << rval;
        break;
      case RSH:
        val = lval >> rval;
        break;
      case LT:
        val = lval < rval;
        break;
      case GT:
        val = lval > rval;
        break;
      case LEQ:
        val = lval <= rval;
        break;
      case GEQ:
        val = lval >= rval;
        break;
      case NEQ:
        val = lval != rval;
        break;
      case EQ:
        val = lval == rval;
        break;
      case REL:
        abs = 0;
      case ABS:
        val = tree->val;
        break;
      default:
        ierror("%sIllegal tree type %d",fn,tree->type);
        break;
    }
  }
  else
    ierror("%sNULL tree",fn);

  *result = val;
  return abs;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
subq $0x18, %rsp
movq %rsi, %rbx
testq %rdi, %rdi
je 0xf697
movq %rdi, %r14
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0xf6c2
leaq 0x8(%rsp), %rsi
callq 0xf665
movl %eax, %ebp
testl %eax, %eax
setne %r15b
jmp 0xf6c8
leaq 0x11825(%rip), %rdi     # 0x20ec3
leaq 0x117fb(%rip), %rsi     # 0x20ea0
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x6b2c
pushq $0x1
popq %rbp
movq %r14, (%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
pushq $0x1
popq %rbp
xorl %r15d, %r15d
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0xf6e5
leaq 0x10(%rsp), %rsi
callq 0xf665
testl %eax, %eax
setne %cl
cmovel %eax, %ebp
jmp 0xf6e7
xorl %ecx, %ecx
movl (%r14), %edx
cmpq $0x16, %rdx
ja 0xf8a9
leaq 0x11645(%rip), %rax     # 0x20d40
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
jmpq *%rdx
movq 0x10(%rsp), %r14
addq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setg %r14b
jmp 0xf6b2
movq 0x8(%rsp), %r14
movb 0x10(%rsp), %cl
sarq %cl, %r14
jmp 0xf6b2
movq 0x10(%rsp), %r14
xorq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0xf8c6
movq 0x8(%rsp), %rax
cqto
idivq %rcx
movq %rdx, %r14
jmp 0xf6b2
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rsp)
jmp 0xf820
movq 0x10(%rsp), %r14
andq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x10(%rsp), %r14
imulq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setl %r14b
jmp 0xf6b2
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0xf8c6
movq 0x8(%rsp), %rax
cqto
idivq %rcx
movq %rax, %r14
jmp 0xf6b2
cmpq $0x0, 0x8(%rsp)
setne %al
cmpq $0x0, 0x10(%rsp)
setne %cl
andb %al, %cl
movzbl %cl, %r14d
jmp 0xf6b2
movq 0x8(%rsp), %r14
subq 0x10(%rsp), %r14
testb %cl, %cl
pushq $0x1
popq %rax
cmovnel %ebp, %eax
testb %r15b, %r15b
cmovel %eax, %ebp
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setle %r14b
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
sete %r14b
jmp 0xf6b2
xorl %r14d, %r14d
subq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x8(%rsp), %r14
movb 0x10(%rsp), %cl
shlq %cl, %r14
jmp 0xf6b2
movq 0x8(%rsp), %r14
notq %r14
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setge %r14b
jmp 0xf6b2
movq 0x10(%rsp), %r14
orq 0x8(%rsp), %r14
jmp 0xf6b2
movq 0x10(%rsp), %rax
xorl %r14d, %r14d
orq 0x8(%rsp), %rax
jmp 0xf8a0
xorl %ebp, %ebp
movq 0x18(%r14), %r14
jmp 0xf6b2
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setne %r14b
jmp 0xf6b2
leaq 0x115fc(%rip), %rdi     # 0x20eac
leaq 0x115e9(%rip), %rsi     # 0x20ea0
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x6b2c
jmp 0xf6b2
movq 0x243d3(%rip), %rsi     # 0x33ca0
movl 0x241b5(%rip), %edx     # 0x33a88
xorl %r14d, %r14d
pushq $0x67
popq %rdi
xorl %eax, %eax
callq 0x6c19
jmp 0xf6b2