// File: toxemicsquire4[P]csci41_calc/main.cc
// Function: main
int main() {		
  string str, command, check; //basic things needed for calculator
  map <char, int> var; //keeps track of variables
	char var_name, operation, equal;
	int a, b;
	Number x, y;	//objects we will pass to functions

while (true) {
	cin >> ws;
	char input = cin.peek();  // Checks the next char
	if ( input == '+' || input == '-' || input == '*' || input == '/' || input == '%' || input == '^' ) { // If char is an operation, enters solution loop
		while (true) {	
			cin >> operation;
			cin >> ws;
			input = cin.peek();
			if ( isalpha(input) ) {	 // If variable, will set y.
				cin >> var_name;
				if (!cin) die();
				auto search = var.find(var_name);
				if ( search == var.end() ) die(); // If variable doesn't exist, run ERROR.
				else {
					b = var[var_name];
					y.set_value(b);
					var[var_name]+= 1; // Increments value
					if ( var[var_name] > 255 ) die();
				}
			}
			else if ( isdigit(input) ) {
				cin >> b; 
				if (!cin) die(); 
					y.set_value(b);
			}
			else die();
			if ( operation == '+' ) x.set_value(add(x, y));
			else if ( operation == '-' ) x.set_value(subtract(x, y));
			else if ( operation == '*' ) x.set_value(multiply(x, y));
			else if ( operation == '/' && y.get_value() != 0 ) x.set_value(division(x, y));
			else if ( operation == '%' ) x.set_value(modulate(x, y));
			else if ( operation == '^' ) {
				if ( x.get_value() == 0 && y.get_value() == 0 ) die();
				else x.set_value(exponate(x, y));
			}
			else die();  // No other operations possible
			input = cin.peek(); // Checks for end of input... if end, output answer
			if ( input == '\n' ) {
				cout << x.get_value() << endl;
				break;
			}
		}
	}
	else if ( isalpha(input) ) { // If given a letter, will check for either setting variable or starting equation
		cin >> str;
		if ( !cin ) die();
		if ( str == "LET" ) { // If LET, set variable
			cin >> var_name >> equal >> a;
			if ( !cin ) die();
			if ( equal != '=' ) die();
			auto search = var.find(var_name);
			if ( search != var.end() ) die();
			if ( a < 0 || a > 255 ) die();
			else var[var_name] = a;
		}
		else if ( str == "QUIT" ) exit(0); // QUIT
		else if ( str.size() == 1 ) {	// If variable, will set x.
			var_name = str.at(0);
			auto search = var.find(var_name);
			if ( search == var.end() ) die(); // If variable does not exist, ERROR
			else {
				a = var[var_name];
				x.set_value(a);
				var[var_name]++;
				if ( var[var_name] > 255 ) die();
				input = cin.peek(); // Checks for end of input... if end, output answer
				if ( input == '\n' ) {
					cout << x.get_value() << endl;
				}
			}
		}
		else die();
	}
	else if ( isdigit(input) ) { // If given a digit, will set x.
		cin >> a;
		x.set_value(a);
		input = cin.peek(); // Checks for end of input... if end, output answer
		if ( input == '\n' ) {
			cout << x.get_value() << endl;
		}
	}
	else exit(0);
}

}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x210, %rsp            # imm = 0x210
movl $0x0, -0x4(%rbp)
leaq -0x28(%rbp), %rdi
callq 0x21a0
leaq -0x48(%rbp), %rdi
callq 0x21a0
leaq -0x68(%rbp), %rdi
callq 0x21a0
leaq -0x98(%rbp), %rdi
callq 0x3030
jmp 0x256b
movq 0x5a6e(%rip), %rdi      # 0x7fe0
movq 0x5a4f(%rip), %rsi      # 0x7fc8
callq 0x2060
jmp 0x2580
movq 0x5a59(%rip), %rdi      # 0x7fe0
callq 0x2080
movl %eax, -0x124(%rbp)
jmp 0x2594
movl -0x124(%rbp), %eax
movb %al, -0xbd(%rbp)
movsbl -0xbd(%rbp), %eax
cmpl $0x2b, %eax
je 0x25ec
movsbl -0xbd(%rbp), %eax
cmpl $0x2d, %eax
je 0x25ec
movsbl -0xbd(%rbp), %eax
cmpl $0x2a, %eax
je 0x25ec
movsbl -0xbd(%rbp), %eax
cmpl $0x2f, %eax
je 0x25ec
movsbl -0xbd(%rbp), %eax
cmpl $0x25, %eax
je 0x25ec
movsbl -0xbd(%rbp), %eax
cmpl $0x5e, %eax
jne 0x2b5d
jmp 0x25ee
jmp 0x25f0
movq 0x59e9(%rip), %rdi      # 0x7fe0
leaq -0x9a(%rbp), %rsi
callq 0x2190
jmp 0x2605
movq 0x59d4(%rip), %rdi      # 0x7fe0
movq 0x59b5(%rip), %rsi      # 0x7fc8
callq 0x2060
jmp 0x261a
movq 0x59bf(%rip), %rdi      # 0x7fe0
callq 0x2080
movl %eax, -0x128(%rbp)
jmp 0x262e
movl -0x128(%rbp), %eax
movb %al, -0xbd(%rbp)
movsbl -0xbd(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
je 0x27d7
movq 0x598a(%rip), %rdi      # 0x7fe0
leaq -0x99(%rbp), %rsi
callq 0x2190
jmp 0x2664
movq 0x5975(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20a0
movb %al, -0x129(%rbp)
jmp 0x2682
movb -0x129(%rbp), %al
testb $0x1, %al
jne 0x268e
jmp 0x26d5
callq 0x2510
jmp 0x2695
jmp 0x26d5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0xb8(%rbp)
movl %eax, -0xbc(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x3240
leaq -0x68(%rbp), %rdi
callq 0x20c0
leaq -0x48(%rbp), %rdi
callq 0x20c0
leaq -0x28(%rbp), %rdi
callq 0x20c0
jmp 0x2fd7
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x3050
movq %rax, -0x138(%rbp)
jmp 0x26f1
movq -0x138(%rbp), %rax
movq %rax, -0xc8(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x30b0
movq %rax, -0xd0(%rbp)
leaq -0xc8(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x3080
testb $0x1, %al
jne 0x272b
jmp 0x2737
callq 0x2510
jmp 0x2732
jmp 0x27d5
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x140(%rbp)
jmp 0x2753
movq -0x140(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa4(%rbp)
movl -0xa4(%rbp), %esi
leaq -0xac(%rbp), %rdi
callq 0x31c0
jmp 0x2776
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x148(%rbp)
jmp 0x2792
movq -0x148(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x150(%rbp)
jmp 0x27bb
movq -0x150(%rbp), %rax
cmpl $0xff, (%rax)
jle 0x27d3
callq 0x2510
jmp 0x27d1
jmp 0x27d3
jmp 0x27d5
jmp 0x2851
movsbl -0xbd(%rbp), %edi
callq 0x2110
cmpl $0x0, %eax
je 0x2846
movq 0x57f1(%rip), %rdi      # 0x7fe0
leaq -0xa4(%rbp), %rsi
callq 0x20b0
jmp 0x27fd
movq 0x57dc(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20a0
movb %al, -0x151(%rbp)
jmp 0x281b
movb -0x151(%rbp), %al
testb $0x1, %al
jne 0x2827
jmp 0x2830
callq 0x2510
jmp 0x282e
jmp 0x2830
movl -0xa4(%rbp), %esi
leaq -0xac(%rbp), %rdi
callq 0x31c0
jmp 0x2844
jmp 0x284f
callq 0x2510
jmp 0x284d
jmp 0x284f
jmp 0x2851
movsbl -0x9a(%rbp), %eax
cmpl $0x2b, %eax
jne 0x28a7
movl -0xa8(%rbp), %eax
movl %eax, -0xd4(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xd8(%rbp)
movl -0xd4(%rbp), %edi
movl -0xd8(%rbp), %esi
callq 0x2370
movl %eax, -0x158(%rbp)
jmp 0x288e
movl -0x158(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x28a2
jmp 0x2ae1
movsbl -0x9a(%rbp), %eax
cmpl $0x2d, %eax
jne 0x28fd
movl -0xa8(%rbp), %eax
movl %eax, -0xdc(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xe0(%rbp)
movl -0xdc(%rbp), %edi
movl -0xe0(%rbp), %esi
callq 0x23b0
movl %eax, -0x15c(%rbp)
jmp 0x28e4
movl -0x15c(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x28f8
jmp 0x2adf
movsbl -0x9a(%rbp), %eax
cmpl $0x2a, %eax
jne 0x2953
movl -0xa8(%rbp), %eax
movl %eax, -0xe4(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xe8(%rbp)
movl -0xe4(%rbp), %edi
movl -0xe8(%rbp), %esi
callq 0x23f0
movl %eax, -0x160(%rbp)
jmp 0x293a
movl -0x160(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x294e
jmp 0x2add
movsbl -0x9a(%rbp), %eax
cmpl $0x2f, %eax
jne 0x29d0
leaq -0xac(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x164(%rbp)
jmp 0x2973
movl -0x164(%rbp), %eax
cmpl $0x0, %eax
je 0x29d0
movl -0xa8(%rbp), %eax
movl %eax, -0xec(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xf0(%rbp)
movl -0xec(%rbp), %edi
movl -0xf0(%rbp), %esi
callq 0x2430
movss %xmm0, -0x168(%rbp)
jmp 0x29b1
movss -0x168(%rbp), %xmm0
cvttss2si %xmm0, %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x29cb
jmp 0x2adb
movsbl -0x9a(%rbp), %eax
cmpl $0x25, %eax
jne 0x2a26
movl -0xa8(%rbp), %eax
movl %eax, -0xf4(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0xf8(%rbp)
movl -0xf4(%rbp), %edi
movl -0xf8(%rbp), %esi
callq 0x2470
movl %eax, -0x16c(%rbp)
jmp 0x2a0d
movl -0x16c(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x2a21
jmp 0x2ad9
movsbl -0x9a(%rbp), %eax
cmpl $0x5e, %eax
jne 0x2ace
leaq -0xa8(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x170(%rbp)
jmp 0x2a4a
movl -0x170(%rbp), %eax
cmpl $0x0, %eax
jne 0x2a7d
leaq -0xac(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x174(%rbp)
jmp 0x2a69
movl -0x174(%rbp), %eax
cmpl $0x0, %eax
jne 0x2a7d
callq 0x2510
jmp 0x2a7b
jmp 0x2acc
movl -0xa8(%rbp), %eax
movl %eax, -0xfc(%rbp)
movl -0xac(%rbp), %eax
movl %eax, -0x100(%rbp)
movl -0xfc(%rbp), %edi
movl -0x100(%rbp), %esi
callq 0x24d0
movss %xmm0, -0x178(%rbp)
jmp 0x2ab0
movss -0x178(%rbp), %xmm0
cvttss2si %xmm0, %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x2aca
jmp 0x2acc
jmp 0x2ad7
callq 0x2510
jmp 0x2ad5
jmp 0x2ad7
jmp 0x2ad9
jmp 0x2adb
jmp 0x2add
jmp 0x2adf
jmp 0x2ae1
movq 0x54f8(%rip), %rdi      # 0x7fe0
callq 0x2080
movl %eax, -0x17c(%rbp)
jmp 0x2af5
movl -0x17c(%rbp), %eax
movb %al, -0xbd(%rbp)
movsbl -0xbd(%rbp), %eax
cmpl $0xa, %eax
jne 0x2b53
leaq -0xa8(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x180(%rbp)
jmp 0x2b21
movl -0x180(%rbp), %esi
movq 0x54a2(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, -0x188(%rbp)
jmp 0x2b3c
movq -0x188(%rbp), %rdi
movq 0x546e(%rip), %rsi      # 0x7fb8
callq 0x2160
jmp 0x2b51
jmp 0x2b58
jmp 0x25ee
jmp 0x2fd2
movsbl -0xbd(%rbp), %edi
callq 0x21d0
cmpl $0x0, %eax
je 0x2f15
movq 0x5467(%rip), %rdi      # 0x7fe0
leaq -0x28(%rbp), %rsi
callq 0x2180
jmp 0x2b84
movq 0x5455(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20a0
movb %al, -0x189(%rbp)
jmp 0x2ba2
movb -0x189(%rbp), %al
testb $0x1, %al
jne 0x2bae
jmp 0x2bb7
callq 0x2510
jmp 0x2bb5
jmp 0x2bb7
leaq 0x2456(%rip), %rsi      # 0x5014
leaq -0x28(%rbp), %rdi
callq 0x31e0
movb %al, -0x18a(%rbp)
jmp 0x2bcf
movb -0x18a(%rbp), %al
testb $0x1, %al
jne 0x2bde
jmp 0x2d2c
movq 0x53fb(%rip), %rdi      # 0x7fe0
leaq -0x99(%rbp), %rsi
callq 0x2190
movq %rax, -0x198(%rbp)
jmp 0x2bfa
movq -0x198(%rbp), %rdi
leaq -0x9b(%rbp), %rsi
callq 0x2190
movq %rax, -0x1a0(%rbp)
jmp 0x2c16
movq -0x1a0(%rbp), %rdi
leaq -0xa0(%rbp), %rsi
callq 0x20b0
jmp 0x2c2b
movq 0x53ae(%rip), %rdi      # 0x7fe0
movq (%rdi), %rax
movq -0x18(%rax), %rax
addq %rax, %rdi
callq 0x20a0
movb %al, -0x1a1(%rbp)
jmp 0x2c49
movb -0x1a1(%rbp), %al
testb $0x1, %al
jne 0x2c55
jmp 0x2c5e
callq 0x2510
jmp 0x2c5c
jmp 0x2c5e
movsbl -0x9b(%rbp), %eax
cmpl $0x3d, %eax
je 0x2c73
callq 0x2510
jmp 0x2c71
jmp 0x2c73
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x3050
movq %rax, -0x1b0(%rbp)
jmp 0x2c8f
movq -0x1b0(%rbp), %rax
movq %rax, -0x108(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x30b0
movq %rax, -0x110(%rbp)
leaq -0x108(%rbp), %rdi
leaq -0x110(%rbp), %rsi
callq 0x3210
testb $0x1, %al
jne 0x2cc9
jmp 0x2cd2
callq 0x2510
jmp 0x2cd0
jmp 0x2cd2
cmpl $0x0, -0xa0(%rbp)
jl 0x2ce7
cmpl $0xff, -0xa0(%rbp)
jle 0x2cf0
callq 0x2510
jmp 0x2cee
jmp 0x2d27
movl -0xa0(%rbp), %eax
movl %eax, -0x1bc(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x1b8(%rbp)
jmp 0x2d18
movq -0x1b8(%rbp), %rax
movl -0x1bc(%rbp), %ecx
movl %ecx, (%rax)
jmp 0x2f10
leaq 0x22e5(%rip), %rsi      # 0x5018
leaq -0x28(%rbp), %rdi
callq 0x31e0
movb %al, -0x1bd(%rbp)
jmp 0x2d44
movb -0x1bd(%rbp), %al
testb $0x1, %al
jne 0x2d50
jmp 0x2d57
xorl %edi, %edi
callq 0x2170
leaq -0x28(%rbp), %rdi
callq 0x20e0
cmpq $0x1, %rax
jne 0x2f03
xorl %eax, %eax
movl %eax, %esi
leaq -0x28(%rbp), %rdi
callq 0x2220
movq %rax, -0x1c8(%rbp)
jmp 0x2d80
movq -0x1c8(%rbp), %rax
movb (%rax), %al
movb %al, -0x99(%rbp)
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x3050
movq %rax, -0x1d0(%rbp)
jmp 0x2dab
movq -0x1d0(%rbp), %rax
movq %rax, -0x118(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x30b0
movq %rax, -0x120(%rbp)
leaq -0x118(%rbp), %rdi
leaq -0x120(%rbp), %rsi
callq 0x3080
testb $0x1, %al
jne 0x2de5
jmp 0x2df1
callq 0x2510
jmp 0x2dec
jmp 0x2f01
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x1d8(%rbp)
jmp 0x2e0d
movq -0x1d8(%rbp), %rax
movl (%rax), %eax
movl %eax, -0xa0(%rbp)
movl -0xa0(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x2e30
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x1e0(%rbp)
jmp 0x2e4c
movq -0x1e0(%rbp), %rax
movl (%rax), %ecx
incl %ecx
movl %ecx, (%rax)
leaq -0x98(%rbp), %rdi
leaq -0x99(%rbp), %rsi
callq 0x30e0
movq %rax, -0x1e8(%rbp)
jmp 0x2e75
movq -0x1e8(%rbp), %rax
cmpl $0xff, (%rax)
jle 0x2e8d
callq 0x2510
jmp 0x2e8b
jmp 0x2e8d
movq 0x514c(%rip), %rdi      # 0x7fe0
callq 0x2080
movl %eax, -0x1ec(%rbp)
jmp 0x2ea1
movl -0x1ec(%rbp), %eax
movb %al, -0xbd(%rbp)
movsbl -0xbd(%rbp), %eax
cmpl $0xa, %eax
jne 0x2eff
leaq -0xa8(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x1f0(%rbp)
jmp 0x2ecd
movl -0x1f0(%rbp), %esi
movq 0x50f6(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, -0x1f8(%rbp)
jmp 0x2ee8
movq -0x1f8(%rbp), %rdi
movq 0x50c2(%rip), %rsi      # 0x7fb8
callq 0x2160
jmp 0x2efd
jmp 0x2eff
jmp 0x2f01
jmp 0x2f0c
callq 0x2510
jmp 0x2f0a
jmp 0x2f0c
jmp 0x2f0e
jmp 0x2f10
jmp 0x2fd0
movsbl -0xbd(%rbp), %edi
callq 0x2110
cmpl $0x0, %eax
je 0x2fc7
movq 0x50af(%rip), %rdi      # 0x7fe0
leaq -0xa0(%rbp), %rsi
callq 0x20b0
jmp 0x2f3f
movl -0xa0(%rbp), %esi
leaq -0xa8(%rbp), %rdi
callq 0x31c0
jmp 0x2f53
movq 0x5086(%rip), %rdi      # 0x7fe0
callq 0x2080
movl %eax, -0x1fc(%rbp)
jmp 0x2f67
movl -0x1fc(%rbp), %eax
movb %al, -0xbd(%rbp)
movsbl -0xbd(%rbp), %eax
cmpl $0xa, %eax
jne 0x2fc5
leaq -0xa8(%rbp), %rdi
callq 0x2ff0
movl %eax, -0x200(%rbp)
jmp 0x2f93
movl -0x200(%rbp), %esi
movq 0x5030(%rip), %rdi      # 0x7fd0
callq 0x21f0
movq %rax, -0x208(%rbp)
jmp 0x2fae
movq -0x208(%rbp), %rdi
movq 0x4ffc(%rip), %rsi      # 0x7fb8
callq 0x2160
jmp 0x2fc3
jmp 0x2fc5
jmp 0x2fce
xorl %edi, %edi
callq 0x2170
jmp 0x2fd0
jmp 0x2fd2
jmp 0x2569
movq -0xb8(%rbp), %rdi
callq 0x2210
nopw %cs:(%rax,%rax)
nopl (%rax)