// File: /workspace/github_cpp_makefile_star2_O1/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 0x38(%rsp), %rbx
movq %rax, 0x10(%rbx)
movups %xmm0, (%rbx)
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb $0x0, (%rcx)
movl $0x2, 0xc(%rsp)
leaq 0x12b20(%rip), %rsi     # 0x1a95d
movq %r15, %rdi
callq 0x20a0
movl %eax, %ebp
testl %eax, %eax
je 0x82ae
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 0x3ba4
leaq 0xd8(%rsp), %rsi
leaq 0x30(%rsp), %rdx
leaq 0xb(%rsp), %rcx
movq %r12, %rdi
callq 0xff4c
movl %eax, %r12d
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x7eb3
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x5c0a
testb %al, %al
je 0x7fb2
movq 0x30(%rsp), %rax
leaq 0x1a8(%rsp), %r13
movq %rax, -0x8(%r13)
movq %r13, %rdi
movq %rbx, %rsi
callq 0xe0e0
leaq 0x1c0(%rsp), %rdi
leaq 0x1d0(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
callq 0x3ba4
movq 0x70(%rsp), %rax
leaq 0x1a0(%rsp), %rdx
movq %rax, 0x40(%rdx)
leaq 0x10(%rsp), %rsi
leaq 0xc(%rsp), %rcx
movq %r14, %rdi
callq 0x843c
movq 0x1c0(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7f4a
movq 0x1d0(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r13, %rdi
callq 0xdea4
movq %r14, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x5c0a
leaq 0x38(%rsp), %rbx
testb %al, %al
jne 0x8002
leaq 0x148(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x119ee(%rip), %rsi     # 0x1996d
leaq 0x11a0a(%rip), %rdx     # 0x19990
leaq 0x138(%rsp), %rdi
callq 0x3c34
leaq 0x138(%rsp), %rsi
movq %r14, %rdi
movl $0x1, %edx
callq 0x4e82
movq 0x138(%rsp), %rdi
jmp 0x7ff1
leaq 0x128(%rsp), %r13
movq %r13, -0x10(%r13)
leaq 0x119cc(%rip), %rsi     # 0x19991
leaq 0x119e3(%rip), %rdx     # 0x199af
leaq 0x118(%rsp), %rdi
callq 0x3c34
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0x5696
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0x8002
movq (%r13), %rsi
incq %rsi
callq 0x2200
testb %r12b, %r12b
je 0x806b
movq 0x10(%rsp), %rdx
movq 0x18(%rsp), %rsi
movq 0x38(%rsp), %rax
cmpq %rsi, %rdx
setne %r8b
je 0x80c3
movq 0x40(%rsp), %rdi
cmpq %rdi, %rax
je 0x8136
addq $0x48, %rdx
movb $0x1, %cl
movl -0x48(%rdx), %r8d
cmpl (%rax), %r8d
jne 0x804a
movl -0x44(%rdx), %r8d
cmpl 0x4(%rax), %r8d
je 0x804c
xorl %ecx, %ecx
addq $0x48, %rax
cmpq %rsi, %rdx
setne %r8b
je 0x813d
addq $0x48, %rdx
cmpq %rdi, %rax
jne 0x8037
jmp 0x8138
leaq 0x11983(%rip), %rsi     # 0x199f5
leaq 0xf8(%rsp), %rdi
movq %r15, %rdx
callq 0xddc7
leaq 0x11978(%rip), %rsi     # 0x19a01
leaq 0xf8(%rsp), %rdi
callq 0x2380
leaq 0x88(%rsp), %r15
movq %r15, -0x10(%r15)
movq (%rax), %rdx
movq %rax, %rcx
addq $0x10, %rcx
cmpq %rcx, %rdx
je 0x80c7
movq %rdx, 0x78(%rsp)
movq (%rcx), %rdx
movq %rdx, 0x88(%rsp)
jmp 0x80ce
movb $0x1, %cl
jmp 0x813d
movups (%rcx), %xmm0
movups %xmm0, (%r15)
movq 0x8(%rax), %rdx
leaq 0x78(%rsp), %rsi
movq %rdx, 0x8(%rsi)
movq %rcx, (%rax)
movq $0x0, 0x8(%rax)
movb $0x0, 0x10(%rax)
movq %r14, %rdi
callq 0x5696
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x810c
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x82ae
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x82ae
movb $0x1, %cl
testb %r8b, %r8b
jne 0x8149
cmpq 0x40(%rsp), %rax
jne 0x8149
testb $0x1, %cl
jne 0x819e
leaq 0xc8(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x11853(%rip), %rsi     # 0x199b0
leaq 0x11890(%rip), %rdx     # 0x199f4
leaq 0xb8(%rsp), %rdi
callq 0x3c34
leaq 0xb8(%rsp), %rsi
movq %r14, %rdi
callq 0x5696
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x819e
movq 0xc8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %r13
movq 0x30(%rsp), %rax
leaq 0x160(%rsp), %rdi
movq %rax, -0x8(%rdi)
movq %rbx, %rsi
callq 0xe0e0
movl %ebp, %r12d
leaq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
movq %rax, -0x10(%rax)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
callq 0x3ba4
movq 0x70(%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 0x3ba4
leaq 0x158(%rsp), %rsi
leaq 0x98(%rsp), %rdx
movq %r13, %rdi
callq 0x16176
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x824c
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
movl %r12d, %ebp
je 0x8274
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x160(%rsp), %rdi
callq 0xdea4
movq 0x90(%r14), %rdi
movq 0x98(%r14), %r15
callq 0x10294
movq %r15, %rdi
movl %eax, %esi
callq 0x166b4
movq 0x98(%r14), %rdi
movl 0xc(%rsp), %esi
callq 0x16acc
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0x82ca
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
testl %ebp, %ebp
setne %bpl
movq %rbx, %rdi
callq 0xdea4
leaq 0x10(%rsp), %rdi
callq 0xdea4
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 0x841f
movq 0x148(%rsp), %rsi
jmp 0x8410
jmp 0x841c
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
cmpq %r12, %rdi
je 0x841f
movq 0xc8(%rsp), %rsi
jmp 0x8410
jmp 0x841c
movq %rax, %rbx
movq 0x98(%rsp), %rdi
cmpq %rbp, %rdi
je 0x8367
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x8367
movq %rax, %rbx
leaq 0x158(%rsp), %rdi
jmp 0x83c8
movq %rax, %rbx
leaq 0x160(%rsp), %rdi
jmp 0x83ef
movq %rax, %rbx
movq 0x78(%rsp), %rdi
cmpq %r15, %rdi
je 0x83a0
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x83a0
movq %rax, %rbx
leaq 0x108(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x841f
movq 0x108(%rsp), %rsi
jmp 0x8410
jmp 0x841c
movq %rax, %rbx
leaq 0x1a0(%rsp), %rdi
callq 0xde7a
jmp 0x841f
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r13, %rdi
je 0x841f
movq 0x128(%rsp), %rsi
jmp 0x8410
movq %rax, %rbx
movq %r13, %rdi
callq 0xdea4
jmp 0x841f
jmp 0x841c
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %r13, %rdi
je 0x841f
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x841f
jmp 0x841c
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
callq 0xde7a
leaq 0x10(%rsp), %rdi
callq 0xdea4
movq %rbx, %rdi
callq 0x2330
nop