// File: 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
movq %rsp, %rbp
subq $0x200, %rsp            # imm = 0x200
movb %cl, %al
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movq %rdx, -0x20(%rbp)
andb $0x1, %al
movb %al, -0x21(%rbp)
movq -0x10(%rbp), %rdi
movq %rdi, -0x1a0(%rbp)
movl $0x106, %esi            # imm = 0x106
callq 0x9300
testb $0x1, %al
jne 0xb29c
jmp 0xb709
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rdi
callq 0x18250
movq -0x1a0(%rbp), %rdi
movq -0x20(%rbp), %rax
movl $0x11e, (%rax)          # imm = 0x11E
movq -0x20(%rbp), %rax
movl $0x0, 0x4(%rax)
movq -0x18(%rbp), %rsi
callq 0xa800
testb $0x1, %al
jne 0xb2dd
jmp 0xb673
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x1b0(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x48(%rbp), %rdi
movq %rdi, -0x1a8(%rbp)
callq 0x3130
movq -0x1b0(%rbp), %rdi
movq -0x1a8(%rbp), %rsi
callq 0x189d0
jmp 0xb31b
leaq -0x48(%rbp), %rdi
callq 0x31a0
movq -0x1a0(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x1c0(%rbp)
movq -0x18(%rbp), %rdx
leaq 0x1a6c6(%rip), %rsi     # 0x25a0a
leaq -0x98(%rbp), %rdi
movq %rdi, -0x1b8(%rbp)
callq 0x124f0
movq -0x1c0(%rbp), %rsi
movq -0x1b8(%rbp), %rdx
leaq -0x78(%rbp), %rdi
callq 0x1ded0
jmp 0xb370
movq -0x20(%rbp), %rdi
addq $0x20, %rdi
leaq -0x78(%rbp), %rsi
movq %rsi, -0x1d8(%rbp)
callq 0x3340
movq -0x1d8(%rbp), %rdi
callq 0x31a0
leaq -0x98(%rbp), %rdi
callq 0x31a0
movq -0x1a0(%rbp), %rax
movq 0x98(%rax), %rax
movq %rax, -0x1d0(%rbp)
movq -0x20(%rbp), %rsi
addq $0x20, %rsi
leaq -0xb8(%rbp), %rdi
movq %rdi, -0x1c8(%rbp)
callq 0x3130
movq -0x1d0(%rbp), %rdi
movq -0x1c8(%rbp), %rsi
callq 0x1e060
jmp 0xb3e5
leaq -0xb8(%rbp), %rdi
callq 0x31a0
movq -0x1a0(%rbp), %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x9300
testb $0x1, %al
jne 0xb40b
jmp 0xb5d7
movq -0x1a0(%rbp), %rdi
movq -0x20(%rbp), %rsi
callq 0xbf10
movq -0x1a0(%rbp), %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x9300
testb $0x1, %al
jne 0xb525
leaq -0xd9(%rbp), %rdi
movq %rdi, -0x1e0(%rbp)
callq 0x3430
movq -0x1e0(%rbp), %rdx
leaq 0x1a5c0(%rip), %rsi     # 0x25a15
leaq -0xd8(%rbp), %rdi
callq 0x62d0
jmp 0xb463
movq -0x1a0(%rbp), %rdi
leaq -0xd8(%rbp), %rsi
movl $0x1, %edx
callq 0x8b50
jmp 0xb47d
leaq -0xd8(%rbp), %rdi
callq 0x31a0
leaq -0xd9(%rbp), %rdi
callq 0x32e0
jmp 0xb525
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x48(%rbp), %rdi
callq 0x31a0
jmp 0xb71b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x98(%rbp), %rdi
callq 0x31a0
jmp 0xb71b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb8(%rbp), %rdi
callq 0x31a0
jmp 0xb71b
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xb514
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xd8(%rbp), %rdi
callq 0x31a0
leaq -0xd9(%rbp), %rdi
callq 0x32e0
jmp 0xb71b
movq -0x1a0(%rbp), %rax
movq 0x90(%rax), %rax
movq %rax, -0x1e8(%rbp)
movq -0x18(%rbp), %rsi
leaq -0x100(%rbp), %rdi
callq 0x3130
movq -0x20(%rbp), %rsi
leaq -0x148(%rbp), %rdi
callq 0x12770
jmp 0xb55c
movq -0x1e8(%rbp), %rdi
movzbl -0x21(%rbp), %ecx
andl $0x1, %ecx
leaq -0x100(%rbp), %rsi
leaq -0x148(%rbp), %rdx
callq 0x183f0
jmp 0xb57f
leaq -0x148(%rbp), %rdi
callq 0x12800
leaq -0x100(%rbp), %rdi
callq 0x31a0
movb $0x1, -0x1(%rbp)
jmp 0xb70d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xb5c6
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x148(%rbp), %rdi
callq 0x12800
leaq -0x100(%rbp), %rdi
callq 0x31a0
jmp 0xb71b
leaq -0x169(%rbp), %rdi
movq %rdi, -0x1f0(%rbp)
callq 0x3430
movq -0x1f0(%rbp), %rdx
leaq 0x1a45d(%rip), %rsi     # 0x25a55
leaq -0x168(%rbp), %rdi
callq 0x62d0
jmp 0xb606
movq -0x1a0(%rbp), %rdi
leaq -0x168(%rbp), %rsi
callq 0x88a0
jmp 0xb61b
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x1(%rbp)
jmp 0xb70d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xb662
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x168(%rbp), %rdi
callq 0x31a0
leaq -0x169(%rbp), %rdi
callq 0x32e0
jmp 0xb71b
leaq -0x191(%rbp), %rdi
movq %rdi, -0x1f8(%rbp)
callq 0x3430
movq -0x1f8(%rbp), %rdx
leaq 0x1a3f9(%rip), %rsi     # 0x25a8d
leaq -0x190(%rbp), %rdi
callq 0x62d0
jmp 0xb6a2
movq -0x1a0(%rbp), %rdi
leaq -0x190(%rbp), %rsi
callq 0x88a0
jmp 0xb6b7
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x191(%rbp), %rdi
callq 0x32e0
movb $0x1, -0x1(%rbp)
jmp 0xb70d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0xb6fb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x190(%rbp), %rdi
callq 0x31a0
leaq -0x191(%rbp), %rdi
callq 0x32e0
jmp 0xb71b
movb $0x0, -0x1(%rbp)
movb -0x1(%rbp), %al
andb $0x1, %al
addq $0x200, %rsp            # imm = 0x200
popq %rbp
retq
movq -0x50(%rbp), %rdi
callq 0x3420
nopw %cs:(%rax,%rax)