// File: /workspace/github_c_makefile_star2_O3/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 0x10157
movq %rdi, %r14
movq 0x8(%rdi), %rdi
testq %rdi, %rdi
je 0x10184
leaq 0x8(%rsp), %rsi
callq 0x10125
movl %eax, %ebp
testl %eax, %eax
setne %r15b
jmp 0x1018c
leaq 0x12d55(%rip), %rdi     # 0x22eb3
leaq 0x12d2b(%rip), %rsi     # 0x22e90
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x52b0
movl $0x1, %ebp
movq %r14, (%rbx)
movl %ebp, %eax
addq $0x18, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
movl $0x1, %ebp
xorl %r15d, %r15d
movq 0x10(%r14), %rdi
testq %rdi, %rdi
je 0x101a9
leaq 0x10(%rsp), %rsi
callq 0x10125
testl %eax, %eax
setne %cl
cmovel %eax, %ebp
jmp 0x101ab
xorl %ecx, %ecx
movl (%r14), %edx
cmpq $0x16, %rdx
ja 0x10372
leaq 0x12b71(%rip), %rax     # 0x22d30
movslq (%rax,%rdx,4), %rdx
addq %rax, %rdx
jmpq *%rdx
movq 0x10(%rsp), %r14
addq 0x8(%rsp), %r14
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setg %r14b
jmp 0x10174
movq 0x8(%rsp), %r14
movb 0x10(%rsp), %cl
sarq %cl, %r14
jmp 0x10174
movq 0x10(%rsp), %r14
xorq 0x8(%rsp), %r14
jmp 0x10174
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x1038f
movq 0x8(%rsp), %rax
cqto
idivq %rcx
movq %rdx, %r14
jmp 0x10174
xorl %r14d, %r14d
cmpq $0x0, 0x8(%rsp)
jmp 0x102e9
movq 0x10(%rsp), %r14
andq 0x8(%rsp), %r14
jmp 0x10174
movq 0x10(%rsp), %r14
imulq 0x8(%rsp), %r14
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setl %r14b
jmp 0x10174
movq 0x10(%rsp), %rcx
testq %rcx, %rcx
je 0x1038f
movq 0x8(%rsp), %rax
cqto
idivq %rcx
movq %rax, %r14
jmp 0x10174
cmpq $0x0, 0x8(%rsp)
setne %al
cmpq $0x0, 0x10(%rsp)
setne %cl
andb %al, %cl
movzbl %cl, %r14d
jmp 0x10174
movq 0x8(%rsp), %r14
subq 0x10(%rsp), %r14
testb %cl, %cl
movl $0x1, %eax
cmovnel %ebp, %eax
testb %r15b, %r15b
cmovel %eax, %ebp
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setle %r14b
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
sete %r14b
jmp 0x10174
xorl %r14d, %r14d
subq 0x8(%rsp), %r14
jmp 0x10174
movq 0x8(%rsp), %r14
movb 0x10(%rsp), %cl
shlq %cl, %r14
jmp 0x10174
movq 0x8(%rsp), %r14
notq %r14
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setge %r14b
jmp 0x10174
movq 0x10(%rsp), %r14
orq 0x8(%rsp), %r14
jmp 0x10174
movq 0x10(%rsp), %rax
xorl %r14d, %r14d
orq 0x8(%rsp), %rax
jmp 0x10369
xorl %ebp, %ebp
movq 0x18(%r14), %r14
jmp 0x10174
movq 0x8(%rsp), %rax
xorl %r14d, %r14d
cmpq 0x10(%rsp), %rax
setne %r14b
jmp 0x10174
leaq 0x12b23(%rip), %rdi     # 0x22e9c
leaq 0x12b10(%rip), %rsi     # 0x22e90
xorl %r14d, %r14d
xorl %eax, %eax
callq 0x52b0
jmp 0x10174
movq 0x2351a(%rip), %rsi     # 0x338b0
movl 0x232fc(%rip), %edx     # 0x33698
xorl %r14d, %r14d
movl $0x67, %edi
xorl %eax, %eax
callq 0x6f14
jmp 0x10174