// File: /workspace/github_c_makefile_star2_O1/nimble-code[P]Uno/Src/uno_bounds.c
// Function: eval_const_expr
int
eval_const_expr(treenode *n, treenode *m)
{	int a=0, b=0;

	if (!n) return 0;

	if (n->hdr.type == TN_INT)
		return ((leafnode *)n)->data.ival;

	if (n->hdr.type == TN_IDENT)
	{	if (strcmp(((leafnode *)n)->data.sval->str, statename) == 0)
			return get_state_val();
	}

	if (uno_prop
	&&  n->hdr.type == TN_FUNC_CALL)
	{
		return eval_fct(n, m);
	}

	if (n->hdr.type == TN_EXPR)
	{
		if (n->lnode)
			a = eval_const_expr(n->lnode, m);
		if (n->rnode)
			b = eval_const_expr(n->rnode, m);

		if (!nogood)
		switch (n->hdr.tok) {
		case NOT:	return !b;
		case B_NOT:	return ~b;
		case CASE:	return b;

		case PLUS:	return a+b;
		case MINUS:	return a-b;
		case STAR:	return a*b;
		case DIV:	if (b == 0)
				{	fprintf(stderr, "uno: %s:%d division by zero error\n",
						n->hdr.fnm, n->hdr.line);
					break;
				}
				return a/b;
		case MOD:	if (b == 0)
				{	fprintf(stderr, "uno: %s:%d division by zero error\n",
						n->hdr.fnm, n->hdr.line);
					break;
				}
				return a%b;

		case EQUAL:	return (a == b);
		case LESS:	return (a < b);
		case LESS_EQ:	return (a <= b);
		case GRTR:	return (a > b);
		case GRTR_EQ:	return (a >= b);
		case NOT_EQ:	return (a != b);

		case AND:	return (a && b);
		case OR:	return (a || b);
		case B_OR:	return (a | b);
		case B_AND:	return (a & b);
		case B_XOR:	return (a ^ b);
		case B_NOT_EQ:	return (a != b);
		case L_SHIFT:	return (a << b);
		case R_SHIFT:	return (a >> b);

		default:
				printf("saw token type: %s (%s)\n",
					(char *) toksym(n->hdr.tok,0),
					x_stmnt(n));
				break;
		}
	}
	nogood = 1;
	return 0;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %rbx
pushq %rax
xorl %ebx, %ebx
testq %rdi, %rdi
je 0x1b146
movq %rsi, %r15
movq %rdi, %r14
movl 0x1c(%rdi), %ebx
cmpl $0x2d, %ebx
je 0x1b0bd
cmpl $0x30, %ebx
jne 0x1b0d8
movl 0x40(%r14), %ebx
jmp 0x1b146
movq 0x40(%r14), %rax
movq 0x8(%rax), %rdi
leaq 0x1d0dc(%rip), %rax     # 0x381a8
movq (%rax), %rsi
callq 0x3180
testl %eax, %eax
je 0x1b153
cmpl $0x3, %ebx
jne 0x1b0ff
leaq 0x54db4(%rip), %rax     # 0x6fe98
cmpq $0x0, (%rax)
je 0x1b0ff
movq %r14, %rdi
movq %r15, %rsi
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1cd4e
cmpl $0x28, %ebx
jne 0x1b13a
movq 0x40(%r14), %rdi
xorl %ebx, %ebx
movl $0x0, %ebp
testq %rdi, %rdi
je 0x1b11e
movq %r15, %rsi
callq 0x1b08f
movl %eax, %ebp
movq 0x48(%r14), %rdi
testq %rdi, %rdi
je 0x1b131
movq %r15, %rsi
callq 0x1b08f
movl %eax, %ebx
cmpl $0x0, 0x65850(%rip)     # 0x80988
je 0x1b162
movl $0x1, 0x65844(%rip)     # 0x80988
xorl %ebx, %ebx
movl %ebx, %eax
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
retq
addq $0x8, %rsp
popq %rbx
popq %r14
popq %r15
popq %rbp
jmp 0x1cd2e
movl 0x18(%r14), %edi
leal -0x131(%rdi), %eax
cmpl $0x32, %eax
ja 0x1b18a
leaq 0x15784(%rip), %rcx     # 0x308fc
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
xorl %eax, %eax
cmpl %ebx, %ebp
jmp 0x1b24c
cmpl $0x10f, %edi            # imm = 0x10F
je 0x1b146
xorl %esi, %esi
callq 0x73a0
movq %rax, %rbx
movq %r14, %rdi
callq 0x5e8a
leaq 0x15860(%rip), %rdi     # 0x30a0b
movq %rbx, %rsi
movq %rax, %rdx
xorl %eax, %eax
callq 0x3100
jmp 0x1b13a
testl %ebx, %ebx
je 0x1b271
movl %ebp, %eax
cltd
idivl %ebx
movl %edx, %ebx
jmp 0x1b146
subl %ebx, %ebp
jmp 0x1b263
xorl %eax, %eax
cmpl %ebx, %ebp
setg %al
jmp 0x1b258
xorl %ebp, %ebx
jmp 0x1b146
imull %ebp, %ebx
jmp 0x1b146
movl %ebx, %ecx
shll %cl, %ebp
jmp 0x1b263
testl %ebp, %ebp
setne %al
testl %ebx, %ebx
setne %cl
andb %al, %cl
movzbl %cl, %ebx
jmp 0x1b146
xorl %eax, %eax
cmpl %ebx, %ebp
setle %al
jmp 0x1b258
orl %ebp, %ebx
jmp 0x1b146
xorl %eax, %eax
cmpl %ebx, %ebp
setge %al
jmp 0x1b258
xorl %eax, %eax
cmpl %ebx, %ebp
jmp 0x1b231
addl %ebp, %ebx
jmp 0x1b146
xorl %eax, %eax
testl %ebx, %ebx
sete %al
jmp 0x1b258
andl %ebp, %ebx
jmp 0x1b146
testl %ebx, %ebx
je 0x1b27e
movl %ebp, %eax
cltd
idivl %ebx
jmp 0x1b258
xorl %eax, %eax
orl %ebx, %ebp
setne %al
jmp 0x1b258
xorl %eax, %eax
cmpl %ebx, %ebp
setl %al
movl %eax, %ebx
jmp 0x1b146
movl %ebx, %ecx
sarl %cl, %ebp
movl %ebp, %ebx
jmp 0x1b146
notl %ebx
jmp 0x1b146
movq %r14, %rdi
callq 0x42de
jmp 0x1b13a
movq %r14, %rdi
callq 0x4300
jmp 0x1b13a