// File: /workspace/github_cpp_makefile_star2_O3/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 0x6a76
testb %al, %al
je 0xa853
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 0x3bac
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq 0x110(%rsp), %rcx
callq 0xfeaa
movb %al, (%rbp)
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rcx
cmpq %rcx, %rdi
je 0xa842
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
movb (%rbp), %al
movl (%r13), %ecx
cmpl $0x11e, %ecx            # imm = 0x11E
sete %dl
testb %dl, %al
je 0xa869
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 $0x1, %al
je 0xa885
movq 0x8(%rsp), %rax
movl %ecx, (%rax)
movl 0x4(%r13), %eax
movq 0x10(%rsp), %r14
jmp 0xa94a
leaq 0xf310(%rip), %rsi      # 0x19b9c
leaq 0xb8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
callq 0xdcc7
leaq 0xf304(%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 0xa8d5
movq %rdx, 0x18(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x28(%rsp)
jmp 0xa8dc
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 0x5694
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0xa917
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
movq 0x10(%rsp), %r14
je 0xa93d
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 0x5c08
testb %al, %al
je 0xaa05
movb $0x1, (%rbx)
leaq 0x4(%rsp), %rsi
movq %rsp, %rdx
movq %r15, %rdi
callq 0x858a
testb %al, %al
je 0xaa10
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 0xaa5c
leaq 0xa8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf206(%rip), %rsi      # 0x19bca
leaq 0xf237(%rip), %rdx      # 0x19c02
leaq 0x98(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c42
movq %r15, %rdi
movq %rbx, %rsi
callq 0x5694
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xaa63
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xaa63
movb $0x0, (%rbx)
movb $0x1, %bpl
jmp 0xa855
leaq 0x68(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf210(%rip), %rsi      # 0x19c30
leaq 0xf245(%rip), %rdx      # 0x19c6c
leaq 0x58(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c42
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x58(%rsp), %rdi
movb $0x1, %bpl
cmpq %r14, %rdi
je 0xa855
movq 0x68(%rsp), %rsi
jmp 0xaac8
movl $0x0, (%r14)
movq %r15, %rdi
movl $0x136, %esi            # imm = 0x136
callq 0x5c08
movb $0x1, %bpl
testb %al, %al
jne 0xa855
leaq 0x88(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xf175(%rip), %rsi      # 0x19c03
leaq 0xf19a(%rip), %rdx      # 0x19c2f
leaq 0x78(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c42
movq %r15, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0xa855
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa855
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r14, %rdi
je 0xab77
movq 0x88(%rsp), %rsi
jmp 0xab6f
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %r14, %rdi
je 0xab77
movq 0xa8(%rsp), %rsi
jmp 0xab6f
movq %rax, %rbx
movq 0x58(%rsp), %rdi
cmpq %r14, %rdi
je 0xab77
movq 0x68(%rsp), %rsi
jmp 0xab6f
movq %rax, %rbx
movq 0x18(%rsp), %rdi
cmpq %r14, %rdi
je 0xab3d
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xab3d
movq %rax, %rbx
leaq 0xc8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0xab77
movq 0xc8(%rsp), %rsi
jmp 0xab6f
movq %rax, %rbx
movq 0x38(%rsp), %rdi
leaq 0x48(%rsp), %rax
cmpq %rax, %rdi
je 0xab77
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop