// File: /workspace/github_cpp_makefile_star2_O3/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 %r13
pushq %r12
pushq %rbx
subq $0x1e8, %rsp            # imm = 0x1E8
movq %rsi, %r15
movq %rdi, %r14
xorps %xmm0, %xmm0
movaps %xmm0, 0x10(%rsp)
xorl %eax, %eax
movq %rax, 0x20(%rsp)
leaq 0x58(%rsp), %rbx
movq %rax, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq 0x80(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movl $0x2, 0xc(%rsp)
leaq 0x12b8d(%rip), %rsi     # 0x1a95d
movq %r15, %rdi
callq 0x20a0
movl %eax, %ebp
testl %eax, %eax
je 0x8213
movq 0x90(%r14), %r12
leaq 0xe8(%rsp), %r13
movq %r13, -0x10(%r13)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0xd8(%rsp), %rdi
callq 0x3bac
leaq 0xd8(%rsp), %rsi
leaq 0x50(%rsp), %rdx
leaq 0xb(%rsp), %rcx
movq %r12, %rdi
callq 0xfeaa
movl %eax, %r12d
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x7e46
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x5c08
testb %al, %al
je 0x7f48
movq 0x50(%rsp), %rax
leaq 0x1a8(%rsp), %r13
movq %rax, -0x8(%r13)
movq %r13, %rdi
movq %rbx, %rsi
callq 0xdfee
leaq 0x1c0(%rsp), %rdi
leaq 0x1d0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
callq 0x3bac
movq 0x90(%rsp), %rax
leaq 0x1a0(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
callq 0x83a4
movq 0x1c0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7ee0
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r13, %rdi
callq 0xdda4
movq %r14, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x5c08
leaq 0x58(%rsp), %rbx
testb %al, %al
jne 0x7f98
leaq 0x148(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x11a58(%rip), %rsi     # 0x1996d
leaq 0x11a74(%rip), %rdx     # 0x19990
leaq 0x138(%rsp), %rdi
callq 0x3c42
leaq 0x138(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x4e96
movq 0x138(%rsp), %rdi
jmp 0x7f87
leaq 0x128(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x11a36(%rip), %rsi     # 0x19991
leaq 0x11a4d(%rip), %rdx     # 0x199af
leaq 0x118(%rsp), %rdi
callq 0x3c42
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0x7f98
movq (%r13), %rsi
incq %rsi
callq 0x2200
testb %r12b, %r12b
je 0x7fe3
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdi
movq 0x58(%rsp), %rax
movq 0x60(%rsp), %rcx
movb $0x1, %dl
cmpq %rdi, %rsi
je 0x803c
cmpq %rcx, %rax
je 0x8046
movl (%rsi), %r8d
cmpl (%rax), %r8d
jne 0x7fd7
movl 0x4(%rsi), %r8d
cmpl 0x4(%rax), %r8d
je 0x7fd9
xorl %edx, %edx
addq $0x48, %rsi
addq $0x48, %rax
jmp 0x7fb3
leaq 0x11a0b(%rip), %rsi     # 0x199f5
leaq 0xf8(%rsp), %rdi
movq %r15, %rdx
callq 0xdcc7
leaq 0x11a00(%rip), %rsi     # 0x19a01
leaq 0xf8(%rsp), %rdi
callq 0x2380
leaq 0x40(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x81b0
movq %rdx, 0x30(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x40(%rsp)
jmp 0x81b7
cmpq %rcx, %rax
sete %al
testb %dl, %al
jne 0x809b
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x11956(%rip), %rsi     # 0x199b0
leaq 0x11993(%rip), %rdx     # 0x199f4
leaq 0xb8(%rsp), %rdi
callq 0x3c42
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x809b
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %r13
movq 0x50(%rsp), %rax
leaq 0x160(%rsp), %rdi
movq %rax, -0x8(%rdi)
movq %rbx, %rsi
callq 0xdfee
movl %ebp, %r12d
leaq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x70(%rsp), %rsi
movq 0x78(%rsp), %rdx
addq %rsi, %rdx
callq 0x3bac
movq 0x90(%rsp), %rax
movq %rax, 0x198(%rsp)
leaq 0xa8(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r15), %rsi
movq 0x8(%r15), %rdx
addq %rsi, %rdx
leaq 0x98(%rsp), %rdi
callq 0x3bac
leaq 0x158(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rdi
callq 0x16098
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x814c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
movl %r12d, %ebp
je 0x8174
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x160(%rsp), %rdi
callq 0xdda4
movq 0x90(%r14), %rdi
movq 0x98(%r14), %r15
callq 0x101ba
movq %r15, %rdi
movl %eax, %esi
callq 0x165d6
movq 0x98(%r14), %rdi
movl 0xc(%rsp), %esi
callq 0x169e8
jmp 0x8213
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x30(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x5694
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x81f2
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8213
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x8235
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
testl %ebp, %ebp
setne %bpl
movq %rbx, %rdi
callq 0xdda4
leaq 0x10(%rsp), %rdi
callq 0xdda4
movl %ebp, %eax
addq $0x1e8, %rsp            # imm = 0x1E8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0x8387
movq 0x148(%rsp), %rsi
jmp 0x8378
jmp 0x8384
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x8387
movq 0xc8(%rsp), %rsi
jmp 0x8378
jmp 0x8384
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x82d2
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x82d2
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x8330
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
jmp 0x8357
movq %rax, %rbx
movq 0x30(%rsp), %rdi
cmpq %r15, %rdi
je 0x8308
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8308
movq %rax, %rbx
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x8387
movq 0x108(%rsp), %rsi
jmp 0x8378
jmp 0x8384
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0xdd7a
jmp 0x8387
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0x8387
movq 0x128(%rsp), %rsi
jmp 0x8378
movq %rax, %rbx
movq %r13, %rdi
callq 0xdda4
jmp 0x8387
jmp 0x8384
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x8387
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8387
jmp 0x8384
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
callq 0xdd7a
leaq 0x10(%rsp), %rdi
callq 0xdda4
movq %rbx, %rdi
callq 0x2330
nop