// File: SeanLee97[P]LL1-Parser/grammar.cpp
// Function: Grammar::get_first(std::vector<bool, std::allocator<bool>>)
vector<vector<int> > Grammar::get_first(vector<bool> local_is_epsilon) {
	// array
	vector<vector<int> > temp_first(num_nonterminals + 1, vector<int>(0));
	bool complete = false;

	while(!complete) {
		complete = true;
		for(int i = 0; i < full_rules.size(); i++) {   // line
			for(int j = 1; j < full_rules[i].size(); j++) {  // symbol of line
				if(full_rules[i][j] == 0) {
					//  0 为结束标记 end
					break;

				// full_rules[i][j] - terminal
				} else if(full_rules[i][j] < 0) {

					// full_rules[i][j] 是否在 temp_first[full_rules[i][0]] 中
					if(!_in_array(temp_first[full_rules[i][0]], full_rules[i][j])) {
						temp_first[full_rules[i][0]].push_back(abs(full_rules[i][j]));
						complete = false; 
						// 找到first terminal退出
						break;
					} else break;

				// full_rules[i][j] - nonterminal
				// temp_first[full_rules[i][j]] 的first集不为空
				// temp_first[full_rules[i][j]] 的first集也为当前nonterminal的first集,故追加上
				} else if(full_rules[i][j] > 0 && temp_first[full_rules[i][j]].size() > 0) {

					vector<int> cur_elements_first = temp_first[full_rules[i][j]];

					for(int k = 0; k < cur_elements_first.size(); k++) {
						if(!_in_array(temp_first[full_rules[i][0]], cur_elements_first[k])) {
							temp_first[full_rules[i][0]].push_back(cur_elements_first[k]);
							complete = false;
						}
					}
				}
				
				// 当前nonterminal !-> epsilon，则退出
				if(! local_is_epsilon[abs(full_rules[i][j]) - 1]) {
					break;
				}
			}
		}
	}

	return temp_first;			
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x150, %rsp            # imm = 0x150
movq %rdx, -0xf0(%rbp)
movq %rdi, -0xe8(%rbp)
movq %rdi, %rax
movq %rax, -0xe0(%rbp)
movq %rdi, -0x8(%rbp)
movq %rsi, -0x10(%rbp)
movq %rdx, -0x18(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0xd8(%rbp)
movb $0x0, -0x19(%rbp)
movl 0x4(%rax), %eax
incl %eax
cltq
movq %rax, -0xd0(%rbp)
leaq -0x39(%rbp), %rdi
movq %rdi, -0xc8(%rbp)
callq 0x8550
movq -0xc8(%rbp), %rdx
xorl %eax, %eax
movl %eax, %esi
leaq -0x38(%rbp), %rdi
callq 0x8570
jmp 0x4f82
leaq -0x4d(%rbp), %rdi
movq %rdi, -0xf8(%rbp)
callq 0x85e0
movq -0xe8(%rbp), %rdi
movq -0xd0(%rbp), %rsi
movq -0xf8(%rbp), %rcx
leaq -0x38(%rbp), %rdx
callq 0x8600
jmp 0x4fb2
leaq -0x4d(%rbp), %rdi
callq 0x3bd0
leaq -0x38(%rbp), %rdi
callq 0x3900
leaq -0x39(%rbp), %rdi
callq 0x3ae0
movb $0x0, -0x4e(%rbp)
movb -0x4e(%rbp), %al
xorb $-0x1, %al
testb $0x1, %al
jne 0x4fdf
jmp 0x5536
movb $0x1, -0x4e(%rbp)
movl $0x0, -0x54(%rbp)
movq -0xd8(%rbp), %rdi
movslq -0x54(%rbp), %rax
movq %rax, -0x100(%rbp)
addq $0x2c8, %rdi            # imm = 0x2C8
callq 0x8790
movq %rax, %rcx
movq -0x100(%rbp), %rax
cmpq %rcx, %rax
jae 0x5531
movl $0x1, -0x58(%rbp)
movq -0xd8(%rbp), %rdi
movslq -0x58(%rbp), %rax
movq %rax, -0x108(%rbp)
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
movq %rax, %rcx
movq -0x108(%rbp), %rax
cmpq %rcx, %rax
jae 0x5521
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jne 0x50c6
jmp 0x5521
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x50b8
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x4d(%rbp), %rdi
callq 0x3bd0
leaq -0x38(%rbp), %rdi
callq 0x3900
leaq -0x39(%rbp), %rdi
callq 0x3ae0
jmp 0x5568
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jge 0x5248
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x70(%rbp), %rdi
callq 0x87e0
jmp 0x5132
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
movq -0xd8(%rbp), %rdi
movl (%rax), %edx
leaq -0x70(%rbp), %rsi
callq 0x5580
movb %al, -0x109(%rbp)
jmp 0x516f
movb -0x109(%rbp), %al
xorb $-0x1, %al
movb %al, -0x10a(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3900
movb -0x10a(%rbp), %al
testb $0x1, %al
jne 0x5195
jmp 0x5243
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movq %rdi, -0x120(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq -0x120(%rbp), %rdi
movq %rax, -0x118(%rbp)
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
movq -0x118(%rbp), %rdi
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
movl %eax, -0x74(%rbp)
leaq -0x74(%rbp), %rsi
callq 0x88d0
jmp 0x520f
movb $0x0, -0x4e(%rbp)
jmp 0x5521
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x555c
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0x70(%rbp), %rdi
callq 0x3900
jmp 0x555c
jmp 0x5521
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
cmpl $0x0, (%rax)
jle 0x548e
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rdi
callq 0x87c0
cmpq $0x0, %rax
jbe 0x548e
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0x90(%rbp), %rdi
callq 0x87e0
jmp 0x52fb
movl $0x0, -0x94(%rbp)
movslq -0x94(%rbp), %rax
movq %rax, -0x128(%rbp)
leaq -0x90(%rbp), %rdi
callq 0x87c0
movq %rax, %rcx
movq -0x128(%rbp), %rax
cmpq %rcx, %rax
jae 0x546f
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, %rsi
leaq -0xb0(%rbp), %rdi
callq 0x87e0
jmp 0x5375
movslq -0x94(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x86c0
movq -0xd8(%rbp), %rdi
movl (%rax), %edx
leaq -0xb0(%rbp), %rsi
callq 0x5580
movb %al, -0x129(%rbp)
jmp 0x53a5
movb -0x129(%rbp), %al
xorb $-0x1, %al
movb %al, -0x12a(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3900
movb -0x12a(%rbp), %al
testb $0x1, %al
jne 0x53ce
jmp 0x5459
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
xorl %eax, %eax
movl %eax, %esi
callq 0x86c0
movq -0xe8(%rbp), %rdi
movslq (%rax), %rsi
callq 0x86a0
movq %rax, -0x138(%rbp)
movslq -0x94(%rbp), %rsi
leaq -0x90(%rbp), %rdi
callq 0x86c0
movq -0x138(%rbp), %rdi
movq %rax, %rsi
callq 0x8900
jmp 0x542b
movb $0x0, -0x4e(%rbp)
jmp 0x5459
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
jmp 0x547d
movq %rax, %rcx
movl %edx, %eax
movq %rcx, -0x48(%rbp)
movl %eax, -0x4c(%rbp)
leaq -0xb0(%rbp), %rdi
callq 0x3900
jmp 0x547d
jmp 0x545b
movl -0x94(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x94(%rbp)
jmp 0x5305
leaq -0x90(%rbp), %rdi
callq 0x3900
jmp 0x548e
leaq -0x90(%rbp), %rdi
callq 0x3900
jmp 0x555c
jmp 0x5490
jmp 0x5492
movq -0xd8(%rbp), %rdi
addq $0x2c8, %rdi            # imm = 0x2C8
movslq -0x54(%rbp), %rsi
callq 0x86a0
movq %rax, %rdi
movslq -0x58(%rbp), %rsi
callq 0x86c0
movq -0xf0(%rbp), %rdi
movl (%rax), %eax
movl %eax, %ecx
negl %ecx
cmovnsl %ecx, %eax
decl %eax
movslq %eax, %rsi
callq 0x86e0
movq %rdx, -0x148(%rbp)
movq %rax, -0x140(%rbp)
jmp 0x54df
movq -0x148(%rbp), %rax
movq -0x140(%rbp), %rcx
movq %rcx, -0xc0(%rbp)
movq %rax, -0xb8(%rbp)
leaq -0xc0(%rbp), %rdi
callq 0x8970
xorb $-0x1, %al
testb $0x1, %al
jne 0x550f
jmp 0x5511
jmp 0x5521
jmp 0x5513
movl -0x58(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x58(%rbp)
jmp 0x5022
jmp 0x5523
movl -0x54(%rbp), %eax
addl $0x1, %eax
movl %eax, -0x54(%rbp)
jmp 0x4fea
jmp 0x4fd1
movb $0x1, -0x19(%rbp)
testb $0x1, -0x19(%rbp)
jne 0x554c
movq -0xe8(%rbp), %rdi
callq 0x3710
movq -0xe0(%rbp), %rax
addq $0x150, %rsp            # imm = 0x150
popq %rbp
retq
movq -0xe8(%rbp), %rdi
callq 0x3710
movq -0x48(%rbp), %rdi
callq 0x3390
nopw %cs:(%rax,%rax)