// File: /workspace/github_cpp_makefile_star2_O2/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 $0xe8, %rsp
movq %r9, %rbp
movq %r8, %r13
movq %rcx, %r14
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %rbx
callq 0x52ec
testb %al, %al
je 0x7b01
movq %r15, 0x10(%rsp)
movq %r14, 0x18(%rsp)
movq 0x120(%rsp), %r14
movq %rbx, 0x20(%rsp)
movq 0x90(%rbx), %r15
leaq 0xc8(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rsi
callq 0x2270
movq %r15, %rdi
movq %rbx, %rsi
movq %r13, %rdx
movq %r14, %rcx
callq 0xb36a
movb %al, (%rbp)
leaq 0xc8(%rsp), %rdi
callq 0x20f0
movb (%rbp), %cl
movl (%r13), %eax
cmpl $0x11e, %eax            # imm = 0x11E
sete %dl
testb %dl, %cl
je 0x7b17
xorl %ebp, %ebp
movl %ebp, %eax
addq $0xe8, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
testb %cl, %cl
je 0x7b32
movq 0x10(%rsp), %rcx
movl %eax, (%rcx)
movl 0x4(%r13), %eax
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
jmp 0x7b9e
leaq 0xa063(%rip), %rsi      # 0x11b9c
leaq 0x28(%rsp), %rbx
movq %rbx, %rdi
movq %r12, %rdx
callq 0x970c
leaq 0xa05a(%rip), %rdx      # 0x11baa
leaq 0xa8(%rsp), %rdi
movq %rbx, %rsi
callq 0x9670
movq 0x20(%rsp), %r14
movq 0x18(%rsp), %r15
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0xa8(%rsp), %rdi
callq 0x20f0
leaq 0x28(%rsp), %rdi
callq 0x20f0
movq 0x10(%rsp), %rax
movl $0x15e, (%rax)          # imm = 0x15E
xorl %eax, %eax
movq 0x128(%rsp), %rbx
movl %eax, (%r15)
movq %r14, %rdi
movl $0x135, %esi            # imm = 0x135
callq 0x49b0
testb %al, %al
je 0x7c34
movb $0x1, (%rbx)
leaq 0xc(%rsp), %rsi
leaq 0x8(%rsp), %rdx
movq %r14, %rdi
callq 0x64cc
testb %al, %al
je 0x7c39
movq 0x130(%rsp), %rax
movl 0xc(%rsp), %ecx
movl %ecx, (%rax)
cmpl $0x0, 0x8(%rsp)
setne %al
addl $0xfffffef3, %ecx       # imm = 0xFFFFFEF3
cmpl $-0x3, %ecx
setb %cl
orb %al, %cl
cmpb $0x1, %cl
jne 0x7c71
leaq 0x9fc7(%rip), %rsi      # 0x11bca
leaq 0x88(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x36b8
leaq 0x88(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0x88(%rsp), %rdi
callq 0x20f0
jmp 0x7c75
movb $0x0, (%rbx)
jmp 0x7c69
leaq 0x9ff0(%rip), %rsi      # 0x11c30
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x36b8
leaq 0x48(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x444c
leaq 0x48(%rsp), %rdi
callq 0x20f0
movb $0x1, %bpl
jmp 0x7b03
andl $0x0, (%r15)
movq %r14, %rdi
movl $0x136, %esi            # imm = 0x136
callq 0x49b0
movb $0x1, %bpl
testb %al, %al
jne 0x7b03
leaq 0x9f6f(%rip), %rsi      # 0x11c03
leaq 0x68(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x36b8
leaq 0x68(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x444c
leaq 0x68(%rsp), %rdi
callq 0x20f0
jmp 0x7b03
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
jmp 0x7d13
jmp 0x7ce7
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x7d13
jmp 0x7ce7
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
jmp 0x7d13
movq %rax, %rbx
jmp 0x7d18
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
callq 0x20f0
jmp 0x7d01
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x7d13
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310