// File: /workspace/github_cpp_makefile_star2_O1/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, %ebp
movq %rdx, %r14
movq %rsi, %r12
movq %rdi, %r15
movl $0x106, %esi            # imm = 0x106
callq 0x5c0a
movl %eax, %ebx
testb %al, %al
je 0x7579
movl %ebp, 0xc(%rsp)
movb %bl, 0xb(%rsp)
movq 0x90(%r15), %rdi
callq 0xfafe
movq $0x11e, (%r14)          # imm = 0x11E
movq %r15, %rdi
movq %r12, %rsi
callq 0x6a86
testb %al, %al
je 0x758d
movq 0x90(%r15), %r13
leaq 0x80(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rbp
movq %rbp, %rdi
callq 0x3ba4
movq %r13, %rdi
movq %rbp, %rsi
callq 0x1029e
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7361
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r15), %r13
leaq 0x123d5(%rip), %rsi     # 0x19744
leaq 0x90(%rsp), %rbp
movq %rbp, %rdi
movq %r12, %rdx
callq 0xddc7
leaq 0xf0(%rsp), %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x15e04
leaq 0x20(%r14), %rdi
leaq 0xf0(%rsp), %r13
movq %r13, %rsi
callq 0x2270
movq (%r13), %rdi
leaq 0x100(%rsp), %rax
cmpq %rax, %rdi
je 0x73ca
movq 0x100(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x73eb
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r15), %r13
leaq 0x60(%rsp), %rbx
movq %rbx, -0x10(%rbx)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
leaq 0x50(%rsp), %rbp
movq %rbp, %rdi
callq 0x3ba4
movq %r13, %rdi
movq %rbp, %rsi
callq 0x160a4
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x7435
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r15, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x5c0a
testb %al, %al
je 0x75c3
movq %r15, %rdi
movq %r14, %rsi
callq 0x7d1e
movq %r15, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x5c0a
testb %al, %al
jne 0x74b1
leaq 0x40(%rsp), %rbx
movq %rbx, -0x10(%rbx)
leaq 0x122d9(%rip), %rsi     # 0x1974f
leaq 0x12311(%rip), %rdx     # 0x1978e
leaq 0x30(%rsp), %r13
movq %r13, %rdi
callq 0x3c34
movq %r15, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x74b1
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x90(%r15), %r13
leaq 0x20(%rsp), %rbp
movq %rbp, -0x10(%rbp)
movq (%r12), %rsi
movq 0x8(%r12), %rdx
addq %rsi, %rdx
leaq 0x10(%rsp), %rdi
callq 0x3ba4
movq (%r14), %rax
leaq 0x118(%rsp), %r15
movq %rax, -0x8(%r15)
leaq 0x8(%r14), %rsi
movq %r15, %rdi
callq 0xe0e0
leaq 0x130(%rsp), %rdi
leaq 0x140(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x20(%r14), %rsi
movq 0x28(%r14), %rdx
addq %rsi, %rdx
callq 0x3ba4
movq 0x40(%r14), %rax
leaq 0x110(%rsp), %rdx
movq %rax, 0x40(%rdx)
movzbl 0xc(%rsp), %ecx
leaq 0x10(%rsp), %rsi
movq %r13, %rdi
callq 0xfc28
movq 0x130(%rsp), %rdi
cmpq %r12, %rdi
je 0x7556
movq 0x140(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r15, %rdi
callq 0xdea4
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
movb 0xb(%rsp), %bl
je 0x7579
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movl %ebx, %eax
addq $0x158, %rsp            # imm = 0x158
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0xc0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x12226(%rip), %rsi     # 0x197c7
leaq 0x12251(%rip), %rdx     # 0x197f9
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c34
movq %r15, %rdi
movq %rbx, %rsi
callq 0x49ee
leaq 0xe0(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x121b8(%rip), %rsi     # 0x1978f
leaq 0x121e8(%rip), %rdx     # 0x197c6
leaq 0xd0(%rsp), %rbx
movq %rbx, %rdi
callq 0x3c34
movq %r15, %rdi
movq %rbx, %rsi
callq 0x49ee
movq %rax, %r14
movq 0x30(%rsp), %rdi
cmpq %rbx, %rdi
je 0x76ce
movq 0x40(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
leaq 0x110(%rsp), %rdi
callq 0xde7a
jmp 0x7636
movq %rax, %r14
movq %r15, %rdi
callq 0xdea4
jmp 0x7636
movq %rax, %r14
movq 0x10(%rsp), %rdi
cmpq %rbp, %rdi
je 0x76ce
movq 0x20(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
movq 0xd0(%rsp), %rdi
cmpq %r12, %rdi
je 0x76ce
movq 0xe0(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
movq 0x50(%rsp), %rdi
cmpq %rbx, %rdi
je 0x76ce
movq 0x60(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
leaq 0xa0(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x76ce
movq 0xa0(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
movq 0x70(%rsp), %rdi
cmpq %rbx, %rdi
je 0x76ce
movq 0x80(%rsp), %rsi
jmp 0x76c6
movq %rax, %r14
movq 0xb0(%rsp), %rdi
cmpq %r12, %rdi
je 0x76ce
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
callq 0x2330