// File: /workspace/github_cpp_makefile_star2_O1/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, %rbx
leaq 0xc0(%rsp), %rax
movq %rax, -0x10(%rax)
movq $0x0, -0x8(%rax)
movb $0x0, (%rax)
movl $0x113, %esi            # imm = 0x113
callq 0x5c0a
testb %al, %al
je 0x9dfe
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(%rbx), %r14
leaq 0x268(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x10546(%rip), %rsi     # 0x19fb5
leaq 0x10549(%rip), %rdx     # 0x19fbf
leaq 0x258(%rsp), %rdi
callq 0x3c34
leaq 0x90(%rsp), %rdi
leaq 0x258(%rsp), %rdx
movq %r14, %rsi
callq 0x15e04
leaq 0x50(%rsp), %rdi
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x2270
movq (%r14), %rdi
leaq 0xa0(%rsp), %r15
cmpq %r15, %rdi
je 0x9ad0
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0x9aed
movq 0x268(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %r14
leaq 0x248(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x104b8(%rip), %rsi     # 0x19fc0
leaq 0x104ba(%rip), %rdx     # 0x19fc9
leaq 0x238(%rsp), %rdi
callq 0x3c34
leaq 0x90(%rsp), %rdi
leaq 0x238(%rsp), %rdx
movq %r14, %rsi
callq 0x15e04
leaq 0x30(%rsp), %rdi
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x2270
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x9b61
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0x9b7e
movq 0x248(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %r14
leaq 0x228(%rsp), %r12
movq %r12, -0x10(%r12)
leaq 0x10431(%rip), %rsi     # 0x19fca
leaq 0x10432(%rip), %rdx     # 0x19fd2
leaq 0x218(%rsp), %rdi
callq 0x3c34
leaq 0x90(%rsp), %rdi
leaq 0x218(%rsp), %rdx
movq %r14, %rsi
callq 0x15e04
leaq 0x10(%rsp), %rdi
leaq 0x90(%rsp), %r14
movq %r14, %rsi
callq 0x2270
movq (%r14), %rdi
cmpq %r15, %rdi
je 0x9bf2
movq 0xa0(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0x9c0f
movq 0x228(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %r14
leaq 0x208(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x1f8(%rsp), %rdi
callq 0x3ba4
leaq 0x1f8(%rsp), %rsi
movq %r14, %rdi
callq 0x160a4
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
je 0x9c69
movq 0x208(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
movl $0x12d, %esi            # imm = 0x12D
callq 0x5c0a
testb %al, %al
je 0xa219
leaq 0xb0(%rsp), %rsi
movq %rbx, %rdi
callq 0xa586
testb %al, %al
jne 0x9ce6
leaq 0x1e8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10372(%rip), %rsi     # 0x1a017
leaq 0x103a0(%rip), %rdx     # 0x1a04c
leaq 0x1d8(%rsp), %rdi
callq 0x3c34
leaq 0x1d8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5696
movq 0x1d8(%rsp), %rdi
cmpq %r14, %rdi
je 0x9ce6
movq 0x1e8(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x9d4b
leaq 0x1c8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x10343(%rip), %rsi     # 0x1a04d
leaq 0x1038d(%rip), %rdx     # 0x1a09e
leaq 0x1b8(%rsp), %rdi
callq 0x3c34
leaq 0x1b8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5696
movq 0x1b8(%rsp), %rdi
cmpq %r14, %rdi
je 0x9d4b
movq 0x1c8(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0xd4(%rsp), %rsi
leaq 0xd0(%rsp), %rdx
movq %rbx, %rdi
callq 0x8632
testb %al, %al
je 0x9e05
movq 0x98(%rbx), %r14
leaq 0x288(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x278(%rsp), %rdi
callq 0x3ba4
leaq 0x1a8(%rsp), %r12
movq %r12, -0x10(%r12)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x198(%rsp), %rdi
callq 0x3ba4
leaq 0x278(%rsp), %rsi
leaq 0x198(%rsp), %rdx
movq %r14, %rdi
callq 0x166d6
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0x9df4
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x278(%rsp), %rdi
jmp 0x9e44
xorl %ebp, %ebp
jmp 0xa1a9
leaq 0x2a8(%rsp), %r15
movq %r15, -0x10(%r15)
leaq 0x10287(%rip), %rsi     # 0x1a09f
leaq 0x102c6(%rip), %rdx     # 0x1a0e5
leaq 0x298(%rsp), %rdi
callq 0x3c34
leaq 0x298(%rsp), %rsi
movq %rbx, %rdi
callq 0x5696
movq 0x298(%rsp), %rdi
cmpq %r15, %rdi
je 0x9e54
movq (%r15), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
movl $0x12e, %esi            # imm = 0x12E
callq 0x5c0a
testb %al, %al
jne 0x9eb9
leaq 0x188(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1026e(%rip), %rsi     # 0x1a0e6
leaq 0x102a9(%rip), %rdx     # 0x1a128
leaq 0x178(%rsp), %rdi
callq 0x3c34
leaq 0x178(%rsp), %rsi
movq %rbx, %rdi
callq 0x5696
movq 0x178(%rsp), %rdi
cmpq %r14, %rdi
je 0x9eb9
movq 0x188(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x98(%rbx), %r14
leaq 0x168(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x30(%rsp), %rsi
movq 0x38(%rsp), %rdx
addq %rsi, %rdx
leaq 0x158(%rsp), %rdi
callq 0x3ba4
leaq 0x158(%rsp), %rsi
movq %r14, %rdi
callq 0x160a4
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0x9f13
movq 0x168(%rsp), %rsi
incq %rsi
callq 0x2200
leaq 0x148(%rsp), %r13
movb $0x1, %al
movl %eax, 0xc(%rsp)
leaq 0xe8(%rsp), %rbp
leaq 0x101f9(%rip), %r14     # 0x1a129
leaq 0x1021a(%rip), %r15     # 0x1a151
leaq 0x138(%rsp), %r12
movq %rbx, %rdi
callq 0x6efc
testb %al, %al
je 0x9fa1
movq %rbx, %rdi
movl $0x12c, %esi            # imm = 0x12C
callq 0x5c0a
testb %al, %al
jne 0x9f3f
movq %r13, 0x138(%rsp)
movq %r12, %rdi
movq %r14, %rsi
movq %r15, %rdx
callq 0x3c34
movq %rbx, %rdi
movq %r12, %rsi
movl $0x1, %edx
callq 0x4e82
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0x9f3f
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0x9f3f
movq %rbp, %r14
movq 0x98(%rbx), %rbp
leaq 0x80(%rsp), %rax
movq %rax, 0x70(%rsp)
movq 0x50(%rsp), %rsi
movq 0x58(%rsp), %rdx
addq %rsi, %rdx
leaq 0x70(%rsp), %rdi
callq 0x3ba4
movq %rbp, %rdi
leaq 0x70(%rsp), %rsi
callq 0x167f6
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0x9ffe
movq 0x80(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
movl $0x104, %esi            # imm = 0x104
callq 0x5c0a
movl %eax, %ebp
testb %al, %al
jne 0xa096
testb $0x1, 0xc(%rsp)
je 0xa1e2
movq %r14, %rbp
movq %r14, 0xd8(%rsp)
leaq 0xd8(%rsp), %r14
movq %r14, %rdi
leaq 0x10156(%rip), %rsi     # 0x1a193
leaq 0x101a6(%rip), %rdx     # 0x1a1ea
callq 0x3c34
movq %rbx, %rdi
movq %r14, %rsi
movl $0x1, %edx
callq 0x4e82
leaq 0x100c9(%rip), %r14     # 0x1a129
movq 0xd8(%rsp), %rdi
movl $0x0, 0xc(%rsp)
cmpq %rbp, %rdi
je 0x9f3f
movq 0xe8(%rsp), %rsi
incq %rsi
callq 0x2200
movl $0x0, 0xc(%rsp)
jmp 0x9f3f
movq 0x98(%rbx), %r14
leaq 0x128(%rsp), %r15
movq %r15, -0x10(%r15)
movq 0x10(%rsp), %rsi
movq 0x18(%rsp), %rdx
addq %rsi, %rdx
leaq 0x118(%rsp), %rdi
callq 0x3ba4
leaq 0x118(%rsp), %rsi
movq %r14, %rdi
callq 0x160a4
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0xa0f0
movq 0x128(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
movl $0x113, %esi            # imm = 0x113
callq 0x5c0a
testb %al, %al
jne 0xa155
leaq 0x108(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0x1003e(%rip), %rsi     # 0x1a152
leaq 0x10077(%rip), %rdx     # 0x1a192
leaq 0xf8(%rsp), %rdi
callq 0x3c34
leaq 0xf8(%rsp), %rsi
movq %rbx, %rdi
callq 0x5696
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa155
movq 0x108(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa171
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa18d
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa1a9
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xa1ce
movq 0xc0(%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), %r14
movq %r14, -0x10(%r14)
leaq 0xfff6(%rip), %rsi      # 0x1a1eb
leaq 0x1001e(%rip), %rdx     # 0x1a21a
leaq 0x2b8(%rsp), %rdi
callq 0x3c34
leaq 0x2b8(%rsp), %rsi
movq %rbx, %rdi
callq 0x49ee
leaq 0x2e8(%rsp), %r14
movq %r14, -0x10(%r14)
leaq 0xfda7(%rip), %rsi      # 0x19fd3
leaq 0xfde3(%rip), %rdx      # 0x1a016
leaq 0x2d8(%rsp), %rdi
callq 0x3c34
leaq 0x2d8(%rsp), %rsi
movq %rbx, %rdi
callq 0x49ee
movq %rax, %rbx
movq 0xf8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x108(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x178(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x188(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x198(%rsp), %rdi
cmpq %r12, %rdi
je 0xa2e2
movq 0x1a8(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa2e2
movq %rax, %rbx
movq 0x298(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4d6
movq 0x2a8(%rsp), %rsi
jmp 0xa4c7
movq %rax, %rbx
movq 0x278(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4d6
movq 0x288(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x1b8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x1c8(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x1d8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x1e8(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x2d8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x2e8(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x118(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4d6
movq 0x128(%rsp), %rsi
jmp 0xa4c7
movq %rax, %rbx
movq 0x158(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4d6
movq 0x168(%rsp), %rsi
jmp 0xa4c7
movq %rax, %rbx
movq 0x1f8(%rsp), %rdi
cmpq %r15, %rdi
je 0xa4d6
movq 0x208(%rsp), %rsi
jmp 0xa4c7
movq %rax, %rbx
movq 0x218(%rsp), %rdi
cmpq %r12, %rdi
je 0xa4d6
movq 0x228(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x238(%rsp), %rdi
cmpq %r12, %rdi
je 0xa4d6
movq 0x248(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x258(%rsp), %rdi
cmpq %r12, %rdi
je 0xa4d6
movq 0x268(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
jmp 0xa52a
jmp 0xa4d3
movq %rax, %rbx
movq 0x2b8(%rsp), %rdi
cmpq %r14, %rdi
je 0xa4d6
movq 0x2c8(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
jmp 0xa4d3
movq %rax, %rbx
movq 0xd8(%rsp), %rdi
cmpq %rbp, %rdi
je 0xa4d6
movq 0xe8(%rsp), %rsi
jmp 0xa4c7
movq %rax, %rbx
movq 0x70(%rsp), %rdi
leaq 0x80(%rsp), %rax
cmpq %rax, %rdi
je 0xa4d6
movq 0x80(%rsp), %rsi
jmp 0xa4c7
jmp 0xa4d3
movq %rax, %rbx
movq 0x138(%rsp), %rdi
cmpq %r13, %rdi
je 0xa4d6
movq 0x148(%rsp), %rsi
incq %rsi
callq 0x2200
jmp 0xa4d6
jmp 0xa4d3
movq %rax, %rbx
movq 0x10(%rsp), %rdi
leaq 0x20(%rsp), %rax
cmpq %rax, %rdi
je 0xa4f2
movq 0x20(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x30(%rsp), %rdi
leaq 0x40(%rsp), %rax
cmpq %rax, %rdi
je 0xa50e
movq 0x40(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0x50(%rsp), %rdi
leaq 0x60(%rsp), %rax
cmpq %rax, %rdi
je 0xa52a
movq 0x60(%rsp), %rsi
incq %rsi
callq 0x2200
movq 0xb0(%rsp), %rdi
leaq 0xc0(%rsp), %rax
cmpq %rax, %rdi
je 0xa54f
movq 0xc0(%rsp), %rsi
incq %rsi
callq 0x2200
movq %rbx, %rdi
callq 0x2330
nop