// File: /workspace/github_cpp_makefile_star2_O1/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::ProcedureBody()
bool Parser::ProcedureBody(){
	bool resyncEnabled = true;
	bool procDec = false;
	//get symbol declarations for next procedure
	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);
		}
		
		// GEN: set the procedure's FP and SP in the program body after all declarations have been made
		// Each procedure declaration added its bytes to the frame size so this is the max size
		int frameSize = Scopes->getFrameSize();
		generator->setProcedurePointers(frameSize);
		
		//get statements for procedure body
		if( CheckToken(T_BEGIN) ){
			resyncEnabled = true;
			while(true){
				while( Statement() ){
					if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after statement in procedure",true);
				}
				if( CheckToken(T_END) ){

					// Add label for procedure end and return
					string labelEnd;
					labelEnd = generator->newLabel("Procedure_End");
					generator->placeLabel( labelEnd );
					generator->ProcedureReturn();

					if( CheckToken(T_PROCEDURE) ) return true;
					else{
						ReportError("expected 'end procedure' at end of procedure declaration");
						return true;
					}
				}
				else if(resyncEnabled){
					resyncEnabled = false;
					ReportLineError("Bad line. Expected Statement or 'end' reserved keyword in procedure body.");
				}
				else{
					ReportFatalError("expected 'end procedure' at end of procedure declaration");
					return false;
				}
			}
		}
		else if(resyncEnabled){
			resyncEnabled = false;
			ReportLineError("Bad line. Expected Declaration or 'begin' reserved keyword in procedure body.");
		}
		else{
			ReportFatalError("Parser resync failed. Couldn't find a valid declaration or the 'begin reserved keyword in procedure body.");
			return false;
		}
		
	}

}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x198, %rsp            # imm = 0x198
movq %rdi, %rbx
leaq 0xe(%rsp), %rax
movb $0x0, (%rax)
leaq 0x128(%rsp), %r12
leaq 0x48(%rsp), %r15
movb $0x1, %bpl
leaq 0x118(%rsp), %r13
movq %rbx, %rdi
leaq 0xe(%rsp), %rsi
callq 0x6b20
testb %al, %al
je 0x7802
movb 0xe(%rsp), %r14b
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
cmpb $0x1, %r14b
jne 0x778b
testb %al, %al
leaq 0x48(%rsp), %r15
jne 0x770a
leaq 0xe8(%rsp), %rax
movq %rax, 0xd8(%rsp)
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0x11cd9(%rip), %rsi     # 0x1943b
leaq 0x11d07(%rip), %rdx     # 0x19470
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
callq 0x4374
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rcx
jmp 0x77e6
testb %al, %al
leaq 0x48(%rsp), %r15
jne 0x770a
leaq 0xc8(%rsp), %rax
movq %rax, 0xb8(%rsp)
leaq 0xb8(%rsp), %r14
movq %r14, %rdi
leaq 0x11cb7(%rip), %rsi     # 0x19471
leaq 0x11ce4(%rip), %rdx     # 0x194a5
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rcx
movq %rcx, %rax
cmpq %rcx, %rdi
je 0x770a
movq (%rax), %rsi
incq %rsi
callq 0x2200
jmp 0x770a
movq 0x90(%rbx), %rdi
callq 0x10294
movq 0x98(%rbx), %rdi
movl %eax, %esi
callq 0x160c6
movq %rbx, %rdi
movl $0x103, %esi            # imm = 0x103
callq 0x5c0a
testb %al, %al
movb %al, 0xf(%rsp)
je 0x7915
movb $0x1, %bpl
leaq 0x11fbb(%rip), %r14     # 0x197fa
movq %rbx, %rdi
callq 0x6efc
movq %rbx, %rdi
testb %al, %al
je 0x78a5
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x783f
movq %r12, 0x118(%rsp)
movq %r13, %rdi
movq %r14, %rsi
leaq 0x11fb2(%rip), %rdx     # 0x19823
callq 0x3c34
movq %rbx, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x783f
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x783f
movl $0x104, %esi            # imm = 0x104
callq 0x5c0a
testb %al, %al
jne 0x7986
testb $0x1, %bpl
je 0x7b4b
movq %r15, 0x38(%rsp)
leaq 0x38(%rsp), %rbp
movq %rbp, %rdi
leaq 0x11f96(%rip), %rsi     # 0x1986b
leaq 0x11fd8(%rip), %rdx     # 0x198b4
callq 0x3c34
movq %rbx, %rdi
movq %rbp, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x38(%rsp), %rdi
xorl %ebp, %ebp
cmpq %r15, %rdi
je 0x783f
movq 0x48(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %ebp, %ebp
jmp 0x783f
testb $0x1, %bpl
leaq 0x108(%rsp), %r15
je 0x7b80
movq %r15, 0xf8(%rsp)
leaq 0xf8(%rsp), %r14
movq %r14, %rdi
leaq 0x11f74(%rip), %rsi     # 0x198b5
leaq 0x11fba(%rip), %rdx     # 0x19902
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x797a
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
xorl %ebp, %ebp
leaq 0x48(%rsp), %r15
jmp 0x7b2c
leaq 0x28(%rsp), %rax
movq %rax, 0x18(%rsp)
movq $0x0, 0x20(%rsp)
movb $0x0, 0x28(%rsp)
movq 0x98(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x88(%rsp), %rax
movq %rax, 0x78(%rsp)
leaq 0x78(%rsp), %rdi
leaq 0x11e61(%rip), %rsi     # 0x19824
leaq 0x11e67(%rip), %rdx     # 0x19831
callq 0x3c34
leaq 0x178(%rsp), %r14
movq %r14, %rdi
movq 0x10(%rsp), %rsi
leaq 0x78(%rsp), %rdx
callq 0x15e04
leaq 0x18(%rsp), %rdi
movq %r14, %rsi
callq 0x2270
movq 0x178(%rsp), %rdi
leaq 0x188(%rsp), %rax
cmpq %rax, %rdi
je 0x7a1b
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
leaq 0x98(%rsp), %r14
je 0x7a45
movq 0x88(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %rax
movq %rax, 0x10(%rsp)
leaq 0x68(%rsp), %rax
movq %rax, 0x58(%rsp)
movq 0x18(%rsp), %rsi
movq 0x20(%rsp), %rdx
addq %rsi, %rdx
leaq 0x58(%rsp), %rdi
callq 0x3ba4
movq 0x10(%rsp), %rdi
leaq 0x58(%rsp), %rsi
callq 0x160a4
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x7a9d
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %rdi
callq 0x165ea
movq %rbx, %rdi
movl $0x106, %esi            # imm = 0x106
callq 0x5c0a
testb %al, %al
jne 0x7b10
leaq 0xa8(%rsp), %rax
movq %rax, 0x98(%rsp)
movq %r14, %rdi
leaq 0x11d5e(%rip), %rsi     # 0x19832
leaq 0x11d8f(%rip), %rdx     # 0x1986a
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
callq 0x5696
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x7b10
movq 0xa8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7b2c
movq 0x28(%rsp), %rsi
incq %rsi
callq 0x2200
cmpb $0x0, 0xf(%rsp)
je 0x770a
movb $0x1, %al
addq $0x198, %rsp            # imm = 0x198
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x168(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x11cd4(%rip), %rsi     # 0x19832
leaq 0x11d05(%rip), %rdx     # 0x1986a
leaq 0x158(%rsp), %r14
movq %r14, %rdi
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49ee
leaq 0x148(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x11d70(%rip), %rsi     # 0x19903
leaq 0x11dd2(%rip), %rdx     # 0x1996c
leaq 0x138(%rsp), %r14
movq %r14, %rdi
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
callq 0x49ee
movq %rax, %rbx
movq 0x98(%rsp), %rdi
leaq 0xa8(%rsp), %rax
cmpq %rax, %rdi
je 0x7c67
movq 0xa8(%rsp), %rsi
jmp 0x7c18
jmp 0x7c64
movq %rax, %rbx
movq 0x78(%rsp), %rdi
leaq 0x88(%rsp), %rax
cmpq %rax, %rdi
je 0x7c67
movq 0x88(%rsp), %rsi
jmp 0x7c18
jmp 0x7c64
movq %rax, %rbx
movq 0x58(%rsp), %rdi
leaq 0x68(%rsp), %rax
cmpq %rax, %rdi
je 0x7c67
movq 0x68(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x7c67
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d16
movq 0x108(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d16
movq 0x148(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0x18(%rsp), %rdi
leaq 0x28(%rsp), %rax
cmpq %rax, %rdi
je 0x7d16
movq 0x28(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0xb8(%rsp), %rdi
leaq 0xc8(%rsp), %rax
cmpq %rax, %rdi
je 0x7d16
movq 0xc8(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
leaq 0xe8(%rsp), %rax
cmpq %rax, %rdi
je 0x7d16
movq 0xe8(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d16
movq 0x168(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0x38(%rsp), %rdi
cmpq %r15, %rdi
je 0x7d16
movq 0x48(%rsp), %rsi
jmp 0x7d0e
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r12, %rdi
je 0x7d16
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330