// File: /workspace/github_cpp_makefile_star2_O3/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::RelationPrime(int&, int&, bool, bool)
bool Parser::RelationPrime(int &inputType, int &inputSize, bool catchTypeError, bool catchSizeError){
	//Type and size of relation being compared to.
	int termType, termSize;

	//get relationsal op to pass to the codegenerator evaluation stack
	string op = token->ascii;
	
	if (CheckToken(T_COMPARE)){
		//Get next term, otherwise report missing term error.
		if( Term(termType, termSize) ){
			if(catchTypeError){
				//Ensure both terms are of type integer or bool. The two types can be compared against each other.
				if( ((inputType != TYPE_BOOL) && (inputType != TYPE_INTEGER)) || ((termType != TYPE_BOOL) && (termType != TYPE_INTEGER)) ){
					ReportError("Relational operators are only valid for terms of type bool or integers '0' and '1'.");
					catchTypeError = false;
				}
			}
			if(catchSizeError){
				//Ensure compatible sizes are used.
				if( (inputSize != termSize) && ( (inputSize != 0) && (termSize != 0) ) ){
					ReportError("Expected term of size " + to_string(inputSize) + ", but found one of size " + to_string(termSize) + ".");
					catchSizeError = false;
				}
				//Assign termSize to inputSize if termSize is non-zero.
				else if(termSize != 0) inputSize = termSize;
			}
		}
		else{
			ReportError("Expected term after relational operator.");
			catchTypeError = false;
			catchSizeError = false;
		}
		//Check for another relational operator and term.
		RelationPrime(inputType, inputSize, catchTypeError, catchSizeError);
		
		//evaluate relation expression and push to the codegenerator evaluation stack
		generator->evalExpr( op, inputSize, termSize, inputType, termType );
		
		return true;
	}
	else return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x178, %rsp            # imm = 0x178
movl %r8d, %ebp
movl %ecx, %r13d
movq %rdx, %r15
movq %rsi, %r14
movq %rdi, %r12
movq 0x80(%rdi), %rax
leaq 0xc8(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq (%rax), %rsi
movq 0x8(%rax), %rdx
addq %rsi, %rdx
leaq 0xb8(%rsp), %rdi
callq 0x3bac
movq %r12, %rdi
movl $0x139, %esi            # imm = 0x139
callq 0x5c08
movl %eax, %ebx
testb %al, %al
je 0xbf67
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rdx
movq %r12, %rdi
callq 0xbc90
testb %al, %al
je 0xbe5d
testb %r13b, %r13b
je 0xbdcc
movl (%r14), %eax
cmpl $0x10c, %eax            # imm = 0x10C
je 0xbd63
cmpl $0x10a, %eax            # imm = 0x10A
jne 0xbd78
movb $0x1, %sil
movl 0x10(%rsp), %eax
cmpl $0x10a, %eax            # imm = 0x10A
je 0xbdce
cmpl $0x10c, %eax            # imm = 0x10C
je 0xbdce
leaq 0x148(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xe6cf(%rip), %rsi      # 0x1a45a
leaq 0xe71b(%rip), %rdx      # 0x1a4ad
leaq 0x138(%rsp), %rdi
callq 0x3c42
leaq 0x138(%rsp), %rsi
movq %r12, %rdi
callq 0x5694
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0xbdcc
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %esi, %esi
testb %bpl, %bpl
je 0xbeb3
movl (%r15), %r13d
movl 0xc(%rsp), %ecx
cmpl %ecx, %r13d
je 0xbfa0
testq %r13, %r13
sete %al
testl %ecx, %ecx
sete %dl
orb %al, %dl
jne 0xbfa0
movl %r13d, %edi
negl %edi
cmovsl %r13d, %edi
movl $0x1, %ebp
cmpl $0xa, %edi
jb 0xbfb9
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %edi, %ecx
cmpl $0x63, %ecx
jbe 0xbfb2
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xbfb7
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xbfb9
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xbe1d
addl $-0x3, %ebp
jmp 0xbfb9
leaq 0x128(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0xe655(%rip), %rsi      # 0x1a4c5
leaq 0xe676(%rip), %rdx      # 0x1a4ed
leaq 0x118(%rsp), %rdi
callq 0x3c42
leaq 0x118(%rsp), %rsi
movq %r12, %rdi
callq 0x5694
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0xbeb1
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %esi, %esi
xorl %eax, %eax
movzbl %sil, %ecx
movzbl %al, %r8d
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0xbcd2
movq 0x98(%r12), %r12
leaq 0x108(%rsp), %r13
movq %r13, -0x10(%r13)
movq 0xb8(%rsp), %rsi
movq 0xc0(%rsp), %rdx
addq %rsi, %rdx
leaq 0xf8(%rsp), %rdi
callq 0x3bac
movl (%r15), %ecx
movl 0xc(%rsp), %r8d
movl (%r14), %r9d
movl 0x10(%rsp), %eax
movl %eax, (%rsp)
leaq 0x158(%rsp), %rdi
leaq 0xf8(%rsp), %rdx
movq %r12, %rsi
callq 0x11dd6
leaq 0x168(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xbf4a
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xf8(%rsp), %rdi
cmpq %r13, %rdi
je 0xbf67
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xbf8c
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2200
movl %ebx, %eax
addq $0x178, %rsp            # imm = 0x178
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movb $0x1, %al
testl %ecx, %ecx
je 0xbeb5
movl %ecx, (%r15)
jmp 0xbeb5
addl $-0x2, %ebp
jmp 0xbfb9
decl %ebp
movl %edi, 0x8(%rsp)
movl %esi, 0x14(%rsp)
shrl $0x1f, %r13d
leal (%rbp,%r13), %esi
leaq 0x88(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x78(%rsp), %rdi
movl $0x2d, %edx
callq 0x2240
leaq 0x78(%rsp), %rax
addq (%rax), %r13
movq %r13, %rdi
movl %ebp, %esi
movl 0x8(%rsp), %edx
callq 0xdf80
leaq 0xe4ac(%rip), %rcx      # 0x1a4ae
movl $0x16, %r8d
leaq 0x78(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2220
leaq 0xa8(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xc046
movq %rdx, 0x98(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xa8(%rsp)
jmp 0xc04c
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
leaq 0x98(%rsp), %rdi
movq %rdx, 0x8(%rdi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
leaq 0xe316(%rip), %rsi      # 0x1a388
callq 0x2380
leaq 0x48(%rsp), %rsi
movq %rsi, -0x10(%rsi)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xc09e
movq %rdx, 0x38(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x48(%rsp)
jmp 0xc0a4
movups (%rcx), %xmm0
movups %xmm0, (%rsi)
movq 0x8(%rax), %rdx
movq %rdx, 0x40(%rsp)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movl 0xc(%rsp), %r13d
movl %r13d, %esi
negl %esi
cmovsl %r13d, %esi
movl $0x1, %ebp
cmpl $0xa, %esi
jb 0xc118
movl $0x4, %ebp
movl $0xd1b71759, %eax       # imm = 0xD1B71759
movl %esi, %ecx
cmpl $0x63, %ecx
jbe 0xc111
cmpl $0x3e7, %ecx            # imm = 0x3E7
jbe 0xc116
cmpl $0x2710, %ecx           # imm = 0x2710
jb 0xc118
movl %ecx, %edx
imulq %rax, %rdx
shrq $0x2d, %rdx
addl $0x4, %ebp
cmpl $0x1869f, %ecx          # imm = 0x1869F
movl %edx, %ecx
ja 0xc0e0
addl $-0x3, %ebp
jmp 0xc118
addl $-0x2, %ebp
jmp 0xc118
decl %ebp
movl %esi, 0x8(%rsp)
shrl $0x1f, %r13d
leal (%rbp,%r13), %esi
leaq 0x28(%rsp), %rax
movq %rax, -0x10(%rax)
leaq 0x18(%rsp), %rdi
movl $0x2d, %edx
callq 0x2240
addq 0x18(%rsp), %r13
movq %r13, %rdi
movl %ebp, %esi
movl 0x8(%rsp), %edx
callq 0xdf80
movq 0x38(%rsp), %rcx
movq 0x40(%rsp), %r8
movq 0x20(%rsp), %rdx
leaq (%rdx,%r8), %rax
movl $0xf, %edi
leaq 0x48(%rsp), %rbp
cmpq %rbp, %rcx
je 0xc177
movq 0x48(%rsp), %rdi
movq 0x18(%rsp), %rsi
cmpq %rdi, %rax
jbe 0xc19a
movl $0xf, %edi
leaq 0x28(%rsp), %r9
cmpq %r9, %rsi
je 0xc195
movq 0x28(%rsp), %rdi
cmpq %rdi, %rax
jbe 0xc1a6
leaq 0x38(%rsp), %rdi
callq 0x20c0
jmp 0xc1b4
leaq 0x18(%rsp), %rdi
xorl %esi, %esi
xorl %edx, %edx
callq 0x2220
leaq 0x68(%rsp), %rdx
movq %rdx, -0x10(%rdx)
movq (%rax), %rsi
leaq 0x10(%rax), %rcx
cmpq %rcx, %rsi
je 0xc1d8
movq %rsi, 0x58(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x68(%rsp)
jmp 0xc1de
movups (%rcx), %xmm0
movups %xmm0, (%rdx)
movq %rax, %rdx
addq $0x8, %rdx
movq 0x8(%rax), %rsi
movq %rsi, 0x60(%rsp)
movq %rcx, (%rax)
movq $0x0, (%rdx)
movb $0x0, (%rcx)
leaq 0xe2aa(%rip), %rsi      # 0x1a4ac
leaq 0x58(%rsp), %rdi
callq 0x2380
leaq 0xe8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xc23c
movq %rdx, 0xd8(%rsp)
movq (%rcx), %rdx
movq %rdx, 0xe8(%rsp)
jmp 0xc244
movups (%rcx), %xmm0
movups %xmm0, (%r13)
movq 0x8(%rax), %rdx
leaq 0xd8(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r12, %rdi
callq 0x5694
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0xc288
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
leaq 0xa8(%rsp), %r13
je 0xc2ab
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xc2c7
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x38(%rsp), %rdi
cmpq %rbp, %rdi
je 0xc2de
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rsp), %rdi
cmpq %r13, %rdi
je 0xc2fb
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xc31d
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %eax, %eax
movl 0x14(%rsp), %esi
jmp 0xbeb5
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0xc34d
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc34d
movq %rax, %rbx
leaq 0x68(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xc36d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc36d
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0xc38e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc38e
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xc3af
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc3af
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0xc3d9
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc3d9
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0xc454
movq 0x88(%rsp), %rsi
jmp 0xc447
jmp 0xc451
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0xc454
movq 0x148(%rsp), %rsi
jmp 0xc447
jmp 0xc451
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0xc454
movq 0x128(%rsp), %rsi
jmp 0xc447
jmp 0xc451
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r13, %rdi
je 0xc454
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xc454
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0xc479
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop