// File: /workspace/github_cpp_makefile_star2_O2/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProcedureHeader(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char>>&, scopeValue&, bool)
bool Parser::ProcedureHeader(string &id, scopeValue &procDeclaration, bool global){
	if( CheckToken(T_PROCEDURE) ){
		//Create new scope in nested symbol tables for the procedure
		Scopes->newScope();
		
		//Set the symbol table entry's type and size to the correct values for a procedure
		procDeclaration.type = TYPE_PROCEDURE;
		procDeclaration.size = 0;
		
		//get procedure identifier and set value to be added to the symbol table
		if( Identifier(id) ){
			Scopes->ChangeScopeName(id);
			
			// Get unique label from code generator and place at the start of the procedure
			procDeclaration.CallLabel = generator->newLabel( "Procedure_" + id );
			generator->placeLabel( procDeclaration.CallLabel );
		
			//get parameter list for the procedure, if it has parameters
			if( CheckToken(T_LPAREN) ){
				ParameterList(procDeclaration);
				if( !CheckToken(T_RPAREN) ) ReportLineError("Bad Line. Expected ')' after parameter list in procedure header");
				Scopes->addSymbol(id, procDeclaration, global);
				return true;
				
			}
			else{
				ReportFatalError("Expected '(' in procedure header before parameter list.");
				return true;
			}
		}
		else{
			ReportFatalError("Expected procedure identifier in procedure header.");
			return true;
		}
	}
	else return false;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x158, %rsp            # imm = 0x158
movl %ecx, %ebx
movq %rdx, %r15
movq %rsi, %r12
movq %rdi, %r14
movl $0x106, %esi            # imm = 0x106
callq 0x49b0
testb %al, %al
je 0x5a3c
movb %al, 0xb(%rsp)
movq 0x90(%r14), %rdi
callq 0xb0c2
movq $0x11e, (%r15)          # imm = 0x11E
movq %r14, %rdi
movq %r12, %rsi
callq 0x52ec
testb %al, %al
je 0x5a4e
movq 0x90(%r14), %r13
leaq 0xf0(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rsi
callq 0x2270
movq %r13, %rdi
movq %rbp, %rsi
callq 0xb4e0
movl %ebx, 0xc(%rsp)
leaq 0xf0(%rsp), %rdi
callq 0x20f0
movq 0x98(%r14), %r13
leaq 0xbe42(%rip), %rsi      # 0x11744
leaq 0xd0(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rdx
callq 0x970c
leaq 0x10(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0xeaa4
leaq 0x20(%r15), %r13
leaq 0x10(%rsp), %rbp
movq %r13, %rdi
movq %rbp, %rsi
callq 0x2240
movq %rbp, %rdi
callq 0x20f0
leaq 0xd0(%rsp), %rdi
callq 0x20f0
movq 0x98(%r14), %rbp
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
movq %r13, %rsi
callq 0x2270
movq %rbp, %rdi
movq %rbx, %rsi
callq 0xeb7e
leaq 0xb0(%rsp), %rdi
callq 0x20f0
movq %r14, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x49b0
testb %al, %al
movl 0xc(%rsp), %ebx
je 0x5a71
movq %r14, %rdi
movq %r15, %rsi
callq 0x5eea
movq %r14, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x49b0
testb %al, %al
jne 0x59e5
leaq 0xbd93(%rip), %rsi      # 0x1174f
leaq 0x50(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x36b8
leaq 0x50(%rsp), %rsi
pushq $0x1
popq %rdx
movq %r14, %rdi
callq 0x444c
leaq 0x50(%rsp), %rdi
callq 0x20f0
movq 0x90(%r14), %r14
leaq 0x30(%rsp), %rdi
movq %r12, %rsi
callq 0x2270
leaq 0x110(%rsp), %rdi
movq %r15, %rsi
callq 0x97e6
movzbl %bl, %ecx
leaq 0x30(%rsp), %rsi
leaq 0x110(%rsp), %rdx
movq %r14, %rdi
callq 0xb1c2
leaq 0x110(%rsp), %rdi
callq 0x9836
leaq 0x30(%rsp), %rdi
callq 0x20f0
movb 0xb(%rsp), %al
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xbd72(%rip), %rsi      # 0x117c7
leaq 0x70(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x36b8
leaq 0x70(%rsp), %rsi
movq %r14, %rdi
callq 0x4278
leaq 0xbd17(%rip), %rsi      # 0x1178f
leaq 0x90(%rsp), %rdi
leaq 0x10(%rsp), %rdx
callq 0x36b8
leaq 0x90(%rsp), %rsi
movq %r14, %rdi
callq 0x4278
movq %rax, %rbx
leaq 0x50(%rsp), %rdi
jmp 0x5b05
jmp 0x5abf
movq %rax, %rbx
leaq 0x90(%rsp), %rdi
jmp 0x5b05
jmp 0x5abf
movq %rax, %rbx
leaq 0x70(%rsp), %rdi
jmp 0x5b05
movq %rax, %rbx
jmp 0x5b0a
movq %rax, %rbx
leaq 0x110(%rsp), %rdi
callq 0x9836
jmp 0x5ad9
movq %rax, %rbx
leaq 0x30(%rsp), %rdi
jmp 0x5b05
movq %rax, %rbx
leaq 0xb0(%rsp), %rdi
jmp 0x5b05
movq %rax, %rbx
leaq 0xd0(%rsp), %rdi
jmp 0x5b05
movq %rax, %rbx
leaq 0xf0(%rsp), %rdi
callq 0x20f0
movq %rbx, %rdi
callq 0x2310