// File: AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProcedureCall(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>)
bool Parser::ProcedureCall(string id){
	//argument list whose type and size values will be compared against those declared in the procedure's parameter list
	vector<scopeValue> argList;
	scopeValue procedureCall;
	bool isGlobal;
	int offset = 2;
	bool found;
	
	//ensure an id was found in the assignment statement check called right before ProcedureCall, otherwise return false
	if( id == "" ) return false;
	
	// Get procedure's declared information from scope table
	found = Scopes->checkSymbol(id, procedureCall, isGlobal);
	
	//get argument list used in the procedure call
	if( CheckToken(T_LPAREN) ){
		ArgumentList(argList, procedureCall, offset);
		if( !CheckToken(T_RPAREN) ) ReportLineError("Expected ')' closing procedure call");
	}
	else ReportError("expected '(' in procedure call");
	
	// Compare called argument list against the declared parameter list
	if( found ){
		bool match = true;
		
		// Iterators to go through the parameter and argument lists
		vector<scopeValue>::iterator it1 = argList.begin();
		vector<scopeValue>::iterator it2 = procedureCall.arguments.begin();
		
		while( (it1 != argList.end()) && (it2 != procedureCall.arguments.end()) ){
			if( (it1->type != it2->type) || (it1->size != it2->size) ) match = false;
			++it1;
			++it2;
		}
		if( (it1 != argList.end()) || (it2 != procedureCall.arguments.end()) || (!match) ){
			ReportError("Procedure call argument list does not match declared parameter list.");
		}
		
		// Set procedure call, then pop arguments after call and reset the Frame and Stack pointers
		generator->callProcedure( procedureCall, id);
		generator->setSPfromFP( Scopes->getFrameSize() );
		generator->popArguments( offset );
		return true;
	}
	else{
		ReportError("Procedure: " + id + " was not declared in this scope.");
		return true;
	}
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x2c0, %rsp            # imm = 0x2C0
movq %rsi, -0x260(%rbp)
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x268(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x12830
leaq -0x78(%rbp), %rdi
callq 0x126b0
movq -0x260(%rbp), %rdi
movl $0x2, -0x80(%rbp)
leaq 0x1ac35(%rip), %rsi     # 0x26c81
callq 0x6520
movb %al, -0x251(%rbp)
jmp 0xc059
movb -0x251(%rbp), %al
testb $0x1, %al
jne 0xc065
jmp 0xc08f
movb $0x0, -0x1(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xc735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc755
movq -0x260(%rbp), %rsi
movq -0x268(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x270(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x3130
jmp 0xc0b9
movq -0x270(%rbp), %rdi
leaq -0xb8(%rbp), %rsi
leaq -0x78(%rbp), %rdx
leaq -0x79(%rbp), %rcx
callq 0x18720
movb %al, -0x271(%rbp)
jmp 0xc0dc
movb -0x271(%rbp), %al
andb $0x1, %al
movb %al, -0x81(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x31a0
movq -0x268(%rbp), %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x9300
movb %al, -0x272(%rbp)
jmp 0xc10f
movb -0x272(%rbp), %al
testb $0x1, %al
jne 0xc11e
jmp 0xc276
leaq -0x100(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x12770
jmp 0xc130
movq -0x268(%rbp), %rdi
leaq -0x30(%rbp), %rsi
leaq -0x100(%rbp), %rdx
leaq -0x80(%rbp), %rcx
callq 0xc780
jmp 0xc14d
leaq -0x100(%rbp), %rdi
callq 0x12800
movq -0x268(%rbp), %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x9300
movb %al, -0x273(%rbp)
jmp 0xc172
movb -0x273(%rbp), %al
testb $0x1, %al
jne 0xc271
jmp 0xc182
leaq -0x121(%rbp), %rdi
movq %rdi, -0x280(%rbp)
callq 0x3430
movq -0x280(%rbp), %rdx
leaq 0x19a90(%rip), %rsi     # 0x25c33
leaq -0x120(%rbp), %rdi
callq 0x62d0
jmp 0xc1b1
movq -0x268(%rbp), %rdi
leaq -0x120(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xc1cb
leaq -0x120(%rbp), %rdi
callq 0x31a0
leaq -0x121(%rbp), %rdi
callq 0x32e0
jmp 0xc271
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x31a0
jmp 0xc755
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x100(%rbp), %rdi
callq 0x12800
jmp 0xc755
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc260
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x120(%rbp), %rdi
callq 0x31a0
leaq -0x121(%rbp), %rdi
callq 0x32e0
jmp 0xc755
jmp 0xc317
leaq -0x149(%rbp), %rdi
movq %rdi, -0x288(%rbp)
callq 0x3430
movq -0x288(%rbp), %rdx
leaq 0x199c0(%rip), %rsi     # 0x25c57
leaq -0x148(%rbp), %rdi
callq 0x62d0
jmp 0xc2a5
movq -0x268(%rbp), %rdi
leaq -0x148(%rbp), %rsi
callq 0x9060
jmp 0xc2ba
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0x149(%rbp), %rdi
callq 0x32e0
jmp 0xc317
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc306
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x31a0
leaq -0x149(%rbp), %rdi
callq 0x32e0
jmp 0xc755
testb $0x1, -0x81(%rbp)
je 0xc680
movb $0x1, -0x14a(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x12850
movq %rax, -0x158(%rbp)
leaq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x12850
movq %rax, -0x160(%rbp)
leaq -0x30(%rbp), %rdi
callq 0x128c0
movq %rax, -0x168(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x12880
movb %al, %cl
xorl %eax, %eax
testb $0x1, %cl
movb %al, -0x289(%rbp)
jne 0xc383
jmp 0xc3b0
leaq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x128c0
movq %rax, -0x170(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x170(%rbp), %rsi
callq 0x12880
movb %al, -0x289(%rbp)
movb -0x289(%rbp), %al
testb $0x1, %al
jne 0xc3bf
jmp 0xc43f
leaq -0x158(%rbp), %rdi
callq 0x128f0
movl (%rax), %eax
movl %eax, -0x290(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x128f0
movq %rax, %rcx
movl -0x290(%rbp), %eax
cmpl (%rcx), %eax
jne 0xc41b
leaq -0x158(%rbp), %rdi
callq 0x128f0
movl 0x4(%rax), %eax
movl %eax, -0x294(%rbp)
leaq -0x160(%rbp), %rdi
callq 0x128f0
movq %rax, %rcx
movl -0x294(%rbp), %eax
cmpl 0x4(%rcx), %eax
je 0xc422
movb $0x0, -0x14a(%rbp)
leaq -0x158(%rbp), %rdi
callq 0x12910
leaq -0x160(%rbp), %rdi
callq 0x12910
jmp 0xc34f
leaq -0x30(%rbp), %rdi
callq 0x128c0
movq %rax, -0x178(%rbp)
leaq -0x158(%rbp), %rdi
leaq -0x178(%rbp), %rsi
callq 0x12880
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x295(%rbp)
jne 0xc4b5
leaq -0x78(%rbp), %rdi
addq $0x8, %rdi
callq 0x128c0
movq %rax, -0x180(%rbp)
leaq -0x160(%rbp), %rdi
leaq -0x180(%rbp), %rsi
callq 0x12880
movb %al, %cl
movb $0x1, %al
testb $0x1, %cl
movb %al, -0x295(%rbp)
jne 0xc4b5
movb -0x14a(%rbp), %al
xorb $-0x1, %al
movb %al, -0x295(%rbp)
movb -0x295(%rbp), %al
testb $0x1, %al
jne 0xc4c4
jmp 0xc565
leaq -0x1a1(%rbp), %rdi
movq %rdi, -0x2a0(%rbp)
callq 0x3430
movq -0x2a0(%rbp), %rdx
leaq 0x19791(%rip), %rsi     # 0x25c76
leaq -0x1a0(%rbp), %rdi
callq 0x62d0
jmp 0xc4f3
movq -0x268(%rbp), %rdi
leaq -0x1a0(%rbp), %rsi
callq 0x9060
jmp 0xc508
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1a1(%rbp), %rdi
callq 0x32e0
jmp 0xc565
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc554
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x1a0(%rbp), %rdi
callq 0x31a0
leaq -0x1a1(%rbp), %rdi
callq 0x32e0
jmp 0xc755
movq -0x268(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x2a8(%rbp)
leaq -0x1f0(%rbp), %rdi
leaq -0x78(%rbp), %rsi
callq 0x12770
jmp 0xc58c
movq -0x260(%rbp), %rsi
leaq -0x210(%rbp), %rdi
callq 0x3130
jmp 0xc5a1
movq -0x2a8(%rbp), %rdi
leaq -0x1f0(%rbp), %rsi
leaq -0x210(%rbp), %rdx
callq 0x1e190
jmp 0xc5bd
leaq -0x210(%rbp), %rdi
callq 0x31a0
leaq -0x1f0(%rbp), %rdi
callq 0x12800
movq -0x268(%rbp), %rax
movq 0x90(%rax), %rdi
movq 0x98(%rax), %rax
movq %rax, -0x2b8(%rbp)
callq 0x189b0
movl %eax, -0x2ac(%rbp)
jmp 0xc5fe
movl -0x2ac(%rbp), %esi
movq -0x2b8(%rbp), %rdi
callq 0x1e630
jmp 0xc612
movq -0x268(%rbp), %rax
movq 0x98(%rax), %rdi
movl -0x80(%rbp), %esi
callq 0x1ec60
jmp 0xc62a
movb $0x1, -0x1(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xc735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc66f
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x210(%rbp), %rdi
callq 0x31a0
leaq -0x1f0(%rbp), %rdi
callq 0x12800
jmp 0xc755
movq -0x260(%rbp), %rdx
leaq 0x1962d(%rip), %rsi     # 0x25cbb
leaq -0x250(%rbp), %rdi
callq 0x124f0
jmp 0xc69c
leaq 0x19624(%rip), %rdx     # 0x25cc7
leaq -0x230(%rbp), %rdi
leaq -0x250(%rbp), %rsi
callq 0x12330
jmp 0xc6b8
movq -0x268(%rbp), %rdi
leaq -0x230(%rbp), %rsi
callq 0x9060
jmp 0xc6cd
leaq -0x230(%rbp), %rdi
callq 0x31a0
leaq -0x250(%rbp), %rdi
callq 0x31a0
movb $0x1, -0x1(%rbp)
movl $0x1, -0x98(%rbp)
jmp 0xc735
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
jmp 0xc727
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x90(%rbp)
movl %eax, -0x94(%rbp)
leaq -0x230(%rbp), %rdi
callq 0x31a0
leaq -0x250(%rbp), %rdi
callq 0x31a0
jmp 0xc755
leaq -0x78(%rbp), %rdi
callq 0x12800
leaq -0x30(%rbp), %rdi
callq 0x12930
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x2c0, %rsp            # imm = 0x2C0
popq %rbp
retq
leaq -0x78(%rbp), %rdi
callq 0x12800
leaq -0x30(%rbp), %rdi
callq 0x12930
movq -0x90(%rbp), %rdi
callq 0x3420
nopw %cs:(%rax,%rax)