// File: /workspace/github_cpp_makefile_star2_O2/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
pushq %r15
pushq %r14
pushq %r12
pushq %rbx
subq $0x1e0, %rsp            # imm = 0x1E0
movq %rsi, %r15
xorps %xmm0, %xmm0
andq $0x0, 0x20(%rsp)
leaq 0x138(%rsp), %rax
movups %xmm0, -0x28(%rax)
andq $0x0, -0x18(%rax)
movq %rax, -0x10(%rax)
andq $0x0, -0x8(%rax)
movq %rdi, %r14
movaps %xmm0, 0x10(%rsp)
movb $0x0, (%rax)
movl $0x2, 0xc(%rsp)
leaq 0xc96e(%rip), %rsi      # 0x1293d
movq %r15, %rdi
callq 0x3757
movl %eax, %ebx
testb %al, %al
jne 0x624f
movq 0x90(%r14), %r12
leaq 0xe8(%rsp), %rdi
movq %r15, %rsi
callq 0x2270
leaq 0xe8(%rsp), %rsi
leaq 0x108(%rsp), %rdx
leaq 0xb(%rsp), %rcx
movq %r12, %rdi
callq 0xb36a
movl %eax, %ebp
leaq 0xe8(%rsp), %rdi
callq 0x20f0
movq %r14, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x49b0
testb %al, %al
je 0x60bc
leaq 0x198(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x97e6
leaq 0x10(%rsp), %rsi
leaq 0x198(%rsp), %rdx
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
callq 0x6328
leaq 0x198(%rsp), %rdi
callq 0x9836
movq %r14, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x49b0
testb %al, %al
jne 0x60f2
leaq 0xb8e0(%rip), %rsi      # 0x1196d
leaq 0xc8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x36b8
leaq 0xc8(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x444c
leaq 0xc8(%rsp), %rdi
jmp 0x60ed
leaq 0xb8ce(%rip), %rsi      # 0x11991
leaq 0xa8(%rsp), %rdi
leaq 0x28(%rsp), %rdx
callq 0x36b8
leaq 0xa8(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0xa8(%rsp), %rdi
callq 0x20f0
testb %bpl, %bpl
je 0x613c
movq 0x10(%rsp), %rax
movq 0x18(%rsp), %rdx
movq 0x110(%rsp), %rcx
movq 0x118(%rsp), %rsi
movb $0x1, %dil
cmpq %rdx, %rax
je 0x618c
cmpq %rsi, %rcx
je 0x6197
movl (%rax), %r8d
cmpl (%rcx), %r8d
jne 0x6130
movl 0x4(%rax), %r8d
cmpl 0x4(%rcx), %r8d
je 0x6132
xorl %edi, %edi
addq $0x48, %rax
addq $0x48, %rcx
jmp 0x6114
leaq 0xb8b2(%rip), %rsi      # 0x119f5
leaq 0x28(%rsp), %rdi
movq %r15, %rdx
callq 0x970c
leaq 0xb8aa(%rip), %rdx      # 0x11a01
leaq 0x48(%rsp), %rdi
leaq 0x28(%rsp), %rsi
callq 0x9670
leaq 0x48(%rsp), %rsi
movq %r14, %rdi
callq 0x47e0
leaq 0x48(%rsp), %rdi
callq 0x20f0
leaq 0x28(%rsp), %rdi
callq 0x20f0
jmp 0x624f
cmpq %rsi, %rcx
sete %al
testb %dil, %al
jne 0x61cd
leaq 0xb812(%rip), %rsi      # 0x119b0
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
movq 0x98(%r14), %r12
leaq 0x150(%rsp), %rdi
leaq 0x108(%rsp), %rsi
callq 0x97e6
leaq 0x68(%rsp), %rdi
movq %r15, %rsi
callq 0x2270
leaq 0x150(%rsp), %rsi
leaq 0x68(%rsp), %rdx
movq %r12, %rdi
callq 0xec20
leaq 0x68(%rsp), %rdi
callq 0x20f0
leaq 0x150(%rsp), %rdi
callq 0x9836
movq 0x90(%r14), %rdi
movq 0x98(%r14), %r15
callq 0xb4d6
movq %r15, %rdi
movl %eax, %esi
callq 0xeece
movq 0x98(%r14), %rdi
movl 0xc(%rsp), %esi
callq 0xf1ae
xorb $0x1, %bl
leaq 0x108(%rsp), %rdi
callq 0x9836
leaq 0x10(%rsp), %rdi
callq 0x9850
movl %ebx, %eax
addq $0x1e0, %rsp            # imm = 0x1E0
popq %rbx
popq %r12
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
leaq 0xc8(%rsp), %rdi
jmp 0x62fc
jmp 0x6305
movq %rax, %rbx
leaq 0x88(%rsp), %rdi
jmp 0x62fc
jmp 0x6305
movq %rax, %rbx
leaq 0x68(%rsp), %rdi
callq 0x20f0
jmp 0x62ab
movq %rax, %rbx
leaq 0x150(%rsp), %rdi
jmp 0x62e8
movq %rax, %rbx
leaq 0x48(%rsp), %rdi
callq 0x20f0
jmp 0x62c7
movq %rax, %rbx
leaq 0x28(%rsp), %rdi
jmp 0x62fc
jmp 0x6305
movq %rax, %rbx
leaq 0xa8(%rsp), %rdi
jmp 0x62fc
movq %rax, %rbx
leaq 0x198(%rsp), %rdi
callq 0x9836
jmp 0x6308
jmp 0x6305
movq %rax, %rbx
leaq 0xe8(%rsp), %rdi
callq 0x20f0
jmp 0x6308
jmp 0x6305
movq %rax, %rbx
leaq 0x108(%rsp), %rdi
callq 0x9836
leaq 0x10(%rsp), %rdi
callq 0x9850
movq %rbx, %rdi
callq 0x2310
nop