// File: /workspace/github_cpp_makefile_star2_O1/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::Destination(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, int&, int&, scopeValue&, bool&, bool&, bool&, int&)
bool Parser::Destination(string &id, int &dType, int &dSize, scopeValue &destinationValue, bool &found, bool &isGlobal, bool &indirect, int &indirect_type){
	//Variable to hold destination symbol's information from the nested scope tables
	int type, size;

	if( Identifier(id) ){
		found = Scopes->checkSymbol(id, destinationValue, isGlobal);

		/* if a procedure is found, return false. 
		 *This can't be a destination and the found id will be passed to a procedure call */
		if( (found) && (destinationValue.type == TYPE_PROCEDURE) ) return false;
		else if(!found){
			ReportError("Destination: " + id + " was not declared in this scope");
			dType = T_UNKNOWN;
			dSize = 0;
		}
		else{
			dType = destinationValue.type;
			dSize = destinationValue.size;
		}
		
		if(CheckToken(T_LBRACKET)){
			indirect = true;
			if( Expression(type, size) ){
				//ensure array index is a single numeric value
				indirect_type = type;
				if( size != 0 || ( (type != TYPE_FLOAT) && ( type != TYPE_INTEGER) && ( type != TYPE_BOOL) ) ) {
					ReportError("Destination array's index must be a scalar numeric value");
				}
				else dSize = 0;
				
				if( CheckToken(T_RBRACKET) ){
					return true;
				}
				else{
					ReportLineError("expected ']' after destination array's index");
					return true;
				}
			}
			else{
				ReportLineError("Bad Line. Expected scalar numeric expression in array index.");
				return true;
			}
		}
		else{
			indirect = false;
			return true;
		}
	}
	else return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0xd8, %rsp
movq %r9, %rbp
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
callq 0x6a86
testb %al, %al
je 0xa8da
movq %r15, 0x8(%rsp)
movq %r14, 0x10(%rsp)
movq %rbx, %r14
movq 0x90(%rbx), %r15
leaq 0x48(%rsp), %rax
movq %rax, -0x10(%rax)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x38(%rsp), %rbx
movq %rbx, %rdi
callq 0x3ba4
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x110(%rsp), %rcx
callq 0xff4c
movb %al, (%rbp)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xa8c7
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
movb (%rbp), %cl
movl (%r13), %eax
cmpl $0x11e, %eax            # imm = 0x11E
sete %dl
testb %dl, %cl
je 0xa8f0
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xd8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %r14, %r15
testb %cl, %cl
je 0xa90c
movq 0x8(%rsp), %rcx
movl %eax, (%rcx)
movl 0x4(%r13), %eax
movq 0x10(%rsp), %r14
jmp 0xa9d1
leaq 0xf289(%rip), %rsi      # 0x19b9c
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xddc7
leaq 0xf27d(%rip), %rsi      # 0x19baa
movq %rbx, %rdi
callq 0x2380
leaq 0x28(%rsp), %r14
movq %r14, -0x10(%r14)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0xa95c
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0xa963
movups (%rcx), %xmm0
movups %xmm0, (%r14)
movq 0x8(%rax), %rdx
leaq 0x18(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r15, %rdi
callq 0x5696
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0xa99e
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq 0x10(%rsp), %r14
je 0xa9c4
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x8(%rsp), %rax
movl $0x15e, (%rax)          # imm = 0x15E
xorl %eax, %eax
movq 0x118(%rsp), %rbx
movl %eax, (%r14)
movq %r15, %rdi
movl $0x135, %esi            # imm = 0x135
callq 0x5c0a
testb %al, %al
je 0xaa8c
movb $0x1, (%rbx)
leaq 0x4(%rsp), %rsi
movq %rsp, %rdx
movq %r15, %rdi
callq 0x8632
testb %al, %al
je 0xaa97
movq 0x120(%rsp), %rax
movl 0x4(%rsp), %ecx
movl %ecx, (%rax)
cmpl $0x0, (%rsp)
setne %al
addl $0xfffffef3, %ecx       # imm = 0xFFFFFEF3
cmpl $-0x3, %ecx
setb %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0xaae3
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf17f(%rip), %rsi      # 0x19bca
leaq 0xf1b0(%rip), %rdx      # 0x19c02
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c34
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5696
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xaaea
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xaaea
movb $0x0, (%rbx)
movb $0x1, %bpl
jmp 0xa8dc
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf189(%rip), %rsi      # 0x19c30
leaq 0xf1be(%rip), %rdx      # 0x19c6c
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c34
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x58(%rsp), %rdi
movb $0x1, %bpl
cmpq %r14, %rdi
je 0xa8dc
movq 0x68(%rsp), %rsi
jmp 0xab4f
movl $0x0, (%r14)
movq %r15, %rdi
movl $0x136, %esi            # imm = 0x136
callq 0x5c0a
movb $0x1, %bpl
testb %al, %al
jne 0xa8dc
leaq 0x88(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf0ee(%rip), %rsi      # 0x19c03
leaq 0xf113(%rip), %rdx      # 0x19c2f
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c34
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0xa8dc
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa8dc
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0xabfe
movq 0x88(%rsp), %rsi
jmp 0xabf6
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xabfe
movq 0xa8(%rsp), %rsi
jmp 0xabf6
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0xabfe
movq 0x68(%rsp), %rsi
jmp 0xabf6
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0xabc4
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xabc4
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xabfe
movq 0xc8(%rsp), %rsi
jmp 0xabf6
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xabfe
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330