// File: /workspace/github_c_makefile_star2_O1/mist64[P]cbm6502asm/src/express.c
// Function: evaluate
int evaluate(char *str, long *value) {
	int i;
	char c;

	expdef = TRUE; /* assume expression will be defined */
	lastval = FALSE;
	lp = str;
	osp = vsp = MAXESTK;
	opstk[--osp] = '$';
	while ((c = *lp)) {
		if (isspace(c) || c == ';') break;
		if (osp <= 0 || vsp <= 0)
			error_msg("evaluation stack overflow ", str, 4);
		if (osp > MAXESTK || vsp > MAXESTK)
			error_msg("evaluation stack underflow ", str, 4);
		lp++; /* point to next character */

		if (isalpha(c) || c == '.' ||
		    c == '_') { /* it must be a symbol */
			pushval(evalsym());
			continue;
		}
		if (c == '\"' || c == '\'') { /* it is a character constant */
			pushval(evalchar(c));
			continue;
		}
		if (isdigit(c)) { /* it is a decimal number */
			lp--;     /* point to the digit again */
			pushval(evalocal());
			continue;
		}
		if (c == RADIX2) { /* it is a binary constant */
			pushval(evalcon(2));
			continue;
		}
		if (c == RADIX8) { /* it is an octal constant */
			pushval(evalcon(8));
			continue;
		}
		if (c == RADIX16) { /* it is a hexidecimal constant */
			pushval(evalcon(16));
			continue;
		}

		if (c == '!') {           /* start of 2 character operator */
			c = toupper(*lp); /* get the rest of the operator */
			lp++;
			if (!(c == 'N' || c == '.' || c == '+' || c == 'X'))
				display_error(error = 'E');
			else {
				if (c == 'N') c = '~';
				if (c == '.') c = '&';
				if (c == '+') c = '|';
				if (c == 'X') c = '^';
				eval(c);
			}
			continue;
		}
		if (c == '*') { /* multiply or location counter */
			/* if preceded by nothing or an operator then it is the
			 * location counter */
			if (!lastval)
				pushval(loc_cntr);
			else
				/* if preceded by a constant or symbol then it
				 * is the multiply operator */
				eval(c);
			continue;
		}
		if (c == '>' || c == '<' || c == '/') {
			eval(c);
			continue;
		}
		if (c == '+') { /* unary or binary operator */
			/* if preceded by nothing or an operator then it is a
			 * unary +, ignore it */
			/* if preceded by a constant or symbol then it is a
			 * binary operator */
			if (lastval) eval(c);
			continue;
		}
		if (c == '-') { /* unary or binary operator */
			/* if preceded by nothing or an operator then it is a
			 * unary operator */
			if (!lastval) c = '_';
			/* if preceded by a constant or symbol then it is a
			 * binary operator */
			eval(c);
			continue;
		}
		if (c == '(') {
			eval(c);
			continue;
		}
		if (c == ')') {
			int more = TRUE;
			while (more)
				if (opstk[osp] == '(') {
					more = FALSE;
					osp++;
					pushval(stack[vsp++]);
				} else if (opstk[osp] == '$') {
					display_error(error = 'B');
					more = FALSE;
				} else
					do_oper();
			continue;
		}
		display_error(error = 'C'); /* no valid state if we get here */
	}
	while (opstk[osp] != '$') do_oper();
	for (i = osp; i < MAXESTK; i++)
		if (opstk[i] == '(')
			display_error(
			        error = 'B'); /* too many ( in expression */
	if (vsp != MAXESTK - 1)
		display_error(error = 'E'); /* stack was messed up */
	if (error) stack[vsp] = 0;
	*value = stack[vsp];
	return (expdef);
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
pushq %rax
movq %rsi, (%rsp)
leaq 0x9405(%rip), %rax      # 0xddd8
movl $0x1, (%rax)
movl $0x0, 0x9a95(%rip)      # 0xe478
movq %rdi, 0x98e6(%rip)      # 0xe2d0
movl $0x32, 0x9a7c(%rip)     # 0xe470
movl $0x31, 0x9a76(%rip)     # 0xe474
movb $0x24, 0x9aac(%rip)     # 0xe4b1
movb (%rdi), %bl
testb %bl, %bl
je 0x4cc3
movq %rdi, %r14
callq 0x1230
movq %rax, %r15
leaq 0x5b2f(%rip), %r12      # 0xa550
leaq 0x5b43(%rip), %r13      # 0xa56b
cmpb $0x3b, %bl
je 0x4cc3
movq (%r15), %rax
movsbq %bl, %rbp
movzwl (%rax,%rbp,2), %eax
andl $0x2000, %eax           # imm = 0x2000
jne 0x4cc3
cmpl $0x0, 0x9a26(%rip)      # 0xe474
jle 0x4a59
cmpl $0x0, 0x9a19(%rip)      # 0xe470
jg 0x4a69
movq %r12, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1e94
cmpl $0x32, 0x9a04(%rip)     # 0xe474
jg 0x4a7b
cmpl $0x33, 0x99f7(%rip)     # 0xe470
jl 0x4a8b
movq %r13, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1e94
movq 0x983e(%rip), %rbx      # 0xe2d0
leaq 0x1(%rbx), %rax
movq %rax, 0x9833(%rip)      # 0xe2d0
movq (%r15), %rax
movzwl (%rax,%rbp,2), %eax
btl $0xa, %eax
jb 0x4ad0
movzbl %bpl, %ecx
cmpl $0x2d, %ecx
jg 0x4ac6
cmpl $0x22, %ecx
je 0x4abd
cmpl $0x27, %ecx
jne 0x4af3
movl %ebp, %edi
callq 0x461d
jmp 0x4ad5
cmpl $0x5f, %ecx
je 0x4ad0
cmpl $0x2e, %ecx
jne 0x4af3
callq 0x430c
movq %rax, %rdi
callq 0x46f5
movq 0x97ec(%rip), %rax      # 0xe2d0
movb (%rax), %bl
testb %bl, %bl
jne 0x4a28
jmp 0x4cc3
btl $0xb, %eax
jb 0x4b67
movzbl %bpl, %eax
cmpl $0x3b, %eax
jg 0x4b78
addl $-0x21, %eax
cmpl $0xe, %eax
ja 0x4c19
leaq 0x59ff(%rip), %rcx      # 0xa514
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x1030
movq (%rax), %rax
movsbq 0x1(%rbx), %rcx
movl (%rax,%rcx,4), %eax
addq $0x2, %rbx
movq %rbx, 0x9797(%rip)      # 0xe2d0
movl %eax, %ecx
shll $0x18, %ecx
cmpl $0x4dffffff, %ecx       # imm = 0x4DFFFFFF
jg 0x4c55
cmpl $0x2b000000, %ecx       # imm = 0x2B000000
je 0x4c65
cmpl $0x2e000000, %ecx       # imm = 0x2E000000
je 0x4c65
jmp 0x4caa
movq %rbx, 0x9762(%rip)      # 0xe2d0
callq 0x44e1
jmp 0x4ad5
cmpl $0x3c, %eax
je 0x4c0d
cmpl $0x3e, %eax
je 0x4c0d
cmpl $0x40, %eax
jne 0x4c19
movl $0x8, %edi
jmp 0x4bcd
movl $0x10, %edi
jmp 0x4bcd
leaq 0x98d8(%rip), %rbx      # 0xe480
movslq 0x98c5(%rip), %rax      # 0xe474
movzbl (%rax,%rbx), %ecx
cmpl $0x24, %ecx
je 0x4c99
cmpl $0x28, %ecx
je 0x4c2d
callq 0x47ba
jmp 0x4ba8
movl $0x2, %edi
callq 0x444b
jmp 0x4ad5
cmpl $0x0, 0x989a(%rip)      # 0xe478
movl $0x5f, %eax
cmovel %eax, %ebp
jmp 0x4c0d
cmpl $0x0, 0x9889(%rip)      # 0xe478
jne 0x4c0d
leaq 0x8c18(%rip), %rax      # 0xd810
movq (%rax), %rdi
jmp 0x4ad8
cmpl $0x0, 0x9871(%rip)      # 0xe478
je 0x4add
movl %ebp, %edi
callq 0x490c
jmp 0x4add
leaq 0x91d0(%rip), %rax      # 0xddf0
movb $0x43, (%rax)
movl $0x43, %edi
jmp 0x4cb9
incl %eax
movl %eax, 0x983f(%rip)      # 0xe474
movslq 0x9834(%rip), %rax      # 0xe470
leal 0x1(%rax), %ecx
movl %ecx, 0x982b(%rip)      # 0xe470
leaq 0x9694(%rip), %rcx      # 0xe2e0
movq (%rcx,%rax,8), %rdi
jmp 0x4ad8
cmpl $0x4e000000, %ecx       # imm = 0x4E000000
je 0x4c65
cmpl $0x58000000, %ecx       # imm = 0x58000000
jne 0x4caa
cmpl $0x4e000000, %ecx       # imm = 0x4E000000
movl $0x7e, %ecx
cmovel %ecx, %eax
cmpb $0x2e, %al
movl $0x26, %ecx
cmovel %ecx, %eax
cmpb $0x2b, %al
movl $0x7c, %ecx
cmovel %ecx, %eax
cmpb $0x58, %al
movl $0x5e, %ecx
cmovel %ecx, %eax
movsbl %al, %edi
jmp 0x4c0f
leaq 0x9150(%rip), %rax      # 0xddf0
movb $0x42, (%rax)
movl $0x42, %edi
jmp 0x4cb9
leaq 0x913f(%rip), %rax      # 0xddf0
movb $0x45, (%rax)
movl $0x45, %edi
callq 0x1ed1
jmp 0x4add
movslq 0x97aa(%rip), %rax      # 0xe474
leaq 0x97af(%rip), %rbx      # 0xe480
cmpb $0x24, (%rax,%rbx)
je 0x4ce5
callq 0x47ba
movslq 0x9791(%rip), %rax      # 0xe474
jmp 0x4cd1
cmpl $0x31, %eax
jg 0x4d12
movslq %eax, %r14
leaq 0x90fc(%rip), %r15      # 0xddf0
cmpb $0x28, (%r14,%rbx)
jne 0x4d09
movb $0x42, (%r15)
movl $0x42, %edi
callq 0x1ed1
incq %r14
cmpl $0x32, %r14d
jne 0x4cf4
cmpl $0x31, 0x9757(%rip)     # 0xe470
je 0x4d2f
leaq 0x90ce(%rip), %rax      # 0xddf0
movb $0x45, (%rax)
movl $0x45, %edi
callq 0x1ed1
leaq 0x90ba(%rip), %rax      # 0xddf0
cmpb $0x0, (%rax)
je 0x4d51
movslq 0x972e(%rip), %rax      # 0xe470
leaq 0x9597(%rip), %rcx      # 0xe2e0
movq $0x0, (%rcx,%rax,8)
movslq 0x9718(%rip), %rax      # 0xe470
leaq 0x9581(%rip), %rcx      # 0xe2e0
movq (%rcx,%rax,8), %rax
movq (%rsp), %rcx
movq %rax, (%rcx)
leaq 0x9067(%rip), %rax      # 0xddd8
movl (%rax), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nop