// File: AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ArithOpPrime(int&, int&, bool, bool)
bool Parser::ArithOpPrime( int &inputType, int &inputSize, bool catchTypeError, bool catchSizeError ){
	//Size and type of next Relation in the ArithOp sequence
	int relationType, relationSize;
	
	//Get operation to pass to the codegenerator
	string op = token->ascii;
	
	//if '+' or '-' can't be found then return false ('null'). Otherwise continue function.
	if( CheckToken(T_ADD) );
	else if( CheckToken(T_SUBTRACT) );
	else return false;
	
	//Get next Relation. Otherwise report Missing Relation error.
	if( Relation(relationType, relationSize)){
		//Only allow number (integer / float) relations in arithmetic operations.
		if(catchTypeError){
			if( !isNumber(relationType) || !isNumber(inputType) ){
				ReportError("Only integer and float values are allowed for arithmetic operations.");
				catchTypeError = false;
			}
		}
		//Ensure compatible sizes are used in ArithOp.
		if(catchSizeError){
			//Error if sizes are not identical and both are non-zero
			if( (inputSize != relationSize) && (inputSize != 0) && (relationSize != 0) ){
				ReportError("Expected Relation of size " + to_string(inputSize) + ", but found one of size " + to_string(relationSize) + ".");
				catchSizeError = false;
			}
			//Assign inputSize as exprSize if inputSize is non-zero.
			else if(relationSize != 0) inputSize = relationSize;
		}
	}
	else{
		ReportError("Expected relation after arithmetic operator.");
		catchTypeError = false;
		catchSizeError = false;
	}
	//Continue to look for other +/- <relation> in case there is a missing arithOp or doubled up arithmetic operators
	ArithOpPrime( inputType, inputSize, catchTypeError, catchSizeError );
	
	//Evaluate arith op and push to the stack
	generator->evalExpr( op, inputSize, relationSize, inputType, relationType );
	
	return true;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1f0, %rsp            # imm = 0x1F0
movb %r8b, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
andb $0x1, %cl
movb %cl, -0x21(%rbp)
andb $0x1, %al
movb %al, -0x22(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x1c0(%rbp)
movq 0x80(%rax), %rsi
leaq -0x50(%rbp), %rdi
callq 0x3130
movq -0x1c0(%rbp), %rdi
movl $0x132, %esi            # imm = 0x132
callq 0x9300
movb %al, -0x1b1(%rbp)
jmp 0x10009
movb -0x1b1(%rbp), %al
testb $0x1, %al
jne 0x10015
jmp 0x10028
jmp 0x10061
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x104cb
movq -0x1c0(%rbp), %rdi
movl $0x133, %esi            # imm = 0x133
callq 0x9300
movb %al, -0x1c1(%rbp)
jmp 0x10041
movb -0x1c1(%rbp), %al
testb $0x1, %al
jne 0x1004d
jmp 0x1004f
jmp 0x1005f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x104b4
jmp 0x10061
movq -0x1c0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
leaq -0x2c(%rbp), %rdx
callq 0xff40
movb %al, -0x1c2(%rbp)
jmp 0x1007d
movb -0x1c2(%rbp), %al
testb $0x1, %al
jne 0x1008c
jmp 0x10356
testb $0x1, -0x21(%rbp)
je 0x10171
movq -0x1c0(%rbp), %rdi
leaq -0x28(%rbp), %rsi
callq 0xf850
movb %al, -0x1c3(%rbp)
jmp 0x100ae
movb -0x1c3(%rbp), %al
testb $0x1, %al
jne 0x100ba
jmp 0x100e2
movq -0x1c0(%rbp), %rdi
movq -0x18(%rbp), %rsi
callq 0xf850
movb %al, -0x1c4(%rbp)
jmp 0x100d2
movb -0x1c4(%rbp), %al
testb $0x1, %al
jne 0x1016f
jmp 0x100e2
leaq -0x81(%rbp), %rdi
movq %rdi, -0x1d0(%rbp)
callq 0x3430
movq -0x1d0(%rbp), %rdx
leaq 0x16590(%rip), %rsi     # 0x26693
leaq -0x80(%rbp), %rdi
callq 0x62d0
jmp 0x1010e
movq -0x1c0(%rbp), %rdi
leaq -0x80(%rbp), %rsi
callq 0x9060
jmp 0x10120
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x81(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x21(%rbp)
jmp 0x1016f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1015e
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x80(%rbp), %rdi
callq 0x31a0
leaq -0x81(%rbp), %rdi
callq 0x32e0
jmp 0x104cb
jmp 0x10171
testb $0x1, -0x22(%rbp)
je 0x10351
movq -0x20(%rbp), %rax
movl (%rax), %eax
cmpl -0x2c(%rbp), %eax
je 0x1033e
movq -0x20(%rbp), %rax
cmpl $0x0, (%rax)
je 0x1033e
cmpl $0x0, -0x2c(%rbp)
je 0x1033e
movq -0x20(%rbp), %rax
movl (%rax), %esi
leaq -0x128(%rbp), %rdi
callq 0x123d0
jmp 0x101b5
leaq 0x1651c(%rip), %rsi     # 0x266d8
leaq -0x108(%rbp), %rdi
leaq -0x128(%rbp), %rdx
callq 0x12380
jmp 0x101d1
leaq 0x16476(%rip), %rdx     # 0x2664e
leaq -0xe8(%rbp), %rdi
leaq -0x108(%rbp), %rsi
callq 0x12330
jmp 0x101ed
movl -0x2c(%rbp), %esi
leaq -0x148(%rbp), %rdi
callq 0x123d0
jmp 0x101fe
leaq -0xc8(%rbp), %rdi
leaq -0xe8(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x12990
jmp 0x1021a
leaq 0x16551(%rip), %rdx     # 0x26772
leaq -0xa8(%rbp), %rdi
leaq -0xc8(%rbp), %rsi
callq 0x12330
jmp 0x10236
movq -0x1c0(%rbp), %rdi
leaq -0xa8(%rbp), %rsi
callq 0x9060
jmp 0x1024b
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0xc8(%rbp), %rdi
callq 0x31a0
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0xe8(%rbp), %rdi
callq 0x31a0
leaq -0x108(%rbp), %rdi
callq 0x31a0
leaq -0x128(%rbp), %rdi
callq 0x31a0
movb $0x0, -0x22(%rbp)
jmp 0x1034f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x1032d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10321
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10315
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x10309
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x102fd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0xa8(%rbp), %rdi
callq 0x31a0
leaq -0xc8(%rbp), %rdi
callq 0x31a0
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0xe8(%rbp), %rdi
callq 0x31a0
leaq -0x108(%rbp), %rdi
callq 0x31a0
leaq -0x128(%rbp), %rdi
callq 0x31a0
jmp 0x104cb
cmpl $0x0, -0x2c(%rbp)
je 0x1034d
movl -0x2c(%rbp), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
jmp 0x1034f
jmp 0x10351
jmp 0x103f3
leaq -0x169(%rbp), %rdi
movq %rdi, -0x1d8(%rbp)
callq 0x3430
movq -0x1d8(%rbp), %rdx
leaq 0x1637c(%rip), %rsi     # 0x266f3
leaq -0x168(%rbp), %rdi
callq 0x62d0
jmp 0x10385
movq -0x1c0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x9060
jmp 0x1039a
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
movb $0x0, -0x21(%rbp)
movb $0x0, -0x22(%rbp)
jmp 0x103f3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
jmp 0x103e2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
jmp 0x104cb
movq -0x1c0(%rbp), %rdi
movq -0x18(%rbp), %rsi
movq -0x20(%rbp), %rdx
movzbl -0x22(%rbp), %r8d
movzbl -0x21(%rbp), %ecx
andl $0x1, %ecx
andl $0x1, %r8d
callq 0xffb0
jmp 0x10419
movq -0x1c0(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x1e0(%rbp)
leaq -0x1b0(%rbp), %rdi
leaq -0x50(%rbp), %rsi
callq 0x3130
jmp 0x10440
movq -0x1e0(%rbp), %rsi
movq -0x20(%rbp), %rax
movl (%rax), %ecx
movl -0x2c(%rbp), %r8d
movq -0x18(%rbp), %rax
movl (%rax), %r9d
movl -0x28(%rbp), %edx
movq %rsp, %rax
movl %edx, (%rax)
leaq -0x190(%rbp), %rdi
leaq -0x1b0(%rbp), %rdx
callq 0x1abf0
jmp 0x10475
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x1b0(%rbp), %rdi
callq 0x31a0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x60(%rbp)
jmp 0x104b4
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x58(%rbp)
movl %eax, -0x5c(%rbp)
leaq -0x1b0(%rbp), %rdi
callq 0x31a0
jmp 0x104cb
leaq -0x50(%rbp), %rdi
callq 0x31a0
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x1f0, %rsp            # imm = 0x1F0
popq %rbp
retq
leaq -0x50(%rbp), %rdi
callq 0x31a0
movq -0x58(%rbp), %rdi
callq 0x3420
nopl (%rax)