// File: /workspace/github_cpp_makefile_star2_O3/AndrewAlbert[P]Compiler-Theory/SourceCode/parser.cpp
// Function: Parser::LoopStatement()
bool Parser::LoopStatement(){
	int type, size;
	string id;
	bool resyncEnabled = true;
	
	//Determine if a loop statement is going to be declared
	if( !CheckToken(T_FOR) ) return false;
	string labelCond, labelTrue, labelEnd;
	labelCond = generator->newLabel("Loop_Check");
	labelTrue = generator->newLabel("Loop_True");
	labelEnd = generator->newLabel("Loop_End");
	
	generator->placeLabel(labelCond);

	/* get assignment statement and expression for loop: '( <assignment_statement> ; <expression> )'
	 * Throws errors if '(' or ')' is missing. Throws warnings for other missing components */
	if( !CheckToken(T_LPAREN) ) ReportFatalError("expected '(' before assignment and expression in for loop statement");

	if( !Assignment(id) ) ReportError("expected an assignment at start of for loop statement");

	if( !CheckToken(T_SEMICOLON) ) ReportError("expected ';' separating assignment statement and expression in for loop statement");

	if( !Expression(type, size) ) ReportError("expected a valid expression following assignment in for loop statement");
	else generator->condBranch( labelTrue, labelEnd );

	if( !CheckToken(T_RPAREN) ) ReportError("expected ')' after assignment and expression in for loop statement");
	generator->placeLabel(labelTrue);
	while(true){
		while( Statement() ){
			if( !CheckToken(T_SEMICOLON) ) ReportLineError("expected ';' after statement in for loop",true);
		}
		
		/* check for correct closure of loop: 'end loop' */
		generator->branch(labelCond);

		if( CheckToken(T_END) ){
			generator->placeLabel(labelEnd);
			if( !CheckToken(T_FOR) ) ReportError("missing 'for' in the 'end for' closure of the for loop statement");
			return true;
		}
		else if(resyncEnabled){
			resyncEnabled = false;
			ReportLineError("Bad line. Could not find a valid statement or 'end' reserved keyword in loop statement.");
		}
		else{
			ReportFatalError("expected 'end for' at end of for loop statement");
			return false;	
		}
	}
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x2f8, %rsp            # imm = 0x2F8
movq %rdi, %r14
leaq 0xe0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x113, %esi            # imm = 0x113
callq 0x5c08
movl %eax, %ebp
testb %al, %al
je 0xa0f5
leaq 0x60(%rsp), %rcx
movq %rcx, -0x10(%rcx)
xorl %eax, %eax
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x40(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
leaq 0x20(%rsp), %rcx
movq %rcx, -0x10(%rcx)
movq %rax, -0x8(%rcx)
movb %al, (%rcx)
movq 0x98(%r14), %rbx
leaq 0x268(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x105f6(%rip), %rsi     # 0x19fb5
leaq 0x105f9(%rip), %rdx     # 0x19fbf
leaq 0x258(%rsp), %rdi
callq 0x3c42
leaq 0x90(%rsp), %rdi
leaq 0x258(%rsp), %rdx
movq %rbx, %rsi
callq 0x15d26
leaq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
leaq 0xa0(%rsp), %r15
cmpq %r15, %rdi
je 0x9a20
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0x9a3d
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %rbx
leaq 0x248(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x10568(%rip), %rsi     # 0x19fc0
leaq 0x1056a(%rip), %rdx     # 0x19fc9
leaq 0x238(%rsp), %rdi
callq 0x3c42
leaq 0x90(%rsp), %rdi
leaq 0x238(%rsp), %rdx
movq %rbx, %rsi
callq 0x15d26
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x9ab1
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0x9ace
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %rbx
leaq 0x228(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x104e1(%rip), %rsi     # 0x19fca
leaq 0x104e2(%rip), %rdx     # 0x19fd2
leaq 0x218(%rsp), %rdi
callq 0x3c42
leaq 0x90(%rsp), %rdi
leaq 0x218(%rsp), %rdx
movq %rbx, %rsi
callq 0x15d26
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %rbx
movq %rbx, %rsi
callq 0x2270
movq (%rbx), %rdi
cmpq %r15, %rdi
je 0x9b42
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0x9b5f
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %rbx
leaq 0x208(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1f8(%rsp), %rdi
callq 0x3bac
leaq 0x1f8(%rsp), %rsi
movq %rbx, %rdi
callq 0x15fc6
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
je 0x9bb9
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x5c08
testb %al, %al
je 0xa165
leaq 0xd0(%rsp), %rsi
movq %r14, %rdi
callq 0xa4dc
testb %al, %al
jne 0x9c36
leaq 0x1e8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x10422(%rip), %rsi     # 0x1a017
leaq 0x10450(%rip), %rdx     # 0x1a04c
leaq 0x1d8(%rsp), %rdi
callq 0x3c42
leaq 0x1d8(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0x1d8(%rsp), %rdi
cmpq %r15, %rdi
je 0x9c36
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c08
testb %al, %al
jne 0x9c9b
leaq 0x1c8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x103f3(%rip), %rsi     # 0x1a04d
leaq 0x1043d(%rip), %rdx     # 0x1a09e
leaq 0x1b8(%rsp), %rdi
callq 0x3c42
leaq 0x1b8(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0x9c9b
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xf4(%rsp), %rsi
leaq 0xf0(%rsp), %rdx
movq %r14, %rdi
callq 0x858a
testb %al, %al
je 0x9d4e
movq 0x98(%r14), %rbx
leaq 0x288(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x278(%rsp), %rdi
callq 0x3bac
leaq 0x1a8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x3bac
leaq 0x278(%rsp), %rsi
leaq 0x198(%rsp), %rdx
movq %rbx, %rdi
callq 0x165f8
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0x9d44
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x278(%rsp), %rdi
jmp 0x9d8d
leaq 0x2a8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x1033e(%rip), %rsi     # 0x1a09f
leaq 0x1037d(%rip), %rdx     # 0x1a0e5
leaq 0x298(%rsp), %rdi
callq 0x3c42
leaq 0x298(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0x298(%rsp), %rdi
cmpq %r15, %rdi
je 0x9d9d
movq (%r15), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x5c08
testb %al, %al
jne 0x9e02
leaq 0x188(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x10325(%rip), %rsi     # 0x1a0e6
leaq 0x10360(%rip), %rdx     # 0x1a128
leaq 0x178(%rsp), %rdi
callq 0x3c42
leaq 0x178(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0x9e02
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%r14), %rbx
leaq 0x168(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x158(%rsp), %rdi
callq 0x3bac
leaq 0x158(%rsp), %rsi
movq %rbx, %rdi
callq 0x15fc6
movb %bpl, 0xb(%rsp)
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x9e61
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x148(%rsp), %rbp
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0x102b3(%rip), %r15     # 0x1a129
leaq 0x102d4(%rip), %r12     # 0x1a151
leaq 0x138(%rsp), %r13
movq %r14, %rdi
callq 0x6efe
testb %al, %al
je 0x9ee7
movq %r14, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c08
testb %al, %al
jne 0x9e85
movq %rbp, 0x138(%rsp)
movq %r13, %rdi
movq %r15, %rsi
movq %r12, %rdx
callq 0x3c42
movq %r14, %rdi
movq %r13, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0x9e85
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x9e85
movq 0x98(%r14), %rbx
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3bac
movq %rbx, %rdi
leaq 0x70(%rsp), %rsi
callq 0x16718
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x9f41
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x5c08
testb %al, %al
jne 0x9fdd
testb $0x1, 0xc(%rsp)
je 0xa12e
leaq 0xc0(%rsp), %rax
movq %rax, 0xb0(%rsp)
leaq 0xb0(%rsp), %rbx
movq %rbx, %rdi
leaq 0x10210(%rip), %rsi     # 0x1a193
leaq 0x10260(%rip), %rdx     # 0x1a1ea
callq 0x3c42
movq %r14, %rdi
movq %rbx, %rsi
movl $0x1, %edx
callq 0x4e96
movq 0xb0(%rsp), %rdi
movl $0x0, 0xc(%rsp)
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0x9e85
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
movl $0x0, 0xc(%rsp)
jmp 0x9e85
movq 0x98(%r14), %rbx
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x118(%rsp), %rdi
callq 0x3bac
movb 0xb(%rsp), %bpl
leaq 0x118(%rsp), %rsi
movq %rbx, %rdi
callq 0x15fc6
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0xa03c
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2200
movq %r14, %rdi
movl $0x113, %esi            # imm = 0x113
callq 0x5c08
testb %al, %al
jne 0xa0a1
leaq 0x108(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x100f2(%rip), %rsi     # 0x1a152
leaq 0x1012b(%rip), %rdx     # 0x1a192
leaq 0xf8(%rsp), %rdi
callq 0x3c42
leaq 0xf8(%rsp), %rsi
movq %r14, %rdi
callq 0x5694
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa0a1
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa0bd
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa0d9
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa0f5
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0xa11a
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2200
movl %ebp, %eax
addq $0x2f8, %rsp            # imm = 0x2F8
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
leaq 0x2c8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x100aa(%rip), %rsi     # 0x1a1eb
leaq 0x100d2(%rip), %rdx     # 0x1a21a
leaq 0x2b8(%rsp), %rdi
callq 0x3c42
leaq 0x2b8(%rsp), %rsi
movq %r14, %rdi
callq 0x4a02
leaq 0x2e8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0xfe5b(%rip), %rsi      # 0x19fd3
leaq 0xfe97(%rip), %rdx      # 0x1a016
leaq 0x2d8(%rsp), %rdi
callq 0x3c42
leaq 0x2d8(%rsp), %rsi
movq %r14, %rdi
callq 0x4a02
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x108(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x188(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0xa22e
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa22e
movq %rax, %rbx
movq 0x298(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x2a8(%rsp), %rsi
jmp 0xa41e
movq %rax, %rbx
movq 0x278(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x288(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x1c8(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x1e8(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x2d8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x2e8(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x128(%rsp), %rsi
jmp 0xa41e
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x168(%rsp), %rsi
jmp 0xa41e
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x208(%rsp), %rsi
jmp 0xa41e
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xa42d
movq 0x228(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0xa42d
movq 0x248(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0xa42d
movq 0x268(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
jmp 0xa481
jmp 0xa42a
movq %rax, %rbx
movq 0x2b8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa42d
movq 0x2c8(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
jmp 0xa42a
movq %rax, %rbx
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xa42d
movq 0xc0(%rsp), %rsi
jmp 0xa41e
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xa42d
movq 0x80(%rsp), %rsi
jmp 0xa41e
jmp 0xa42a
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa42d
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa42d
jmp 0xa42a
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa449
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa465
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa481
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xd0(%rsp), %rdi
leaq 0xe0(%rsp), %rax
cmpq %rax, %rdi
je 0xa4a6
movq 0xe0(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330