// File: 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
movq %rsp, %rbp
subq $0x170, %rsp            # imm = 0x170
movq 0x20(%rbp), %rax
movq 0x18(%rbp), %rax
movq 0x10(%rbp), %rax
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
movq %rcx, -0x28(%rbp)
movq %r8, -0x30(%rbp)
movq %r9, -0x38(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x130(%rbp)
movq -0x18(%rbp), %rsi
callq 0xa800
testb $0x1, %al
jne 0xf43c
jmp 0xf830
movq -0x130(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x148(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x60(%rbp), %rdi
movq %rdi, -0x140(%rbp)
callq 0x3130
movq -0x148(%rbp), %rdi
movq -0x140(%rbp), %rsi
movq -0x30(%rbp), %rdx
movq 0x10(%rbp), %rcx
callq 0x18720
movb %al, -0x131(%rbp)
jmp 0xf488
movb -0x131(%rbp), %cl
movq -0x38(%rbp), %rax
andb $0x1, %cl
movb %cl, (%rax)
leaq -0x60(%rbp), %rdi
callq 0x31a0
movq -0x38(%rbp), %rax
testb $0x1, (%rax)
je 0xf4d8
movq -0x30(%rbp), %rax
cmpl $0x11e, (%rax)          # imm = 0x11E
jne 0xf4d8
movb $0x0, -0x1(%rbp)
jmp 0xf834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x60(%rbp), %rdi
callq 0x31a0
jmp 0xf842
movq -0x38(%rbp), %rax
testb $0x1, (%rax)
jne 0xf599
movq -0x18(%rbp), %rdx
leaq 0x16972(%rip), %rsi     # 0x25e62
leaq -0xb0(%rbp), %rdi
movq %rdi, -0x150(%rbp)
callq 0x124f0
movq -0x150(%rbp), %rsi
leaq 0x1695f(%rip), %rdx     # 0x25e70
leaq -0x90(%rbp), %rdi
callq 0x12330
jmp 0xf51f
movq -0x130(%rbp), %rdi
leaq -0x90(%rbp), %rsi
callq 0x9060
jmp 0xf534
leaq -0x90(%rbp), %rdi
callq 0x31a0
leaq -0xb0(%rbp), %rdi
callq 0x31a0
movq -0x20(%rbp), %rax
movl $0x15e, (%rax)          # imm = 0x15E
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
jmp 0xf5b2
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xf588
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x31a0
leaq -0xb0(%rbp), %rdi
callq 0x31a0
jmp 0xf842
movq -0x30(%rbp), %rax
movl (%rax), %ecx
movq -0x20(%rbp), %rax
movl %ecx, (%rax)
movq -0x30(%rbp), %rax
movl 0x4(%rax), %ecx
movq -0x28(%rbp), %rax
movl %ecx, (%rax)
jmp 0xf5b4
movq -0x130(%rbp), %rdi
movl $0x135, %esi            # imm = 0x135
callq 0x9300
testb $0x1, %al
jne 0xf5ce
jmp 0xf823
movq -0x130(%rbp), %rdi
movq 0x18(%rbp), %rax
movb $0x1, (%rax)
leaq -0x3c(%rbp), %rsi
leaq -0x40(%rbp), %rdx
callq 0xcab0
testb $0x1, %al
jne 0xf5f2
jmp 0xf788
movl -0x3c(%rbp), %ecx
movq 0x20(%rbp), %rax
movl %ecx, (%rax)
cmpl $0x0, -0x40(%rbp)
jne 0xf628
cmpl $0x10b, -0x3c(%rbp)     # imm = 0x10B
je 0xf6bd
cmpl $0x10a, -0x3c(%rbp)     # imm = 0x10A
je 0xf6bd
cmpl $0x10c, -0x3c(%rbp)     # imm = 0x10C
je 0xf6bd
leaq -0xd1(%rbp), %rdi
movq %rdi, -0x158(%rbp)
callq 0x3430
movq -0x158(%rbp), %rdx
leaq 0x16847(%rip), %rsi     # 0x25e90
leaq -0xd0(%rbp), %rdi
callq 0x62d0
jmp 0xf657
movq -0x130(%rbp), %rdi
leaq -0xd0(%rbp), %rsi
callq 0x9060
jmp 0xf66c
leaq -0xd0(%rbp), %rdi
callq 0x31a0
leaq -0xd1(%rbp), %rdi
callq 0x32e0
jmp 0xf6c7
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xf6ac
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xd0(%rbp), %rdi
callq 0x31a0
leaq -0xd1(%rbp), %rdi
callq 0x32e0
jmp 0xf842
movq -0x28(%rbp), %rax
movl $0x0, (%rax)
movq -0x130(%rbp), %rdi
movl $0x136, %esi            # imm = 0x136
callq 0x9300
testb $0x1, %al
jne 0xf6de
jmp 0xf6e7
movb $0x1, -0x1(%rbp)
jmp 0xf834
leaq -0xf9(%rbp), %rdi
movq %rdi, -0x160(%rbp)
callq 0x3430
movq -0x160(%rbp), %rdx
leaq 0x167c1(%rip), %rsi     # 0x25ec9
leaq -0xf8(%rbp), %rdi
callq 0x62d0
jmp 0xf716
movq -0x130(%rbp), %rdi
leaq -0xf8(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xf730
leaq -0xf8(%rbp), %rdi
callq 0x31a0
leaq -0xf9(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x1(%rbp)
jmp 0xf834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xf777
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0xf8(%rbp), %rdi
callq 0x31a0
leaq -0xf9(%rbp), %rdi
callq 0x32e0
jmp 0xf842
leaq -0x121(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x3430
movq -0x168(%rbp), %rdx
leaq 0x1674d(%rip), %rsi     # 0x25ef6
leaq -0x120(%rbp), %rdi
callq 0x62d0
jmp 0xf7b7
movq -0x130(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xf7d1
leaq -0x120(%rbp), %rdi
callq 0x31a0
leaq -0x121(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x1(%rbp)
jmp 0xf834
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
jmp 0xf815
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x68(%rbp)
movl %eax, -0x6c(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x31a0
leaq -0x121(%rbp), %rdi
callq 0x32e0
jmp 0xf842
movq 0x18(%rbp), %rax
movb $0x0, (%rax)
movb $0x1, -0x1(%rbp)
jmp 0xf834
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x170, %rsp            # imm = 0x170
popq %rbp
retq
movq -0x68(%rbp), %rdi
callq 0x3420
nopl (%rax,%rax)