// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x170, %rsp            # imm = 0x170
movl %r8d, %ebp
movl %ecx, %r12d
movq %rdx, %r14
movq %rsi, %rbx
movq %rdi, %r15
movq 0x80(%rdi), %rsi
leaq 0x130(%rsp), %rdi
callq 0x2270
movq %r15, %rdi
movl $0x132, %esi            # imm = 0x132
callq 0x49b0
testb %al, %al
jne 0x820c
movq %r15, %rdi
movl $0x133, %esi            # imm = 0x133
callq 0x49b0
testb %al, %al
je 0x842b
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r15, %rdi
callq 0x816e
testb %al, %al
je 0x8388
testb %r12b, %r12b
je 0x827e
movl 0xc(%rsp), %eax
andl $-0x2, %eax
cmpl $0x10a, %eax            # imm = 0x10A
jne 0x8248
movl (%rbx), %eax
andl $-0x2, %eax
movb $0x1, %r12b
cmpl $0x10a, %eax            # imm = 0x10A
je 0x8281
leaq 0xa17e(%rip), %rsi      # 0x123cd
leaq 0x110(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x36b8
leaq 0x110(%rsp), %rsi
movq %r15, %rdi
callq 0x47e0
leaq 0x110(%rsp), %rdi
callq 0x20f0
xorl %r12d, %r12d
testb %bpl, %bpl
je 0x83b8
movl (%r14), %esi
movl 0x8(%rsp), %ecx
cmpl %ecx, %esi
je 0x844c
testl %esi, %esi
sete %al
testl %ecx, %ecx
sete %dl
orb %al, %dl
jne 0x844c
leaq 0x90(%rsp), %rdi
callq 0x96b3
leaq 0xa153(%rip), %rsi      # 0x12412
leaq 0xb0(%rsp), %rdi
leaq 0x90(%rsp), %rdx
callq 0x968f
leaq 0xa0ad(%rip), %rdx      # 0x12388
leaq 0xd0(%rsp), %rdi
leaq 0xb0(%rsp), %rsi
callq 0x9670
movl 0x8(%rsp), %esi
leaq 0x70(%rsp), %rdi
callq 0x96b3
leaq 0x10(%rsp), %rdi
leaq 0xd0(%rsp), %rsi
leaq 0x70(%rsp), %rdx
callq 0x9871
leaq 0xa190(%rip), %rdx      # 0x124ac
leaq 0xf0(%rsp), %rdi
leaq 0x10(%rsp), %rsi
callq 0x9670
leaq 0xf0(%rsp), %rsi
movq %r15, %rdi
callq 0x47e0
leaq 0xf0(%rsp), %rdi
callq 0x20f0
leaq 0x10(%rsp), %rdi
callq 0x20f0
leaq 0x70(%rsp), %rdi
callq 0x20f0
leaq 0xd0(%rsp), %rdi
callq 0x20f0
leaq 0xb0(%rsp), %rdi
callq 0x20f0
leaq 0x90(%rsp), %rdi
callq 0x20f0
jmp 0x83b8
leaq 0xa09e(%rip), %rsi      # 0x1242d
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x36b8
leaq 0x50(%rsp), %rsi
movq %r15, %rdi
callq 0x47e0
leaq 0x50(%rsp), %rdi
callq 0x20f0
xorl %r12d, %r12d
xorl %eax, %eax
movzbl %r12b, %ecx
movzbl %al, %r8d
movq %r15, %rdi
movq %rbx, %rsi
movq %r14, %rdx
callq 0x81b4
movq 0x98(%r15), %r15
leaq 0x30(%rsp), %rdi
leaq 0x130(%rsp), %rsi
callq 0x2270
movl (%r14), %ecx
movl 0x8(%rsp), %r8d
movl (%rbx), %r9d
movl 0xc(%rsp), %eax
movl %eax, (%rsp)
leaq 0x150(%rsp), %rdi
leaq 0x30(%rsp), %rdx
movq %r15, %rsi
callq 0xcbbe
leaq 0x150(%rsp), %rdi
callq 0x20f0
leaq 0x30(%rsp), %rdi
callq 0x20f0
movb $0x1, %bl
jmp 0x842d
xorl %ebx, %ebx
leaq 0x130(%rsp), %rdi
callq 0x20f0
movl %ebx, %eax
addq $0x170, %rsp            # imm = 0x170
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
testl %ecx, %ecx
je 0x83ba
movl %ecx, (%r14)
jmp 0x83ba
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x20f0
jmp 0x8473
movq %rax, %rbx
leaq 0x10(%rsp), %rdi
callq 0x20f0
jmp 0x8482
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
callq 0x20f0
jmp 0x8491
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
callq 0x20f0
jmp 0x84a3
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
callq 0x20f0
leaq 0x90(%rsp), %rdi
jmp 0x84e4
movq %rax, %rbx
jmp 0x84b0
jmp 0x84eb
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
jmp 0x84e4
jmp 0x84eb
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x84e4
jmp 0x84eb
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0x20f0
jmp 0x84ee
movq %rax, %rbx
leaq 0x130(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310
nop