// File: /workspace/github_c_makefile_star2_O3/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, %r12
leaq 0x938c(%rip), %r13      # 0xddd8
movl $0x1, (%r13)
movl $0x0, 0x9a1a(%rip)      # 0xe478
movq %rdi, 0x986b(%rip)      # 0xe2d0
movl $0x32, 0x9a01(%rip)     # 0xe470
movl $0x31, 0x99fb(%rip)     # 0xe474
movb $0x24, 0x9a31(%rip)     # 0xe4b1
movb (%rdi), %bpl
testb %bpl, %bpl
je 0x4d81
movq %rdi, %r14
movq %r12, (%rsp)
callq 0x1230
movq %rax, %r15
leaq 0x5ac9(%rip), %r13      # 0xa56b
leaq 0x99d7(%rip), %rbx      # 0xe480
movl 0x99c5(%rip), %eax      # 0xe474
cmpb $0x3b, %bpl
je 0x4d8e
movq (%r15), %rcx
movsbq %bpl, %rbp
movzwl (%rcx,%rbp,2), %ecx
andl $0x2000, %ecx           # imm = 0x2000
jne 0x4d8e
testl %eax, %eax
setle %dl
movl 0x9995(%rip), %ecx      # 0xe470
testl %ecx, %ecx
setle %sil
orb %dl, %sil
cmpb $0x1, %sil
jne 0x4b0a
leaq 0x5a5f(%rip), %rdi      # 0xa550
movq %r14, %rsi
movl $0x4, %edx
callq 0x1e8b
movl 0x9970(%rip), %eax      # 0xe474
movl 0x9966(%rip), %ecx      # 0xe470
cmpl $0x32, %eax
jg 0x4b14
cmpl $0x33, %ecx
jl 0x4b24
movq %r13, %rdi
movq %r14, %rsi
movl $0x4, %edx
callq 0x1e8b
movq 0x97a5(%rip), %r12      # 0xe2d0
leaq 0x1(%r12), %rax
movq %rax, 0x9799(%rip)      # 0xe2d0
movq (%r15), %rax
movzwl (%rax,%rbp,2), %eax
btl $0xa, %eax
jb 0x4b6a
movzbl %bpl, %ecx
cmpl $0x2d, %ecx
jg 0x4b60
cmpl $0x22, %ecx
je 0x4b57
cmpl $0x27, %ecx
jne 0x4b8f
movl %ebp, %edi
callq 0x46a4
jmp 0x4b6f
cmpl $0x5f, %ecx
je 0x4b6a
cmpl $0x2e, %ecx
jne 0x4b8f
callq 0x4380
movq %rax, %rdi
callq 0x4782
movq 0x9752(%rip), %rax      # 0xe2d0
movb (%rax), %bpl
testb %bpl, %bpl
jne 0x4aa9
jmp 0x4d88
btl $0xb, %eax
jb 0x4c30
movzbl %bpl, %eax
cmpl $0x3b, %eax
jg 0x4c41
addl $-0x21, %eax
cmpl $0xe, %eax
ja 0x4cbf
leaq 0x595b(%rip), %rcx      # 0xa514
movslq (%rcx,%rax,4), %rax
addq %rcx, %rax
jmpq *%rax
callq 0x1030
movq (%rax), %rax
movsbq 0x1(%r12), %rcx
movl (%rax,%rcx,4), %eax
addq $0x2, %r12
movq %r12, 0x96f2(%rip)      # 0xe2d0
movl %eax, %ecx
shll $0x18, %ecx
cmpl $0x4dffffff, %ecx       # imm = 0x4DFFFFFF
jg 0x4cd3
cmpl $0x2b000000, %ecx       # imm = 0x2B000000
je 0x4ce7
cmpl $0x2e000000, %ecx       # imm = 0x2E000000
je 0x4ce7
jmp 0x4d68
movslq 0x9861(%rip), %rax      # 0xe474
movzbl (%rax,%rbx), %ecx
cmpl $0x24, %ecx
je 0x4d48
cmpl $0x28, %ecx
je 0x4d20
callq 0x4847
jmp 0x4c0c
movq %r12, 0x9699(%rip)      # 0xe2d0
callq 0x455e
jmp 0x4b6f
cmpl $0x3c, %eax
je 0x4c57
cmpl $0x3e, %eax
je 0x4c57
cmpl $0x40, %eax
jne 0x4cbf
movl $0x8, %edi
jmp 0x4c8b
movl %ebp, %edi
jmp 0x4d16
cmpl $0x0, 0x9813(%rip)      # 0xe478
je 0x4d59
movl $0x2a, %edi
jmp 0x4d16
movl $0x10, %edi
jmp 0x4c8b
movl $0x28, %edi
jmp 0x4d16
movl $0x2, %edi
callq 0x44c8
jmp 0x4b6f
cmpl $0x0, 0x97dc(%rip)      # 0xe478
je 0x4b77
movl $0x2b, %edi
jmp 0x4d16
cmpl $0x0, 0x97c8(%rip)      # 0xe478
movl $0x2d, %edi
movl $0x5f, %eax
cmovel %eax, %edi
jmp 0x4d16
leaq 0x912a(%rip), %rax      # 0xddf0
movb $0x43, (%rax)
movl $0x43, %edi
jmp 0x4d77
cmpl $0x4e000000, %ecx       # imm = 0x4E000000
je 0x4ce7
cmpl $0x58000000, %ecx       # imm = 0x58000000
jne 0x4d68
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
callq 0x499b
jmp 0x4b77
incl %eax
movl %eax, 0x974c(%rip)      # 0xe474
movslq 0x9741(%rip), %rax      # 0xe470
leal 0x1(%rax), %ecx
movl %ecx, 0x9738(%rip)      # 0xe470
leaq 0x95a1(%rip), %rcx      # 0xe2e0
movq (%rcx,%rax,8), %rdi
jmp 0x4b72
leaq 0x90a1(%rip), %rax      # 0xddf0
movb $0x42, (%rax)
movl $0x42, %edi
jmp 0x4d77
leaq 0x8ab0(%rip), %rax      # 0xd810
movq (%rax), %rdi
jmp 0x4b72
leaq 0x9081(%rip), %rax      # 0xddf0
movb $0x45, (%rax)
movl $0x45, %edi
callq 0x1ec8
jmp 0x4b77
movl $0x31, %eax
jmp 0x4db9
movl 0x96e6(%rip), %eax      # 0xe474
movslq %eax, %rcx
cmpb $0x24, (%rcx,%rbx)
movq (%rsp), %r12
leaq 0x9038(%rip), %r13      # 0xddd8
je 0x4db4
callq 0x4847
movslq 0x96c6(%rip), %rax      # 0xe474
cmpb $0x24, (%rax,%rbx)
jne 0x4da2
cmpl $0x31, %eax
jg 0x4de7
movslq %eax, %rbx
leaq 0x96bd(%rip), %r14      # 0xe480
leaq 0x9026(%rip), %r15      # 0xddf0
cmpb $0x28, (%rbx,%r14)
jne 0x4ddf
movb $0x42, (%r15)
movl $0x42, %edi
callq 0x1ec8
incq %rbx
cmpl $0x32, %ebx
jne 0x4dca
movl $0x31, %eax
cmpl $0x31, 0x967d(%rip)     # 0xe470
je 0x4e10
leaq 0x8ff4(%rip), %rax      # 0xddf0
movb $0x45, (%rax)
movl $0x45, %edi
callq 0x1ec8
movslq 0x9660(%rip), %rax      # 0xe470
leaq 0x8fd9(%rip), %rcx      # 0xddf0
cmpb $0x0, (%rcx)
je 0x4e2f
leaq 0x94bd(%rip), %rcx      # 0xe2e0
movq $0x0, (%rcx,%rax,8)
xorl %eax, %eax
jmp 0x4e3a
leaq 0x94aa(%rip), %rcx      # 0xe2e0
movq (%rcx,%rax,8), %rax
movq %rax, (%r12)
movl (%r13), %eax
addq $0x8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)