// File: SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::get_follow(std::vector<bool, std::allocator<bool>>, std::vector<std::vector<int, std::allocator<int>>, std::allocator<std::vector<int, std::allocator<int>>>>)
vector<vector<int> > Grammar::get_follow(vector<bool> local_is_epsilon, vector<vector<int> > local_first_sets ) {
	vector<vector<int> > temp_follow(num_nonterminals + 1, vector<int>(0));
	int count = 0;

	while(count < 20) {

		for(int i = 0; i < full_rules.size(); i++) {
			for(int j = 1; j < full_rules[i].size(); j++) {
				// terminal 不存在follow集，退出
				if(full_rules[i][j] < 0) 
					continue;
				// nonterminal
				else if(full_rules[i][j] > 0) {

					for(int k = j + 1; k < full_rules[i].size(); k++) {
						// 
						if(full_rules[i][k] == 0 && temp_follow[full_rules[i][0]].size() != 0) {
							// 
							temp_follow[full_rules[i][j]] = _push_unique_elements(temp_follow[full_rules[i][j]], temp_follow[full_rules[i][0]]);

						} else if(temp_follow[full_rules[i][k]].size() == 0) break;

						// terminal
						else if(full_rules[i][k] < 0) {
							// push
							if(!_in_array(temp_follow[full_rules[i][j]], abs(full_rules[i][k]))) {
								temp_follow[full_rules[i][j]].push_back(abs(full_rules[i][k]));
							}
							break;
						}
						//  full_rules[i][k] - nontermail
						else if(full_rules[i][k] > 0) {
							// 
							temp_follow[full_rules[i][j]] = _push_unique_elements(temp_follow[full_rules[i][j]], local_first_sets[full_rules[i][k]]);

							if(local_is_epsilon[full_rules[i][k] - 1]) continue;
							else break;
						}
					}
				} else break;

			}
		}
		++count;
	}

	return temp_follow;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x1c0, %rsp            # imm = 0x1C0
movq %rcx, -0x160(%rbp)
movq %rdx, -0x158(%rbp)
movq %rdi, -0x150(%rbp)
movq %rdi, %rax
movq %rax, -0x148(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq %rcx, -0x20(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x140(%rbp)
movb $0x0, -0x21(%rbp)
movl 0x4(%rax), %eax
incl %eax
cltq
movq %rax, -0x138(%rbp)
leaq -0x41(%rbp), %rdi
movq %rdi, -0x130(%rbp)
callq 0x8550
movq -0x130(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x40(%rbp), %rdi
callq 0x8570
jmp 0x569d
leaq -0x55(%rbp), %rdi
movq %rdi, -0x168(%rbp)
callq 0x85e0
movq -0x150(%rbp), %rdi
movq -0x138(%rbp), %rsi
movq -0x168(%rbp), %rcx
leaq -0x40(%rbp), %rdx
callq 0x8600
jmp 0x56cd
leaq -0x55(%rbp), %rdi
callq 0x3bd0
leaq -0x40(%rbp), %rdi
callq 0x3900
leaq -0x41(%rbp), %rdi
callq 0x3ae0
movl $0x0, -0x5c(%rbp)
cmpl $0x14, -0x5c(%rbp)
jge 0x5e0f
movl $0x0, -0x60(%rbp)
movq -0x140(%rbp), %rdi
movslq -0x60(%rbp), %rax
movq %rax, -0x170(%rbp)
addq $0x2c8, %rdi            # imm = 0x2C8
callq 0x8790
movq %rax, %rcx
movq -0x170(%rbp), %rax
cmpq %rcx, %rax
jae 0x5e01
movl $0x1, -0x64(%rbp)
movq -0x140(%rbp), %rdi
movslq -0x64(%rbp), %rax
movq %rax, -0x178(%rbp)
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
movq %rax, %rcx
movq -0x178(%rbp), %rax
cmpq %rcx, %rax
jae 0x5df1
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jge 0x57dc
jmp 0x5de3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x57ce
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x55(%rbp), %rdi
callq 0x3bd0
leaq -0x40(%rbp), %rdi
callq 0x3900
leaq -0x41(%rbp), %rdi
callq 0x3ae0
jmp 0x5e41
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jle 0x5ddd
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
movq -0x140(%rbp), %rdi
movslq -0x68(%rbp), %rax
movq %rax, -0x180(%rbp)
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
movq %rax, %rcx
movq -0x180(%rbp), %rax
cmpq %rcx, %rax
jae 0x5ddb
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jne 0x5a10
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
cmpq $0x0, %rax
je 0x5a10
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x98(%rbp), %rdi
callq 0x87e0
jmp 0x5901
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x87e0
jmp 0x5944
movq -0x140(%rbp), %rsi
leaq -0x80(%rbp), %rdi
leaq -0x98(%rbp), %rdx
leaq -0xb0(%rbp), %rcx
callq 0x5e50
jmp 0x5964
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rdi
leaq -0x80(%rbp), %rsi
callq 0x89a0
leaq -0x80(%rbp), %rdi
callq 0x3900
leaq -0xb0(%rbp), %rdi
callq 0x3900
leaq -0x98(%rbp), %rdi
callq 0x3900
jmp 0x5dcb
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5e35
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x59ff
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3900
leaq -0x98(%rbp), %rdi
callq 0x3900
jmp 0x5e35
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
cmpq $0x0, %rax
jne 0x5a55
jmp 0x5ddb
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jge 0x5bd8
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0xc8(%rbp), %rdi
callq 0x87e0
jmp 0x5ac4
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
movq -0x140(%rbp), %rdi
movl (%rax), %edx
movl %edx, %eax
negl %eax
cmovnsl %eax, %edx
leaq -0xc8(%rbp), %rsi
callq 0x5580
movb %al, -0x181(%rbp)
jmp 0x5b0b
movb -0x181(%rbp), %al
xorb $-0x1, %al
movb %al, -0x182(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3900
movb -0x182(%rbp), %al
testb $0x1, %al
jne 0x5b34
jmp 0x5bd3
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movq %rdi, -0x198(%rbp)
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq -0x198(%rbp), %rdi
movq %rax, -0x190(%rbp)
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
movq -0x190(%rbp), %rdi
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0xcc(%rbp)
leaq -0xcc(%rbp), %rsi
callq 0x88d0
jmp 0x5bb4
jmp 0x5bd3
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0xc8(%rbp), %rdi
callq 0x3900
jmp 0x5e35
jmp 0x5ddb
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jle 0x5dc5
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x100(%rbp), %rdi
callq 0x87e0
jmp 0x5c47
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
movq -0x160(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x118(%rbp), %rdi
callq 0x87e0
jmp 0x5c8a
movq -0x140(%rbp), %rsi
leaq -0xe8(%rbp), %rdi
leaq -0x100(%rbp), %rdx
leaq -0x118(%rbp), %rcx
callq 0x5e50
jmp 0x5cad
movq -0x140(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movq %rdi, -0x1b0(%rbp)
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x64(%rbp), %rsi
callq 0x86c0
movq -0x150(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rdi
leaq -0xe8(%rbp), %rsi
movq %rsi, -0x1b8(%rbp)
callq 0x89a0
movq -0x1b8(%rbp), %rdi
callq 0x3900
leaq -0x118(%rbp), %rdi
callq 0x3900
leaq -0x100(%rbp), %rdi
callq 0x3900
movq -0x1b0(%rbp), %rdi
movslq -0x60(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x68(%rbp), %rsi
callq 0x86c0
movq -0x158(%rbp), %rdi
movl (%rax), %eax
decl %eax
movslq %eax, %rsi
callq 0x86e0
movq %rdx, -0x1a8(%rbp)
movq %rax, -0x1a0(%rbp)
jmp 0x5d5f
movq -0x1a8(%rbp), %rax
movq -0x1a0(%rbp), %rcx
movq %rcx, -0x128(%rbp)
movq %rax, -0x120(%rbp)
leaq -0x128(%rbp), %rdi
callq 0x8970
testb $0x1, %al
jne 0x5d8d
jmp 0x5dc3
jmp 0x5dcd
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
jmp 0x5db5
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x50(%rbp)
movl %eax, -0x54(%rbp)
leaq -0x118(%rbp), %rdi
callq 0x3900
leaq -0x100(%rbp), %rdi
callq 0x3900
jmp 0x5e35
jmp 0x5ddb
jmp 0x5dc7
jmp 0x5dc9
jmp 0x5dcb
jmp 0x5dcd
movl -0x68(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x68(%rbp)
jmp 0x5811
jmp 0x5ddf
jmp 0x5df1
jmp 0x5de1
jmp 0x5de3
movl -0x64(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x64(%rbp)
jmp 0x5738
jmp 0x5df3
movl -0x60(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x60(%rbp)
jmp 0x5700
movl -0x5c(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x5c(%rbp)
jmp 0x56ef
movb $0x1, -0x21(%rbp)
testb $0x1, -0x21(%rbp)
jne 0x5e25
movq -0x150(%rbp), %rdi
callq 0x3710
movq -0x148(%rbp), %rax
addq $0x1c0, %rsp            # imm = 0x1C0
popq %rbp
retq
movq -0x150(%rbp), %rdi
callq 0x3710
movq -0x50(%rbp), %rdi
callq 0x3390
nopw (%rax,%rax)