// File: /workspace/github_cpp_makefile_star2_O1/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProgramBody()
bool Parser::ProgramBody(){
	bool resyncEnabled = true;
	bool procDec = false;
	string labelBegin = generator->newLabel("Begin_Program");
	//Get Procedure and Variable Declarations
	while(true){
		while( Declaration(procDec) ){
			if(procDec){
				if( !CheckToken(T_SEMICOLON) ) ReportWarning("expected ';' after procedure declaration in procedure");
			}
			else if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after variable declaration in procedure", true);
		}
		if(CheckToken(T_BEGIN)){
			// GEN: Place label to procedure entry and set the Stack Pointer
			generator->placeLabel(labelBegin);
			generator->setSPfromFP( Scopes->getFrameSize() );
			//reset resync for statements
			resyncEnabled = false;
			while(true){
				//get all valid statements
				while( Statement() ){
					if( !CheckToken(T_SEMICOLON) ) ReportLineError("Expected ';' at end of statement in program body.", true);
				}
				//get program body's end
				if(CheckToken(T_END)){
					if( CheckToken(T_PROGRAM) ) return true;
					else ReportError("Expected 'end program' to close program execution.");
				}
				//use up resync attempt if parser can't find a statement or 'end'
				else if(resyncEnabled){
					resyncEnabled = false;
					ReportLineError("Bad line. Expected Statement or 'END' reserved keyword in program body.");
				}
				//if resync failed, report a fatal error
				else ReportFatalError("Parser resync failed. Could not find another valid statement or end of program.");
			}
		}
		//use up resync attempt if parser can't find a declaration or 'begin'
		else if(resyncEnabled){
			resyncEnabled = false;
			ReportLineError("Bad line. Expected Declaration or 'BEGIN' reserved keyword in program body.");
		}
		//if resync failed, report a fatal error
		else{
			ReportFatalError("Parser resync failed. Could not find another valid declaration or start of program execution.");
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x148, %rsp            # imm = 0x148
movq %rdi, %rbx
movb $0x0, 0x3(%rsp)
movq 0x98(%rdi), %r14
leaq 0x138(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x12e99(%rip), %rsi     # 0x1942d
leaq 0x12e9f(%rip), %rdx     # 0x1943a
leaq 0x128(%rsp), %r15
movq %r15, %rdi
callq 0x3c34
leaq 0xc8(%rsp), %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x15e04
movq 0x128(%rsp), %rdi
cmpq %r12, %rdi
je 0x65db
movq 0x138(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x98(%rsp), %rbp
leaq 0xb8(%rsp), %r15
movb $0x1, %al
movl %eax, 0x4(%rsp)
leaq 0x3(%rsp), %r14
leaq 0x88(%rsp), %r12
movq %rbx, %rdi
movq %r14, %rsi
callq 0x6b20
testb %al, %al
je 0x66cf
cmpb $0x1, 0x3(%rsp)
jne 0x666c
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x65fe
movq %r15, 0xa8(%rsp)
leaq 0xa8(%rsp), %r13
movq %r13, %rdi
leaq 0x12df8(%rip), %rsi     # 0x1943b
leaq 0x12e26(%rip), %rdx     # 0x19470
callq 0x3c34
movq %rbx, %rdi
movq %r13, %rsi
callq 0x4374
movq 0xa8(%rsp), %rdi
movq %r15, %rax
cmpq %r15, %rdi
jne 0x66bf
jmp 0x65fe
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x65fe
movq %rbp, 0x88(%rsp)
movq %r12, %rdi
leaq 0x12de2(%rip), %rsi     # 0x19471
leaq 0x12e0f(%rip), %rdx     # 0x194a5
callq 0x3c34
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x88(%rsp), %rdi
movq %rbp, %rax
cmpq %rbp, %rdi
je 0x65fe
movq (%rax), %rsi
incq %rsi
callq 0x2200
jmp 0x65fe
movq %rbx, %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x5c0a
testb %al, %al
jne 0x6755
testb $0x1, 0x4(%rsp)
je 0x6913
leaq 0x18(%rsp), %rax
movq %rax, 0x8(%rsp)
leaq 0x8(%rsp), %r13
movq %r13, %rdi
leaq 0x12e57(%rip), %rsi     # 0x1955b
leaq 0x12e9b(%rip), %rdx     # 0x195a6
callq 0x3c34
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x8(%rsp), %rdi
movl $0x0, 0x4(%rsp)
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x65fe
movq 0x18(%rsp), %rsi
incq %rsi
callq 0x2200
movl $0x0, 0x4(%rsp)
jmp 0x65fe
movq 0x98(%rbx), %r14
leaq 0x78(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0xc8(%rsp), %rsi
movq 0xd0(%rsp), %rdx
addq %rsi, %rdx
leaq 0x68(%rsp), %rdi
callq 0x3ba4
leaq 0x68(%rsp), %rsi
movq %r14, %rdi
callq 0x160a4
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x67a6
movq 0x78(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x90(%rbx), %rdi
movq 0x98(%rbx), %r14
callq 0x10294
movq %r14, %rdi
movl %eax, %esi
callq 0x166b4
leaq 0x58(%rsp), %r15
leaq 0x28(%rsp), %r12
leaq 0x12d04(%rip), %r13     # 0x194d8
leaq 0x12d2f(%rip), %rbp     # 0x1950a
leaq 0x48(%rsp), %r14
movq %rbx, %rdi
callq 0x6efc
testb %al, %al
je 0x6843
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x67e0
leaq 0x38(%rsp), %rax
movq %rax, 0x28(%rsp)
movq %r12, %rdi
leaq 0x12c95(%rip), %rsi     # 0x194a6
leaq 0x12cbf(%rip), %rdx     # 0x194d7
callq 0x3c34
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x67e0
movq 0x38(%rsp), %rsi
jmp 0x689a
movq %rbx, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x5c0a
testb %al, %al
je 0x68dc
movq %rbx, %rdi
movl $0x101, %esi            # imm = 0x101
callq 0x5c0a
testb %al, %al
jne 0x68a7
movq %r15, 0x48(%rsp)
movq %r14, %rdi
movq %r13, %rsi
movq %rbp, %rdx
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5696
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x67e0
movq 0x58(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x67e0
leaq 0xd8(%rsp), %rax
movq -0x10(%rax), %rdi
cmpq %rax, %rdi
je 0x68c8
movq 0xd8(%rsp), %rsi
incq %rsi
callq 0x2200
movb $0x1, %al
addq $0x148, %rsp            # imm = 0x148
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x118(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x12c1c(%rip), %rsi     # 0x1950b
leaq 0x12c64(%rip), %rdx     # 0x1955a
leaq 0x108(%rsp), %rdi
callq 0x3c34
leaq 0x108(%rsp), %rsi
movq %rbx, %rdi
callq 0x49ee
leaq 0xf8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x12c81(%rip), %rsi     # 0x195a7
leaq 0x12cd7(%rip), %rdx     # 0x19604
leaq 0xe8(%rsp), %rdi
callq 0x3c34
leaq 0xe8(%rsp), %rsi
movq %rbx, %rdi
callq 0x49ee
movq %rax, %rbx
movq 0x68(%rsp), %rdi
cmpq %r15, %rdi
je 0x6a5f
movq 0x78(%rsp), %rsi
jmp 0x6a4e
movq %rax, %rbx
movq 0x128(%rsp), %rdi
jmp 0x6a6c
jmp 0x6a5c
movq %rax, %rbx
movq 0xe8(%rsp), %rdi
cmpq %r14, %rdi
je 0x6a5f
movq 0xf8(%rsp), %rsi
jmp 0x6a4e
jmp 0x6a5c
movq %rax, %rbx
movq 0x108(%rsp), %rdi
cmpq %r14, %rdi
je 0x6a5f
movq 0x118(%rsp), %rsi
jmp 0x6a4e
jmp 0x6a5c
movq %rax, %rbx
movq 0x28(%rsp), %rdi
leaq 0x38(%rsp), %rax
cmpq %rax, %rdi
je 0x6a5f
movq 0x38(%rsp), %rsi
jmp 0x6a4e
jmp 0x6a5c
jmp 0x6a5c
movq %rax, %rbx
movq 0x48(%rsp), %rdi
cmpq %r15, %rdi
je 0x6a5f
movq 0x58(%rsp), %rsi
jmp 0x6a4e
jmp 0x6a5c
movq %rax, %rbx
movq 0x8(%rsp), %rdi
leaq 0x18(%rsp), %rax
cmpq %rax, %rdi
je 0x6a5f
movq 0x18(%rsp), %rsi
jmp 0x6a4e
jmp 0x6a5c
jmp 0x6a5c
jmp 0x6a5c
movq %rax, %rbx
movq 0x88(%rsp), %rdi
cmpq %rbp, %rdi
je 0x6a5f
movq 0x98(%rsp), %rsi
jmp 0x6a4e
movq %rax, %rbx
movq 0xa8(%rsp), %rdi
cmpq %r15, %rdi
je 0x6a5f
movq 0xb8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x6a5f
jmp 0x6a5c
jmp 0x6a5c
movq %rax, %rbx
leaq 0xd8(%rsp), %r12
movq -0x10(%r12), %rdi
cmpq %r12, %rdi
je 0x6a7d
movq (%r12), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop